diff --git a/direct/src/showbase/showBase.cxx b/direct/src/showbase/showBase.cxx index d0674efea8..3de17456f2 100644 --- a/direct/src/showbase/showBase.cxx +++ b/direct/src/showbase/showBase.cxx @@ -19,35 +19,11 @@ #include "showBase.h" #include "throw_event.h" -#include "camera.h" -#include "renderRelation.h" -#include "namedNode.h" -#include "renderModeTransition.h" -#include "textureTransition.h" -#include "textureTransition.h" #include "interactiveGraphicsPipe.h" #include "graphicsWindow.h" #include "chancfg.h" -#include "cullFaceTransition.h" -#include "dftraverser.h" #include "renderBuffer.h" -#include "clockObject.h" -#include "animControl.h" -#include "nodeRelation.h" -#include "dataGraphTraversal.h" -#include "depthTestTransition.h" -#include "depthWriteTransition.h" -#include "materialTransition.h" -#include "camera.h" -#include "orthographicLens.h" -#include "appTraverser.h" #include "get_config_path.h" -#include "allTransitionsWrapper.h" -#include "dataGraphTraversal.h" -#include "depthTestAttrib.h" -#include "depthWriteAttrib.h" -#include "cullFaceAttrib.h" -#include "materialAttrib.h" #include "qpcamera.h" ConfigureDef(config_showbase); @@ -65,7 +41,8 @@ std::string chan_config = "single"; std::string window_title = "Panda3D"; -PT(GraphicsPipe) make_graphics_pipe() { +PT(GraphicsPipe) +make_graphics_pipe() { PT(GraphicsPipe) main_pipe; // load display modules @@ -88,35 +65,6 @@ PT(GraphicsPipe) make_graphics_pipe() { return main_pipe; } -ChanConfig make_graphics_window(GraphicsPipe *pipe, NodeRelation *render_arc) { - PT(GraphicsWindow) main_win; - ChanCfgOverrides override; - - // Turn on backface culling and depth buffer - CullFaceTransition *cfa = new CullFaceTransition(CullFaceProperty::M_cull_clockwise); - render_arc->set_transition(cfa); - DepthTestTransition *dta = new DepthTestTransition; - render_arc->set_transition(dta); - DepthWriteTransition *dwa = new DepthWriteTransition; - render_arc->set_transition(dwa); - - // Now use ChanConfig to create the window. - Node *render_top = render_arc->get_parent(); - - override.setField(ChanCfgOverrides::Mask, - ((unsigned int)(W_DOUBLE|W_DEPTH|W_MULTISAMPLE))); - - std::string title = config_showbase.GetString("window-title", window_title); - override.setField(ChanCfgOverrides::Title, title); - - std::string conf = config_showbase.GetString("chan-config", chan_config); - ChanConfig chan_config(pipe, conf, render_top, override); - main_win = chan_config.get_win(); - assert(main_win != (GraphicsWindow*)0L); - - return chan_config; -} - qpChanConfig qpmake_graphics_window(GraphicsPipe *pipe, const qpNodePath &render) { PT(GraphicsWindow) main_win; @@ -145,122 +93,6 @@ throw_new_frame() { } -// Create a scene graph, associated with the indicated window, that -// can contain 2-d geometry and will be rendered on top of the -// existing 3-d window. Returns the top node of the scene graph. -NodePath -setup_panda_2d(GraphicsWindow *win, const string &graph_name) { - PT(Node) render2d_top; - - render2d_top = new NamedNode(graph_name + "_top"); - Node *render2d = new NamedNode(graph_name); - RenderRelation *render2d_arc = new RenderRelation(render2d_top, render2d); - - // Set up some overrides to turn off certain properties which we - // probably won't need for 2-d objects. - - // It's particularly important to turn off the depth test, since - // we'll be keeping the same depth buffer already filled by the - // previously-drawn 3-d scene--we don't want to pay for a clear - // operation, but we also don't want to collide with that depth - // buffer. - render2d_arc->set_transition(new DepthTestTransition(DepthTestProperty::M_none), 1); - render2d_arc->set_transition(new DepthWriteTransition(DepthWriteTransition::off()), 1); - render2d_arc->set_transition(new MaterialTransition(MaterialTransition::off()), 1); - render2d_arc->set_transition(new CullFaceTransition(CullFaceProperty::M_cull_none), 1); - - // Create a 2-d camera. - Camera *cam2d = new Camera("cam2d"); - new RenderRelation(render2d, cam2d); - - PT(Lens) lens = new OrthographicLens; - lens->set_film_size(2.0); - lens->set_near_far(-1000.0f, 1000.0f); - cam2d->set_lens(lens); - - add_render_layer(win, render2d_top, cam2d); - - NodePath render2d_np = NodePath(); - render2d_np.extend_by(render2d_arc); - return render2d_np; -} - -// Create an auxiliary scene graph starting at the indicated node, -// layered on top of the previously-created layers. -void -add_render_layer(GraphicsWindow *win, Node *render_top, Camera *camera) { - GraphicsChannel *chan = win->get_channel(0); - nassertv(chan != (GraphicsChannel *)NULL); - - GraphicsLayer *layer = chan->make_layer(); - nassertv(layer != (GraphicsLayer *)NULL); - - DisplayRegion *dr = layer->make_display_region(); - nassertv(dr != (DisplayRegion *)NULL); - camera->set_scene(render_top); - dr->set_camera(camera); -} - -bool -toggle_wireframe(NodeRelation *render_arc) { - static bool wireframe_mode = false; - - wireframe_mode = !wireframe_mode; - if (!wireframe_mode) { - // Set the normal, filled mode on the render arc. - RenderModeTransition *rma = new RenderModeTransition(RenderModeProperty::M_filled); - CullFaceTransition *cfa = new CullFaceTransition(CullFaceProperty::M_cull_clockwise); - render_arc->set_transition(rma); - render_arc->set_transition(cfa); - - } else { - // Set the initial state up for wireframe mode. - RenderModeTransition *rma = new RenderModeTransition(RenderModeProperty::M_wireframe); - CullFaceTransition *cfa = new CullFaceTransition(CullFaceProperty::M_cull_none); - render_arc->set_transition(rma); - render_arc->set_transition(cfa); - } - return wireframe_mode; -} - - -bool -toggle_backface(NodeRelation *render_arc) { - static bool backface_mode = false; - - // Toggle the state variable - backface_mode = !backface_mode; - - if (backface_mode) { - // Turn backface culling off - CullFaceTransition *cfa = new CullFaceTransition(CullFaceProperty::M_cull_none); - render_arc->set_transition(cfa); - } else { - // Turn backface culling on - CullFaceTransition *cfa = new CullFaceTransition(CullFaceProperty::M_cull_clockwise); - render_arc->set_transition(cfa); - } - return backface_mode; -} - - -bool -toggle_texture(NodeRelation *render_arc) { - static bool textures_enabled = true; - - textures_enabled = !textures_enabled; - if (textures_enabled) { - // Remove the override from the initial state. - render_arc->clear_transition(TextureTransition::get_class_type()); - } else { - // Set an override on the initial state to disable texturing. - TextureTransition *ta = new TextureTransition; - ta->set_priority(100); - render_arc->set_transition(ta); - } - return textures_enabled; -} - void take_snapshot(GraphicsWindow *win, const string &name) { GraphicsStateGuardian* gsg = win->get_gsg(); diff --git a/direct/src/showbase/showBase.h b/direct/src/showbase/showBase.h index 2eb501243f..2c69e736ec 100644 --- a/direct/src/showbase/showBase.h +++ b/direct/src/showbase/showBase.h @@ -19,18 +19,17 @@ #ifndef SHOWBASE_H #define SHOWBASE_H -#include +#include "directbase.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "eventHandler.h" +#include "graphicsPipe.h" +#include "graphicsWindow.h" +#include "animControl.h" +#include "pointerTo.h" +#include "dconfig.h" +#include "dSearchPath.h" +#include "qpnodePath.h" +#include "chancfg.h" ConfigureDecl(config_showbase, EXPCL_DIRECT, EXPTP_DIRECT); typedef Config::Config ConfigShowbase; @@ -43,30 +42,21 @@ BEGIN_PUBLISH EXPCL_DIRECT DSearchPath &get_particle_path(); EXPCL_DIRECT PT(GraphicsPipe) make_graphics_pipe(); -EXPCL_DIRECT ChanConfig -make_graphics_window(GraphicsPipe *pipe, - NodeRelation *render_arc); EXPCL_DIRECT qpChanConfig qpmake_graphics_window(GraphicsPipe *pipe, const qpNodePath &render); EXPCL_DIRECT void throw_new_frame(); -EXPCL_DIRECT NodePath setup_panda_2d(GraphicsWindow *win, const string &name); -EXPCL_DIRECT void add_render_layer(GraphicsWindow *win, Node *render_top, - Camera *camera); -EXPCL_DIRECT bool toggle_wireframe(NodeRelation *render_arc); -EXPCL_DIRECT bool toggle_texture(NodeRelation *render_arc); -EXPCL_DIRECT bool toggle_backface(NodeRelation *render_arc); +EXPCL_DIRECT void take_snapshot(GraphicsWindow *win, const string &name); + +EXPCL_DIRECT ConfigShowbase &get_config_showbase(); + // klunky interface since we cant pass array from python->C++ EXPCL_DIRECT void add_fullscreen_testsize(unsigned int xsize,unsigned int ysize); EXPCL_DIRECT void runtest_fullscreen_sizes(GraphicsWindow *win); EXPCL_DIRECT bool query_fullscreen_testresult(unsigned int xsize,unsigned int ysize); -EXPCL_DIRECT void take_snapshot(GraphicsWindow *win, const string &name); - -EXPCL_DIRECT ConfigShowbase &get_config_showbase(); - END_PUBLISH #endif diff --git a/panda/metalibs/panda/panda.cxx b/panda/metalibs/panda/panda.cxx index aa08731276..bc9b7cbecd 100644 --- a/panda/metalibs/panda/panda.cxx +++ b/panda/metalibs/panda/panda.cxx @@ -5,25 +5,24 @@ #include "panda.h" -#include -#include -#include -#include +#include "config_device.h" +#include "config_display.h" +#include "config_pnmimagetypes.h" +#include "config_pgraph.h" #ifdef DO_PSTATS -#include +#include "config_pstats.h" #endif -#include #ifdef LINK_IN_GL -#include +#include "config_glgsg.h" #ifdef HAVE_WGL -#include +#include "config_wgldisplay.h" #endif #endif #ifdef LINK_IN_PHYSICS -#include -#include +#include "config_physics.h" +#include "config_particlesystem.h" #endif //////////////////////////////////////////////////////////////////// @@ -38,12 +37,11 @@ void init_libpanda() { init_libdevice(); init_libdisplay(); - init_libgraph(); + init_libpgraph(); init_libpnmimagetypes(); #ifdef DO_PSTATS init_libpstatclient(); #endif - init_libsgraph(); #ifdef LINK_IN_GL init_libglgsg(); diff --git a/panda/metalibs/pandaegg/pandaegg.cxx b/panda/metalibs/pandaegg/pandaegg.cxx index 159e6b655f..7fe397b6ad 100644 --- a/panda/metalibs/pandaegg/pandaegg.cxx +++ b/panda/metalibs/pandaegg/pandaegg.cxx @@ -5,9 +5,9 @@ #include "pandaegg.h" -#include -#include -#include +#include "config_egg.h" +#include "config_builder.h" +#include "config_egg2pg.h" //////////////////////////////////////////////////////////////////// // Function: init_libpandaegg @@ -21,5 +21,5 @@ void init_libpandaegg() { init_libegg(); init_libbuilder(); - init_libegg2sg(); + init_libegg2pg(); } diff --git a/panda/src/builder/Sources.pp b/panda/src/builder/Sources.pp index 8589a6486f..576d5d4ef9 100644 --- a/panda/src/builder/Sources.pp +++ b/panda/src/builder/Sources.pp @@ -4,7 +4,7 @@ #begin lib_target #define TARGET builder #define LOCAL_LIBS \ - linmath gobj sgraph sgattrib graph putil gsgbase mathutil pnmimage \ + pgraph linmath gobj putil gsgbase mathutil pnmimage \ pandabase #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx diff --git a/panda/src/builder/builder.cxx b/panda/src/builder/builder.cxx index b1c14754bc..66818e05cf 100644 --- a/panda/src/builder/builder.cxx +++ b/panda/src/builder/builder.cxx @@ -19,14 +19,11 @@ #include "builderFuncs.h" #include "builderMisc.h" #include "notify.h" -#include "namedNode.h" -#include "geomNode.h" #include "pmap.h" #include "builder.h" -#include "renderRelation.h" #include "pandaNode.h" #include "qpgeomNode.h" - +#include "dcast.h" //////////////////////////////////////////////////////////////////// // Function: Builder::Constructor @@ -69,31 +66,6 @@ Builder:: // with the same Node pointer have different names, then they should // be given two different GeomNodes. -class NodeMap : public Namable { -public: - NodeMap(NamedNode *node, const BuilderBucket *bucket) - : _node(node), _bucket(bucket) { } - - bool operator < (const NodeMap &other) const { - if (_node != other._node) { - return _node < other._node; - } - if (_bucket->get_name() != other._bucket->get_name()) { - return _bucket->get_name() < other._bucket->get_name(); - } - return (_bucket->_trans.compare_to(other._bucket->_trans) < 0); - } - - NamedNode *_node; - - // Although a bucket pointer is stored here in the NodeMap class, - // you should not use it except to extract the name and/or the - // _trans member. Remember, this bucket pointer stands for any of - // possibly several bucket pointers, all different, except that they - // share the same name and _trans. - const BuilderBucket *_bucket; -}; - class qpNodeMap : public Namable { public: qpNodeMap(PandaNode *node, const BuilderBucket *bucket) @@ -107,7 +79,6 @@ public: return _bucket->get_name() < other._bucket->get_name(); } return 0; - // return (_bucket->_state < other._bucket->_state); } PandaNode *_node; @@ -122,127 +93,6 @@ public: -//////////////////////////////////////////////////////////////////// -// Function: Builder::build -// Access: Public -// Description: Creates Geoms for all the primitives added to all -// buckets, and adds them where appropriate to place -// them in the scene graph under their respective -// parents, and/or returns a single GeomNode that -// contains all geometry whose bucket did not reference -// a particular scene graph node to parent them to. -// -// If a bucket's _node pointer was a GeomNode, the -// geometry will be added directly to that node. If the -// _node pointer was any other kind of node, a GeomNode -// will be created and parented to that node, and its -// name will be the name of the bucket. In this case, -// the name of the bucket can also be used to different -// nodes: if two buckets reference the same node, but -// have different names, then two different GeomNodes -// are created, one with each name. -//////////////////////////////////////////////////////////////////// -GeomNode *Builder:: -build(const string &default_name) { - typedef pmap > GeomNodeMap; - GeomNodeMap geom_nodes; - - // First, build all the Geoms and create GeomNodes for them. Each - // unique Node gets its own GeomNode. If the Node is itself a - // GeomNode, that GeomNode is used directly. - Buckets::iterator i; - for (i = _buckets.begin(); - i != _buckets.end(); - ++i) { - BuilderBucket *bucket = (*i).get_bucket(); - NamedNode *node = bucket->_node; - // const string &name = bucket->get_name(); - GeomNode *geom_node = NULL; - - if (node!=NULL && node->is_of_type(GeomNode::get_class_type())) { - // The node is a GeomNode. In this case, we simply use that - // node. We can't separate them out by name in this case; we'll - // just assign to it the first nonempty name we encounter. - geom_node = (GeomNode *)node; - - // Since the caller already created this GeomNode and passed it - // in, we'll leave it up to the caller to name the node and set - // up the state transitions leading into it. - - } else { - // The node is not a GeomNode, so look it up in the map. - GeomNodeMap::iterator f = geom_nodes.find(NodeMap(node, bucket)); - if (f != geom_nodes.end()) { - geom_node = (*f).second; - - } else { - // No such node/name combination. Create a new one. - geom_node = bucket->make_geom_node(); - if (geom_node != NULL) { - geom_nodes[NodeMap(node, bucket)] = geom_node; - } - } - } - - if (geom_node != NULL) { - (*i).build(geom_node); - } - } - - // Now go through and parent the geom_nodes under their respective - // group nodes. Save out the geom_node associated with a NULL Node; - // this one is returned from this function. - - GeomNode *base_geom_node = NULL; - - GeomNodeMap::iterator gi; - - for (gi = geom_nodes.begin(); - gi != geom_nodes.end(); - ++gi) { - const NodeMap &nm = (*gi).first; - GeomNode *geom_node = (*gi).second; - - NamedNode *node = nm._node; - const string &name = nm._bucket->get_name(); - const NodeTransitions &trans = nm._bucket->_trans; - - // Assign the name to the geom, if it doesn't have one already. - if (!geom_node->has_name()) { - if (!name.empty()) { - geom_node->set_name(name); - - } else if (!default_name.empty()) { - geom_node->set_name(default_name); - } - } - - // Only reparent the geom_node if it has no parent already. - int num_parents = - geom_node->get_num_parents(RenderRelation::get_class_type()); - if (num_parents == 0) { - if (geom_node->get_num_geoms() == 0) { - // If there was nothing added, never mind. - delete geom_node; - - } else if (node==NULL) { - nassertr(base_geom_node == NULL, NULL); - base_geom_node = geom_node; - - } else { - RenderRelation *arc = new RenderRelation(node, geom_node); - // Now, this is our only opportunity to apply the scene-graph - // state specified in the bucket to the node: we have created - // our own geom_node for these buckets, and we have parented - // it to the scene graph. - arc->copy_transitions_from(trans); - } - } - } - - return base_geom_node; -} - //////////////////////////////////////////////////////////////////// // Function: Builder::build // Access: Public diff --git a/panda/src/builder/builder.h b/panda/src/builder/builder.h index 021efa122e..927379832c 100644 --- a/panda/src/builder/builder.h +++ b/panda/src/builder/builder.h @@ -175,7 +175,6 @@ #include "pset.h" -class GeomNode; class qpGeomNode; @@ -196,7 +195,6 @@ public: INLINE bool add_prim_nonindexed(const BuilderBucket &bucket, const BuilderPrimI &prim); - GeomNode *build(const string &default_name = ""); qpGeomNode *qpbuild(const string &default_name = ""); protected: diff --git a/panda/src/builder/builderBucket.cxx b/panda/src/builder/builderBucket.cxx index d5b2c3fcca..1f26279d2d 100644 --- a/panda/src/builder/builderBucket.cxx +++ b/panda/src/builder/builderBucket.cxx @@ -21,8 +21,6 @@ #include "builderBucket.h" #include "builderFuncs.h" #include "builderMisc.h" -#include "namedNode.h" -#include "geomNode.h" #include "qpgeomNode.h" @@ -36,7 +34,6 @@ BuilderBucket *BuilderBucket::_default_bucket = NULL; //////////////////////////////////////////////////////////////////// BuilderBucket:: BuilderBucket() { - _node = NULL; _qpnode = NULL; (*this) = (*get_default_bucket()); } @@ -49,7 +46,6 @@ BuilderBucket() { //////////////////////////////////////////////////////////////////// BuilderBucket:: BuilderBucket(const BuilderBucket ©) { - _node = NULL; _qpnode = NULL; (*this) = copy; } @@ -71,12 +67,10 @@ operator = (const BuilderBucket ©) { set_texcoords(copy._texcoords); set_colors(copy._colors); - _node = copy._node; _qpnode = copy._qpnode; _drawBin = copy._drawBin; _drawOrder = copy._drawOrder; - _trans = copy._trans; _state = copy._state; return *this; @@ -108,20 +102,6 @@ make_copy() const { } -//////////////////////////////////////////////////////////////////// -// Function: BuilderBucket::make_geom_node -// Access: Public, Virtual -// Description: Called by the builder when it is time to create a new -// GeomNode. This function should allocate and return a -// new GeomNode suitable for adding geometry to. You -// may redefine it to return a subclass of GeomNode, or -// to do some initialization to the node. -//////////////////////////////////////////////////////////////////// -GeomNode *BuilderBucket:: -make_geom_node() { - return new GeomNode; -} - //////////////////////////////////////////////////////////////////// // Function: BuilderBucket::qpmake_geom_node // Access: Public, Virtual @@ -183,9 +163,6 @@ operator < (const BuilderBucket &other) const { return get_name() < other.get_name(); } - if (_node != other._node) { - return _node < other._node; - } if (_qpnode != other._qpnode) { return _qpnode < other._qpnode; } @@ -204,10 +181,6 @@ operator < (const BuilderBucket &other) const { if (_drawOrder != other._drawOrder) return _drawOrder < other._drawOrder; - int compare = _trans.compare_to(other._trans); - if (compare != 0) { - return (compare < 0); - } if (_state != other._state) { return _state < other._state; } @@ -224,9 +197,6 @@ void BuilderBucket:: output(ostream &out) const { out << "Bucket \"" << get_name() << "\""; - if (_node != (NamedNode *)NULL) { - out << " attached to " << *_node << "\n"; - } if (_qpnode != (PandaNode *)NULL) { out << " attached to " << *_qpnode << "\n"; } @@ -275,7 +245,6 @@ output(ostream &out) const { //////////////////////////////////////////////////////////////////// BuilderBucket:: BuilderBucket(int) { - _node = NULL; _qpnode = NULL; _drawBin = -1; diff --git a/panda/src/builder/builderBucket.h b/panda/src/builder/builderBucket.h index c1e3bb3bfb..965dbfe975 100644 --- a/panda/src/builder/builderBucket.h +++ b/panda/src/builder/builderBucket.h @@ -26,7 +26,6 @@ #include "namable.h" #include "pointerToArray.h" #include "luse.h" -#include "nodeTransitions.h" #include "pta_Vertexf.h" #include "pta_Normalf.h" #include "pta_Colorf.h" @@ -35,10 +34,7 @@ #include "stdlib.h" - -class NamedNode; class Geom; -class GeomNode; class PandaNode; class qpGeomNode; @@ -68,7 +64,6 @@ public: virtual ~BuilderBucket(); virtual BuilderBucket *make_copy() const; - virtual GeomNode *make_geom_node(); virtual qpGeomNode *qpmake_geom_node(); virtual Geom *done_geom(Geom *geom); void add_attrib(const RenderAttrib *attrib); @@ -91,13 +86,11 @@ public: virtual void output(ostream &out) const; - NamedNode *_node; PandaNode *_qpnode; short _drawBin; unsigned int _drawOrder; - NodeTransitions _trans; CPT(RenderState) _state; protected: diff --git a/panda/src/builder/builderBucketNode.cxx b/panda/src/builder/builderBucketNode.cxx index 08ee63bd71..e04fe88f00 100644 --- a/panda/src/builder/builderBucketNode.cxx +++ b/panda/src/builder/builderBucketNode.cxx @@ -19,7 +19,6 @@ #include "builderFuncs.h" #include "builderBucketNode.h" -#include "geomNode.h" #include "qpgeomNode.h" //////////////////////////////////////////////////////////////////// @@ -50,56 +49,6 @@ add_prim(const BuilderPrimI &prim) { return result; } -//////////////////////////////////////////////////////////////////// -// Function: BuilderBucketNode::build -// Access: Public -// Description: Builds all the geometry assigned to this particular -// bucket, and assigns it to the indicated GeomNode. -// Returns the number of Geoms created. -//////////////////////////////////////////////////////////////////// -int BuilderBucketNode:: -build(GeomNode *geom_node) const { - int count = 0; - - { - // First, the nonindexed. - Prims::const_iterator pi, last_pi; - last_pi = _prims.begin(); - - for (pi = _prims.begin(); - pi != _prims.end(); - ++pi) { - if ((*last_pi) < (*pi)) { - count += mesh_and_build(last_pi, pi, *_bucket, geom_node, - (BuilderPrim *)0); - last_pi = pi; - } - } - count += mesh_and_build(last_pi, pi, *_bucket, geom_node, - (BuilderPrim *)0); - } - - { - // Then, the indexed. - IPrims::const_iterator pi, last_pi; - last_pi = _iprims.begin(); - - for (pi = _iprims.begin(); - pi != _iprims.end(); - ++pi) { - if ((*last_pi) < (*pi)) { - count += mesh_and_build(last_pi, pi, *_bucket, geom_node, - (BuilderPrimI *)0); - last_pi = pi; - } - } - count += mesh_and_build(last_pi, pi, *_bucket, geom_node, - (BuilderPrimI *)0); - } - - return count; -} - //////////////////////////////////////////////////////////////////// // Function: BuilderBucketNode::build diff --git a/panda/src/builder/builderBucketNode.h b/panda/src/builder/builderBucketNode.h index fed672f62c..cf7d6cca0c 100644 --- a/panda/src/builder/builderBucketNode.h +++ b/panda/src/builder/builderBucketNode.h @@ -57,7 +57,6 @@ public: INLINE bool operator == (const BuilderBucketNode &other) const; INLINE bool operator != (const BuilderBucketNode &other) const; - int build(GeomNode *geom_node) const; int build(qpGeomNode *geom_node) const; protected: diff --git a/panda/src/builder/builderFuncs.I b/panda/src/builder/builderFuncs.I index 9f53351a49..8a05b9616c 100644 --- a/panda/src/builder/builderFuncs.I +++ b/panda/src/builder/builderFuncs.I @@ -484,10 +484,10 @@ expand(const PrimType &prim, BuilderBucket &bucket, OutputIterator result) { // creates corresponding geometry for them in the // indicated GeomNode. //////////////////////////////////////////////////////////////////// -template +template static int build_geoms(InputIterator first, InputIterator last, - BuilderBucket &bucket, GeomNode *geom_node, + BuilderBucket &bucket, qpGeomNode *geom_node, PrimType *) { if (first==last) { return 0; @@ -794,10 +794,10 @@ public: // to infer the PrimType (BuilderPrim or BuilderPrimI) // from the iterator's value type, and template on that. //////////////////////////////////////////////////////////////////// -template +template static int __mesh_and_build(InputIterator first, InputIterator last, - BuilderBucket &bucket, GeomNode *geom_node, + BuilderBucket &bucket, qpGeomNode *geom_node, PrimType *) { if (first==last) { return 0; @@ -877,10 +877,10 @@ __mesh_and_build(InputIterator first, InputIterator last, // runs them through the mesher if specified by the // bucket, and builds them into the indicated GeomNode. //////////////////////////////////////////////////////////////////// -template +template int mesh_and_build(InputIterator first, InputIterator last, - BuilderBucket &bucket, GeomNode *geom_node, + BuilderBucket &bucket, qpGeomNode *geom_node, value_type *value_type_ptr) { return __mesh_and_build(first, last, bucket, geom_node, value_type_ptr); } diff --git a/panda/src/builder/builderFuncs.h b/panda/src/builder/builderFuncs.h index 6d3e3860fd..f6827fc637 100644 --- a/panda/src/builder/builderFuncs.h +++ b/panda/src/builder/builderFuncs.h @@ -18,13 +18,11 @@ #ifndef BUILDERFUNCS_H #define BUILDERFUNCS_H -#include - +#include "pandabase.h" #include "pvector.h" -#include - class BuilderBucket; +class qpGeomNode; //////////////////////////////////////////////////////////////////// @@ -56,10 +54,10 @@ expand(const PrimType &prim, BuilderBucket &bucket, // runs them through the mesher if specified by the // bucket, and builds them into the indicated GeomNode. //////////////////////////////////////////////////////////////////// -template +template int mesh_and_build(InputIterator first, InputIterator last, - BuilderBucket &bucket, GeomNode *geom_node); + BuilderBucket &bucket, qpGeomNode *geom_node); diff --git a/panda/src/builder/builderNormalVisualizer.cxx b/panda/src/builder/builderNormalVisualizer.cxx index 04efef8b7b..860182b1fb 100644 --- a/panda/src/builder/builderNormalVisualizer.cxx +++ b/panda/src/builder/builderNormalVisualizer.cxx @@ -18,7 +18,6 @@ #include "builderFuncs.h" #include "builderNormalVisualizer.h" -#include "geomNode.h" #include "qpgeomNode.h" #ifdef SUPPORT_SHOW_NORMALS @@ -57,12 +56,6 @@ add_prim(const BuilderPrimI &prim) { add_prim(prim_ni); } -void BuilderNormalVisualizer:: -show_normals(GeomNode *node) { - // Ok, now we've got a bunch of normals saved up; create some geometry. - mesh_and_build(_lines.begin(), _lines.end(), _bucket, node, (BuilderPrim *)0); -} - void BuilderNormalVisualizer:: show_normals(qpGeomNode *node) { // Ok, now we've got a bunch of normals saved up; create some geometry. diff --git a/panda/src/builder/builderNormalVisualizer.h b/panda/src/builder/builderNormalVisualizer.h index f4a607fdf4..d8823f6e1a 100644 --- a/panda/src/builder/builderNormalVisualizer.h +++ b/panda/src/builder/builderNormalVisualizer.h @@ -47,7 +47,6 @@ public: void add_prim(const BuilderPrim &prim); void add_prim(const BuilderPrimI &prim); - void show_normals(GeomNode *node); void show_normals(qpGeomNode *node); private: diff --git a/panda/src/chan/Sources.pp b/panda/src/chan/Sources.pp index 27f8bebee0..24e3c96a44 100644 --- a/panda/src/chan/Sources.pp +++ b/panda/src/chan/Sources.pp @@ -4,12 +4,12 @@ #begin lib_target #define TARGET chan #define LOCAL_LIBS \ - putil linmath mathutil event graph sgattrib + pgraph putil linmath mathutil event #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx #define SOURCES \ - animBundle.I animBundle.h animBundleNode.I animBundleNode.h \ + animBundle.I animBundle.h \ qpanimBundleNode.I qpanimBundleNode.h \ animChannel.I animChannel.h animChannelBase.I \ animChannelBase.h animChannelMatrixXfmTable.I \ @@ -20,25 +20,24 @@ config_chan.h movingPartBase.I movingPartBase.h \ movingPartMatrix.I movingPartMatrix.h movingPartScalar.I \ movingPartScalar.h partBundle.I partBundle.N partBundle.h \ - partBundleNode.I partBundleNode.h \ qppartBundleNode.I qppartBundleNode.h \ partGroup.I partGroup.h \ vector_PartGroupStar.h #define INCLUDED_SOURCES \ - animBundle.cxx animBundleNode.cxx \ + animBundle.cxx \ qpanimBundleNode.cxx \ animChannel.cxx \ animChannelBase.cxx animChannelMatrixXfmTable.cxx \ animChannelScalarTable.cxx animControl.cxx \ animControlCollection.cxx animGroup.cxx auto_bind.cxx \ config_chan.cxx movingPartBase.cxx movingPartMatrix.cxx \ - movingPartScalar.cxx partBundle.cxx partBundleNode.cxx \ + movingPartScalar.cxx partBundle.cxx \ qppartBundleNode.cxx \ partGroup.cxx vector_PartGroupStar.cxx #define INSTALL_HEADERS \ - animBundle.I animBundle.h animBundleNode.I animBundleNode.h \ + animBundle.I animBundle.h \ qpanimBundleNode.I qpanimBundleNode.h \ animChannel.I animChannel.h animChannelBase.I animChannelBase.h \ animChannelFixed.I animChannelFixed.h animChannelMatrixXfmTable.I \ @@ -49,7 +48,6 @@ movingPart.I movingPart.h movingPartBase.I \ movingPartBase.h movingPartMatrix.I movingPartMatrix.h \ movingPartScalar.I movingPartScalar.h partBundle.I partBundle.h \ - partBundleNode.I partBundleNode.h \ qppartBundleNode.I qppartBundleNode.h \ partGroup.I partGroup.h \ vector_PartGroupStar.h diff --git a/panda/src/chan/animBundleNode.I b/panda/src/chan/animBundleNode.I deleted file mode 100644 index ef76ecb335..0000000000 --- a/panda/src/chan/animBundleNode.I +++ /dev/null @@ -1,73 +0,0 @@ -// Filename: animBundleNode.I -// Created by: drose (22Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: AnimBundleNode::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE AnimBundleNode:: -AnimBundleNode(AnimBundle *bundle) : - NamedNode(bundle->get_name()), - _bundle(bundle) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: AnimBundleNode::Constructor -// Access: Protected -// Description: -//////////////////////////////////////////////////////////////////// -INLINE AnimBundleNode:: -AnimBundleNode(void) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: AnimBundleNode::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE AnimBundleNode:: -AnimBundleNode(const AnimBundleNode ©) : - NamedNode(copy), - _bundle(copy._bundle) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: AnimBundleNode::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void AnimBundleNode:: -operator = (const AnimBundleNode ©) { - NamedNode::operator = (copy); - _bundle = copy._bundle; -} - -//////////////////////////////////////////////////////////////////// -// Function: AnimBundleNode::get_bundle -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE AnimBundle *AnimBundleNode:: -get_bundle() const { - return _bundle; -} diff --git a/panda/src/chan/animBundleNode.cxx b/panda/src/chan/animBundleNode.cxx deleted file mode 100644 index 176e30a5a4..0000000000 --- a/panda/src/chan/animBundleNode.cxx +++ /dev/null @@ -1,114 +0,0 @@ -// Filename: animBundleNode.cxx -// Created by: drose (22Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "animBundleNode.h" -#include -#include -#include -#include - -TypeHandle AnimBundleNode::_type_handle; - - -//////////////////////////////////////////////////////////////////// -// Function: AnimBundleNode::make_copy -// Access: Public, Virtual -// Description: Returns a newly-allocated Node that is a shallow copy -// of this one. It will be a different Node pointer, -// but its internal data may or may not be shared with -// that of the original Node. -//////////////////////////////////////////////////////////////////// -Node *AnimBundleNode:: -make_copy() const { - return new AnimBundleNode(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: AnimBundleNode::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void AnimBundleNode:: -write_datagram(BamWriter *manager, Datagram &me) -{ - NamedNode::write_datagram(manager, me); - manager->write_pointer(me, _bundle); -} - -//////////////////////////////////////////////////////////////////// -// Function: AnimBundleNode::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void AnimBundleNode:: -fillin(DatagramIterator& scan, BamReader* manager) -{ - NamedNode::fillin(scan, manager); - manager->read_pointer(scan); -} - -//////////////////////////////////////////////////////////////////// -// Function: AnimBundleNode::complete_pointers -// Access: Public -// Description: Takes in a vector of pointes to TypedWritable -// objects that correspond to all the requests for -// pointers that this object made to BamReader. -//////////////////////////////////////////////////////////////////// -int AnimBundleNode:: -complete_pointers(TypedWritable **p_list, BamReader* manager) -{ - int start = NamedNode::complete_pointers(p_list, manager); - _bundle = DCAST(AnimBundle, p_list[start]); - return start+1; -} - -//////////////////////////////////////////////////////////////////// -// Function: AnimBundleNode::make_AnimBundleNode -// Access: Protected -// Description: Factory method to generate a AnimBundleNode object -//////////////////////////////////////////////////////////////////// -TypedWritable* AnimBundleNode:: -make_AnimBundleNode(const FactoryParams ¶ms) -{ - AnimBundleNode *me = new AnimBundleNode; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: AnimBundleNode::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a AnimBundleNode object -//////////////////////////////////////////////////////////////////// -void AnimBundleNode:: -register_with_read_factory(void) -{ - BamReader::get_factory()->register_factory(get_class_type(), make_AnimBundleNode); -} - - - diff --git a/panda/src/chan/animBundleNode.h b/panda/src/chan/animBundleNode.h deleted file mode 100644 index a816244ecc..0000000000 --- a/panda/src/chan/animBundleNode.h +++ /dev/null @@ -1,81 +0,0 @@ -// Filename: animBundleNode.h -// Created by: drose (22Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef ANIMBUNDLENODE_H -#define ANIMBUNDLENODE_H - -#include - -#include "animBundle.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : AnimBundleNode -// Description : This is a node that contains a pointer to an -// AnimBundle. Its primary raison d'être is to allow -// the AnimBundles to be stored in the scene graph, so -// they may conveniently be loaded as egg files, for -// instance. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA AnimBundleNode : public NamedNode { -PUBLISHED: - INLINE AnimBundleNode(AnimBundle *bundle); - INLINE AnimBundleNode(const AnimBundleNode ©); - INLINE void operator = (const AnimBundleNode ©); - - virtual Node *make_copy() const; - INLINE AnimBundle *get_bundle() const; - -private: - PT(AnimBundle) _bundle; - -public: - static void register_with_read_factory(void); - virtual void write_datagram(BamWriter* manager, Datagram &me); - virtual int complete_pointers(TypedWritable **p_list, - BamReader *manager); - - static TypedWritable *make_AnimBundleNode(const FactoryParams ¶ms); - -protected: - INLINE AnimBundleNode(void); - 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() { - NamedNode::init_type(); - register_type(_type_handle, "AnimBundleNode", - NamedNode::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "animBundleNode.I" - -#endif diff --git a/panda/src/chan/animChannel.h b/panda/src/chan/animChannel.h index 4cc8a4685b..d5bb71307d 100644 --- a/panda/src/chan/animChannel.h +++ b/panda/src/chan/animChannel.h @@ -19,11 +19,11 @@ #ifndef ANIMCHANNEL_H #define ANIMCHANNEL_H -#include +#include "pandabase.h" #include "animChannelBase.h" -#include +#include "lmatrix.h" //////////////////////////////////////////////////////////////////// // Class : AnimChannel diff --git a/panda/src/chan/auto_bind.cxx b/panda/src/chan/auto_bind.cxx index 42413742ab..c943b572bb 100644 --- a/panda/src/chan/auto_bind.cxx +++ b/panda/src/chan/auto_bind.cxx @@ -23,154 +23,6 @@ #include "config_chan.h" #include "string_utils.h" -#include "animBundleNode.h" -#include "partBundleNode.h" -#include "renderRelation.h" -#include "traverserVisitor.h" -#include "dftraverser.h" -#include "nullLevelState.h" -#include "nullTransitionWrapper.h" - -typedef pset AnimNodes; -typedef pmap Anims; - -typedef pset PartNodes; -typedef pmap Parts; - - -//////////////////////////////////////////////////////////////////// -// Class : CollectNodes -// Description : This is a traverser visitor that locates bundle nodes -// and adds them to their respective maps. -//////////////////////////////////////////////////////////////////// -class CollectNodes : - public TraverserVisitor { -public: - bool reached_node(Node *node, const NullTransitionWrapper &, - NullLevelState &) { - if (node->is_of_type(AnimBundleNode::get_class_type())) { - AnimBundleNode *bn = DCAST(AnimBundleNode, node); - _anims[bn->get_bundle()->get_name()].insert(bn); - - } else if (node->is_of_type(PartBundleNode::get_class_type())) { - PartBundleNode *bn = DCAST(PartBundleNode, node); - _parts[bn->get_bundle()->get_name()].insert(bn); - } - - return true; - } - - Anims _anims; - Parts _parts; -}; - - -//////////////////////////////////////////////////////////////////// -// Function: bind_anims -// Description: A support function for auto_bind(), below. Given a -// set of AnimBundles and a set of PartBundles that all -// share the same name, perform whatever bindings make -// sense. -//////////////////////////////////////////////////////////////////// -static void -bind_anims(const PartNodes &parts, const AnimNodes &anims, - AnimControlCollection &controls, - int hierarchy_match_flags) { - - PartNodes::const_iterator pni; - - for (pni = parts.begin(); pni != parts.end(); ++pni) { - PartBundle *part = (*pni)->get_bundle(); - - AnimNodes::const_iterator ani; - for (ani = anims.begin(); ani != anims.end(); ++ani) { - AnimBundle *anim = (*ani)->get_bundle(); - - if (chan_cat.is_info()) { - chan_cat.info() - << "Attempting to bind " << *part << " to " << *anim << "\n"; - } - - PT(AnimControl) control = - part->bind_anim(anim, hierarchy_match_flags); - string name = anim->get_name(); - if (control != (AnimControl *)NULL) { - if (controls.find_anim(name) != (AnimControl *)NULL) { - // That name's already used; synthesize another one. - int index = 0; - string new_name; - do { - index++; - new_name = name + '.' + format_string(index); - } while (controls.find_anim(new_name) != (AnimControl *)NULL); - name = new_name; - } - - controls.store_anim(control, name); - } - - if (chan_cat.is_info()) { - if (control == NULL) { - chan_cat.info() - << "Bind failed.\n"; - } else { - chan_cat.info() - << "Bind succeeded, index " - << control->get_channel_index() << "; accessible as " - << name << "\n"; - } - } - } - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: auto_bind -// Description: Walks the scene graph or subgraph beginning at the -// indicated node, and attempts to bind any AnimBundles -// found to their matching PartBundles, when possible. -// -// The list of all resulting AnimControls created is -// filled into controls. -//////////////////////////////////////////////////////////////////// -void -auto_bind(Node *root_node, AnimControlCollection &controls, - int hierarchy_match_flags) { - - // First, locate all the bundles in the subgraph. - CollectNodes cn; - df_traverse(root_node, cn, NullTransitionWrapper(), NullLevelState(), - RenderRelation::get_class_type()); - - // Now, match up the bundles by name. - - Anims::const_iterator ai = cn._anims.begin(); - Parts::const_iterator pi = cn._parts.begin(); - - while (ai != cn._anims.end() && pi != cn._parts.end()) { - if ((*ai).first < (*pi).first) { - // Here's an anim with no matching parts. - ++ai; - - } else if ((*pi).first < (*ai).first) { - // And here's a part with no matching anims. - ++pi; - - } else { - // But here we have (at least one) match! - bind_anims((*pi).second, (*ai).second, controls, - hierarchy_match_flags); - ++pi; - - // We don't increment the anim counter yet. That way, the same - // anim may bind to multiple parts, if they all share the same - // name. - } - } -} - - typedef pset qpAnimNodes; typedef pmap qpAnims; diff --git a/panda/src/chan/auto_bind.h b/panda/src/chan/auto_bind.h index dc6fe88ac9..4754e90559 100644 --- a/panda/src/chan/auto_bind.h +++ b/panda/src/chan/auto_bind.h @@ -24,7 +24,6 @@ #include "animControl.h" #include "animControlCollection.h" -class Node; class PandaNode; BEGIN_PUBLISH @@ -37,10 +36,6 @@ BEGIN_PUBLISH // The list of all resulting AnimControls created is // filled into controls. //////////////////////////////////////////////////////////////////// -EXPCL_PANDA void -auto_bind(Node *root_node, AnimControlCollection &controls, - int hierarchy_match_flags = 0); - EXPCL_PANDA void auto_bind(PandaNode *root_node, AnimControlCollection &controls, int hierarchy_match_flags = 0); diff --git a/panda/src/chan/chan_composite1.cxx b/panda/src/chan/chan_composite1.cxx index 3bdb0a8e75..2b74be96f9 100644 --- a/panda/src/chan/chan_composite1.cxx +++ b/panda/src/chan/chan_composite1.cxx @@ -5,7 +5,6 @@ #include "movingPartMatrix.cxx" #include "movingPartScalar.cxx" #include "partBundle.cxx" -#include "partBundleNode.cxx" #include "qppartBundleNode.cxx" #include "partGroup.cxx" #include "vector_PartGroupStar.cxx" diff --git a/panda/src/chan/chan_composite2.cxx b/panda/src/chan/chan_composite2.cxx index 04ce04840d..a89885463e 100644 --- a/panda/src/chan/chan_composite2.cxx +++ b/panda/src/chan/chan_composite2.cxx @@ -1,6 +1,5 @@ #include "animBundle.cxx" -#include "animBundleNode.cxx" #include "qpanimBundleNode.cxx" #include "animChannel.cxx" #include "animChannelBase.cxx" diff --git a/panda/src/chan/config_chan.cxx b/panda/src/chan/config_chan.cxx index af3933fa52..43f8c77f3e 100644 --- a/panda/src/chan/config_chan.cxx +++ b/panda/src/chan/config_chan.cxx @@ -19,7 +19,6 @@ #include "config_chan.h" #include "animBundle.h" -#include "animBundleNode.h" #include "qpanimBundleNode.h" #include "animChannelBase.h" #include "animChannelMatrixXfmTable.h" @@ -30,7 +29,6 @@ #include "movingPartMatrix.h" #include "movingPartScalar.h" #include "partBundle.h" -#include "partBundleNode.h" #include "qppartBundleNode.h" #include "partGroup.h" @@ -80,7 +78,6 @@ bool read_compressed_channels = config_chan.GetBool("read-compressed-channels", ConfigureFn(config_chan) { AnimBundle::init_type(); - AnimBundleNode::init_type(); qpAnimBundleNode::init_type(); AnimChannelBase::init_type(); AnimChannelMatrixXfmTable::init_type(); @@ -91,7 +88,6 @@ ConfigureFn(config_chan) { MovingPartMatrix::init_type(); MovingPartScalar::init_type(); PartBundle::init_type(); - PartBundleNode::init_type(); qpPartBundleNode::init_type(); PartGroup::init_type(); @@ -110,7 +106,6 @@ ConfigureFn(config_chan) { AnimGroup::register_with_read_factory(); AnimBundle::register_with_read_factory(); - AnimBundleNode::register_with_read_factory(); qpAnimBundleNode::register_with_read_factory(); AnimChannelMatrixXfmTable::register_with_read_factory(); AnimChannelScalarTable::register_with_read_factory(); diff --git a/panda/src/chan/partBundleNode.I b/panda/src/chan/partBundleNode.I deleted file mode 100644 index c19e7967cd..0000000000 --- a/panda/src/chan/partBundleNode.I +++ /dev/null @@ -1,70 +0,0 @@ -// Filename: partBundleNode.I -// Created by: drose (23Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: PartBundleNode::Constructor -// Access: Public -// Description: The PartBundle and its node should be constructed -// together. Generally, the derived classes of -// PartBundleNode will automatically create a PartBundle -// of the appropriate type, and pass it up to this -// constructor. -//////////////////////////////////////////////////////////////////// -INLINE PartBundleNode:: -PartBundleNode(const string &name, PartBundle *bundle) : - NamedNode(name), - _bundle(bundle) -{ - _bundle->_node = this; -} - -//////////////////////////////////////////////////////////////////// -// Function: PartBundleNode::Default Constructor -// Access: Protected -// Description: For internal use only. -//////////////////////////////////////////////////////////////////// -INLINE PartBundleNode:: -PartBundleNode(void) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: PartBundleNode::Copy Constructor -// Access: Protected -// Description: Use make_copy() or copy_subgraph() to copy one of -// these. Copying a PartBundleNode will always force a -// deep copy of the PartGroup hierarchy. -//////////////////////////////////////////////////////////////////// -INLINE PartBundleNode:: -PartBundleNode(const PartBundleNode ©) : - NamedNode(copy), - _bundle(DCAST(PartBundle, copy._bundle->copy_subgraph())) -{ - _bundle->_node = this; -} - -//////////////////////////////////////////////////////////////////// -// Function: PartBundleNode::get_bundle -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE PartBundle *PartBundleNode:: -get_bundle() const { - return _bundle; -} diff --git a/panda/src/chan/partBundleNode.cxx b/panda/src/chan/partBundleNode.cxx deleted file mode 100644 index e5992bb275..0000000000 --- a/panda/src/chan/partBundleNode.cxx +++ /dev/null @@ -1,88 +0,0 @@ -// Filename: partBundleNode.cxx -// Created by: drose (23Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "partBundleNode.h" -#include -#include -#include -#include - -TypeHandle PartBundleNode::_type_handle; - - -//////////////////////////////////////////////////////////////////// -// Function: PartBundleNode::safe_to_flatten -// Access: Public, Virtual -// Description: Returns true if it is generally safe to flatten out -// this particular kind of Node by duplicating -// instances, false otherwise (for instance, a Camera -// cannot be safely flattened, because the Camera -// pointer itself is meaningful). -//////////////////////////////////////////////////////////////////// -bool PartBundleNode:: -safe_to_flatten() const { - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: PartBundleNode::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void PartBundleNode:: -write_datagram(BamWriter *manager, Datagram &me) -{ - NamedNode::write_datagram(manager, me); - manager->write_pointer(me, _bundle); -} - -//////////////////////////////////////////////////////////////////// -// Function: PartBundleNode::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void PartBundleNode:: -fillin(DatagramIterator& scan, BamReader* manager) -{ - NamedNode::fillin(scan, manager); - manager->read_pointer(scan); -} - -//////////////////////////////////////////////////////////////////// -// Function: PartBundleNode::complete_pointers -// Access: Public -// Description: Takes in a vector of pointes to TypedWritable -// objects that correspond to all the requests for -// pointers that this object made to BamReader. -//////////////////////////////////////////////////////////////////// -int PartBundleNode:: -complete_pointers(TypedWritable **p_list, BamReader* manager) -{ - int start = NamedNode::complete_pointers(p_list, manager); - _bundle = DCAST(PartBundle, p_list[start]); - //Let PartBundleNode tell the PartBundle about itselt - _bundle->_node = this; - return start+1; -} - - diff --git a/panda/src/chan/partBundleNode.h b/panda/src/chan/partBundleNode.h deleted file mode 100644 index 0d274b8b30..0000000000 --- a/panda/src/chan/partBundleNode.h +++ /dev/null @@ -1,80 +0,0 @@ -// Filename: partBundleNode.h -// Created by: drose (23Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef PARTBUNDLENODE_H -#define PARTBUNDLENODE_H - -#include - -#include "partBundle.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : PartBundleNode -// Description : This is a node that contains a pointer to an -// PartBundle. Like AnimBundleNode, it exists solely to -// make it easy to store PartBundles in the scene graph. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA PartBundleNode : public NamedNode { -public: - INLINE PartBundleNode(const string &name, PartBundle *bundle); - -protected: - INLINE PartBundleNode(); - INLINE PartBundleNode(const PartBundleNode ©); - -public: - virtual bool safe_to_flatten() const; - -PUBLISHED: - INLINE PartBundle *get_bundle() const; - -private: - PT(PartBundle) _bundle; - -public: - virtual void write_datagram(BamWriter* manager, Datagram &me); - virtual int complete_pointers(TypedWritable **p_list, - BamReader *manager); - -protected: - 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() { - NamedNode::init_type(); - register_type(_type_handle, "PartBundleNode", - NamedNode::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "partBundleNode.I" - -#endif diff --git a/panda/src/chancfg/Sources.pp b/panda/src/chancfg/Sources.pp index d7a5dd93a2..ce5a38eb8b 100644 --- a/panda/src/chancfg/Sources.pp +++ b/panda/src/chancfg/Sources.pp @@ -4,7 +4,7 @@ #begin lib_target #define TARGET chancfg #define LOCAL_LIBS \ - putil display sgattrib linmath graph sgraph gobj display gsgbase \ + putil display linmath gobj display gsgbase \ mathutil #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx diff --git a/panda/src/chancfg/chancfg.I b/panda/src/chancfg/chancfg.I index da19858c9d..aa60ba26c5 100644 --- a/panda/src/chancfg/chancfg.I +++ b/panda/src/chancfg/chancfg.I @@ -16,26 +16,6 @@ // //////////////////////////////////////////////////////////////////// - INLINE PT_NamedNode ChanConfig::get_group_node(const int node_index) const { - return _group_node[node_index]; - } - INLINE int ChanConfig::get_group_membership(const int dr_index) const { - return _group_membership[dr_index]; - } - INLINE int ChanConfig::get_num_groups(void) const { - return _group_node.size(); - } - INLINE int ChanConfig::get_num_drs(void) const { - return _display_region.size(); - } - INLINE PT(DisplayRegion) ChanConfig::get_dr(const int dr_index) const { - return _display_region[dr_index]; - } - INLINE PT(GraphicsWindow) ChanConfig::get_win(void) const { - return _graphics_window; - } - - INLINE PandaNode *qpChanConfig::get_group_node(const int node_index) const { return _group_node[node_index]; } diff --git a/panda/src/chancfg/chancfg.cxx b/panda/src/chancfg/chancfg.cxx index 0eb5eea28a..44214c076b 100644 --- a/panda/src/chancfg/chancfg.cxx +++ b/panda/src/chancfg/chancfg.cxx @@ -21,17 +21,14 @@ #include "displayRegion.h" #include "graphicsChannel.h" #include "hardwareChannel.h" -#include "camera.h" #include "qpcamera.h" #include "frustum.h" #include "perspectiveLens.h" -#include "renderRelation.h" -#include "transformTransition.h" #include "dSearchPath.h" #include "dconfig.h" #include "filename.h" -#include "pt_NamedNode.h" #include "transformState.h" +#include "dcast.h" #include @@ -209,283 +206,6 @@ SetupFOV ChanResolveFOV(SetupFOV& fov, float sizeX, float sizeY) { return ret; } -void ChanConfig::chan_eval(GraphicsWindow* win, WindowItem& W, LayoutItem& L, - SVec& S, - ChanViewport& V, int hw_offset, int xsize, int ysize, - Node *render, bool want_cameras) { - int i = min(L.GetNumRegions(), int(S.size())); - int j; - SVec::iterator k; - std::vectorcamera(W.getNumCameraGroups()); - //first camera is special cased to name "camera" for older code - camera[0] = new NamedNode("camera"); - for(int icam=1;icamget_channel(hw_offset); - } else - chan = win->get_channel((*k).getChan()); - // HW channels always start with the full area of the channel - v = ChanViewport(0.0f, 1.0f, 0.0f, 1.0f); - } else { - chan = win->get_channel(0); - } - ChanViewport v2(ChanScaleViewport(v, (*k).getViewport())); - PT(GraphicsLayer) layer = chan->make_layer(); - PT(DisplayRegion) dr = - layer->make_display_region(v2.left(), v2.right(), - v2.bottom(), v2.top()); - if (want_cameras && camera[0] != (Node *)NULL) { - // now make a camera for it - PT(Camera) cam = new Camera; - dr->set_camera(cam); - _display_region.push_back(dr); - SetupFOV fov = (*k).getFOV(); - // The distinction between ConsoleSize and DisplaySize - // is to handle display regions with orientations that - // are rotated 90 degrees left or right. For example, - // the model shop cave (LAIR) uses projectors on their - // sides, so that what's horizontal on the console is - // vertical in the cave (Display). - float xConsoleSize = xsize*(v2.right()-v2.left()); - float yConsoleSize = ysize*(v2.top()-v2.bottom()); - float xDisplaySize, yDisplaySize; - if ( (*k).getOrientation() == SetupItem::Left || - (*k).getOrientation() == SetupItem::Right ) { - xDisplaySize = yConsoleSize; - yDisplaySize = xConsoleSize; - } else { - xDisplaySize = xConsoleSize; - yDisplaySize = yConsoleSize; - } - fov = ChanResolveFOV(fov, xDisplaySize, yDisplaySize); - if (chancfg_cat->is_debug()) { - chancfg_cat->debug() << "ChanEval:: FOVhoriz = " << fov.getHoriz() - << " FOVvert = " << fov.getVert() << endl; - chancfg_cat->debug() << "ChanEval:: xsize = " << xsize - << " ysize = " << ysize << endl; - } - - // take care of the orientation - PT(TransformTransition) orient; - float hFov, vFov; - - switch ((*k).getOrientation()) { - case SetupItem::Up: - hFov = fov.getHoriz(); vFov = fov.getVert(); - break; - case SetupItem::Down: - hFov = fov.getHoriz(); vFov = fov.getVert(); - orient = new TransformTransition( - LMatrix4f::rotate_mat_normaxis(180.0f, LVector3f::forward())); - break; - case SetupItem::Left: - // vertical and horizontal FOV are being switched - hFov = fov.getVert(); vFov = fov.getHoriz(); - orient = new TransformTransition( - LMatrix4f::rotate_mat_normaxis(90.0f, LVector3f::forward())); - break; - case SetupItem::Right: - // vertical and horizontal FOV are being switched - hFov = fov.getVert(); vFov = fov.getHoriz(); - orient = new TransformTransition( - LMatrix4f::rotate_mat_normaxis(-90.0f, LVector3f::forward())); - break; - } - - PT(Lens) lens = new PerspectiveLens; - lens->set_fov(hFov, vFov); - lens->set_near_far(1.0f, 10000.0f); - cam->set_lens(lens); - - // hfov and vfov for camera are switched from what was specified - // if the orientation is sideways. - if (chancfg_cat->is_debug()) - chancfg_cat->debug() << "ChanEval:: camera hfov = " - << lens->get_hfov() << " vfov = " - << lens->get_vfov() << endl; - cam->set_scene(render); - - RenderRelation *tocam = new RenderRelation(camera[W.getCameraGroup(j)], cam); - if (orient != (TransformTransition *)NULL) { - tocam->set_transition(orient); - } - } - } - _group_node = camera; - return; -} - -ChanConfig::ChanConfig(GraphicsPipe* pipe, std::string cfg, Node *render, - ChanCfgOverrides& overrides) { - ReadChanConfigData(); - // check to make sure we know everything we need to - if (!ConfigDefined(cfg)) { - chancfg_cat.error() - << "no window configuration called '" << cfg << "'" << endl; - _graphics_window = (GraphicsWindow*)0; - return; - } - WindowItem W = (*WindowDB)[cfg]; - - std::string l = W.getLayout(); - if (!LayoutDefined(l)) { - chancfg_cat.error() - << "No layout called '" << l << "'" << endl; - _graphics_window = (GraphicsWindow*)0; - return; - } - LayoutItem L = (*LayoutDB)[l]; - - SetupSyms s = W.getSetups(); - if (!ChanCheckSetups(s)) { - chancfg_cat.error() << "Setup failure" << endl; - _graphics_window = (GraphicsWindow*)0; - return; - } - - SVec S; - S.reserve(s.size()); - for (SetupSyms::iterator i=s.begin(); i!=s.end(); ++i) - S.push_back((*SetupDB)[(*i)]); - - // get the window data - int sizeX = chanconfig.GetInt("win-width", -1); - int sizeY = chanconfig.GetInt("win-height", -1); - if (overrides.defined(ChanCfgOverrides::SizeX)) - sizeX = overrides.getInt(ChanCfgOverrides::SizeX); - if (overrides.defined(ChanCfgOverrides::SizeY)) - sizeY = overrides.getInt(ChanCfgOverrides::SizeY); - if (sizeX < 0) { - if (sizeY < 0) { - if(chancfg_cat.is_debug()) - chancfg_cat.debug() << "Using default chan-window size\n"; - // take the default size - sizeX = W.getSizeX(); - sizeY = W.getSizeY(); - } else { - // vertical size is defined, compute horizontal keeping the aspect from - // the default - sizeX = (W.getSizeX() * sizeY) / W.getSizeY(); - } - } else if (sizeY < 0) { - // horizontal size is defined, compute vertical keeping the aspect from the - // default - sizeY = (W.getSizeY() * sizeX) / W.getSizeX(); - } - - int origX = chanconfig.GetInt("win-origin-x"); - int origY = chanconfig.GetInt("win-origin-y"); - origX = overrides.defined(ChanCfgOverrides::OrigX) ? - overrides.getInt(ChanCfgOverrides::OrigX) : origX; - origY = overrides.defined(ChanCfgOverrides::OrigY) ? - overrides.getInt(ChanCfgOverrides::OrigY) : origY; - - bool border = !chanconfig.GetBool("no-border", !W.getBorder()); - bool fullscreen = chanconfig.GetBool("fullscreen", false); - bool use_cursor = chanconfig.GetBool("cursor-visible", W.getCursor()); - int want_depth_bits = chanconfig.GetInt("want-depth-bits", 1); - int want_color_bits = chanconfig.GetInt("want-color-bits", 1); - - // visual? nope, that's handled with the mode. - uint mask = 0x0; // ?! this really should come from the win config - mask = overrides.defined(ChanCfgOverrides::Mask) ? - overrides.getUInt(ChanCfgOverrides::Mask) : mask; - std::string title = cfg; - title = overrides.defined(ChanCfgOverrides::Title) ? - overrides.getString(ChanCfgOverrides::Title) : title; - - GraphicsWindow::Properties props; - props._xorg = origX; - props._yorg = origY; - props._xsize = sizeX; - props._ysize = sizeY; - props._title = title; - props._mask = mask; - props._border = border; - props._fullscreen = fullscreen; - props._want_depth_bits = want_depth_bits; - props._want_color_bits = want_color_bits; - props._bCursorIsVisible = use_cursor; - - // stereo prep? - // DVR prep? - - bool want_cameras = overrides.defined(ChanCfgOverrides::Cameras) ? - overrides.getBool(ChanCfgOverrides::Cameras) : true; - - // open that sucker - PT(GraphicsWindow) win = pipe->make_window(props); - if(win == (GraphicsWindow *)NULL) { - chancfg_cat.error() << "Could not create window" << endl; - _graphics_window = (GraphicsWindow *)NULL; - return; - } - - // make channels and display regions - ChanViewport V(0.0f, 1.0f, 0.0f, 1.0f); - chan_eval(win, W, L, S, V, W.getChanOffset()+1, sizeX, sizeY, - render, want_cameras); - for(size_t dr_index=0; dr_index<_display_region.size(); dr_index++) - _group_membership.push_back(W.getCameraGroup(dr_index)); - - // sanity check - if (config_sanity_check) { - nout << "ChanConfig Sanity check:" << endl - << "window - " << (void*)win << endl - << " width = " << win->get_width() << " height = " << win->get_height() << endl - << " xorig = " << win->get_xorg() << " yorig = " << win->get_yorg()<< endl; - - int max_channel_index = win->get_max_channel_index(); - for (int c = 0; c < max_channel_index; c++) { - if (win->is_channel_defined(c)) { - GraphicsChannel *chan = win->get_channel(c); - nout << " Chan - " << (void*)chan << endl - << " window = " << (void*)(chan->get_window()) << endl - << " active = " << chan->is_active() << endl; - - int num_layers = chan->get_num_layers(); - for (int l = 0; l < num_layers; l++) { - GraphicsLayer *layer = chan->get_layer(l); - nout << " Layer - " << (void*)layer << endl - << " channel = " << (void*)(layer->get_channel()) << endl - << " active = " << layer->is_active() << endl; - - int num_drs = layer->get_num_drs(); - for (int d = 0; d < num_drs; d++) { - DisplayRegion *dr = layer->get_dr(d); - nout << " DR - " << (void*)dr << endl - << " layer = " << (void*)(dr->get_layer()) << endl; - float ll, rr, bb, tt; - dr->get_dimensions(ll, rr, bb, tt); - nout << " (" << ll << " " << rr << " " << bb << " " << tt << ")" << endl - << " camera = " << (void*)(dr->get_camera()) << endl; - Camera* cmm = dr->get_camera(); - if (cmm != (Camera*)0L) { - nout << " active = " << cmm->is_active() << endl; - int num_cam_drs = cmm->get_num_drs(); - for (int cd = 0; cd < num_cam_drs; cd++) - nout << " dr = " << (void*)cmm->get_dr(cd) << endl; - } - nout << " active = " << dr->is_active() << endl; - } - } - } - } - } - _graphics_window = win; - return; -} - void qpChanConfig::chan_eval(GraphicsWindow* win, WindowItem& W, LayoutItem& L, SVec& S, ChanViewport& V, int hw_offset, int xsize, int ysize, @@ -745,13 +465,14 @@ qpChanConfig::qpChanConfig(GraphicsPipe* pipe, std::string cfg, const qpNodePath float ll, rr, bb, tt; dr->get_dimensions(ll, rr, bb, tt); nout << " (" << ll << " " << rr << " " << bb << " " << tt << ")" << endl - << " camera = " << (void*)(dr->get_camera()) << endl; - Camera* cmm = dr->get_camera(); - if (cmm != (Camera*)0L) { - nout << " active = " << cmm->is_active() << endl; - int num_cam_drs = cmm->get_num_drs(); + << " camera = " << dr->get_qpcamera() << endl; + qpNodePath cmm = dr->get_qpcamera(); + if (!cmm.is_empty()) { + qpCamera *cmm_node = DCAST(qpCamera, cmm.node()); + nout << " active = " << cmm_node->is_active() << endl; + int num_cam_drs = cmm_node->get_num_display_regions(); for (int cd = 0; cd < num_cam_drs; cd++) - nout << " dr = " << (void*)cmm->get_dr(cd) << endl; + nout << " dr = " << (void*)cmm_node->get_display_region(cd) << endl; } nout << " active = " << dr->is_active() << endl; } diff --git a/panda/src/chancfg/chancfg.h b/panda/src/chancfg/chancfg.h index a9b69cc49f..d7e7faa7c0 100644 --- a/panda/src/chancfg/chancfg.h +++ b/panda/src/chancfg/chancfg.h @@ -28,14 +28,11 @@ #include "graphicsPipe.h" #include "graphicsWindow.h" -#include "pt_NamedNode.h" #include "pandaNode.h" #include "qpnodePath.h" #include "pmap.h" -class Node; - class EXPCL_PANDA ChanCfgOverrides { public: enum Field { OrigX, OrigY, SizeX, SizeY, Title, Mask, Cameras }; @@ -105,28 +102,6 @@ public: extern ChanCfgOverrides ChanOverrideNone; typedef pvector SVec; -class NamedNode; - -class EXPCL_PANDA ChanConfig -{ -private: - std::vector _group_node; - std::vector< PT(DisplayRegion) > _display_region; - std::vector _group_membership; - PT(GraphicsWindow) _graphics_window; - void chan_eval(GraphicsWindow* win, WindowItem& W, LayoutItem& L, - SVec& S, ChanViewport& V, int hw_offset, - int xsize, int ysize, Node *render, bool want_cameras); -PUBLISHED: - ChanConfig(GraphicsPipe*, std::string, Node *render, - ChanCfgOverrides& = ChanOverrideNone); - INLINE PT_NamedNode get_group_node(const int node_index) const; - INLINE int get_group_membership(const int dr_index) const; - INLINE int get_num_groups(void) const; - INLINE int get_num_drs(void) const; - INLINE PT(DisplayRegion) get_dr(const int dr_index) const; - INLINE PT(GraphicsWindow) get_win(void) const; -}; class EXPCL_PANDA qpChanConfig { diff --git a/panda/src/char/Sources.pp b/panda/src/char/Sources.pp index bed5800523..236f786b1f 100644 --- a/panda/src/char/Sources.pp +++ b/panda/src/char/Sources.pp @@ -4,13 +4,12 @@ #begin lib_target #define TARGET char #define LOCAL_LIBS \ - chan graph sgraph linmath putil event sgattrib mathutil gsgbase \ + chan linmath putil event mathutil gsgbase \ pstatclient #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx #define SOURCES \ - character.I character.h \ qpcharacter.I qpcharacter.h \ characterJoint.h characterJointBundle.I \ characterJointBundle.h characterSlider.h computedVertices.I \ @@ -18,7 +17,6 @@ computedVerticesMorph.h config_char.h dynamicVertices.h #define INCLUDED_SOURCES \ - character.cxx \ qpcharacter.cxx \ characterJoint.cxx characterJointBundle.cxx \ characterSlider.cxx computedVertices.cxx \ @@ -26,7 +24,6 @@ dynamicVertices.cxx #define INSTALL_HEADERS \ - character.I character.h \ qpcharacter.I qpcharacter.h \ characterJoint.h characterJointBundle.I \ characterJointBundle.h characterSlider.h computedVertices.I \ diff --git a/panda/src/char/char_composite1.cxx b/panda/src/char/char_composite1.cxx index 588f214fba..ee75013673 100644 --- a/panda/src/char/char_composite1.cxx +++ b/panda/src/char/char_composite1.cxx @@ -1,6 +1,5 @@ #include "config_char.cxx" -#include "character.cxx" #include "qpcharacter.cxx" #include "characterJoint.cxx" #include "characterJointBundle.cxx" diff --git a/panda/src/char/character.I b/panda/src/char/character.I deleted file mode 100644 index 9eb7bf0a67..0000000000 --- a/panda/src/char/character.I +++ /dev/null @@ -1,87 +0,0 @@ -// Filename: character.I -// Created by: drose (23Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "characterJointBundle.h" - -//////////////////////////////////////////////////////////////////// -// Function: Character::get_bundle -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CharacterJointBundle *Character:: -get_bundle() const { - return DCAST(CharacterJointBundle, PartBundleNode::get_bundle()); -} - - -//////////////////////////////////////////////////////////////////// -// Function: Character::get_computed_vertices -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ComputedVertices *Character:: -get_computed_vertices() const { - return _computed_vertices; -} - -//////////////////////////////////////////////////////////////////// -// Function: Character::get_num_parts -// Access: Public -// Description: Returns the total number of moving parts (e.g. joints -// and sliders) associated with the character. -//////////////////////////////////////////////////////////////////// -INLINE int Character:: -get_num_parts() const { - return _parts.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: Character::get_part -// Access: Public -// Description: Returns the nth moving part associated with the -// character. -//////////////////////////////////////////////////////////////////// -INLINE PartGroup *Character:: -get_part(int n) const { - nassertr(n >= 0 && n < (int)_parts.size(), NULL); - return _parts[n]; -} - -//////////////////////////////////////////////////////////////////// -// Function: Character::write_parts -// Access: Public -// Description: Writes a list of the character's joints and sliders, -// in their hierchical structure, to the indicated -// output stream. -//////////////////////////////////////////////////////////////////// -INLINE void Character:: -write_parts(ostream &out) const { - get_bundle()->write(out, 0); -} - -//////////////////////////////////////////////////////////////////// -// Function: Character::write_part_values -// Access: Public -// Description: Writes a list of the character's joints and sliders, -// along with each current position, in their hierchical -// structure, to the indicated output stream. -//////////////////////////////////////////////////////////////////// -INLINE void Character:: -write_part_values(ostream &out) const { - get_bundle()->write_with_value(out, 0); -} diff --git a/panda/src/char/character.cxx b/panda/src/char/character.cxx deleted file mode 100644 index 91309b29e5..0000000000 --- a/panda/src/char/character.cxx +++ /dev/null @@ -1,504 +0,0 @@ -// Filename: character.cxx -// Created by: drose (23Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "character.h" -#include "characterJoint.h" -#include "computedVertices.h" -#include "config_char.h" - -#include "geomNode.h" -#include "datagram.h" -#include "datagramIterator.h" -#include "bamReader.h" -#include "bamWriter.h" -#include "pStatTimer.h" -#include "geomNode.h" -#include "animControl.h" -#include "clockObject.h" -#include "pStatTimer.h" - -TypeHandle Character::_type_handle; - -#ifndef CPPPARSER -PStatCollector Character::_anim_pcollector("App:Animation"); -#endif - -//////////////////////////////////////////////////////////////////// -// Function: Character::Copy Constructor -// Access: Protected -// Description: Use make_copy() or copy_subgraph() to copy a character. -//////////////////////////////////////////////////////////////////// -Character:: -Character(const Character ©) : - PartBundleNode(copy.get_name(), new CharacterJointBundle(copy.get_bundle()->get_name())), - _cv(DynamicVertices::deep_copy(copy._cv)), - _computed_vertices(copy._computed_vertices), - _parts(copy._parts), - _char_pcollector(copy._char_pcollector) -{ - // Now make a copy of the joint/slider hierarchy. We could just use - // the PartBundleNode's copy constructor, but if we do it ourselves - // we can simultaneously update our _parts list. - - copy_joints(get_bundle(), copy.get_bundle()); -} - -//////////////////////////////////////////////////////////////////// -// Function: Character::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -Character:: -Character(const string &name) : - PartBundleNode(name, new CharacterJointBundle(name)), - _char_pcollector(_anim_pcollector, name) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: Character::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -Character:: -~Character() { -} - -//////////////////////////////////////////////////////////////////// -// Function: Character::make_copy -// Access: Public, Virtual -// Description: The Character make_copy() function will make a new -// copy of the character, with all of its joints copied, -// and with a new set of dynamic vertex arrays all ready -// to go, but it will not copy any of the original -// Character's geometry, so the new Character won't look -// like much. Use copy_subgraph() to make a full copy -// of the Character. -//////////////////////////////////////////////////////////////////// -Node *Character:: -make_copy() const { - return new Character(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: Character::safe_to_transform -// Access: Public, Virtual -// Description: Returns true if it is generally safe to transform -// this particular kind of Node by calling the xform() -// method, false otherwise. For instance, it's usually -// a bad idea to attempt to xform a Character. -//////////////////////////////////////////////////////////////////// -bool Character:: -safe_to_transform() const { - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: Character::app_traverse -// Access: Public, Virtual -// Description: This is called by the App traversal by virtue of the -// character node's being present in the scene graph. -//////////////////////////////////////////////////////////////////// -void Character:: -app_traverse(const ArcChain &) { - double now = ClockObject::get_global_clock()->get_frame_time(); - get_bundle()->advance_time(now); - - if (char_cat.is_debug()) { - char_cat.debug() << "Animating " << *this << " at time " << now << "\n"; - } - - update(); -} - -//////////////////////////////////////////////////////////////////// -// Function: Character::update -// Access: Public -// Description: Recalculates the character's joints and vertices for -// the current frame. Normally this is performed -// automatically during the render and need not be -// called explicitly. -//////////////////////////////////////////////////////////////////// -void Character:: -update() { - // Statistics - PStatTimer timer(_char_pcollector); - - // First, update all the joints and sliders. - bool any_changed = get_bundle()->update(); - - // Now update the vertices, if we need to. This is likely to be a - // slow operation. - if (any_changed || even_animation) { - if (_computed_vertices != (ComputedVertices *)NULL) { - _computed_vertices->update(this); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: Character::copy_joints -// Access: Private -// Description: Recursively walks the joint/slider hierarchy and -// creates a new copy of the hierarchy. -//////////////////////////////////////////////////////////////////// -void Character:: -copy_joints(PartGroup *copy, PartGroup *orig) { - if (copy->get_type() != orig->get_type()) { - char_cat.warning() - << "Don't know how to copy " << orig->get_type() << "\n"; - } - - PartGroup::Children::const_iterator ci; - for (ci = orig->_children.begin(); ci != orig->_children.end(); ++ci) { - PartGroup *orig_child = (*ci); - PartGroup *copy_child = orig_child->make_copy(); - copy->_children.push_back(copy_child); - copy_joints(copy_child, orig_child); - } - - Parts::iterator pi = find(_parts.begin(), _parts.end(), orig); - if (pi != _parts.end()) { - (*pi) = copy; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: Character::r_copy_subgraph -// Access: Private, Virtual -// Description: This is a virtual function inherited from Node. It's -// called when a copy_subgraph() operation reaches the -// Character node. In the case of a Character, it's -// overridden to do the all right things to copy the -// dynamic geometry to the new Character. -// -// Note that it includes the parameter inst_map, which -// is a map type, and is not (and cannot be) exported -// from PANDA.DLL. Thus, any derivative of Node that is -// not also a member of PANDA.DLL *cannot* access this -// map. -//////////////////////////////////////////////////////////////////// -Node *Character:: -r_copy_subgraph(TypeHandle graph_type, Node::InstanceMap &) const { - Node *copy = make_copy(); - nassertr(copy != (Node *)NULL, NULL); - if (copy->get_type() != get_type()) { - graph_cat.warning() - << "Don't know how to copy nodes of type " << get_type() << "\n"; - } - - // We assume there will be no instancing going on below the - // Character node. If there is, too bad; it will get flattened out. - - // Now we preempt the node's r_copy_subgraph() operation with our - // own function that keeps track of the old vs. new arcs and also - // updates any Geoms we find with our new dynamic vertices. - - Character *char_copy; - DCAST_INTO_R(char_copy, copy, NULL); - ArcMap arc_map; - char_copy->r_copy_char(char_copy, this, graph_type, this, arc_map); - char_copy->copy_arc_pointers(this, arc_map); - - return copy; -} - - -//////////////////////////////////////////////////////////////////// -// Function: Character::r_copy_char -// Access: Private -// Description: Recursively walks the scene graph hierarchy below the -// Character node, duplicating it while noting the -// orig:copy arc mappings, and also updates any -// GeomNodes found. -//////////////////////////////////////////////////////////////////// -void Character:: -r_copy_char(Node *dest, const Node *source, TypeHandle graph_type, - const Character *from, Character::ArcMap &arc_map) { - if (source->is_of_type(GeomNode::get_class_type())) { - const GeomNode *source_gnode; - GeomNode *dest_gnode; - DCAST_INTO_V(source_gnode, source); - DCAST_INTO_V(dest_gnode, dest); - - dest_gnode->clear(); - int num_geoms = source_gnode->get_num_geoms(); - for (int i = 0; i < num_geoms; i++) { - dDrawable *d = source_gnode->get_geom(i); - if (d->is_of_type(Geom::get_class_type())) { - dest_gnode->add_geom(copy_geom(DCAST(Geom, d), from)); - } else { - dest_gnode->add_geom(d); - } - } - } - - int num_children = source->get_num_children(graph_type); - for (int i = 0; i < num_children; i++) { - NodeRelation *source_arc = source->get_child(graph_type, i); - const Node *source_child = source_arc->get_child(); - nassertv(source_child != (Node *)NULL); - - Node *dest_child; - if (source_child->is_of_type(Character::get_class_type())) { - // We make a special case for nodes of type Character. If we - // encounter one of these, we have a character under a - // character, and the nested character's copy should be called - // instead of ours. - dest_child = source_child->copy_subgraph(graph_type); - - } else { - // Otherwise, we assume that make_copy() will make a suitable - // copy of the node. This does limit the sorts of things we can - // have parented to a Character and expect copy_subgraph() to - // work correctly. Too bad. - dest_child = source_child->make_copy(); - r_copy_char(dest_child, source_child, graph_type, from, arc_map); - } - - NodeRelation *dest_arc = - NodeRelation::create_typed_arc(graph_type, dest, dest_child); - nassertv(dest_arc != (NodeRelation *)NULL); - nassertv(dest_arc->is_exact_type(graph_type)); - - dest_arc->copy_transitions_from(source_arc); - arc_map[source_arc] = dest_arc; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: Character::copy_geom -// Access: Private -// Description: Makes a new copy of the Geom with the dynamic vertex -// arrays replaced to reference this character instead -// of the other one. If no arrays have changed, simply -// returns the same Geom. -//////////////////////////////////////////////////////////////////// -PT(Geom) Character:: -copy_geom(Geom *source, const Character *from) { - GeomBindType bind; - PTA_ushort index; - - PTA_Vertexf coords; - PTA_Normalf norms; - PTA_Colorf colors; - PTA_TexCoordf texcoords; - - PT(Geom) dest = source; - - source->get_coords(coords, index); - if ((coords != (void *)NULL) && (coords == (from->_cv._coords))) { - if (dest == source) { - dest = source->make_copy(); - } - dest->set_coords(_cv._coords, index); - } - - source->get_normals(norms, bind, index); - if (bind != G_OFF && norms == from->_cv._norms) { - if (dest == source) { - dest = source->make_copy(); - } - dest->set_normals(_cv._norms, bind, index); - } - - source->get_colors(colors, bind, index); - if (bind != G_OFF && colors == from->_cv._colors) { - if (dest == source) { - dest = source->make_copy(); - } - dest->set_colors(_cv._colors, bind, index); - } - - source->get_texcoords(texcoords, bind, index); - if (bind != G_OFF && texcoords == from->_cv._texcoords) { - if (dest == source) { - dest = source->make_copy(); - } - dest->set_texcoords(_cv._texcoords, bind, index); - } - - return dest; -} - -//////////////////////////////////////////////////////////////////// -// Function: Character::copy_arc_pointers -// Access: Public -// Description: Creates _net_transform_arcs and _local_transform_arcs -// as appropriate in each of the character's joints, as -// copied from the other character. -//////////////////////////////////////////////////////////////////// -void Character:: -copy_arc_pointers(const Character *from, const Character::ArcMap &arc_map) { - nassertv(_parts.size() == from->_parts.size()); - for (int i = 0; i < (int)_parts.size(); i++) { - if (_parts[i]->is_of_type(CharacterJoint::get_class_type())) { - nassertv(_parts[i] != from->_parts[i]); - CharacterJoint *source_joint; - CharacterJoint *dest_joint; - DCAST_INTO_V(source_joint, from->_parts[i]); - DCAST_INTO_V(dest_joint, _parts[i]); - - CharacterJoint::ArcList::const_iterator ai; - for (ai = source_joint->_net_transform_arcs.begin(); - ai != source_joint->_net_transform_arcs.end(); - ++ai) { - NodeRelation *source_arc = (*ai); - - ArcMap::const_iterator mi; - mi = arc_map.find(source_arc); - if (mi != arc_map.end()) { - NodeRelation *dest_arc = (*mi).second; - - // Here's an internal joint that the source Character was - // animating directly. We'll animate our corresponding - // joint the same way. - dest_joint->add_net_transform(dest_arc); - } - } - - for (ai = source_joint->_local_transform_arcs.begin(); - ai != source_joint->_local_transform_arcs.end(); - ++ai) { - NodeRelation *source_arc = (*ai); - - ArcMap::const_iterator mi; - mi = arc_map.find(source_arc); - if (mi != arc_map.end()) { - NodeRelation *dest_arc = (*mi).second; - - // Here's an internal joint that the source Character was - // animating directly. We'll animate our corresponding - // joint the same way. - dest_joint->add_local_transform(dest_arc); - } - } - } - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: Character::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void Character:: -write_datagram(BamWriter *manager, Datagram &me) -{ - PartBundleNode::write_datagram(manager, me); - _cv.write_datagram(manager, me); - manager->write_pointer(me, _computed_vertices); - - me.add_uint16(_parts.size()); - Parts::const_iterator pi; - for (pi = _parts.begin(); pi != _parts.end(); pi++) { - manager->write_pointer(me, (*pi)); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: Character::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void Character:: -fillin(DatagramIterator& scan, BamReader* manager) -{ - PartBundleNode::fillin(scan, manager); - _cv.fillin(scan, manager); - manager->read_pointer(scan); - - // Read the number of parts to expect in the _parts list, and then - // fill the array up with NULLs. We'll fill in the actual values in - // complete_pointers, later. - int num_parts = scan.get_uint16(); - _parts.clear(); - _parts.reserve(num_parts); - for (int i = 0; i < num_parts; i++) { - manager->read_pointer(scan); - _parts.push_back((PartGroup *)NULL); - } - -#ifdef DO_PSTATS - // Reinitialize our collector with our name, now that we know it. - if (has_name()) { - _char_pcollector = - PStatCollector(_anim_pcollector, get_name()); - } -#endif -} - -//////////////////////////////////////////////////////////////////// -// Function: Character::complete_pointers -// Access: Public -// Description: Takes in a vector of pointers to TypedWritable -// objects that correspond to all the requests for -// pointers that this object made to BamReader. -//////////////////////////////////////////////////////////////////// -int Character:: -complete_pointers(TypedWritable **p_list, BamReader* manager) -{ - int start = PartBundleNode::complete_pointers(p_list, manager); - _computed_vertices = DCAST(ComputedVertices, p_list[start]); - start++; - - int num_parts = _parts.size(); - for (int i = 0; i < num_parts; i++) { - _parts[i] = DCAST(PartGroup, p_list[start + i]); - } - start += num_parts; - - return start; -} - -//////////////////////////////////////////////////////////////////// -// Function: Character::make_Character -// Access: Protected -// Description: Factory method to generate a Character object -//////////////////////////////////////////////////////////////////// -TypedWritable* Character:: -make_Character(const FactoryParams ¶ms) -{ - Character *me = new Character; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: Character::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a Character object -//////////////////////////////////////////////////////////////////// -void Character:: -register_with_read_factory(void) -{ - BamReader::get_factory()->register_factory(get_class_type(), make_Character); -} - - - - diff --git a/panda/src/char/character.h b/panda/src/char/character.h deleted file mode 100644 index bbc1e86c1c..0000000000 --- a/panda/src/char/character.h +++ /dev/null @@ -1,136 +0,0 @@ -// Filename: character.h -// Created by: drose (23Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CHARACTER_H -#define CHARACTER_H - -#include "pandabase.h" - -#include "computedVertices.h" - -#include "partBundleNode.h" -#include "namedNode.h" -#include "vector_PartGroupStar.h" -#include "pointerTo.h" -#include "geom.h" -#include "pStatCollector.h" - -class CharacterJointBundle; -class ComputedVertices; - -//////////////////////////////////////////////////////////////////// -// Class : Character -// Description : -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA Character : public PartBundleNode { -protected: - Character(const Character ©); - -public: - Character(const string &name = ""); - virtual ~Character(); - - virtual Node *make_copy() const; - - virtual bool safe_to_transform() const; - -PUBLISHED: - INLINE CharacterJointBundle *get_bundle() const; - - INLINE ComputedVertices *get_computed_vertices() const; - INLINE int get_num_parts() const; - INLINE PartGroup *get_part(int n) const; - - INLINE void write_parts(ostream &out) const; - INLINE void write_part_values(ostream &out) const; - -public: - virtual void app_traverse(const ArcChain &chain); - -PUBLISHED: - void update(); - -private: - void copy_joints(PartGroup *copy, PartGroup *orig); - - typedef pmap ArcMap; - virtual Node *r_copy_subgraph(TypeHandle graph_type, - InstanceMap &inst_map) const; - void r_copy_char(Node *dest, const Node *source, TypeHandle graph_type, - const Character *from, ArcMap &arc_map); - PT(Geom) copy_geom(Geom *source, const Character *from); - void copy_arc_pointers(const Character *from, const ArcMap &arc_map); - - // These are the actual dynamic vertex pools for this character's - // ComputedVertices--the vertices that it will recompute each frame - // based on the soft-skinning and morphing requirements. Note that - // we store this concretely, instead of as a pointer, just because - // we don't really need to make it a pointer. - DynamicVertices _cv; - - // And this is the object that animates them. It *is* a pointer, so - // it can be shared between multiple instances of this character. - PT(ComputedVertices) _computed_vertices; - - // This vector is used by the ComputedVertices object to index back - // into our joints and sliders. - typedef vector_PartGroupStar Parts; - Parts _parts; - - // Statistics - PStatCollector _char_pcollector; - static PStatCollector _anim_pcollector; - -public: - static void register_with_read_factory(void); - virtual void write_datagram(BamWriter* manager, Datagram &me); - virtual int complete_pointers(TypedWritable **p_list, - BamReader *manager); - - static TypedWritable *make_Character(const FactoryParams ¶ms); - -protected: - 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() { - PartBundleNode::init_type(); - register_type(_type_handle, "Character", - PartBundleNode::get_class_type()); - } - -private: - static TypeHandle _type_handle; - - friend class CharacterMaker; - friend class ComputedVerticesMaker; - friend class ComputedVertices; -}; - -#include "character.I" - -#endif - diff --git a/panda/src/char/characterJoint.cxx b/panda/src/char/characterJoint.cxx index bafa3d34f3..b9e86cc8d1 100644 --- a/panda/src/char/characterJoint.cxx +++ b/panda/src/char/characterJoint.cxx @@ -19,12 +19,11 @@ #include "characterJoint.h" #include "config_char.h" -#include -#include -#include -#include -#include -#include +#include "compose_matrix.h" +#include "datagram.h" +#include "datagramIterator.h" +#include "bamReader.h" +#include "bamWriter.h" TypeHandle CharacterJoint::_type_handle; @@ -48,7 +47,7 @@ CharacterJoint(const CharacterJoint ©) : _net_transform(copy._net_transform), _initial_net_transform_inverse(copy._initial_net_transform_inverse) { - // We don't copy the sets of transform arcs. + // We don't copy the sets of transform nodes. } //////////////////////////////////////////////////////////////////// @@ -120,46 +119,6 @@ update_internals(PartGroup *parent, bool self_changed, bool parent_changed) { } } - if (net_changed && !_net_transform_arcs.empty()) { - PT(TransformTransition) t = new TransformTransition(_net_transform); - - ArcList::iterator ai; - ai = _net_transform_arcs.begin(); - while (ai != _net_transform_arcs.end()) { - NodeRelation *arc = *ai; - if (arc->is_attached()) { - arc->set_transition(t); - ++ai; - } else { - // The arc is now invalid; its geometry must have been - // removed. Remove the arc from our set. - ArcList::iterator invalid = ai; - ++ai; - _net_transform_arcs.erase(invalid); - } - } - } - - if (self_changed && !_local_transform_arcs.empty()) { - PT(TransformTransition) t = new TransformTransition(_value); - - ArcList::iterator ai; - ai = _local_transform_arcs.begin(); - while (ai != _local_transform_arcs.end()) { - NodeRelation *arc = *ai; - if (arc->is_attached()) { - arc->set_transition(t); - ++ai; - } else { - // The arc is now invalid; its geometry must have been - // removed. Remove the arc from our set. - ArcList::iterator invalid = ai; - ++ai; - _local_transform_arcs.erase(invalid); - } - } - } - if (net_changed && !_net_transform_nodes.empty()) { CPT(TransformState) t = TransformState::make_mat(_net_transform); @@ -187,85 +146,6 @@ update_internals(PartGroup *parent, bool self_changed, bool parent_changed) { return self_changed || net_changed; } -//////////////////////////////////////////////////////////////////// -// Function: CharacterJoint::add_net_transform -// Access: Public -// Description: Adds the indicated arc to the list of arcs that will -// be updated each frame with the joint's net transform -// from the root. Returns true if the arc is -// successfully added, false if it had already been -// added. -//////////////////////////////////////////////////////////////////// -bool CharacterJoint:: -add_net_transform(NodeRelation *arc) { - return _net_transform_arcs.insert(arc).second; -} - -//////////////////////////////////////////////////////////////////// -// Function: CharacterJoint::remove_net_transform -// Access: Public -// Description: Removes the indicated arc from the list of arcs that -// will be updated each frame with the joint's net -// transform from the root. Returns true if the arc is -// successfully removed, false if it was not on the -// list. -//////////////////////////////////////////////////////////////////// -bool CharacterJoint:: -remove_net_transform(NodeRelation *arc) { - return (_net_transform_arcs.erase(arc) > 0); -} - -//////////////////////////////////////////////////////////////////// -// Function: CharacterJoint::has_net_transform -// Access: Public -// Description: Returns true if the arc is on the list of arcs that -// will be updated each frame with the joint's net -// transform from the root, false otherwise. -//////////////////////////////////////////////////////////////////// -bool CharacterJoint:: -has_net_transform(NodeRelation *arc) const { - return (_net_transform_arcs.count(arc) > 0); -} - -//////////////////////////////////////////////////////////////////// -// Function: CharacterJoint::add_local_transform -// Access: Public -// Description: Adds the indicated arc to the list of arcs that will -// be updated each frame with the joint's local -// transform from its parent. Returns true if the arc -// is successfully added, false if it had already been -// added. -//////////////////////////////////////////////////////////////////// -bool CharacterJoint:: -add_local_transform(NodeRelation *arc) { - return _local_transform_arcs.insert(arc).second; -} - -//////////////////////////////////////////////////////////////////// -// Function: CharacterJoint::remove_local_transform -// Access: Public -// Description: Removes the indicated arc from the list of arcs that -// will be updated each frame with the joint's local -// transform from its parent. Returns true if the arc -// is successfully removed, false if it was not on the -// list. -//////////////////////////////////////////////////////////////////// -bool CharacterJoint:: -remove_local_transform(NodeRelation *arc) { - return (_local_transform_arcs.erase(arc) > 0); -} - -//////////////////////////////////////////////////////////////////// -// Function: CharacterJoint::has_local_transform -// Access: Public -// Description: Returns true if the arc is on the list of arcs that -// will be updated each frame with the joint's local -// transform from its parent, false otherwise. -//////////////////////////////////////////////////////////////////// -bool CharacterJoint:: -has_local_transform(NodeRelation *arc) const { - return (_local_transform_arcs.count(arc) > 0); -} //////////////////////////////////////////////////////////////////// // Function: CharacterJoint::add_net_transform @@ -316,7 +196,6 @@ has_net_transform(PandaNode *node) const { //////////////////////////////////////////////////////////////////// void CharacterJoint:: clear_net_transforms() { - _net_transform_arcs.clear(); _net_transform_nodes.clear(); } @@ -369,7 +248,6 @@ has_local_transform(PandaNode *node) const { //////////////////////////////////////////////////////////////////// void CharacterJoint:: clear_local_transforms() { - _local_transform_arcs.clear(); _local_transform_nodes.clear(); } @@ -382,53 +260,13 @@ clear_local_transforms() { void CharacterJoint:: write_datagram(BamWriter *manager, Datagram &me) { - ArcList::iterator ai; NodeList::iterator ni; - - // First, make sure all of our arcs are still valid, before we try - // to write them out. Remove any invalid arcs. - ai = _net_transform_arcs.begin(); - while (ai != _net_transform_arcs.end()) { - NodeRelation *arc = *ai; - if (arc->is_attached()) { - ++ai; - } else { - // The arc is now invalid; its geometry must have been - // removed. Remove the arc from our set. - ArcList::iterator invalid = ai; - ++ai; - _net_transform_arcs.erase(invalid); - } - } - ai = _local_transform_arcs.begin(); - while (ai != _local_transform_arcs.end()) { - NodeRelation *arc = *ai; - if (arc->is_attached()) { - ++ai; - } else { - // The arc is now invalid; its geometry must have been - // removed. Remove the arc from our set. - ArcList::iterator invalid = ai; - ++ai; - _local_transform_arcs.erase(invalid); - } - } - MovingPartMatrix::write_datagram(manager, me); - me.add_uint16(_net_transform_arcs.size()); - for(ai = _net_transform_arcs.begin(); - ai != _net_transform_arcs.end(); - ai++) { - manager->write_pointer(me, (*ai)); - } - - me.add_uint16(_local_transform_arcs.size()); - for(ai = _local_transform_arcs.begin(); - ai != _local_transform_arcs.end(); - ai++) { - manager->write_pointer(me, (*ai)); - } + // Legacy. We don't store the list of arcs any more. Remove this + // when we go to bam version 4.0. + me.add_uint16(0); + me.add_uint16(0); me.add_uint16(_net_transform_nodes.size()); for(ni = _net_transform_nodes.begin(); @@ -459,15 +297,12 @@ void CharacterJoint:: fillin(DatagramIterator &scan, BamReader *manager) { int i; MovingPartMatrix::fillin(scan, manager); - _num_net_arcs = scan.get_uint16(); - for(i = 0; i < _num_net_arcs; i++) { - manager->read_pointer(scan); - } - _num_local_arcs = scan.get_uint16(); - for(i = 0; i < _num_local_arcs; i++) { - manager->read_pointer(scan); - } + // Remove this when we go to bam 4.0. + int num_net_arcs = scan.get_uint16(); + nassertv(num_net_arcs == 0); + int num_local_arcs = scan.get_uint16(); + nassertv(num_local_arcs == 0); if (manager->get_file_minor_ver() < 7) { // No _node lists before version 3.7. @@ -501,14 +336,6 @@ complete_pointers(TypedWritable **p_list, BamReader* manager) int pi = MovingPartMatrix::complete_pointers(p_list, manager); int i; - for (i = 0; i < _num_net_arcs; i++) { - add_net_transform(DCAST(NodeRelation, p_list[pi++])); - } - - for (i = 0; i < _num_local_arcs; i++) { - add_local_transform(DCAST(NodeRelation, p_list[pi++])); - } - for (i = 0; i < _num_net_nodes; i++) { add_net_transform(DCAST(PandaNode, p_list[pi++])); } diff --git a/panda/src/char/characterJoint.h b/panda/src/char/characterJoint.h index a85e25df44..db67235062 100644 --- a/panda/src/char/characterJoint.h +++ b/panda/src/char/characterJoint.h @@ -19,13 +19,10 @@ #ifndef CHARACTERJOINT_H #define CHARACTERJOINT_H -#include +#include "pandabase.h" -#include -#include -#include -#include -#include +#include "movingPartMatrix.h" +#include "pandaNode.h" //////////////////////////////////////////////////////////////////// // Class : CharacterJoint @@ -47,14 +44,6 @@ public: bool parent_changed); PUBLISHED: - bool add_net_transform(NodeRelation *arc); - bool remove_net_transform(NodeRelation *arc); - bool has_net_transform(NodeRelation *arc) const; - - bool add_local_transform(NodeRelation *arc); - bool remove_local_transform(NodeRelation *arc); - bool has_local_transform(NodeRelation *arc) const; - bool add_net_transform(PandaNode *node); bool remove_net_transform(PandaNode *node); bool has_net_transform(PandaNode *node) const; @@ -66,10 +55,6 @@ PUBLISHED: void clear_local_transforms(); private: - typedef pset< PT_NodeRelation > ArcList; - ArcList _net_transform_arcs; - ArcList _local_transform_arcs; - typedef pset< PT(PandaNode) > NodeList; NodeList _net_transform_nodes; NodeList _local_transform_nodes; @@ -86,7 +71,6 @@ protected: void fillin(DatagramIterator& scan, BamReader* manager); private: - int _num_net_arcs, _num_local_arcs; int _num_net_nodes, _num_local_nodes; public: @@ -94,7 +78,6 @@ public: // for the CharacterMaker's convenenience while creating the // character. It does not store any meaningful value after // creation is complete. - PT_NamedNode _geom_node; PT(PandaNode) _qpgeom_node; // These are filled in as the joint animates. diff --git a/panda/src/char/characterJointBundle.I b/panda/src/char/characterJointBundle.I index 5284f7196c..c120c36096 100644 --- a/panda/src/char/characterJointBundle.I +++ b/panda/src/char/characterJointBundle.I @@ -20,7 +20,7 @@ // #include reference, and please don't bother us about it. The line // must be exactly as shown. /* okcircular */ -#include "character.h" +#include "qpcharacter.h" //////////////////////////////////////////////////////////////////// // Function: CharacterJointBundle::Copy Constructor @@ -35,12 +35,12 @@ CharacterJointBundle(const CharacterJointBundle ©) : } //////////////////////////////////////////////////////////////////// -// Function: CharacterJointBundle::get_node +// Function: CharacterJointBundle::get_qpnode // Access: Public // Description: Returns the Character node associated with this // PartBundle. //////////////////////////////////////////////////////////////////// -INLINE Character *CharacterJointBundle:: -get_node() const { - return DCAST(Character, PartBundle::get_node()); +INLINE qpCharacter *CharacterJointBundle:: +get_qpnode() const { + return DCAST(qpCharacter, PartBundle::get_qpnode()); } diff --git a/panda/src/char/characterJointBundle.cxx b/panda/src/char/characterJointBundle.cxx index 00f12606a9..7020f90340 100644 --- a/panda/src/char/characterJointBundle.cxx +++ b/panda/src/char/characterJointBundle.cxx @@ -17,11 +17,10 @@ //////////////////////////////////////////////////////////////////// #include "characterJointBundle.h" -#include "character.h" -#include -#include -#include -#include +#include "datagram.h" +#include "datagramIterator.h" +#include "bamReader.h" +#include "bamWriter.h" TypeHandle CharacterJointBundle::_type_handle; diff --git a/panda/src/char/characterJointBundle.h b/panda/src/char/characterJointBundle.h index 175ee5f9ed..680d23d1be 100644 --- a/panda/src/char/characterJointBundle.h +++ b/panda/src/char/characterJointBundle.h @@ -19,13 +19,13 @@ #ifndef CHARACTERJOINTBUNDLE_H #define CHARACTERJOINTBUNDLE_H -#include +#include "pandabase.h" -#include -#include -#include +#include "partBundle.h" +#include "partGroup.h" +#include "animControl.h" -class Character; +class qpCharacter; //////////////////////////////////////////////////////////////////// // Class : CharacterJointBundle @@ -40,7 +40,7 @@ public: CharacterJointBundle(const string &name = ""); PUBLISHED: - INLINE Character *get_node() const; + INLINE qpCharacter *get_qpnode() const; public: virtual PartGroup *make_copy() const; diff --git a/panda/src/char/computedVertices.cxx b/panda/src/char/computedVertices.cxx index d4a258944e..6d988848a2 100644 --- a/panda/src/char/computedVertices.cxx +++ b/panda/src/char/computedVertices.cxx @@ -19,15 +19,15 @@ #include "computedVertices.h" #include "characterJoint.h" -#include "character.h" #include "qpcharacter.h" #include "config_char.h" -#include -#include -#include -#include -#include +#include "datagram.h" +#include "datagramIterator.h" +#include "bamReader.h" +#include "bamWriter.h" +#include "ioPtaDatagramLinMath.h" + #include TypeHandle ComputedVertices::_type_handle; @@ -54,11 +54,10 @@ VertexTransform(const VertexTransform ©) : // vertices in the table, according to the values of the // relevant slider. //////////////////////////////////////////////////////////////////// -// QP -template +template static void compute_morphs(ValueType *table, const pvector &morph_list, - Character *character) { + qpCharacter *character) { pvector::const_iterator mli; for (mli = morph_list.begin(); mli != morph_list.end(); ++mli) { const MorphType &morph = (*mli); @@ -129,108 +128,6 @@ read_datagram(DatagramIterator &source) } } -//////////////////////////////////////////////////////////////////// -// Function: ComputedVertices::update -// Access: Public -// Description: Recomputes all of the _coords, _norms, etc. values -// based on the values in _orig_coords, _orig_norms, -// etc., and the current positions of all of the joints. -//////////////////////////////////////////////////////////////////// -void ComputedVertices:: -update(Character *character) { - nassertv(character != (Character *)NULL); - nassertv(character->_cv._coords.size() == _orig_coords.size()); - nassertv(character->_cv._norms.size() == _orig_norms.size()); - nassertv(character->_cv._texcoords.size() == _orig_texcoords.size()); - nassertv(character->_cv._colors.size() == _orig_colors.size()); - - const Vertexf *orig_coords = _orig_coords; - const Normalf *orig_norms = _orig_norms; - - memset(character->_cv._coords, 0, sizeof(Vertexf) * character->_cv._coords.size()); - memset(character->_cv._norms, 0, sizeof(Normalf) * character->_cv._norms.size()); - - if (!_vertex_morphs.empty()) { - // We have some vertex morphs. Compute them first. - int table_size = sizeof(Vertexf) * _orig_coords.size(); - Vertexf *morphed_coords = (Vertexf *)alloca(table_size); - memcpy(morphed_coords, _orig_coords, table_size); - - compute_morphs(morphed_coords, _vertex_morphs, character); - orig_coords = morphed_coords; - } - - if (!_normal_morphs.empty()) { - // We also have some normal morphs. Compute them too. - int table_size = sizeof(Normalf) * _orig_norms.size(); - Normalf *morphed_norms = (Normalf *)alloca(table_size); - memcpy(morphed_norms, _orig_norms, table_size); - - compute_morphs(morphed_norms, _normal_morphs, character); - orig_norms = morphed_norms; - } - - if (!_texcoord_morphs.empty()) { - // We have some uv morphs. These don't particularly need to be - // done before the joints are computed, but do them now anyway. - int table_size = sizeof(TexCoordf) * _orig_texcoords.size(); - - // **** Is this right? Test it! - // TexCoordf *morphed_texcoords = (TexCoordf *)alloca(table_size); - memcpy(character->_cv._texcoords, _orig_texcoords, table_size); - - compute_morphs(character->_cv._texcoords.p(), _texcoord_morphs, character); - } - - if (!_color_morphs.empty()) { - // We have some color morphs. Do these now too. - int table_size = sizeof(Colorf) * _orig_colors.size(); - - // **** Is this right? Test it! - // Colorf *morphed_colors = (Colorf *)alloca(table_size); - memcpy(character->_cv._colors, _orig_colors, table_size); - - compute_morphs(character->_cv._colors.p(), _color_morphs, character); - } - - // Now that we've computed all the morphs, it's safe to transform - // vertices into their proper coordinate space, according to the - // current positions of all the joints. - - LMatrix4f mat = LMatrix4f::ident_mat(); - int last_joint_index = -1; - - VertexTransforms::const_iterator vti; - for (vti = _transforms.begin(); vti != _transforms.end(); ++vti) { - const VertexTransform &vt = (*vti); - - // We cache the matrix from the last joint, because we are likely - // to encounter the same joint several times in a row. - if (vt._joint_index != last_joint_index) { - last_joint_index = vt._joint_index; - - // We won't encounter -1 after the first few joints. - nassertv(vt._joint_index >= 0); - CharacterJoint *joint; - DCAST_INTO_V(joint, character->get_part(vt._joint_index)); - - mat = - joint->_initial_net_transform_inverse * - joint->_net_transform; - } - - Vertices::const_iterator vi; - for (vi = vt._vindex.begin(); vi != vt._vindex.end(); ++vi) { - int i = (*vi); - character->_cv._coords[i] += (orig_coords[i] * mat) * vt._effect; - } - for (vi = vt._nindex.begin(); vi != vt._nindex.end(); ++vi) { - int i = (*vi); - character->_cv._norms[i] += (orig_norms[i] * mat) * vt._effect; - } - } -} - //////////////////////////////////////////////////////////////////// // Function: ComputedVertices::update // Access: Public @@ -333,46 +230,6 @@ update(qpCharacter *character) { } } -//////////////////////////////////////////////////////////////////// -// Function: ComputedVertices::make_orig -// Access: Public -// Description: Copies all the values loaded in the _coords, _norms, -// etc. arrays into the corresponding _orig_coords, -// etc. arrays. -//////////////////////////////////////////////////////////////////// -void ComputedVertices:: -make_orig(Character *character) { - nassertv(character != (Character *)NULL); - - if (character->_cv._coords.empty()) { - _orig_coords.clear(); - } else { - _orig_coords = PTA_Vertexf::empty_array(0); - _orig_coords.v() = character->_cv._coords.v(); - } - - if (character->_cv._norms.empty()) { - _orig_norms.clear(); - } else { - _orig_norms = PTA_Normalf::empty_array(0); - _orig_norms.v() = character->_cv._norms.v(); - } - - if (character->_cv._colors.empty()) { - _orig_colors.clear(); - } else { - _orig_colors = PTA_Colorf::empty_array(0); - _orig_colors.v() = character->_cv._colors.v(); - } - - if (character->_cv._texcoords.empty()) { - _orig_texcoords.clear(); - } else { - _orig_texcoords = PTA_TexCoordf::empty_array(0); - _orig_texcoords.v() = character->_cv._texcoords.v(); - } -} - //////////////////////////////////////////////////////////////////// // Function: ComputedVertices::make_orig // Access: Public @@ -419,7 +276,7 @@ make_orig(qpCharacter *character) { // Description: //////////////////////////////////////////////////////////////////// void ComputedVertices:: -write(ostream &out, Character *character) const { +write(ostream &out, qpCharacter *character) const { VertexTransforms::const_iterator vti; out << "ComputedVertices:\n"; diff --git a/panda/src/char/computedVertices.h b/panda/src/char/computedVertices.h index 5a81d09148..7fd3936fc1 100644 --- a/panda/src/char/computedVertices.h +++ b/panda/src/char/computedVertices.h @@ -27,7 +27,6 @@ #include "vector_ushort.h" #include "typedWritableReferenceCount.h" -class Character; class qpCharacter; class CharacterJoint; @@ -42,12 +41,10 @@ class EXPCL_PANDA ComputedVertices : public TypedWritableReferenceCount { public: INLINE ComputedVertices(); - void update(Character *character); void update(qpCharacter *character); - void make_orig(Character *character); void make_orig(qpCharacter *character); - void write(ostream &out, Character *character) const; + void write(ostream &out, qpCharacter *character) const; private: typedef vector_ushort Vertices; diff --git a/panda/src/char/config_char.cxx b/panda/src/char/config_char.cxx index 02cec32870..549e29ba36 100644 --- a/panda/src/char/config_char.cxx +++ b/panda/src/char/config_char.cxx @@ -18,7 +18,6 @@ #include "config_char.h" -#include "character.h" #include "qpcharacter.h" #include "characterJoint.h" #include "characterJointBundle.h" @@ -67,7 +66,6 @@ init_libchar() { } initialized = true; - Character::init_type(); qpCharacter::init_type(); CharacterJoint::init_type(); CharacterJointBundle::init_type(); @@ -83,7 +81,6 @@ init_libchar() { //Registration of writeable object's creation //functions with BamReader's factory - Character::register_with_read_factory(); qpCharacter::register_with_read_factory(); CharacterJoint::register_with_read_factory(); CharacterJointBundle::register_with_read_factory(); diff --git a/panda/src/collide/Sources.pp b/panda/src/collide/Sources.pp index affeca08d4..2ceb136237 100644 --- a/panda/src/collide/Sources.pp +++ b/panda/src/collide/Sources.pp @@ -4,90 +4,60 @@ #begin lib_target #define TARGET collide #define LOCAL_LIBS \ - sgmanip tform sgraphutil gobj graph putil \ + tform gobj pgraph putil \ pstatclient #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx #define SOURCES \ - collisionEntry.I collisionEntry.h \ qpcollisionEntry.I qpcollisionEntry.h \ - collisionHandler.h \ qpcollisionHandler.h \ - collisionHandlerEvent.I collisionHandlerEvent.h \ qpcollisionHandlerEvent.I qpcollisionHandlerEvent.h \ - collisionHandlerFloor.I collisionHandlerFloor.h \ qpcollisionHandlerFloor.I qpcollisionHandlerFloor.h \ - collisionHandlerPhysical.I collisionHandlerPhysical.h \ qpcollisionHandlerPhysical.I qpcollisionHandlerPhysical.h \ - collisionHandlerPusher.I collisionHandlerPusher.h \ qpcollisionHandlerPusher.I qpcollisionHandlerPusher.h \ - collisionHandlerQueue.h \ qpcollisionHandlerQueue.h \ - collisionLevelState.I collisionLevelState.h \ qpcollisionLevelState.I qpcollisionLevelState.h \ - collisionNode.I collisionNode.h \ qpcollisionNode.I qpcollisionNode.h \ collisionPlane.I collisionPlane.h \ collisionPolygon.I collisionPolygon.h collisionRay.I \ collisionRay.h collisionSegment.I collisionSegment.h \ collisionSolid.I collisionSolid.h collisionSphere.I \ collisionSphere.h \ - collisionTraverser.I collisionTraverser.h \ qpcollisionTraverser.I qpcollisionTraverser.h \ config_collide.h #define INCLUDED_SOURCES \ - collisionEntry.cxx \ qpcollisionEntry.cxx \ - collisionHandler.cxx \ qpcollisionHandler.cxx \ - collisionHandlerEvent.cxx \ qpcollisionHandlerEvent.cxx \ - collisionHandlerFloor.cxx \ qpcollisionHandlerFloor.cxx \ - collisionHandlerPhysical.cxx \ qpcollisionHandlerPhysical.cxx \ - collisionHandlerPusher.cxx \ qpcollisionHandlerPusher.cxx \ - collisionHandlerQueue.cxx \ qpcollisionHandlerQueue.cxx \ - collisionLevelState.cxx \ qpcollisionLevelState.cxx \ - collisionNode.cxx \ qpcollisionNode.cxx \ collisionPlane.cxx \ collisionPolygon.cxx collisionRay.cxx collisionSegment.cxx \ collisionSolid.cxx collisionSphere.cxx \ - collisionTraverser.cxx \ qpcollisionTraverser.cxx \ config_collide.cxx #define INSTALL_HEADERS \ - collisionEntry.I collisionEntry.h \ qpcollisionEntry.I qpcollisionEntry.h \ - collisionHandler.h \ qpcollisionHandler.h \ - collisionHandlerEvent.I collisionHandlerEvent.h \ qpcollisionHandlerEvent.I qpcollisionHandlerEvent.h \ - collisionHandlerFloor.I collisionHandlerFloor.h \ qpcollisionHandlerFloor.I qpcollisionHandlerFloor.h \ - collisionHandlerPhysical.I collisionHandlerPhysical.h \ qpcollisionHandlerPhysical.I qpcollisionHandlerPhysical.h \ - collisionHandlerPusher.I collisionHandlerPusher.h \ qpcollisionHandlerPusher.I qpcollisionHandlerPusher.h \ - collisionHandlerQueue.h \ qpcollisionHandlerQueue.h \ - collisionLevelState.I collisionLevelState.h \ qpcollisionLevelState.I qpcollisionLevelState.h \ - collisionNode.I collisionNode.h \ qpcollisionNode.I qpcollisionNode.h \ collisionPlane.I collisionPlane.h \ collisionPolygon.I collisionPolygon.h collisionRay.I collisionRay.h \ collisionSegment.I collisionSegment.h \ collisionSolid.I collisionSolid.h collisionSphere.I \ collisionSphere.h \ - collisionTraverser.I collisionTraverser.h \ qpcollisionTraverser.I qpcollisionTraverser.h #define IGATESCAN all diff --git a/panda/src/collide/collide_composite1.cxx b/panda/src/collide/collide_composite1.cxx index cc1af2b86e..bfa1229b00 100644 --- a/panda/src/collide/collide_composite1.cxx +++ b/panda/src/collide/collide_composite1.cxx @@ -1,21 +1,12 @@ #include "config_collide.cxx" -#include "collisionEntry.cxx" #include "qpcollisionEntry.cxx" -#include "collisionHandler.cxx" #include "qpcollisionHandler.cxx" -#include "collisionHandlerEvent.cxx" #include "qpcollisionHandlerEvent.cxx" -#include "collisionHandlerFloor.cxx" #include "qpcollisionHandlerFloor.cxx" -#include "collisionHandlerPhysical.cxx" #include "qpcollisionHandlerPhysical.cxx" -#include "collisionHandlerPusher.cxx" #include "qpcollisionHandlerPusher.cxx" -#include "collisionHandlerQueue.cxx" #include "qpcollisionHandlerQueue.cxx" -#include "collisionLevelState.cxx" #include "qpcollisionLevelState.cxx" -#include "collisionNode.cxx" #include "qpcollisionNode.cxx" diff --git a/panda/src/collide/collide_composite2.cxx b/panda/src/collide/collide_composite2.cxx index d4f5031734..66df431553 100644 --- a/panda/src/collide/collide_composite2.cxx +++ b/panda/src/collide/collide_composite2.cxx @@ -5,7 +5,6 @@ #include "collisionSegment.cxx" #include "collisionSolid.cxx" #include "collisionSphere.cxx" -#include "collisionTraverser.cxx" #include "qpcollisionTraverser.cxx" diff --git a/panda/src/collide/collisionEntry.I b/panda/src/collide/collisionEntry.I deleted file mode 100644 index c450c1579e..0000000000 --- a/panda/src/collide/collisionEntry.I +++ /dev/null @@ -1,297 +0,0 @@ -// Filename: collisionEntry.I -// Created by: drose (24Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CollisionEntry:: -CollisionEntry() { - _flags = 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::get_from -// Access: Public -// Description: Returns the CollisionSolid pointer for the particular -// solid that triggered this collision. -//////////////////////////////////////////////////////////////////// -INLINE const CollisionSolid *CollisionEntry:: -get_from() const { - return _from; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::has_into -// Access: Public -// Description: Returns true if the "into" solid is, in fact, a -// CollisionSolid, and its pointer is known (in which -// case get_into() may be called to retrieve it). If -// this returns false, the collision was detected into a -// GeomNode, and there is no CollisionSolid pointer to -// be retrieved. -//////////////////////////////////////////////////////////////////// -INLINE bool CollisionEntry:: -has_into() const { - return (_into != (CollisionSolid *)NULL); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::get_into -// Access: Public -// Description: Returns the CollisionSolid pointer for the particular -// solid was collided into. This pointer might be NULL -// if the collision was into a piece of visible -// geometry, instead of a normal CollisionSolid -// collision; see has_into(). -//////////////////////////////////////////////////////////////////// -INLINE const CollisionSolid *CollisionEntry:: -get_into() const { - return _into; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::get_from_node -// Access: Public -// Description: Returns the node that contains the CollisionSolid -// that triggered this collision. This will be a node -// that has been added to a CollisionTraverser via -// add_collider(). -//////////////////////////////////////////////////////////////////// -INLINE CollisionNode *CollisionEntry:: -get_from_node() const { - return _from_node; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::get_from_space -// Access: Public -// Description: Returns the global coordinate space of the -// CollisionNode returned by get_from_node(), as of the -// time of the collision. This will be equivalent to a -// wrt() from the node to render. -//////////////////////////////////////////////////////////////////// -INLINE const LMatrix4f &CollisionEntry:: -get_from_space() const { - return _from_space; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::get_into_node -// Access: Public -// Description: Returns the node that contains the CollisionSolid -// that was collided into. This returns a NamedNode -// pointer instead of something more specific, because -// it might be either a CollisionNode or a GeomNode. -// -// Also see get_into_node_path(). -//////////////////////////////////////////////////////////////////// -INLINE NamedNode *CollisionEntry:: -get_into_node() const { - return _into_node; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::get_into_node_path -// Access: Public -// Description: Returns the NodePath that represents the specific -// CollisionNode or GeomNode instance that was collided -// into. This is the same node returned by -// get_into_node(), represented as a NodePath; however, -// it may be more useful because the NodePath can -// resolve the particular instance of the node, if there -// is more than one. -//////////////////////////////////////////////////////////////////// -INLINE const NodePath &CollisionEntry:: -get_into_node_path() const { - return _into_node_path; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::get_into_space -// Access: Public -// Description: Returns the global coordinate space of the -// CollisionNode or GeomNode returned by -// get_into_node(), as of the time of the collision. -//////////////////////////////////////////////////////////////////// -INLINE const LMatrix4f &CollisionEntry:: -get_into_space() const { - return _into_space; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::get_wrt_space -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE const LMatrix4f &CollisionEntry:: -get_wrt_space() const { - return _wrt_space; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::get_inv_wrt_space -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE const LMatrix4f &CollisionEntry:: -get_inv_wrt_space() const { - return _inv_wrt_space; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::set_into_intersection_point -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void CollisionEntry:: -set_into_intersection_point(const LPoint3f &point) { - _into_intersection_point = point; - _flags |= F_has_into_intersection_point; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::has_into_intersection_point -// Access: Public -// Description: Returns true if the detected collision knows its -// intersection point in the coordinate space of the -// collided-into object, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool CollisionEntry:: -has_into_intersection_point() const { - return (_flags & F_has_into_intersection_point) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::get_into_intersection_point -// Access: Public -// Description: Returns the intersection point in the coordinate -// space of the collided-into object. It is an error to -// call this if has_into_intersection_point() returns -// false. -//////////////////////////////////////////////////////////////////// -INLINE const LPoint3f &CollisionEntry:: -get_into_intersection_point() const { - nassertr(has_into_intersection_point(), _into_intersection_point); - return _into_intersection_point; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::has_from_intersection_point -// Access: Public -// Description: Returns true if the detected collision knows its -// intersection point in the coordinate space of the -// colliding object, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool CollisionEntry:: -has_from_intersection_point() const { - // Since we derive the from_intersection_point from the - // into_intersection_point, this is really the same question. - return has_into_intersection_point(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::get_from_intersection_point -// Access: Public -// Description: Returns the intersection point in the coordinate -// space of the colliding object. It is an error to -// call this if has_from_intersection_point() returns -// false. -//////////////////////////////////////////////////////////////////// -INLINE LPoint3f CollisionEntry:: -get_from_intersection_point() const { - return get_into_intersection_point() * get_inv_wrt_space(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::set_into_surface_normal -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void CollisionEntry:: -set_into_surface_normal(const LVector3f &normal) { - _into_surface_normal = normal; - _flags |= F_has_into_surface_normal; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::has_into_surface_normal -// Access: Public -// Description: Returns true if the detected collision knows the -// surface normal of the collided-into object at the -// point of the collision, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool CollisionEntry:: -has_into_surface_normal() const { - return (_flags & F_has_into_surface_normal) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::get_into_surface_normal -// Access: Public -// Description: Returns the surface normal of the collided-into -// object at the point of the collision. It is an error -// to call this if has_into_surface_normal() returns -// false. -//////////////////////////////////////////////////////////////////// -INLINE const LVector3f &CollisionEntry:: -get_into_surface_normal() const { - nassertr(has_into_surface_normal(), _into_surface_normal); - return _into_surface_normal; -} - - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::set_into_depth -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void CollisionEntry:: -set_into_depth(float depth) { - _into_depth = depth; - _flags |= F_has_into_depth; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::has_into_depth -// Access: Public -// Description: Returns true if the collision entry knows how "deep" -// the collision was into the collided-into object; that -// is, how far into the surface of the collided-into -// object the colliding object has penetrated. -//////////////////////////////////////////////////////////////////// -INLINE bool CollisionEntry:: -has_into_depth() const { - return (_flags & F_has_into_depth) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::get_into_depth -// Access: Public -// Description: Returns how "deep" the collision was into the -// collided-into object; that is, how far into the -// surface of the collided-into object the colliding -// object has penetrated. It is an error to call this -// if has_into_depth() returns false. -//////////////////////////////////////////////////////////////////// -INLINE float CollisionEntry:: -get_into_depth() const { - nassertr(has_into_depth(), 0.0); - return _into_depth; -} diff --git a/panda/src/collide/collisionEntry.cxx b/panda/src/collide/collisionEntry.cxx deleted file mode 100644 index 8397700183..0000000000 --- a/panda/src/collide/collisionEntry.cxx +++ /dev/null @@ -1,66 +0,0 @@ -// Filename: collisionEntry.cxx -// Created by: drose (24Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "collisionEntry.h" - -TypeHandle CollisionEntry::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -CollisionEntry:: -CollisionEntry(const CollisionEntry ©) : - _from(copy._from), - _into(copy._into), - _from_node(copy._from_node), - _into_node(copy._into_node), - _into_node_path(copy._into_node_path), - _from_space(copy._from_space), - _into_space(copy._into_space), - _wrt_space(copy._wrt_space), - _inv_wrt_space(copy._inv_wrt_space), - _flags(copy._flags), - _into_intersection_point(copy._into_intersection_point), - _into_surface_normal(copy._into_surface_normal), - _into_depth(copy._into_depth) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionEntry::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void CollisionEntry:: -operator = (const CollisionEntry ©) { - _from = copy._from; - _into = copy._into; - _from_node = copy._from_node; - _into_node = copy._into_node; - _into_node_path = copy._into_node_path; - _from_space = copy._from_space; - _into_space = copy._into_space; - _wrt_space = copy._wrt_space; - _inv_wrt_space = copy._inv_wrt_space; - _flags = copy._flags; - _into_intersection_point = copy._into_intersection_point; - _into_surface_normal = copy._into_surface_normal; - _into_depth = copy._into_depth; -} diff --git a/panda/src/collide/collisionEntry.h b/panda/src/collide/collisionEntry.h deleted file mode 100644 index bd0033e208..0000000000 --- a/panda/src/collide/collisionEntry.h +++ /dev/null @@ -1,131 +0,0 @@ -// Filename: collisionEntry.h -// Created by: drose (24Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef COLLISIONENTRY_H -#define COLLISIONENTRY_H - -#include - -#include "collisionSolid.h" -#include "collisionNode.h" - -#include -#include -#include -#include -#include - -/////////////////////////////////////////////////////////////////// -// Class : CollisionEntry -// Description : Defines a single collision event. One of these is -// created for each collision detected by a -// CollisionTraverser, to be dealt with by the -// CollisionHandler. -// -// A CollisionEntry provides slots for a number of data -// values (such as intersection point and normal) that -// might or might not be known for each collision. It -// is up to the handler to determine what information is -// known and to do the right thing with it. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA CollisionEntry : public TypedReferenceCount { -public: - INLINE CollisionEntry(); - CollisionEntry(const CollisionEntry ©); - void operator = (const CollisionEntry ©); - -PUBLISHED: - INLINE const CollisionSolid *get_from() const; - INLINE bool has_into() const; - INLINE const CollisionSolid *get_into() const; - - INLINE CollisionNode *get_from_node() const; - INLINE NamedNode *get_into_node() const; - INLINE const NodePath &get_into_node_path() const; - - INLINE const LMatrix4f &get_from_space() const; - INLINE const LMatrix4f &get_into_space() const; - INLINE const LMatrix4f &get_wrt_space() const; - INLINE const LMatrix4f &get_inv_wrt_space() const; - - INLINE void set_into_intersection_point(const LPoint3f &point); - INLINE bool has_into_intersection_point() const; - INLINE const LPoint3f &get_into_intersection_point() const; - - INLINE bool has_from_intersection_point() const; - INLINE LPoint3f get_from_intersection_point() const; - - INLINE void set_into_surface_normal(const LVector3f &normal); - INLINE bool has_into_surface_normal() const; - INLINE const LVector3f &get_into_surface_normal() const; - - INLINE void set_into_depth(float depth); - INLINE bool has_into_depth() const; - INLINE float get_into_depth() const; - -private: - CPT(CollisionSolid) _from; - CPT(CollisionSolid) _into; - - PT(CollisionNode) _from_node; - PT_NamedNode _into_node; - NodePath _into_node_path; - LMatrix4f _from_space; - LMatrix4f _into_space; - LMatrix4f _wrt_space; - LMatrix4f _inv_wrt_space; - - enum Flags { - F_has_into_intersection_point = 0x0001, - F_has_into_surface_normal = 0x0002, - F_has_into_depth = 0x0004, - }; - - int _flags; - - LPoint3f _into_intersection_point; - LVector3f _into_surface_normal; - float _into_depth; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - TypedReferenceCount::init_type(); - register_type(_type_handle, "CollisionEntry", - TypedReferenceCount::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; - - friend class CollisionTraverser; - friend class qpCollisionTraverser; -}; - -#include "collisionEntry.I" - -#endif - - - diff --git a/panda/src/collide/collisionHandler.cxx b/panda/src/collide/collisionHandler.cxx deleted file mode 100644 index 52cb3897ce..0000000000 --- a/panda/src/collide/collisionHandler.cxx +++ /dev/null @@ -1,62 +0,0 @@ -// Filename: collisionHandler.cxx -// Created by: drose (24Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "collisionHandler.h" - -TypeHandle CollisionHandler::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandler::begin_group -// Access: Public, Virtual -// Description: Will be called by the CollisionTraverser before a new -// traversal is begun. It instructs the handler to -// reset itself in preparation for a number of -// CollisionEntries to be sent. -//////////////////////////////////////////////////////////////////// -void CollisionHandler:: -begin_group() { -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandler::add_entry -// Access: Public, Virtual -// Description: Called between a begin_group() .. end_group() -// sequence for each collision that is detected. -//////////////////////////////////////////////////////////////////// -void CollisionHandler:: -add_entry(CollisionEntry *) { -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandler::end_group -// Access: Public, Virtual -// Description: Called by the CollisionTraverser at the completion of -// all collision detections for this traversal. It -// should do whatever finalization is required for the -// handler. -// -// The return value is normally true, but if this -// returns value, the CollisionTraverser will remove the -// handler from its list, allowing the CollisionHandler -// itself to determine when it is no longer needed. -//////////////////////////////////////////////////////////////////// -bool CollisionHandler:: -end_group() { - return true; -} diff --git a/panda/src/collide/collisionHandler.h b/panda/src/collide/collisionHandler.h deleted file mode 100644 index a940347384..0000000000 --- a/panda/src/collide/collisionHandler.h +++ /dev/null @@ -1,68 +0,0 @@ -// Filename: collisionHandler.h -// Created by: drose (24Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef COLLISIONHANDLER_H -#define COLLISIONHANDLER_H - -#include - -#include - -class CollisionEntry; - -/////////////////////////////////////////////////////////////////// -// Class : CollisionHandler -// Description : The abstract interface to a number of classes that -// decide what to do what a collision is detected. One -// of these must be assigned to the CollisionTraverser -// that is processing collisions in order to specify how -// to dispatch detected collisions. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA CollisionHandler : public TypedReferenceCount { -public: - virtual void begin_group(); - virtual void add_entry(CollisionEntry *entry); - virtual bool end_group(); - - -PUBLISHED: - static TypeHandle get_class_type() { - return _type_handle; - } - -public: - static void init_type() { - TypedReferenceCount::init_type(); - register_type(_type_handle, "CollisionHandler", - TypedReferenceCount::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; - - friend class CollisionTraverser; -}; - -#endif - - - diff --git a/panda/src/collide/collisionHandlerEvent.I b/panda/src/collide/collisionHandlerEvent.I deleted file mode 100644 index 1c4fc5d175..0000000000 --- a/panda/src/collide/collisionHandlerEvent.I +++ /dev/null @@ -1,161 +0,0 @@ -// Filename: collisionHandlerEvent.I -// Created by: drose (27Jun00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerEvent::SortEntries::operator () -// Access: Public -// Description: Orders the CollisionEntries in the set so that there -// is one entry for each node/node intersection -// detected. -//////////////////////////////////////////////////////////////////// -INLINE bool CollisionHandlerEvent::SortEntries:: -operator () (const PT(CollisionEntry) &a, - const PT(CollisionEntry) &b) const { - if (a->get_from_node() != b->get_from_node()) { - return a->get_from_node() < b->get_from_node(); - } - if (a->get_into_node() != b->get_into_node()) { - return a->get_into_node() < b->get_into_node(); - } - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerEvent::SortEntries::operator = -// Access: Public -// Description: The assignment operator does absolutely nothing, -// since this is just a function object class that -// stores no data. We define it just to quiet up g++ in -// -Wall mode. -//////////////////////////////////////////////////////////////////// -INLINE void CollisionHandlerEvent::SortEntries:: -operator = (const CollisionHandlerEvent::SortEntries &) { -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerEvent::set_in_pattern -// Access: Public -// Description: Sets the pattern string that indicates how the event -// names are generated for each collision detected. -// This is a string that may contain any of the -// following: -// -// %fn - the name of the "from" object's node -// %in - the name of the "into" object's node -// %ft - 't' if "from" is tangible, 'i' if intangible -// %it - 't' if "into" is tangible, 'i' if intangible -// -// The event name will be based on the in_pattern -// string specified here, with all occurrences of the -// above strings replaced with the corresponding values. -// -// In general, the in_pattern event is thrown on the -// first detection of a collision between two particular -// nodes. In subsequent passes, as long as a collision -// between those two nodes continues to be detected each -// frame, the again_pattern is thrown. The first frame -// in which the collision is no longer detected, the -// out_pattern event is thrown. -//////////////////////////////////////////////////////////////////// -INLINE void CollisionHandlerEvent:: -set_in_pattern(const string &in_pattern) { - _in_pattern = in_pattern; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerEvent::get_in_pattern -// Access: Public -// Description: Returns the pattern string that indicates how the -// event names are generated for each collision -// detected. See set_in_pattern(). -//////////////////////////////////////////////////////////////////// -INLINE string CollisionHandlerEvent:: -get_in_pattern() const { - return _in_pattern; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerEvent::set_again_pattern -// Access: Public -// Description: Sets the pattern string that indicates how the event -// names are generated when a collision between two -// particular nodes is *still* detected. This event is -// thrown each consecutive time a collision between two -// particular nodes is detected, starting with the -// second time. -// -// In general, the in_pattern event is thrown on the -// first detection of a collision between two particular -// nodes. In subsequent passes, as long as a collision -// between those two nodes continues to be detected each -// frame, the again_pattern is thrown. The first frame -// in which the collision is no longer detected, the -// out_pattern event is thrown. -//////////////////////////////////////////////////////////////////// -INLINE void CollisionHandlerEvent:: -set_again_pattern(const string &again_pattern) { - _again_pattern = again_pattern; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerEvent::get_again_pattern -// Access: Public -// Description: Returns the pattern string that indicates how the -// event names are generated when a collision between -// two particular nodes is *still* detected. See -// set_again_pattern() and set_in_pattern(). -//////////////////////////////////////////////////////////////////// -INLINE string CollisionHandlerEvent:: -get_again_pattern() const { - return _again_pattern; -} - - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerEvent::set_out_pattern -// Access: Public -// Description: Sets the pattern string that indicates how the event -// names are generated when a collision between two -// particular nodes is *no longer* detected. -// -// In general, the in_pattern event is thrown on the -// first detection of a collision between two particular -// nodes. In subsequent passes, as long as a collision -// between those two nodes continues to be detected each -// frame, the again_pattern is thrown. The first frame -// in which the collision is no longer detected, the -// out_pattern event is thrown. -//////////////////////////////////////////////////////////////////// -INLINE void CollisionHandlerEvent:: -set_out_pattern(const string &out_pattern) { - _out_pattern = out_pattern; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerEvent::get_out_pattern -// Access: Public -// Description: Returns the pattern string that indicates how the -// event names are generated when a collision between -// two particular nodes is *no longer* detected. See -// set_out_pattern() and set_in_pattern(). -//////////////////////////////////////////////////////////////////// -INLINE string CollisionHandlerEvent:: -get_out_pattern() const { - return _out_pattern; -} - diff --git a/panda/src/collide/collisionHandlerEvent.cxx b/panda/src/collide/collisionHandlerEvent.cxx deleted file mode 100644 index aa6fc4943c..0000000000 --- a/panda/src/collide/collisionHandlerEvent.cxx +++ /dev/null @@ -1,213 +0,0 @@ -// Filename: collisionHandlerEvent.cxx -// Created by: drose (27Jun00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "collisionHandlerEvent.h" -#include "config_collide.h" - -#include -#include - - -TypeHandle CollisionHandlerEvent::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerEvent::Constructor -// Access: Public -// Description: The default CollisionHandlerEvent will throw no -// events. Its pattern strings must first be set via a -// call to set_in_pattern() and/or set_out_pattern(). -//////////////////////////////////////////////////////////////////// -CollisionHandlerEvent:: -CollisionHandlerEvent() { -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerEvent::begin_group -// Access: Public, Virtual -// Description: Will be called by the CollisionTraverser before a new -// traversal is begun. It instructs the handler to -// reset itself in preparation for a number of -// CollisionEntries to be sent. -//////////////////////////////////////////////////////////////////// -void CollisionHandlerEvent:: -begin_group() { - if (collide_cat.is_spam()) { - collide_cat.spam() - << "begin_group.\n"; - } - _last_colliding.swap(_current_colliding); - _current_colliding.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerEvent::add_entry -// Access: Public, Virtual -// Description: Called between a begin_group() .. end_group() -// sequence for each collision that is detected. -//////////////////////////////////////////////////////////////////// -void CollisionHandlerEvent:: -add_entry(CollisionEntry *entry) { - nassertv(entry != (CollisionEntry *)NULL); - - // Record this particular entry for later. This will keep track of - // all the unique pairs of node/node intersections. - bool inserted = _current_colliding.insert(entry).second; - - if (collide_cat.is_spam()) { - collide_cat.spam() - << "Detected collision from " << (void *)entry->get_from_node() - << " to " << (void *)entry->get_into_node() - << ", inserted = " << inserted << "\n"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerEvent::end_group -// Access: Public, Virtual -// Description: Called by the CollisionTraverser at the completion of -// all collision detections for this traversal. It -// should do whatever finalization is required for the -// handler. -//////////////////////////////////////////////////////////////////// -bool CollisionHandlerEvent:: -end_group() { - // Now compare the list of entries we collected this frame with - // those we kept from the last time. Each new entry represents a - // new 'in' event; each missing entry represents a new 'out' event. - - if (collide_cat.is_spam()) { - collide_cat.spam() - << "end_group.\n" - << "current_colliding has " << _current_colliding.size() - << " entries, last_colliding has " << _last_colliding.size() - << "\n"; - } - - Colliding::iterator ca, cb; - - ca = _current_colliding.begin(); - cb = _last_colliding.begin(); - - SortEntries order; - while (ca != _current_colliding.end() && cb != _last_colliding.end()) { - if (order(*ca, *cb)) { - // Here's an element in a but not in b. That's a newly entered - // intersection. - throw_event_pattern(_in_pattern, *ca); - ++ca; - - } else if (order(*cb, *ca)) { - // Here's an element in b but not in a. That's a newly exited - // intersection. - throw_event_pattern(_out_pattern, *cb); - ++cb; - - } else { - // This element is in both b and a. It hasn't changed. - throw_event_pattern(_again_pattern, *cb); - ++ca; - ++cb; - } - } - - while (ca != _current_colliding.end()) { - // Here's an element in a but not in b. That's a newly entered - // intersection. - throw_event_pattern(_in_pattern, *ca); - ++ca; - } - - while (cb != _last_colliding.end()) { - // Here's an element in b but not in a. That's a newly exited - // intersection. - throw_event_pattern(_out_pattern, *cb); - ++cb; - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerEvent::clear -// Access: Public -// Description: Empties the list of elements that all colliders are -// known to be colliding with. No "out" events will be -// thrown; if the same collision is detected next frame, -// a new "in" event will be thrown for each collision. -// -// This can be called each frame to defeat the -// persistent "in" event mechanism, which prevents the -// same "in" event from being thrown repeatedly. -// However, also see set_again_pattern(), which can be -// used to set the event that is thrown when a collision -// is detected for two or more consecutive frames. -//////////////////////////////////////////////////////////////////// -void CollisionHandlerEvent:: -clear() { - _last_colliding.clear(); - _current_colliding.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerEvent::throw_event_pattern -// Access: Private -// Description: Throws an event matching the indicated pattern. -//////////////////////////////////////////////////////////////////// -void CollisionHandlerEvent:: -throw_event_pattern(const string &pattern, CollisionEntry *entry) { - if (pattern.empty()) { - return; - } - - string event; - for (size_t p = 0; p < pattern.size(); ++p) { - if (pattern[p] == '%') { - string cmd = pattern.substr(p + 1, 2); - p += 2; - if (cmd == "fn") { - event += entry->get_from_node()->get_name(); - - } else if (cmd == "in") { - event += entry->get_into_node()->get_name(); - - } else if (cmd == "ft") { - event += - (!entry->get_from()->is_tangible() ? 'i' : 't'); - - } else if (cmd == "it") { - event += - (entry->has_into() && !entry->get_into()->is_tangible() ? 'i' : 't'); - - } else if (cmd == "ig") { - event += - (entry->has_into() ? 'c' : 'g'); - - } else { - collide_cat.error() - << "Invalid symbol in event_pattern: %" << cmd << "\n"; - } - } else { - event += pattern[p]; - } - } - - if (!event.empty()) { - throw_event(event, EventParameter(entry)); - } -} diff --git a/panda/src/collide/collisionHandlerEvent.h b/panda/src/collide/collisionHandlerEvent.h deleted file mode 100644 index 1865b8fc94..0000000000 --- a/panda/src/collide/collisionHandlerEvent.h +++ /dev/null @@ -1,102 +0,0 @@ -// Filename: collisionHandlerEvent.h -// Created by: drose (27Jun00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef COLLISIONHANDLEREVENT_H -#define COLLISIONHANDLEREVENT_H - -#include - -#include "collisionHandler.h" -#include "collisionNode.h" -#include "collisionEntry.h" - -#include - -/////////////////////////////////////////////////////////////////// -// Class : CollisionHandlerEvent -// Description : A specialized kind of CollisionHandler that throws an -// event for each collision detected. The event thrown -// may be based on the name of the moving object or the -// struck object, or both. The first parameter of the -// event will be a pointer to the CollisionEntry that -// triggered it. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA CollisionHandlerEvent : public CollisionHandler { -PUBLISHED: - CollisionHandlerEvent(); - -public: - virtual void begin_group(); - virtual void add_entry(CollisionEntry *entry); - virtual bool end_group(); - -PUBLISHED: - INLINE void set_in_pattern(const string &pattern); - INLINE string get_in_pattern() const; - INLINE void set_again_pattern(const string &pattern); - INLINE string get_again_pattern() const; - INLINE void set_out_pattern(const string &pattern); - INLINE string get_out_pattern() const; - - void clear(); - -private: - void throw_event_pattern(const string &pattern, CollisionEntry *entry); - - string _in_pattern; - string _again_pattern; - string _out_pattern; - - int _index; - - class SortEntries { - public: - INLINE bool - operator () (const PT(CollisionEntry) &a, - const PT(CollisionEntry) &b) const; - INLINE void operator = (const SortEntries &other); - }; - - typedef pset Colliding; - Colliding _current_colliding; - Colliding _last_colliding; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - CollisionHandler::init_type(); - register_type(_type_handle, "CollisionHandlerEvent", - CollisionHandler::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "collisionHandlerEvent.I" - -#endif - - - diff --git a/panda/src/collide/collisionHandlerFloor.I b/panda/src/collide/collisionHandlerFloor.I deleted file mode 100644 index 5670462c3c..0000000000 --- a/panda/src/collide/collisionHandlerFloor.I +++ /dev/null @@ -1,67 +0,0 @@ -// Filename: collisionHandlerFloor.I -// Created by: drose (04Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerFloor::set_offset -// Access: Public -// Description: Sets the linear offset to add to (or subtract from) -// the highest detected collision point to determine the -// actual height at which to set the collider. -//////////////////////////////////////////////////////////////////// -INLINE void CollisionHandlerFloor:: -set_offset(float offset) { - _offset = offset; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerFloor::get_offset -// Access: Public -// Description: Returns the linear offset to add to (or subtract from) -// the highest detected collision point to determine the -// actual height at which to set the collider. -//////////////////////////////////////////////////////////////////// -INLINE float CollisionHandlerFloor:: -get_offset() const { - return _offset; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerFloor::set_max_velocity -// Access: Public -// Description: Sets the maximum speed at which the object will be -// allowed to descend towards a floor below it, in units -// per second. Set this to zero to allow it to -// instantly teleport any distance. -//////////////////////////////////////////////////////////////////// -INLINE void CollisionHandlerFloor:: -set_max_velocity(float max_velocity) { - _max_velocity = max_velocity; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerFloor::get_max_velocity -// Access: Public -// Description: Retrieves the maximum speed at which the object will -// be allowed to descend towards a floor below it, in -// units per second. See set_max_velocity(). -//////////////////////////////////////////////////////////////////// -INLINE float CollisionHandlerFloor:: -get_max_velocity() const { - return _max_velocity; -} diff --git a/panda/src/collide/collisionHandlerFloor.cxx b/panda/src/collide/collisionHandlerFloor.cxx deleted file mode 100644 index 655bc756e7..0000000000 --- a/panda/src/collide/collisionHandlerFloor.cxx +++ /dev/null @@ -1,145 +0,0 @@ -// Filename: collisionHandlerFloor.cxx -// Created by: drose (04Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "collisionHandlerFloor.h" -#include "config_collide.h" - -#include -#include - -#include - -TypeHandle CollisionHandlerFloor::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerFloor::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -CollisionHandlerFloor:: -CollisionHandlerFloor() { - _offset = 0.0f; - _max_velocity = 0.0f; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerFloor::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -CollisionHandlerFloor:: -~CollisionHandlerFloor() { -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerFloor::handle_entries -// Access: Protected, Virtual -// Description: Called by the parent class after all collisions have -// been detected, this manages the various collisions -// and moves around the nodes as necessary. -// -// The return value is normally true, but it may be -// false to indicate the CollisionTraverser should -// disable this handler from being called in the future. -//////////////////////////////////////////////////////////////////// -bool CollisionHandlerFloor:: -handle_entries() { - bool okflag = true; - - FromEntries::const_iterator fi; - for (fi = _from_entries.begin(); fi != _from_entries.end(); ++fi) { - CollisionNode *from_node = (*fi).first; - nassertr(from_node != (CollisionNode *)NULL, false); - const Entries &entries = (*fi).second; - - Colliders::iterator ci; - ci = _colliders.find(from_node); - if (ci == _colliders.end()) { - // Hmm, someone added a CollisionNode to a traverser and gave - // it this CollisionHandler pointer--but they didn't tell us - // about the node. - collide_cat.error() - << get_type() << " doesn't know about " - << *from_node << ", disabling.\n"; - okflag = false; - - } else { - ColliderDef &def = (*ci).second; - if (!def.is_valid()) { - collide_cat.error() - << "Removing invalid collider " << *from_node << " from " - << get_type() << "\n"; - _colliders.erase(ci); - - } else { - // Get the maximum height for all collisions with this node. - bool got_max = false; - float max_height = 0.0f; - - Entries::const_iterator ei; - for (ei = entries.begin(); ei != entries.end(); ++ei) { - CollisionEntry *entry = (*ei); - nassertr(entry != (CollisionEntry *)NULL, false); - nassertr(from_node == entry->get_from_node(), false); - - if (entry->has_from_intersection_point()) { - LPoint3f point = entry->get_from_intersection_point(); - if (collide_cat.is_debug()) { - collide_cat.debug() - << "Intersection point detected at " << point << "\n"; - } - - float height = point[2]; - if (!got_max || height > max_height) { - got_max = true; - max_height = height; - } - } - } - - // Now set our height accordingly. - float adjust = max_height + _offset; - if (!IS_THRESHOLD_ZERO(adjust, 0.001)) { - if (collide_cat.is_debug()) { - collide_cat.debug() - << "Adjusting height by " << adjust << "\n"; - } - - if (adjust < 0.0f && _max_velocity != 0.0f) { - float max_adjust = - _max_velocity * ClockObject::get_global_clock()->get_dt(); - adjust = max(adjust, -max_adjust); - } - - LMatrix4f mat; - def.get_mat(mat); - mat(3, 2) += adjust; - def.set_mat(mat); - } else { - if (collide_cat.is_spam()) { - collide_cat.spam() - << "Leaving height unchanged.\n"; - } - } - } - } - } - - return okflag; -} diff --git a/panda/src/collide/collisionHandlerFloor.h b/panda/src/collide/collisionHandlerFloor.h deleted file mode 100644 index 1fcdf0c109..0000000000 --- a/panda/src/collide/collisionHandlerFloor.h +++ /dev/null @@ -1,78 +0,0 @@ -// Filename: collisionHandlerFloor.h -// Created by: drose (04Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef COLLISIONHANDLERFLOOR_H -#define COLLISIONHANDLERFLOOR_H - -#include - -#include "collisionHandlerPhysical.h" -#include "collisionNode.h" - -/////////////////////////////////////////////////////////////////// -// Class : CollisionHandlerFloor -// Description : A specialized kind of CollisionHandler that sets the -// Z height of the collider to a fixed linear offset -// from the highest detected collision point each frame. -// It's intended to implement walking around on a floor -// of varying height by casting a ray down from the -// avatar's head. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA CollisionHandlerFloor : public CollisionHandlerPhysical { -PUBLISHED: - CollisionHandlerFloor(); - virtual ~CollisionHandlerFloor(); - - INLINE void set_offset(float offset); - INLINE float get_offset() const; - - INLINE void set_max_velocity(float max_vel); - INLINE float get_max_velocity() const; - -protected: - virtual bool handle_entries(); - -private: - float _offset; - float _max_velocity; - - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - CollisionHandlerPhysical::init_type(); - register_type(_type_handle, "CollisionHandlerFloor", - CollisionHandlerPhysical::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "collisionHandlerFloor.I" - -#endif - - - diff --git a/panda/src/collide/collisionHandlerPhysical.I b/panda/src/collide/collisionHandlerPhysical.I deleted file mode 100644 index a680e0dd6e..0000000000 --- a/panda/src/collide/collisionHandlerPhysical.I +++ /dev/null @@ -1,51 +0,0 @@ -// Filename: collisionHandlerPhysical.I -// Created by: drose (03Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPhysical::ColliderDef::set_drive_interface -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void CollisionHandlerPhysical::ColliderDef:: -set_drive_interface(DriveInterface *drive_interface) { - _drive_interface = drive_interface; - _arc.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPhysical::ColliderDef::set_arc -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void CollisionHandlerPhysical::ColliderDef:: -set_arc(NodeRelation *arc) { - _arc = arc; - _drive_interface.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPhysical::ColliderDef::is_valid -// Access: Public -// Description: Returns true if this ColliderDef is still valid; -// e.g. it refers to a valid arc or drive interface. -//////////////////////////////////////////////////////////////////// -INLINE bool CollisionHandlerPhysical::ColliderDef:: -is_valid() const { - return (_arc != (NodeRelation *)NULL) || - (_drive_interface != (DriveInterface *)NULL); -} diff --git a/panda/src/collide/collisionHandlerPhysical.cxx b/panda/src/collide/collisionHandlerPhysical.cxx deleted file mode 100644 index 852756b42d..0000000000 --- a/panda/src/collide/collisionHandlerPhysical.cxx +++ /dev/null @@ -1,210 +0,0 @@ -// Filename: collisionHandlerPhysical.cxx -// Created by: drose (03Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "collisionHandlerPhysical.h" -#include "config_collide.h" - -#include -#include - -TypeHandle CollisionHandlerPhysical::_type_handle; - - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPhysical::ColliderDef::get_mat -// Access: Public -// Description: Fills mat with the matrix representing the current -// position and orientation of this collider. -//////////////////////////////////////////////////////////////////// -void CollisionHandlerPhysical::ColliderDef:: -get_mat(LMatrix4f &mat) const { - if (_arc != (NodeRelation *)NULL) { - TransformTransition *tt; - if (get_transition_into(tt, _arc)) { - mat = tt->get_matrix(); - } else { - mat = LMatrix4f::ident_mat(); - } - - } else if (_drive_interface != (DriveInterface *)NULL) { - mat = _drive_interface->get_mat(); - - } else { - collide_cat.error() - << "Invalid CollisionHandlerPhysical::ColliderDef\n"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPhysical::ColliderDef::set_mat -// Access: Public -// Description: Moves this collider to the position and orientation -// indicated by the given transform. -//////////////////////////////////////////////////////////////////// -void CollisionHandlerPhysical::ColliderDef:: -set_mat(const LMatrix4f &mat) { - if (_arc != (NodeRelation *)NULL) { - if (!_arc->is_attached()) { - collide_cat.error() - << "CollisionHandler is associated with an unattached arc.\n"; - _arc = (NodeRelation *)NULL; - } else { - _arc->set_transition(new TransformTransition(mat)); - } - - } else if (_drive_interface != (DriveInterface *)NULL) { - _drive_interface->set_mat(mat); - _drive_interface->force_dgraph(); - - } else { - collide_cat.error() - << "Invalid CollisionHandlerPhysical::ColliderDef\n"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPhysical::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -CollisionHandlerPhysical:: -CollisionHandlerPhysical() { -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPhysical::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -CollisionHandlerPhysical:: -~CollisionHandlerPhysical() { -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPhysical::begin_group -// Access: Public, Virtual -// Description: Will be called by the CollisionTraverser before a new -// traversal is begun. It instructs the handler to -// reset itself in preparation for a number of -// CollisionEntries to be sent. -//////////////////////////////////////////////////////////////////// -void CollisionHandlerPhysical:: -begin_group() { - CollisionHandlerEvent::begin_group(); - _from_entries.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPhysical::add_entry -// Access: Public, Virtual -// Description: Called between a begin_group() .. end_group() -// sequence for each collision that is detected. -//////////////////////////////////////////////////////////////////// -void CollisionHandlerPhysical:: -add_entry(CollisionEntry *entry) { - nassertv(entry != (CollisionEntry *)NULL); - CollisionHandlerEvent::add_entry(entry); - - if (entry->get_from()->is_tangible() && - (!entry->has_into() || entry->get_into()->is_tangible())) { - _from_entries[entry->get_from_node()].push_back(entry); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPhysical::end_group -// Access: Public, Virtual -// Description: Called by the CollisionTraverser at the completion of -// all collision detections for this traversal. It -// should do whatever finalization is required for the -// handler. -//////////////////////////////////////////////////////////////////// -bool CollisionHandlerPhysical:: -end_group() { - CollisionHandlerEvent::end_group(); - - return handle_entries(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPhysical::add_collider -// Access: Public -// Description: Adds a new collider to the list with a DriveInterface -// pointer that needs to be told about the collider's -// new position, or updates the existing collider with a -// new DriveInterface pointer. -//////////////////////////////////////////////////////////////////// -void CollisionHandlerPhysical:: -add_collider(CollisionNode *node, DriveInterface *drive_interface) { - _colliders[node].set_drive_interface(drive_interface); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPhysical::add_collider -// Access: Public -// Description: Adds a new collider to the list with a NodeRelation -// pointer that will be updated with the collider's -// new position, or updates the existing collider with a -// new NodeRelation pointer. -//////////////////////////////////////////////////////////////////// -void CollisionHandlerPhysical:: -add_collider(CollisionNode *node, NodeRelation *arc) { - _colliders[node].set_arc(arc); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPhysical::remove_collider -// Access: Public -// Description: Removes the collider from the list of colliders that -// this handler knows about. -//////////////////////////////////////////////////////////////////// -bool CollisionHandlerPhysical:: -remove_collider(CollisionNode *node) { - Colliders::iterator ci = _colliders.find(node); - if (ci == _colliders.end()) { - return false; - } - _colliders.erase(ci); - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPhysical::has_collider -// Access: Public -// Description: Returns true if the handler knows about the indicated -// collider, false otherwise. -//////////////////////////////////////////////////////////////////// -bool CollisionHandlerPhysical:: -has_collider(CollisionNode *node) const { - Colliders::const_iterator ci = _colliders.find(node); - return (ci != _colliders.end()); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPhysical::clear_colliders -// Access: Public -// Description: Completely empties the list of colliders this handler -// knows about. -//////////////////////////////////////////////////////////////////// -void CollisionHandlerPhysical:: -clear_colliders() { - _colliders.clear(); -} - - diff --git a/panda/src/collide/collisionHandlerPhysical.h b/panda/src/collide/collisionHandlerPhysical.h deleted file mode 100644 index c65d81cdf3..0000000000 --- a/panda/src/collide/collisionHandlerPhysical.h +++ /dev/null @@ -1,102 +0,0 @@ -// Filename: collisionHandlerPhysical.h -// Created by: drose (03Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef COLLISIONHANDLERPHYSICAL_H -#define COLLISIONHANDLERPHYSICAL_H - -#include - -#include "collisionHandlerEvent.h" -#include "collisionNode.h" - -#include -#include -#include - -/////////////////////////////////////////////////////////////////// -// Class : CollisionHandlerPhysical -// Description : The abstract base class for a number of -// CollisionHandlers that have some physical effect on -// their moving bodies: they need to update the nodes' -// positions based on the effects of the collision. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA CollisionHandlerPhysical : public CollisionHandlerEvent { -public: - CollisionHandlerPhysical(); - virtual ~CollisionHandlerPhysical(); - - virtual void begin_group(); - virtual void add_entry(CollisionEntry *entry); - virtual bool end_group(); - -PUBLISHED: - void add_collider(CollisionNode *node, DriveInterface *drive_interface); - void add_collider(CollisionNode *node, NodeRelation *arc); - bool remove_collider(CollisionNode *node); - bool has_collider(CollisionNode *node) const; - void clear_colliders(); - -protected: - virtual bool handle_entries()=0; - -protected: - typedef pvector< PT(CollisionEntry) > Entries; - typedef pmap FromEntries; - FromEntries _from_entries; - - class ColliderDef { - public: - INLINE void set_drive_interface(DriveInterface *drive_interface); - INLINE void set_arc(NodeRelation *arc); - INLINE bool is_valid() const; - - void get_mat(LMatrix4f &mat) const; - void set_mat(const LMatrix4f &mat); - - PT(DriveInterface) _drive_interface; - PT_NodeRelation _arc; - }; - - typedef pmap Colliders; - Colliders _colliders; - - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - CollisionHandlerEvent::init_type(); - register_type(_type_handle, "CollisionHandlerPhysical", - CollisionHandlerEvent::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "collisionHandlerPhysical.I" - -#endif - - - diff --git a/panda/src/collide/collisionHandlerPusher.I b/panda/src/collide/collisionHandlerPusher.I deleted file mode 100644 index 270df258ab..0000000000 --- a/panda/src/collide/collisionHandlerPusher.I +++ /dev/null @@ -1,37 +0,0 @@ -// Filename: collisionHandlerPusher.I -// Created by: drose (26Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPusher::set_horizontal -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void CollisionHandlerPusher:: -set_horizontal(bool flag) { - _horizontal = flag; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPusher::get_horizontal -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool CollisionHandlerPusher:: -get_horizontal() const { - return _horizontal; -} diff --git a/panda/src/collide/collisionHandlerPusher.cxx b/panda/src/collide/collisionHandlerPusher.cxx deleted file mode 100644 index 81e1fa5d1c..0000000000 --- a/panda/src/collide/collisionHandlerPusher.cxx +++ /dev/null @@ -1,207 +0,0 @@ -// Filename: collisionHandlerPusher.cxx -// Created by: drose (25Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "collisionHandlerPusher.h" -#include "config_collide.h" - -TypeHandle CollisionHandlerPusher::_type_handle; - -/////////////////////////////////////////////////////////////////// -// Class : ShoveData -// Description : The ShoveData class is used within -// CollisionHandlerPusher::handle_entries(), to track -// multiple shoves onto a given collider. It's not -// exported outside this file. -//////////////////////////////////////////////////////////////////// -class ShoveData { -public: - LVector3f _shove; - float _length; - LVector3f _normalized_shove; - bool _valid; -}; - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPusher::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -CollisionHandlerPusher:: -CollisionHandlerPusher() { - _horizontal = true; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPusher::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -CollisionHandlerPusher:: -~CollisionHandlerPusher() { -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerPusher::handle_entries -// Access: Protected, Virtual -// Description: Called by the parent class after all collisions have -// been detected, this manages the various collisions -// and moves around the nodes as necessary. -// -// The return value is normally true, but it may be -// false to indicate the CollisionTraverser should -// disable this handler from being called in the future. -//////////////////////////////////////////////////////////////////// -bool CollisionHandlerPusher:: -handle_entries() { - bool okflag = true; - - FromEntries::const_iterator fi; - for (fi = _from_entries.begin(); fi != _from_entries.end(); ++fi) { - CollisionNode *from_node = (*fi).first; - nassertr(from_node != (CollisionNode *)NULL, false); - const Entries &entries = (*fi).second; - - Colliders::iterator ci; - ci = _colliders.find(from_node); - if (ci == _colliders.end()) { - // Hmm, someone added a CollisionNode to a traverser and gave - // it this CollisionHandler pointer--but they didn't tell us - // about the node. - collide_cat.error() - << "CollisionHandlerPusher doesn't know about " - << *from_node << ", disabling.\n"; - okflag = false; - - } else { - ColliderDef &def = (*ci).second; - if (!def.is_valid()) { - collide_cat.error() - << "Removing invalid collider " << *from_node << " from " - << get_type() << "\n"; - _colliders.erase(ci); - - } else { - // How to apply multiple shoves from different solids onto the - // same collider? One's first intuition is to vector sum all - // the shoves. However, this causes problems when two parallel - // walls shove on the collider, because we end up with a double - // shove. We hack around this by testing if two shove vectors - // share nearly the same direction, and if so, we keep only the - // longer of the two. - - typedef pvector Shoves; - Shoves shoves; - - Entries::const_iterator ei; - for (ei = entries.begin(); ei != entries.end(); ++ei) { - CollisionEntry *entry = (*ei); - nassertr(entry != (CollisionEntry *)NULL, false); - nassertr(from_node == entry->get_from_node(), false); - - if (!entry->has_into_surface_normal() || - !entry->has_into_depth()) { - if (collide_cat.is_debug()) { - collide_cat.debug() - << "Cannot shove on " << *from_node << " for collision into " - << *entry->get_into_node() << "; no normal/depth information.\n"; - } - - } else { - // Shove it just enough to clear the volume. - if (entry->get_into_depth() != 0.0f) { - ShoveData sd; - sd._shove = - entry->get_into_surface_normal() * - entry->get_into_depth(); - - if (collide_cat.is_debug()) { - collide_cat.debug() - << "Shove on " << *from_node << " from " - << *entry->get_into_node() << ": " << sd._shove << "\n"; - } - - sd._length = sd._shove.length(); - sd._normalized_shove = sd._shove / sd._length; - sd._valid = true; - - shoves.push_back(sd); - } - } - } - - if (!shoves.empty()) { - // Now we combine any two shoves that shove in largely the - // same direction. Hacky. - - Shoves::iterator si; - for (si = shoves.begin(); si != shoves.end(); ++si) { - ShoveData &sd = (*si); - Shoves::iterator sj; - for (sj = shoves.begin(); sj != si; ++sj) { - ShoveData &sd2 = (*sj); - if (sd2._valid) { - - float d = sd._normalized_shove.dot(sd2._normalized_shove); - if (collide_cat.is_debug()) { - collide_cat.debug() - << "Considering dot product " << d << "\n"; - } - - if (d > 0.9) { - // These two shoves are largely in the same direction; - // save the larger of the two. - if (sd2._length < sd._length) { - sd2._valid = false; - } else { - sd._valid = false; - } - } - } - } - } - - // Now we can determine the net shove. - LVector3f net_shove(0.0f, 0.0f, 0.0f); - for (si = shoves.begin(); si != shoves.end(); ++si) { - const ShoveData &sd = (*si); - if (sd._valid) { - net_shove += sd._shove; - } - } - - if (_horizontal) { - net_shove[2] = 0.0f; - } - - if (collide_cat.is_debug()) { - collide_cat.debug() - << "Net shove on " << *from_node << " is: " - << net_shove << "\n"; - } - - LMatrix4f mat; - def.get_mat(mat); - def.set_mat(LMatrix4f::translate_mat(net_shove) * mat); - } - } - } - } - - return okflag; -} diff --git a/panda/src/collide/collisionHandlerPusher.h b/panda/src/collide/collisionHandlerPusher.h deleted file mode 100644 index c8686e8e76..0000000000 --- a/panda/src/collide/collisionHandlerPusher.h +++ /dev/null @@ -1,72 +0,0 @@ -// Filename: collisionHandlerPusher.h -// Created by: drose (25Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef COLLISIONHANDLERPUSHER_H -#define COLLISIONHANDLERPUSHER_H - -#include - -#include "collisionHandlerPhysical.h" -#include "collisionNode.h" - -/////////////////////////////////////////////////////////////////// -// Class : CollisionHandlerPusher -// Description : A specialized kind of CollisionHandler that simply -// pushes back on things that attempt to move into solid -// walls. This is the simplest kind of "real-world" -// collisions you can have. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA CollisionHandlerPusher : public CollisionHandlerPhysical { -PUBLISHED: - CollisionHandlerPusher(); - virtual ~CollisionHandlerPusher(); - - INLINE void set_horizontal(bool flag); - INLINE bool get_horizontal() const; - -protected: - virtual bool handle_entries(); - -private: - bool _horizontal; - - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - CollisionHandlerPhysical::init_type(); - register_type(_type_handle, "CollisionHandlerPusher", - CollisionHandlerPhysical::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "collisionHandlerPusher.I" - -#endif - - - diff --git a/panda/src/collide/collisionHandlerQueue.cxx b/panda/src/collide/collisionHandlerQueue.cxx deleted file mode 100644 index 76a5472ab5..0000000000 --- a/panda/src/collide/collisionHandlerQueue.cxx +++ /dev/null @@ -1,145 +0,0 @@ -// Filename: collisionHandlerQueue.cxx -// Created by: drose (27Jun00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "collisionHandlerQueue.h" -#include "config_collide.h" - -TypeHandle CollisionHandlerQueue::_type_handle; - -// This class is used in sort_entries(), below. -class CollisionEntrySorter { -public: - CollisionEntrySorter(CollisionEntry *entry) { - _entry = entry; - LVector3f vec = - entry->get_from_intersection_point() - - entry->get_from()->get_collision_origin(); - _dist2 = vec.length_squared(); - } - bool operator < (const CollisionEntrySorter &other) const { - return _dist2 < other._dist2; - } - - CollisionEntry *_entry; - float _dist2; -}; - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerQueue::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -CollisionHandlerQueue:: -CollisionHandlerQueue() { -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerQueue::begin_group -// Access: Public, Virtual -// Description: Will be called by the CollisionTraverser before a new -// traversal is begun. It instructs the handler to -// reset itself in preparation for a number of -// CollisionEntries to be sent. -//////////////////////////////////////////////////////////////////// -void CollisionHandlerQueue:: -begin_group() { - _entries.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerQueue::add_entry -// Access: Public, Virtual -// Description: Called between a begin_group() .. end_group() -// sequence for each collision that is detected. -//////////////////////////////////////////////////////////////////// -void CollisionHandlerQueue:: -add_entry(CollisionEntry *entry) { - nassertv(entry != (CollisionEntry *)NULL); - _entries.push_back(entry); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerQueue::sort_entries -// Access: Public -// Description: Sorts all the detected collisions front-to-back by -// from_intersection_point() so that those intersection -// points closest to the collider's origin (e.g., the -// center of the CollisionSphere, or the point_a of a -// CollisionSegment) appear first. -//////////////////////////////////////////////////////////////////// -void CollisionHandlerQueue:: -sort_entries() { - // Build up a temporary vector of entries so we can sort the - // pointers. This uses the class defined above. - typedef pvector Sorter; - Sorter sorter; - sorter.reserve(_entries.size()); - - Entries::const_iterator ei; - for (ei = _entries.begin(); ei != _entries.end(); ++ei) { - sorter.push_back(CollisionEntrySorter(*ei)); - } - - sort(sorter.begin(), sorter.end()); - nassertv(sorter.size() == _entries.size()); - - // Now that they're sorted, get them back. We do this in two steps, - // building up a temporary vector first, so we don't accidentally - // delete all the entries when the pointers go away. - Entries sorted_entries; - sorted_entries.reserve(sorter.size()); - Sorter::const_iterator si; - for (si = sorter.begin(); si != sorter.end(); ++si) { - sorted_entries.push_back((*si)._entry); - } - - _entries.swap(sorted_entries); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerQueue::clear_entries -// Access: Public -// Description: Removes all the entries from the queue. -//////////////////////////////////////////////////////////////////// -void CollisionHandlerQueue:: -clear_entries() { - _entries.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerQueue::get_num_entries -// Access: Public -// Description: Returns the number of CollisionEntries detected last -// pass. -//////////////////////////////////////////////////////////////////// -int CollisionHandlerQueue:: -get_num_entries() const { - return _entries.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionHandlerQueue::get_entry -// Access: Public -// Description: Returns the nth CollisionEntry detected last pass. -//////////////////////////////////////////////////////////////////// -CollisionEntry *CollisionHandlerQueue:: -get_entry(int n) const { - nassertr(n >= 0 && n < (int)_entries.size(), NULL); - return _entries[n]; -} diff --git a/panda/src/collide/collisionHandlerQueue.h b/panda/src/collide/collisionHandlerQueue.h deleted file mode 100644 index 86de1f5066..0000000000 --- a/panda/src/collide/collisionHandlerQueue.h +++ /dev/null @@ -1,76 +0,0 @@ -// Filename: collisionHandlerQueue.h -// Created by: drose (27Jun00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef COLLISIONHANDLERQUEUE_H -#define COLLISIONHANDLERQUEUE_H - -#include - -#include "collisionHandler.h" -#include "collisionEntry.h" - -/////////////////////////////////////////////////////////////////// -// Class : CollisionHandlerQueue -// Description : A special kind of CollisionHandler that does nothing -// except remember the CollisionEntries detected the -// last pass. This set of CollisionEntries may then be -// queried by the calling function. It's primarily -// useful when a simple intersection test is being made, -// e.g. for picking from the window. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA CollisionHandlerQueue : public CollisionHandler { -PUBLISHED: - CollisionHandlerQueue(); - -public: - virtual void begin_group(); - virtual void add_entry(CollisionEntry *entry); - -PUBLISHED: - void sort_entries(); - void clear_entries(); - - int get_num_entries() const; - CollisionEntry *get_entry(int n) const; - -private: - typedef pvector< PT(CollisionEntry) > Entries; - Entries _entries; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - CollisionHandler::init_type(); - register_type(_type_handle, "CollisionHandlerQueue", - CollisionHandler::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#endif - - - diff --git a/panda/src/collide/collisionLevelState.I b/panda/src/collide/collisionLevelState.I deleted file mode 100644 index c609eefb0c..0000000000 --- a/panda/src/collide/collisionLevelState.I +++ /dev/null @@ -1,244 +0,0 @@ -// Filename: collisionLevelState.I -// Created by: drose (24Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CollisionLevelState:: -CollisionLevelState(const ArcChain &arc_chain) : - _arc_chain(arc_chain) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CollisionLevelState:: -CollisionLevelState(const CollisionLevelState ©) : - _arc_chain(copy._arc_chain), - _colliders(copy._colliders), - _current(copy._current), - _colliders_with_geom(copy._colliders_with_geom), - _local_bounds(copy._local_bounds) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::Copy Assignment -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void CollisionLevelState:: -operator = (const CollisionLevelState ©) { - _arc_chain = copy._arc_chain; - _colliders = copy._colliders; - _current = copy._current; - _colliders_with_geom = copy._colliders_with_geom; - _local_bounds = copy._local_bounds; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::forward_arc -// Access: Public -// Description: Records that we have traversed past another arc in -// the scene graph. -//////////////////////////////////////////////////////////////////// -INLINE void CollisionLevelState:: -forward_arc(NodeRelation *arc) { - _arc_chain.push_back(arc); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::get_arc_chain -// Access: Public -// Description: Returns the chain of arcs traversed from the top of -// the scene graph. -//////////////////////////////////////////////////////////////////// -INLINE const ArcChain &CollisionLevelState:: -get_arc_chain() const { - return _arc_chain; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::get_num_colliders -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int CollisionLevelState:: -get_num_colliders() const { - return _colliders.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::has_collider -// Access: Public -// Description: Returns true if the nth collider in the LevelState is -// still part of the level. -//////////////////////////////////////////////////////////////////// -INLINE bool CollisionLevelState:: -has_collider(int n) const { - nassertr(n >= 0 && n < (int)_colliders.size(), false); - return (_current & get_mask(n)) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::has_collider_with_geom -// Access: Public -// Description: Returns true if the nth collider in the LevelState is -// still part of the level, and it has the -// "collide_geom" flag set. -//////////////////////////////////////////////////////////////////// -INLINE bool CollisionLevelState:: -has_collider_with_geom(int n) const { - nassertr(n >= 0 && n < (int)_colliders.size(), false); - return (_current & _colliders_with_geom & get_mask(n)) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::has_any_collider -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool CollisionLevelState:: -has_any_collider() const { - return _current != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::has_any_collide_geom -// Access: Public -// Description: Returns true if any Collider in the level state has -// the "collide_geom" flag set, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool CollisionLevelState:: -has_any_collide_geom() const { - return (_current & _colliders_with_geom) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::reached_collision_node -// Access: Public -// Description: Called by the traverser when we reach a CollisionNode -// in the traversal. At this point, we zero out our set -// of colliders with the "collide_geom" flag set, -// because no colliders will test against geometry -// parented beneath a CollisionNode. -//////////////////////////////////////////////////////////////////// -INLINE void CollisionLevelState:: -reached_collision_node() { - _colliders_with_geom = 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::get_collider -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CollisionSolid *CollisionLevelState:: -get_collider(int n) const { - nassertr(n >= 0 && n < (int)_colliders.size(), NULL); - nassertr(has_collider(n), NULL); - - return _colliders[n]._collider; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::get_node -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CollisionNode *CollisionLevelState:: -get_node(int n) const { - nassertr(n >= 0 && n < (int)_colliders.size(), NULL); - nassertr(has_collider(n), NULL); - - return _colliders[n]._node; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::get_space -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE const LMatrix4f &CollisionLevelState:: -get_space(int n) const { - nassertr(n >= 0 && n < (int)_colliders.size(), LMatrix4f::ident_mat()); - nassertr(has_collider(n), LMatrix4f::ident_mat()); - - return _colliders[n]._space; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::get_inv_space -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE const LMatrix4f &CollisionLevelState:: -get_inv_space(int n) const { - nassertr(n >= 0 && n < (int)_colliders.size(), LMatrix4f::ident_mat()); - nassertr(has_collider(n), LMatrix4f::ident_mat()); - - return _colliders[n]._inv_space; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::get_local_bound -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE const GeometricBoundingVolume *CollisionLevelState:: -get_local_bound(int n) const { - nassertr(n >= 0 && n < (int)_colliders.size(), NULL); - nassertr(has_collider(n), NULL); - nassertr(n >= 0 && n < (int)_local_bounds.size(), NULL); - - // For whatever reason, the Intel compiler can't figure this line - // out. - //return _local_bounds[n]; - - // But it can figure out this equivalent line. - return *(_local_bounds + n); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::omit_collider -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void CollisionLevelState:: -omit_collider(int n) { - nassertv(n >= 0 && n < (int)_colliders.size()); - nassertv(has_collider(n)); - - _current &= ~get_mask(n); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::get_mask -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CollisionLevelState::ColliderMask CollisionLevelState:: -get_mask(int n) const { - return ((ColliderMask)1) << n; -} diff --git a/panda/src/collide/collisionLevelState.cxx b/panda/src/collide/collisionLevelState.cxx deleted file mode 100644 index abbf1d6258..0000000000 --- a/panda/src/collide/collisionLevelState.cxx +++ /dev/null @@ -1,103 +0,0 @@ -// Filename: collisionLevelState.cxx -// Created by: drose (24Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "collisionSolid.h" -#include "collisionNode.h" - -#include "collisionLevelState.h" - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::clear -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void CollisionLevelState:: -clear() { - _colliders.clear(); - _local_bounds.clear(); - _current = 0; - _colliders_with_geom = 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::reserve -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void CollisionLevelState:: -reserve(int max_colliders) { - _colliders.reserve(max_colliders); - _local_bounds.reserve(max_colliders); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::prepare_collider -// Access: Public -// Description: Adds the indicated Collider to the set of Colliders -// in the current level state. -//////////////////////////////////////////////////////////////////// -void CollisionLevelState:: -prepare_collider(const ColliderDef &def) { - int index = (int)_colliders.size(); - _colliders.push_back(def); - - CollisionSolid *collider = def._collider; - const BoundingVolume &bv = collider->get_bound(); - if (!bv.is_of_type(GeometricBoundingVolume::get_class_type())) { - _local_bounds.push_back((GeometricBoundingVolume *)NULL); - } else { - GeometricBoundingVolume *gbv; - DCAST_INTO_V(gbv, bv.make_copy()); - gbv->xform(def._space); - _local_bounds.push_back(gbv); - } - - _current |= get_mask(index); - - if (def._node->get_collide_geom()) { - _colliders_with_geom |= get_mask(index); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionLevelState::xform -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void CollisionLevelState:: -xform(const LMatrix4f &mat) { - BoundingVolumes new_bounds; - - int num_colliders = get_num_colliders(); - new_bounds.reserve(num_colliders); - for (int c = 0; c < num_colliders; c++) { - if (!has_collider(c) || - get_local_bound(c) == (GeometricBoundingVolume *)NULL) { - new_bounds.push_back((GeometricBoundingVolume *)NULL); - } else { - const GeometricBoundingVolume *old_bound = get_local_bound(c); - GeometricBoundingVolume *new_bound = - DCAST(GeometricBoundingVolume, old_bound->make_copy()); - new_bound->xform(mat); - new_bounds.push_back(new_bound); - } - } - - _local_bounds = new_bounds; -} diff --git a/panda/src/collide/collisionLevelState.h b/panda/src/collide/collisionLevelState.h deleted file mode 100644 index cee7dfcb3f..0000000000 --- a/panda/src/collide/collisionLevelState.h +++ /dev/null @@ -1,98 +0,0 @@ -// Filename: collisionLevelState.h -// Created by: drose (24Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef COLLISIONLEVELSTATE_H -#define COLLISIONLEVELSTATE_H - -#include - -#include -#include -#include -#include - -#include "plist.h" - -class CollisionSolid; -class CollisionNode; - -//////////////////////////////////////////////////////////////////// -// Class : CollisionLevelState -// Description : This is the state information the -// CollisionTraverser retains for each level during -// traversal. -//////////////////////////////////////////////////////////////////// -class CollisionLevelState { -public: - class ColliderDef { - public: - CollisionSolid *_collider; - CollisionNode *_node; - LMatrix4f _space; - LMatrix4f _inv_space; - }; - - INLINE CollisionLevelState(const ArcChain &arc_chain); - INLINE CollisionLevelState(const CollisionLevelState ©); - INLINE void operator = (const CollisionLevelState ©); - - void clear(); - void reserve(int max_colliders); - void prepare_collider(const ColliderDef &def); - void xform(const LMatrix4f &mat); - - INLINE void forward_arc(NodeRelation *arc); - INLINE const ArcChain &get_arc_chain() const; - - INLINE int get_num_colliders() const; - INLINE bool has_collider(int n) const; - INLINE bool has_collider_with_geom(int n) const; - INLINE bool has_any_collider() const; - INLINE bool has_any_collide_geom() const; - - INLINE void reached_collision_node(); - - INLINE CollisionSolid *get_collider(int n) const; - INLINE CollisionNode *get_node(int n) const; - INLINE const LMatrix4f &get_space(int n) const; - INLINE const LMatrix4f &get_inv_space(int n) const; - INLINE const GeometricBoundingVolume *get_local_bound(int n) const; - - INLINE void omit_collider(int n); - -private: - typedef int ColliderMask; - - INLINE ColliderMask get_mask(int n) const; - - ArcChain _arc_chain; - - typedef PTA(ColliderDef) Colliders; - Colliders _colliders; - ColliderMask _current; - ColliderMask _colliders_with_geom; - - typedef PTA(CPT(GeometricBoundingVolume)) BoundingVolumes; - BoundingVolumes _local_bounds; -}; - -#include "collisionLevelState.I" - -#endif - - diff --git a/panda/src/collide/collisionNode.I b/panda/src/collide/collisionNode.I deleted file mode 100644 index c60b4f43a3..0000000000 --- a/panda/src/collide/collisionNode.I +++ /dev/null @@ -1,166 +0,0 @@ -// Filename: collisionNode.I -// Created by: drose (24Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "collisionSolid.h" - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::set_collide_mask -// Access: Public -// Description: Simultaneously sets both the "from" and "into" -// CollideMask values to the same thing. -//////////////////////////////////////////////////////////////////// -INLINE void CollisionNode:: -set_collide_mask(CollideMask mask) { - _from_collide_mask = mask; - _into_collide_mask = mask; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::set_from_collide_mask -// Access: Public -// Description: Sets the "from" CollideMask. In order for a -// collision to be detected from this object into -// another object, the intersection of this object's -// "from" mask and the other object's "into" mask must -// be nonzero. -//////////////////////////////////////////////////////////////////// -INLINE void CollisionNode:: -set_from_collide_mask(CollideMask mask) { - _from_collide_mask = mask; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::set_into_collide_mask -// Access: Public -// Description: Sets the "into" CollideMask. In order for a -// collision to be detected from another object into -// this object, the intersection of the other object's -// "from" mask and this object's "into" mask must be -// nonzero. -//////////////////////////////////////////////////////////////////// -INLINE void CollisionNode:: -set_into_collide_mask(CollideMask mask) { - _into_collide_mask = mask; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::get_from_collide_mask -// Access: Public -// Description: Returns the current "from" CollideMask. In order for -// a collision to be detected from this object into -// another object, the intersection of this object's -// "from" mask and the other object's "into" mask must -// be nonzero. -//////////////////////////////////////////////////////////////////// -INLINE CollideMask CollisionNode:: -get_from_collide_mask() const { - return _from_collide_mask; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::get_into_collide_mask -// Access: Public -// Description: Returns the current "into" CollideMask. In order for -// a collision to be detected from another object into -// this object, the intersection of the other object's -// "from" mask and this object's "into" mask must be -// nonzero. -//////////////////////////////////////////////////////////////////// -INLINE CollideMask CollisionNode:: -get_into_collide_mask() const { - return _into_collide_mask; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::set_collide_geom -// Access: Public -// Description: Sets the state of the "collide geom" flag for this -// CollisionNode. Normally, this is false; when this is -// set true, the CollisionSolids in this node will test -// for collisions with actual renderable geometry, in -// addition to whatever CollisionSolids may be indicated -// by the from_collide_mask. -// -// Setting this to true causes this to test *all* -// GeomNodes for collisions. It is an all-or-none -// thing; there is no way to collide with only some -// GeomNodes, as GeomNodes have no into_collide_mask. -//////////////////////////////////////////////////////////////////// -INLINE void CollisionNode:: -set_collide_geom(bool flag) { - _collide_geom = flag; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::get_collide_geom -// Access: Public -// Description: Returns the current state of the collide_geom flag. -// See set_collide_geom(). -//////////////////////////////////////////////////////////////////// -INLINE bool CollisionNode:: -get_collide_geom() const { - return _collide_geom; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::get_num_solids -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int CollisionNode:: -get_num_solids() const { - return _solids.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::get_solid -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CollisionSolid *CollisionNode:: -get_solid(int n) const { - nassertr(n >= 0 && n < get_num_solids(), NULL); - return _solids[n]; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::remove_solid -// Access: Public -// Description: Removes the solid with the indicated index. This -// will shift all subsequent indices down by one. -//////////////////////////////////////////////////////////////////// -INLINE void CollisionNode:: -remove_solid(int n) { - nassertv(n >= 0 && n < get_num_solids()); - _solids.erase(_solids.begin() + n); - mark_bound_stale(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::add_solid -// Access: Public -// Description: Adds the indicated solid to the node. Returns the -// index of the new solid within the node's list of -// solids. -//////////////////////////////////////////////////////////////////// -INLINE int CollisionNode:: -add_solid(CollisionSolid *solid) { - _solids.push_back(solid); - mark_bound_stale(); - return _solids.size() - 1; -} diff --git a/panda/src/collide/collisionNode.cxx b/panda/src/collide/collisionNode.cxx deleted file mode 100644 index c7bdf2fc20..0000000000 --- a/panda/src/collide/collisionNode.cxx +++ /dev/null @@ -1,347 +0,0 @@ -// Filename: collisionNode.cxx -// Created by: drose (24Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "collisionNode.h" -#include "config_collide.h" - -#include -#include -#include -#include - -TypeHandle CollisionNode::_type_handle; - - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -CollisionNode:: -CollisionNode(const string &name) : - NamedNode(name), - _from_collide_mask(CollideMask::all_on()), - _into_collide_mask(CollideMask::all_on()), - _collide_geom(false) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -CollisionNode:: -CollisionNode(const CollisionNode ©) : - NamedNode(copy), - _from_collide_mask(copy._from_collide_mask), - _into_collide_mask(copy._into_collide_mask), - _collide_geom(copy._collide_geom), - _solids(copy._solids) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void CollisionNode:: -operator = (const CollisionNode ©) { - NamedNode::operator = (copy); - _from_collide_mask = copy._from_collide_mask; - _into_collide_mask = copy._into_collide_mask; - _collide_geom = copy._collide_geom; - _solids = copy._solids; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -CollisionNode:: -~CollisionNode() { -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::make_copy -// Access: Public, Virtual -// Description: Returns a newly-allocated Node that is a shallow copy -// of this one. It will be a different Node pointer, -// but its internal data may or may not be shared with -// that of the original Node. -//////////////////////////////////////////////////////////////////// -Node *CollisionNode:: -make_copy() const { - return new CollisionNode(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::xform -// Access: Public, Virtual -// Description: Transforms the contents of this node by the indicated -// matrix, if it means anything to do so. For most -// kinds of nodes, this does nothing. -//////////////////////////////////////////////////////////////////// -void CollisionNode:: -xform(const LMatrix4f &mat) { - nassertv(!mat.is_nan()); - - if (mat.almost_equal(LMatrix4f::ident_mat())) { - return; - } - - Solids::iterator si; - for (si = _solids.begin(); si != _solids.end(); ++si) { - CollisionSolid *solid = (*si); - - // We may have to copy each of our solids as we transform them if - // someone else is sharing their pointers. - if (solid->get_ref_count() > 1) { - solid = solid->make_copy(); - (*si) = solid; - } - - solid->xform(mat); - } - mark_bound_stale(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::combine_with -// Access: Public, Virtual -// Description: Collapses this node with the other node, if possible, -// and returns a pointer to the combined node, or NULL -// if the two nodes cannot safely be combined. -// -// The return value may be this, other, or a new node -// altogether. -// -// This function is called from GraphReducer::flatten(), -// and need not deal with children; its job is just to -// decide whether to collapse the two nodes and what the -// collapsed node should look like. -//////////////////////////////////////////////////////////////////// -Node *CollisionNode:: -combine_with(Node *other) { - if (is_exact_type(get_class_type()) && - other->is_exact_type(get_class_type())) { - // Two CollisionNodes can combine, but only if they have the same - // name. - CollisionNode *cother = DCAST(CollisionNode, other); - if (get_name() == cother->get_name()) { - const PT(CollisionSolid) *solids_begin = &cother->_solids[0]; - const PT(CollisionSolid) *solids_end = solids_begin + cother->_solids.size(); - _solids.insert(_solids.end(), solids_begin, solids_end); - mark_bound_stale(); - return this; - } - - // Two CollisionNodes with different names can't combine. - return (Node *)NULL; - } - - return NamedNode::combine_with(other); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::preserve_name -// Access: Public, Virtual -// Description: Returns true if the node's name has extrinsic meaning -// and must be preserved across a flatten operation, -// false otherwise. -//////////////////////////////////////////////////////////////////// -bool CollisionNode:: -preserve_name() const { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::draw_traverse -// Access: Public, Virtual -// Description: This is called by the Draw traversal by virtue of the -// node's being present in the scene graph. Its job is -// to make sure the visualization of the collideable -// geometry is up-to-date. -//////////////////////////////////////////////////////////////////// -void CollisionNode:: -draw_traverse(const ArcChain &) { - Solids::iterator si; - for (si = _solids.begin(); si != _solids.end(); ++si) { - (*si)->update_viz(this); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::output -// Access: Public, Virtual -// Description: Writes a brief description of the node to the -// indicated output stream. This is invoked by the << -// operator. It may be overridden in derived classes to -// include some information relevant to the class. -//////////////////////////////////////////////////////////////////// -void CollisionNode:: -output(ostream &out) const { - NamedNode::output(out); - out << " (" << _solids.size() << " solids)"; -} - - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::recompute_bound -// Access: Protected, Virtual -// Description: Recomputes the dynamic bounding volume for this node. -//////////////////////////////////////////////////////////////////// -BoundingVolume *CollisionNode:: -recompute_bound() { - // First, get ourselves a fresh, empty bounding volume. - BoundingVolume *bound = BoundedObject::recompute_bound(); - nassertr(bound != (BoundingVolume *)NULL, bound); - - // Now actually compute the bounding volume by putting it around all - // of our solids' bounding volumes. - pvector child_volumes; - - Solids::const_iterator gi; - for (gi = _solids.begin(); gi != _solids.end(); ++gi) { - child_volumes.push_back(&(*gi)->get_bound()); - } - - const BoundingVolume **child_begin = &child_volumes[0]; - const BoundingVolume **child_end = child_begin + child_volumes.size(); - - bool success = - bound->around(child_begin, child_end); - -#ifdef NOTIFY_DEBUG - if (!success) { - collide_cat.error() - << "Unable to generate bounding volume for " << *this << ":\n" - << "Cannot put " << bound->get_type() << " around:\n"; - for (int i = 0; i < (int)child_volumes.size(); i++) { - collide_cat.error(false) - << " " << *child_volumes[i] << "\n"; - } - } -#endif - - return bound; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void CollisionNode:: -write_datagram(BamWriter *manager, Datagram &me) -{ - int i; - NamedNode::write_datagram(manager, me); - me.add_uint16(_solids.size()); - - for(i = 0; i < (int)_solids.size(); i++) - { - manager->write_pointer(me, _solids[i]); - } - - me.add_uint32(_from_collide_mask.get_word()); - me.add_uint32(_into_collide_mask.get_word()); - me.add_bool(_collide_geom); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void CollisionNode:: -fillin(DatagramIterator& scan, BamReader* manager) -{ - int i; - NamedNode::fillin(scan, manager); - int num_solids = scan.get_uint16(); - _solids.clear(); - _solids.reserve(num_solids); - - for(i = 0; i < num_solids; i++) { - manager->read_pointer(scan); - _solids.push_back((CollisionSolid *)NULL); - } - - _from_collide_mask.set_word(scan.get_uint32()); - _into_collide_mask.set_word(scan.get_uint32()); - _collide_geom = scan.get_bool(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::complete_pointers -// Access: Public -// Description: Takes in a vector of pointes to TypedWritable -// objects that correspond to all the requests for -// pointers that this object made to BamReader. -//////////////////////////////////////////////////////////////////// -int CollisionNode:: -complete_pointers(TypedWritable **p_list, BamReader* manager) { - int num_solids = _solids.size(); - int start = NamedNode::complete_pointers(p_list, manager); - - for (int i = 0; i < num_solids; i++) { - _solids[i] = DCAST(CollisionSolid, p_list[start + i]); - } - - return start + num_solids; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::make_CollisionNode -// Access: Protected -// Description: Factory method to generate a CollisionNode object -//////////////////////////////////////////////////////////////////// -TypedWritable* CollisionNode:: -make_CollisionNode(const FactoryParams ¶ms) -{ - CollisionNode *me = new CollisionNode; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionNode::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a CollisionNode object -//////////////////////////////////////////////////////////////////// -void CollisionNode:: -register_with_read_factory(void) -{ - BamReader::get_factory()->register_factory(get_class_type(), make_CollisionNode); -} - - - - diff --git a/panda/src/collide/collisionNode.h b/panda/src/collide/collisionNode.h deleted file mode 100644 index 9b58033faf..0000000000 --- a/panda/src/collide/collisionNode.h +++ /dev/null @@ -1,111 +0,0 @@ -// Filename: collisionNode.h -// Created by: drose (24Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef COLLISIONNODE_H -#define COLLISIONNODE_H - -#include - -#include "collisionSolid.h" - -#include -#include - -//////////////////////////////////////////////////////////////////// -// Class : CollisionNode -// Description : A node in the scene graph that can hold any number of -// CollisionSolids. This may either represent a bit of -// static geometry in the scene that things will collide -// with, or an animated object twirling around in the -// world and running into things. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA CollisionNode : public NamedNode { -PUBLISHED: - CollisionNode(const string &name = ""); - -public: - CollisionNode(const CollisionNode ©); - void operator = (const CollisionNode ©); - virtual ~CollisionNode(); - virtual Node *make_copy() const; - virtual void xform(const LMatrix4f &mat); - virtual Node *combine_with(Node *other); - virtual bool preserve_name() const; - -PUBLISHED: - INLINE void set_collide_mask(CollideMask mask); - INLINE void set_from_collide_mask(CollideMask mask); - INLINE void set_into_collide_mask(CollideMask mask); - INLINE CollideMask get_from_collide_mask() const; - INLINE CollideMask get_into_collide_mask() const; - - INLINE void set_collide_geom(bool flag); - INLINE bool get_collide_geom() const; - - INLINE int get_num_solids() const; - INLINE CollisionSolid *get_solid(int n) const; - INLINE void remove_solid(int n); - INLINE int add_solid(CollisionSolid *solid); - -public: - virtual void draw_traverse(const ArcChain &chain); - virtual void output(ostream &out) const; - -protected: - virtual BoundingVolume *recompute_bound(); - -private: - CollideMask _from_collide_mask; - CollideMask _into_collide_mask; - bool _collide_geom; - - typedef pvector< PT(CollisionSolid) > Solids; - Solids _solids; - -public: - static void register_with_read_factory(void); - virtual void write_datagram(BamWriter* manager, Datagram &me); - virtual int complete_pointers(TypedWritable **plist, - BamReader *manager); - - static TypedWritable *make_CollisionNode(const FactoryParams ¶ms); - -protected: - void fillin(DatagramIterator& scan, BamReader* manager); - -public: - static TypeHandle get_class_type(void) { - return _type_handle; - } - static void init_type(void) { - NamedNode::init_type(); - register_type(_type_handle, "CollisionNode", - NamedNode::get_class_type()); - } - virtual TypeHandle get_type(void) const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "collisionNode.I" - -#endif diff --git a/panda/src/collide/collisionPlane.cxx b/panda/src/collide/collisionPlane.cxx index e08723f981..ccd320f525 100644 --- a/panda/src/collide/collisionPlane.cxx +++ b/panda/src/collide/collisionPlane.cxx @@ -18,9 +18,7 @@ #include "collisionPlane.h" -#include "collisionHandler.h" #include "qpcollisionHandler.h" -#include "collisionEntry.h" #include "qpcollisionEntry.h" #include "collisionSphere.h" #include "collisionRay.h" @@ -36,8 +34,6 @@ #include "omniBoundingVolume.h" #include "geomQuad.h" -#include "geomNode.h" - TypeHandle CollisionPlane::_type_handle; //////////////////////////////////////////////////////////////////// @@ -50,20 +46,6 @@ make_copy() { return new CollisionPlane(*this); } -//////////////////////////////////////////////////////////////////// -// Function: CollisionPlane::test_intersection -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int CollisionPlane:: -test_intersection(CollisionHandler *, const CollisionEntry &, - const CollisionSolid *) const { - // Planes cannot currently be intersected from, only into. Do not - // add a CollisionPlane to a CollisionTraverser. - nassertr(false, 0); - return 0; -} - //////////////////////////////////////////////////////////////////// // Function: CollisionPlane::test_intersection // Access: Public, Virtual @@ -86,7 +68,7 @@ test_intersection(qpCollisionHandler *, const qpCollisionEntry &, void CollisionPlane:: xform(const LMatrix4f &mat) { _plane = _plane * mat; - clear_viz_arcs(); + mark_viz_stale(); mark_bound_stale(); } @@ -130,84 +112,6 @@ recompute_bound() { return set_bound_ptr(new OmniBoundingVolume); } -//////////////////////////////////////////////////////////////////// -// Function: CollisionPlane::test_intersection_from_sphere -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int CollisionPlane:: -test_intersection_from_sphere(CollisionHandler *record, - const CollisionEntry &entry) const { - const CollisionSphere *sphere; - DCAST_INTO_R(sphere, entry.get_from(), 0); - - LPoint3f from_center = sphere->get_center() * entry.get_wrt_space(); - LVector3f from_radius_v = - LVector3f(sphere->get_radius(), 0.0f, 0.0f) * entry.get_wrt_space(); - float from_radius = length(from_radius_v); - - float dist = dist_to_plane(from_center); - if (dist > from_radius) { - // No intersection. - return 0; - } - - if (collide_cat.is_debug()) { - collide_cat.debug() - << "intersection detected from " << *entry.get_from_node() << " into " - << entry.get_into_node_path() << "\n"; - } - PT(CollisionEntry) new_entry = new CollisionEntry(entry); - - LVector3f into_normal = get_normal() * entry.get_inv_wrt_space(); - float into_depth = from_radius - dist; - - new_entry->set_into_surface_normal(into_normal); - new_entry->set_into_depth(into_depth); - - record->add_entry(new_entry); - return 1; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionPlane::test_intersection_from_ray -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int CollisionPlane:: -test_intersection_from_ray(CollisionHandler *record, - const CollisionEntry &entry) const { - const CollisionRay *ray; - DCAST_INTO_R(ray, entry.get_from(), 0); - - LPoint3f from_origin = ray->get_origin() * entry.get_wrt_space(); - LVector3f from_direction = ray->get_direction() * entry.get_wrt_space(); - - float t; - if (!_plane.intersects_line(t, from_origin, from_direction)) { - // No intersection. - return 0; - } - - if (t < 0.0f) { - // The intersection point is before the start of the ray. - return 0; - } - - if (collide_cat.is_debug()) { - collide_cat.debug() - << "intersection detected from " << *entry.get_from_node() << " into " - << entry.get_into_node_path() << "\n"; - } - PT(CollisionEntry) new_entry = new CollisionEntry(entry); - - LPoint3f into_intersection_point = from_origin + t * from_direction; - new_entry->set_into_intersection_point(into_intersection_point); - - record->add_entry(new_entry); - return 1; -} - //////////////////////////////////////////////////////////////////// // Function: CollisionPlane::test_intersection_from_sphere // Access: Public, Virtual @@ -286,78 +190,6 @@ test_intersection_from_ray(qpCollisionHandler *record, return 1; } -//////////////////////////////////////////////////////////////////// -// Function: CollisionPlane::recompute_viz -// Access: Public, Virtual -// Description: Rebuilds the geometry that will be used to render a -// visible representation of the collision solid. -//////////////////////////////////////////////////////////////////// -void CollisionPlane:: -recompute_viz(Node *parent) { - if (collide_cat.is_debug()) { - collide_cat.debug() - << "Recomputing viz for " << *this << " on " << *parent << "\n"; - } - - // Since we can't represent an infinite plane, we'll have to be - // satisfied with drawing a big polygon. Choose four points on the - // plane to be the corners of the polygon. - - // We must choose four points fairly reasonably spread apart on - // the plane. We'll start with a center point and one corner - // point, and then use cross products to find the remaining three - // corners of a square. - - // The center point will be on the axis with the largest - // coefficent. The first corner will be diagonal in the other two - // dimensions. - - LPoint3f cp; - LVector3f p1, p2, p3, p4; - - LVector3f normal = get_normal(); - float D = _plane._d; - - if (fabs(normal[0]) > fabs(normal[1]) && - fabs(normal[0]) > fabs(normal[2])) { - // X has the largest coefficient. - cp.set(-D / normal[0], 0.0f, 0.0f); - p1 = LPoint3f(-(normal[1] + normal[2] + D)/normal[0], 1.0f, 1.0f) - cp; - - } else if (fabs(normal[1]) > fabs(normal[2])) { - // Y has the largest coefficient. - cp.set(0.0f, -D / normal[1], 0.0f); - p1 = LPoint3f(1.0f, -(normal[0] + normal[2] + D)/normal[1], 1.0f) - cp; - - } else { - // Z has the largest coefficient. - cp.set(0.0f, 0.0f, -D / normal[2]); - p1 = LPoint3f(1.0f, 1.0f, -(normal[0] + normal[1] + D)/normal[2]) - cp; - } - - p1.normalize(); - p2 = cross(normal, p1); - p3 = cross(normal, p2); - p4 = cross(normal, p3); - - static const double plane_scale = 10.0; - - PTA_Vertexf verts; - verts.push_back(cp + p1 * plane_scale); - verts.push_back(cp + p2 * plane_scale); - verts.push_back(cp + p3 * plane_scale); - verts.push_back(cp + p4 * plane_scale); - - GeomQuad *quad = new GeomQuad; - quad->set_coords(verts); - quad->set_num_prims(1); - - GeomNode *viz = new GeomNode("viz-plane"); - viz->add_geom(quad); - add_solid_viz(parent, viz); - add_wireframe_viz(parent, viz); -} - //////////////////////////////////////////////////////////////////// // Function: CollisionPlane::fill_viz_geom // Access: Protected, Virtual diff --git a/panda/src/collide/collisionPlane.h b/panda/src/collide/collisionPlane.h index 6f8f09f70c..3b221cf5e4 100644 --- a/panda/src/collide/collisionPlane.h +++ b/panda/src/collide/collisionPlane.h @@ -19,12 +19,12 @@ #ifndef COLLISIONPLANE_H #define COLLISIONPLANE_H -#include +#include "pandabase.h" #include "collisionSolid.h" -#include -#include +#include "luse.h" +#include "plane.h" /////////////////////////////////////////////////////////////////// // Class : CollisionPlane @@ -41,11 +41,6 @@ PUBLISHED: public: virtual CollisionSolid *make_copy(); - virtual int - test_intersection(CollisionHandler *record, - const CollisionEntry &entry, - const CollisionSolid *into) const; - virtual int test_intersection(qpCollisionHandler *record, const qpCollisionEntry &entry, @@ -68,19 +63,12 @@ protected: protected: virtual int - test_intersection_from_sphere(CollisionHandler *record, - const CollisionEntry &entry) const; - virtual int - test_intersection_from_ray(CollisionHandler *record, - const CollisionEntry &entry) const; - virtual int test_intersection_from_sphere(qpCollisionHandler *record, const qpCollisionEntry &entry) const; virtual int test_intersection_from_ray(qpCollisionHandler *record, const qpCollisionEntry &entry) const; - virtual void recompute_viz(Node *parent); virtual void fill_viz_geom(); private: diff --git a/panda/src/collide/collisionPolygon.cxx b/panda/src/collide/collisionPolygon.cxx index f622c63178..f38c927aa2 100644 --- a/panda/src/collide/collisionPolygon.cxx +++ b/panda/src/collide/collisionPolygon.cxx @@ -18,9 +18,7 @@ #include "collisionPolygon.h" -#include "collisionHandler.h" #include "qpcollisionHandler.h" -#include "collisionEntry.h" #include "qpcollisionEntry.h" #include "collisionSphere.h" #include "collisionRay.h" @@ -37,8 +35,6 @@ #include "bamWriter.h" #include "geomPolygon.h" -#include "geomNode.h" - #include TypeHandle CollisionPolygon::_type_handle; @@ -124,20 +120,6 @@ verify_points(const LPoint3f *begin, const LPoint3f *end) { return all_ok; } -//////////////////////////////////////////////////////////////////// -// Function: CollisionPolygon::test_intersection -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int CollisionPolygon:: -test_intersection(CollisionHandler *, const CollisionEntry &, - const CollisionSolid *into) const { - // Polygons cannot currently be intersected from, only into. Do not - // add a CollisionPolygon to a CollisionTraverser. - nassertr(false, 0); - return 0; -} - //////////////////////////////////////////////////////////////////// // Function: CollisionPolygon::test_intersection // Access: Public, Virtual @@ -188,7 +170,7 @@ xform(const LMatrix4f &mat) { setup_points(verts_begin, verts_end); } - clear_viz_arcs(); + mark_viz_stale(); mark_bound_stale(); } @@ -243,212 +225,6 @@ recompute_bound() { return bound; } -//////////////////////////////////////////////////////////////////// -// Function: CollisionPolygon::test_intersection_from_sphere -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int CollisionPolygon:: -test_intersection_from_sphere(CollisionHandler *record, - const CollisionEntry &entry) const { - if (_points.size() < 3) { - return 0; - } - - const CollisionSphere *sphere; - DCAST_INTO_R(sphere, entry.get_from(), 0); - - LPoint3f from_center = sphere->get_center() * entry.get_wrt_space(); - LVector3f from_radius_v = - LVector3f(sphere->get_radius(), 0.0f, 0.0f) * entry.get_wrt_space(); - float from_radius = length(from_radius_v); - - float dist = dist_to_plane(from_center); - if (dist > from_radius || dist < -from_radius) { - // No intersection. - return 0; - } - - // Ok, we intersected the plane, but did we intersect the polygon? - - // The nearest point within the plane to our center is the - // intersection of the line (center, center+normal) with the plane. - LPoint3f plane_point; - bool really_intersects = - get_plane().intersects_line(plane_point, - from_center, from_center + get_normal()); - nassertr(really_intersects, 0); - - LPoint2f p = to_2d(plane_point); - - // Now we have found a point on the polygon's plane that corresponds - // to the point tangent to our collision sphere where it first - // touches the plane. We want to decide whether the sphere itself - // will intersect the polygon. We can approximate this by testing - // whether a circle of the given radius centered around this tangent - // point, in the plane of the polygon, would intersect. - - // But even this approximate test is too difficult. To approximate - // the approximation, we'll test two points: (1) the center itself. - // If this is inside the polygon, then certainly the circle - // intersects the polygon, and the sphere collides. (2) a point on - // the outside of the circle, nearest to the center of the polygon. - // If _this_ point is inside the polygon, then again the circle, and - // hence the sphere, intersects. If neither point is inside the - // polygon, chances are reasonably good the sphere doesn't intersect - // the polygon after all. - - if (is_inside(p)) { - // The circle's center is inside the polygon; we have a collision! - - } else { - - if (from_radius > 0.0f) { - // Now find the point on the rim of the circle nearest the - // polygon's center. - - // First, get a vector from the center of the circle to the center - // of the polygon. - LVector2f rim = _median - p; - float rim_length = length(rim); - - if (rim_length <= from_radius) { - // Here's a surprise: the center of the polygon is within the - // circle! Since the center is guaranteed to be interior to the - // polygon (the polygon is convex), it follows that the circle - // intersects the polygon. - - } else { - // Now scale this vector to length radius, and get the new point. - rim = (rim * from_radius / rim_length) + p; - - // Is the new point within the polygon? - if (is_inside(rim)) { - // It sure is! The circle intersects! - - } else { - // No intersection. - return 0; - } - } - } - } - - if (collide_cat.is_debug()) { - collide_cat.debug() - << "intersection detected from " << *entry.get_from_node() << " into " - << entry.get_into_node_path() << "\n"; - } - PT(CollisionEntry) new_entry = new CollisionEntry(entry); - - LVector3f into_normal = get_normal() * entry.get_inv_wrt_space(); - float into_depth = from_radius - dist; - - new_entry->set_into_surface_normal(into_normal); - new_entry->set_into_depth(into_depth); - - record->add_entry(new_entry); - return 1; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionPolygon::test_intersection_from_ray -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int CollisionPolygon:: -test_intersection_from_ray(CollisionHandler *record, - const CollisionEntry &entry) const { - if (_points.size() < 3) { - return 0; - } - - const CollisionRay *ray; - DCAST_INTO_R(ray, entry.get_from(), 0); - - LPoint3f from_origin = ray->get_origin() * entry.get_wrt_space(); - LVector3f from_direction = ray->get_direction() * entry.get_wrt_space(); - - float t; - if (!get_plane().intersects_line(t, from_origin, from_direction)) { - // No intersection. - return 0; - } - - if (t < 0.0f) { - // The intersection point is before the start of the ray. - return 0; - } - - LPoint3f plane_point = from_origin + t * from_direction; - if (!is_inside(to_2d(plane_point))) { - // Outside the polygon's perimeter. - return 0; - } - - if (collide_cat.is_debug()) { - collide_cat.debug() - << "intersection detected from " << *entry.get_from_node() << " into " - << entry.get_into_node_path() << "\n"; - } - PT(CollisionEntry) new_entry = new CollisionEntry(entry); - - new_entry->set_into_intersection_point(plane_point); - - record->add_entry(new_entry); - return 1; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionPolygon::test_intersection_from_segment -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int CollisionPolygon:: -test_intersection_from_segment(CollisionHandler *record, - const CollisionEntry &entry) const { - if (_points.size() < 3) { - return 0; - } - - const CollisionSegment *segment; - DCAST_INTO_R(segment, entry.get_from(), 0); - - LPoint3f from_a = segment->get_point_a() * entry.get_wrt_space(); - LPoint3f from_b = segment->get_point_b() * entry.get_wrt_space(); - LPoint3f from_direction = from_b - from_a; - - float t; - if (!get_plane().intersects_line(t, from_a, from_direction)) { - // No intersection. - return 0; - } - - if (t < 0.0f || t > 1.0f) { - // The intersection point is before the start of the segment or - // after the end of the segment. - return 0; - } - - LPoint3f plane_point = from_a + t * from_direction; - if (!is_inside(to_2d(plane_point))) { - // Outside the polygon's perimeter. - return 0; - } - - if (collide_cat.is_debug()) { - collide_cat.debug() - << "intersection detected from " << *entry.get_from_node() << " into " - << entry.get_into_node_path() << "\n"; - } - PT(CollisionEntry) new_entry = new CollisionEntry(entry); - - new_entry->set_into_intersection_point(plane_point); - - record->add_entry(new_entry); - return 1; -} - //////////////////////////////////////////////////////////////////// // Function: CollisionPolygon::test_intersection_from_sphere // Access: Public, Virtual @@ -655,50 +431,6 @@ test_intersection_from_segment(qpCollisionHandler *record, return 1; } -//////////////////////////////////////////////////////////////////// -// Function: CollisionPolygon::recompute_viz -// Access: Public, Virtual -// Description: Rebuilds the geometry that will be used to render a -// visible representation of the collision solid. -//////////////////////////////////////////////////////////////////// -void CollisionPolygon:: -recompute_viz(Node *parent) { - if (collide_cat.is_debug()) { - collide_cat.debug() - << "Recomputing viz for " << *this << " on " << *parent << "\n"; - } - - if (_points.size() < 3) { - if (collide_cat.is_debug()) { - collide_cat.debug() - << "(Degenerate poly, ignoring.)\n"; - } - return; - } - - PTA_Vertexf verts; - Points::const_iterator pi; - for (pi = _points.begin(); pi != _points.end(); ++pi) { - verts.push_back(to_3d(*pi)); - } - if (_reversed) { - reverse(verts.begin(), verts.end()); - } - - PTA_int lengths; - lengths.push_back(_points.size()); - - GeomPolygon *polygon = new GeomPolygon; - polygon->set_coords(verts); - polygon->set_num_prims(1); - polygon->set_lengths(lengths); - - GeomNode *viz = new GeomNode("viz-polygon"); - viz->add_geom(polygon); - add_solid_viz(parent, viz); - add_wireframe_viz(parent, viz); -} - //////////////////////////////////////////////////////////////////// // Function: CollisionPolygon::fill_viz_geom // Access: Protected, Virtual diff --git a/panda/src/collide/collisionPolygon.h b/panda/src/collide/collisionPolygon.h index ec952f6f34..f9c3baa5d3 100644 --- a/panda/src/collide/collisionPolygon.h +++ b/panda/src/collide/collisionPolygon.h @@ -49,11 +49,6 @@ public: static bool verify_points(const LPoint3f *begin, const LPoint3f *end); - virtual int - test_intersection(CollisionHandler *record, - const CollisionEntry &entry, - const CollisionSolid *into) const; - virtual int test_intersection(qpCollisionHandler *record, const qpCollisionEntry &entry, @@ -69,16 +64,6 @@ protected: virtual BoundingVolume *recompute_bound(); protected: - virtual int - test_intersection_from_sphere(CollisionHandler *record, - const CollisionEntry &entry) const; - virtual int - test_intersection_from_ray(CollisionHandler *record, - const CollisionEntry &entry) const; - virtual int - test_intersection_from_segment(CollisionHandler *record, - const CollisionEntry &entry) const; - virtual int test_intersection_from_sphere(qpCollisionHandler *record, const qpCollisionEntry &entry) const; @@ -89,7 +74,6 @@ protected: test_intersection_from_segment(qpCollisionHandler *record, const qpCollisionEntry &entry) const; - virtual void recompute_viz(Node *parent); virtual void fill_viz_geom(); private: diff --git a/panda/src/collide/collisionRay.I b/panda/src/collide/collisionRay.I index 2e0343fd4c..41032cc610 100644 --- a/panda/src/collide/collisionRay.I +++ b/panda/src/collide/collisionRay.I @@ -134,20 +134,6 @@ get_direction() const { return _direction; } -//////////////////////////////////////////////////////////////////// -// Function: CollisionRay::set_from_lens -// Access: Public -// Description: Accepts a LensNode and a 2-d point in the range -// [-1,1]. Sets the CollisionRay so that it begins at -// the LensNode's near plane and extends to -// infinity, making it suitable for picking objects from -// the screen given a camera and a mouse location. -//////////////////////////////////////////////////////////////////// -INLINE bool CollisionRay:: -set_from_lens(LensNode *camera, float px, float py) { - return set_from_lens(camera, LPoint2f(px, py)); -} - //////////////////////////////////////////////////////////////////// // Function: CollisionRay::set_from_lens // Access: Public diff --git a/panda/src/collide/collisionRay.cxx b/panda/src/collide/collisionRay.cxx index c653c32115..d382c639fe 100644 --- a/panda/src/collide/collisionRay.cxx +++ b/panda/src/collide/collisionRay.cxx @@ -17,9 +17,7 @@ //////////////////////////////////////////////////////////////////// #include "collisionRay.h" -#include "collisionHandler.h" #include "qpcollisionHandler.h" -#include "collisionEntry.h" #include "qpcollisionEntry.h" #include "config_collide.h" #include "geom.h" @@ -33,9 +31,6 @@ #include "bamReader.h" #include "bamWriter.h" -#include "lensNode.h" -#include "geomNode.h" - TypeHandle CollisionRay::_type_handle; @@ -49,17 +44,6 @@ make_copy() { return new CollisionRay(*this); } -//////////////////////////////////////////////////////////////////// -// Function: CollisionRay::test_intersection -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int CollisionRay:: -test_intersection(CollisionHandler *record, const CollisionEntry &entry, - const CollisionSolid *into) const { - return into->test_intersection_from_ray(record, entry); -} - //////////////////////////////////////////////////////////////////// // Function: CollisionRay::test_intersection // Access: Public, Virtual @@ -80,7 +64,7 @@ void CollisionRay:: xform(const LMatrix4f &mat) { _origin = _origin * mat; _direction = _direction * mat; - clear_viz_arcs(); + mark_viz_stale(); mark_bound_stale(); } @@ -107,39 +91,6 @@ output(ostream &out) const { out << "ray, o (" << _origin << "), d (" << _direction << ")"; } -//////////////////////////////////////////////////////////////////// -// Function: CollisionRay::set_from_lens -// Access: Public -// Description: Accepts a LensNode and a 2-d point in the range -// [-1,1]. Sets the CollisionRay so that it begins at -// the LensNode's near plane and extends to -// infinity, making it suitable for picking objects from -// the screen given a camera and a mouse location. -// -// Returns true if the point was acceptable, false -// otherwise. -//////////////////////////////////////////////////////////////////// -bool CollisionRay:: -set_from_lens(LensNode *camera, const LPoint2f &point) { - Lens *lens = camera->get_lens(); - - bool success = true; - LPoint3f near_point, far_point; - if (!lens->extrude(point, near_point, far_point)) { - _origin = LPoint3f::origin(); - _direction = LVector3f::forward(); - success = false; - } else { - _origin = near_point; - _direction = far_point - near_point; - } - - mark_bound_stale(); - mark_viz_stale(); - - return success; -} - //////////////////////////////////////////////////////////////////// // Function: CollisionRay::set_from_lens // Access: Public @@ -186,46 +137,6 @@ recompute_bound() { return set_bound_ptr(new BoundingLine(_origin, _origin + _direction)); } -//////////////////////////////////////////////////////////////////// -// Function: CollisionRay::recompute_viz -// Access: Public, Virtual -// Description: Rebuilds the geometry that will be used to render a -// visible representation of the collision solid. -//////////////////////////////////////////////////////////////////// -void CollisionRay:: -recompute_viz(Node *parent) { - if (collide_cat.is_debug()) { - collide_cat.debug() - << "Recomputing viz for " << *this << " on " << *parent << "\n"; - } - - GeomLinestrip *ray = new GeomLinestrip; - PTA_Vertexf verts; - PTA_Colorf colors; - PTA_int lengths; - - #define NUM_POINTS 100 - verts.reserve(NUM_POINTS); - colors.reserve(NUM_POINTS); - - for (int i = 0; i < NUM_POINTS; i++) { - verts.push_back(_origin + (double)i * _direction); - colors.push_back(Colorf(1.0f, 1.0f, 1.0f, 1.0f)+ - ((double)i / 100.0) * Colorf(0.0f, 0.0f, 0.0f, -1.0f)); - } - ray->set_coords(verts); - ray->set_colors(colors, G_PER_VERTEX); - - lengths.push_back(NUM_POINTS-1); - ray->set_lengths(lengths); - - ray->set_num_prims(1); - - GeomNode *viz = new GeomNode("viz-ray"); - viz->add_geom(ray); - add_other_viz(parent, viz); -} - //////////////////////////////////////////////////////////////////// // Function: CollisionRay::fill_viz_geom // Access: Protected, Virtual diff --git a/panda/src/collide/collisionRay.h b/panda/src/collide/collisionRay.h index 04e8906ee1..7e22374476 100644 --- a/panda/src/collide/collisionRay.h +++ b/panda/src/collide/collisionRay.h @@ -23,7 +23,6 @@ #include "collisionSolid.h" -class LensNode; class qpLensNode; /////////////////////////////////////////////////////////////////// @@ -45,11 +44,6 @@ public: INLINE CollisionRay(const CollisionRay ©); virtual CollisionSolid *make_copy(); - virtual int - test_intersection(CollisionHandler *record, - const CollisionEntry &entry, - const CollisionSolid *into) const; - virtual int test_intersection(qpCollisionHandler *record, const qpCollisionEntry &entry, @@ -69,9 +63,6 @@ PUBLISHED: INLINE void set_direction(float x, float y, float z); INLINE const LVector3f &get_direction() const; - bool set_from_lens(LensNode *camera, const LPoint2f &point); - INLINE bool set_from_lens(LensNode *camera, float px, float py); - bool set_from_lens(qpLensNode *camera, const LPoint2f &point); INLINE bool set_from_lens(qpLensNode *camera, float px, float py); @@ -79,7 +70,6 @@ protected: virtual BoundingVolume *recompute_bound(); protected: - virtual void recompute_viz(Node *parent); virtual void fill_viz_geom(); private: diff --git a/panda/src/collide/collisionSegment.I b/panda/src/collide/collisionSegment.I index bf9d8eee2b..6320e4100f 100644 --- a/panda/src/collide/collisionSegment.I +++ b/panda/src/collide/collisionSegment.I @@ -137,20 +137,6 @@ get_point_b() const { return _b; } -//////////////////////////////////////////////////////////////////// -// Function: CollisionSegment::set_from_lens -// Access: Public -// Description: Accepts a LensNode and a 2-d point in the range -// [-1,1]. Sets the CollisionSegment so that it begins at -// the LensNode's near plane and extends to the -// far plane, making it suitable for picking objects -// from the screen given a camera and a mouse location. -//////////////////////////////////////////////////////////////////// -INLINE bool CollisionSegment:: -set_from_lens(LensNode *camera, float px, float py) { - return set_from_lens(camera, LPoint2f(px, py)); -} - //////////////////////////////////////////////////////////////////// // Function: CollisionSegment::set_from_lens // Access: Public diff --git a/panda/src/collide/collisionSegment.cxx b/panda/src/collide/collisionSegment.cxx index ffe01de4e1..cd493b2bab 100644 --- a/panda/src/collide/collisionSegment.cxx +++ b/panda/src/collide/collisionSegment.cxx @@ -18,9 +18,7 @@ #include "collisionSegment.h" -#include "collisionHandler.h" #include "qpcollisionHandler.h" -#include "collisionEntry.h" #include "qpcollisionEntry.h" #include "config_collide.h" @@ -35,9 +33,6 @@ #include "bamReader.h" #include "bamWriter.h" -#include "geomNode.h" -#include "lensNode.h" - TypeHandle CollisionSegment::_type_handle; @@ -51,17 +46,6 @@ make_copy() { return new CollisionSegment(*this); } -//////////////////////////////////////////////////////////////////// -// Function: CollisionSegment::test_intersection -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int CollisionSegment:: -test_intersection(CollisionHandler *record, const CollisionEntry &entry, - const CollisionSolid *into) const { - return into->test_intersection_from_segment(record, entry); -} - //////////////////////////////////////////////////////////////////// // Function: CollisionSegment::test_intersection // Access: Public, Virtual @@ -82,7 +66,7 @@ void CollisionSegment:: xform(const LMatrix4f &mat) { _a = _a * mat; _b = _b * mat; - clear_viz_arcs(); + mark_viz_stale(); mark_bound_stale(); } @@ -109,35 +93,6 @@ output(ostream &out) const { out << "segment, a (" << _a << "), b (" << _b << ")"; } -//////////////////////////////////////////////////////////////////// -// Function: CollisionSegment::set_from_lens -// Access: Public -// Description: Accepts a LensNode and a 2-d point in the range -// [-1,1]. Sets the CollisionSegment so that it begins at -// the LensNode's near plane and extends to the -// far plane, making it suitable for picking objects -// from the screen given a camera and a mouse location. -// -// Returns true if the point was acceptable, false -// otherwise. -//////////////////////////////////////////////////////////////////// -bool CollisionSegment:: -set_from_lens(LensNode *camera, const LPoint2f &point) { - Lens *proj = camera->get_lens(); - - bool success = true; - if (!proj->extrude(point, _a, _b)) { - _a = LPoint3f::origin(); - _b = _a + LVector3f::forward(); - success = false; - } - - mark_bound_stale(); - mark_viz_stale(); - - return success; -} - //////////////////////////////////////////////////////////////////// // Function: CollisionSegment::set_from_lens // Access: Public @@ -190,35 +145,6 @@ recompute_bound() { return bound; } -//////////////////////////////////////////////////////////////////// -// Function: CollisionSegment::recompute_viz -// Access: Public, Virtual -// Description: Rebuilds the geometry that will be used to render a -// visible representation of the collision solid. -//////////////////////////////////////////////////////////////////// -void CollisionSegment:: -recompute_viz(Node *parent) { - if (collide_cat.is_debug()) { - collide_cat.debug() - << "Recomputing viz for " << *this << " on " << *parent << "\n"; - } - - GeomLine *segment = new GeomLine; - PTA_Vertexf verts; - PTA_Colorf colors; - verts.push_back(_a); - verts.push_back(_b); - colors.push_back(Colorf(1.0f, 1.0f, 1.0f, 1.0f)); - segment->set_coords(verts); - segment->set_colors(colors, G_OVERALL); - - segment->set_num_prims(1); - - GeomNode *viz = new GeomNode("viz-segment"); - viz->add_geom(segment); - add_other_viz(parent, viz); -} - //////////////////////////////////////////////////////////////////// // Function: CollisionSegment::fill_viz_geom // Access: Protected, Virtual diff --git a/panda/src/collide/collisionSegment.h b/panda/src/collide/collisionSegment.h index 402b70f52a..39dc9586b3 100644 --- a/panda/src/collide/collisionSegment.h +++ b/panda/src/collide/collisionSegment.h @@ -23,7 +23,6 @@ #include "collisionSolid.h" -class LensNode; class qpLensNode; /////////////////////////////////////////////////////////////////// @@ -48,11 +47,6 @@ public: INLINE CollisionSegment(const CollisionSegment ©); virtual CollisionSolid *make_copy(); - virtual int - test_intersection(CollisionHandler *record, - const CollisionEntry &entry, - const CollisionSolid *into) const; - virtual int test_intersection(qpCollisionHandler *record, const qpCollisionEntry &entry, @@ -72,9 +66,6 @@ PUBLISHED: INLINE void set_point_b(float x, float y, float z); INLINE const LPoint3f &get_point_b() const; - bool set_from_lens(LensNode *camera, const LPoint2f &point); - INLINE bool set_from_lens(LensNode *camera, float px, float py); - bool set_from_lens(qpLensNode *camera, const LPoint2f &point); INLINE bool set_from_lens(qpLensNode *camera, float px, float py); @@ -82,7 +73,6 @@ protected: virtual BoundingVolume *recompute_bound(); protected: - virtual void recompute_viz(Node *parent); virtual void fill_viz_geom(); private: diff --git a/panda/src/collide/collisionSolid.I b/panda/src/collide/collisionSolid.I index 3ac02d5161..3c1cd7a108 100644 --- a/panda/src/collide/collisionSolid.I +++ b/panda/src/collide/collisionSolid.I @@ -59,6 +59,5 @@ is_tangible() const { //////////////////////////////////////////////////////////////////// INLINE void CollisionSolid:: mark_viz_stale() { - _viz_stale = true; _viz_geom_stale = true; } diff --git a/panda/src/collide/collisionSolid.cxx b/panda/src/collide/collisionSolid.cxx index 2919e4c50d..df7f8589fa 100644 --- a/panda/src/collide/collisionSolid.cxx +++ b/panda/src/collide/collisionSolid.cxx @@ -19,7 +19,6 @@ #include "collisionSolid.h" #include "config_collide.h" -#include "collisionEntry.h" #include "collisionSphere.h" #include "collisionRay.h" #include "collisionSegment.h" @@ -35,14 +34,6 @@ #include "transparencyAttrib.h" #include "qpgeomNode.h" -#include "renderRelation.h" -#include "geomNode.h" -#include "cullFaceTransition.h" -#include "colorTransition.h" -#include "renderModeTransition.h" -#include "transparencyTransition.h" -#include "textureTransition.h" - TypeHandle CollisionSolid::_type_handle; //////////////////////////////////////////////////////////////////// @@ -52,7 +43,6 @@ TypeHandle CollisionSolid::_type_handle; //////////////////////////////////////////////////////////////////// CollisionSolid:: CollisionSolid() { - _viz_stale = true; _viz_geom_stale = true; _tangible = true; } @@ -67,7 +57,6 @@ CollisionSolid(const CollisionSolid ©) : _tangible(copy._tangible) { // Actually, there's not a whole lot here we want to copy. - _viz_stale = true; _viz_geom_stale = true; } @@ -78,21 +67,6 @@ CollisionSolid(const CollisionSolid ©) : //////////////////////////////////////////////////////////////////// CollisionSolid:: ~CollisionSolid() { - clear_viz_arcs(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionSolid::update_viz -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void CollisionSolid:: -update_viz(Node *parent) { - if (_viz_stale) { - clear_viz_arcs(); - recompute_viz(parent); - _viz_stale = false; - } } //////////////////////////////////////////////////////////////////// @@ -137,45 +111,6 @@ write(ostream &out, int indent_level) const { indent(out, indent_level) << (*this) << "\n"; } -//////////////////////////////////////////////////////////////////// -// Function: CollisionSolid::test_intersection_from_sphere -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int CollisionSolid:: -test_intersection_from_sphere(CollisionHandler *, - const CollisionEntry &) const { - report_undefined_intersection_test(CollisionSphere::get_class_type(), - get_type()); - return 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionSolid::test_intersection_from_ray -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int CollisionSolid:: -test_intersection_from_ray(CollisionHandler *, - const CollisionEntry &) const { - report_undefined_intersection_test(CollisionRay::get_class_type(), - get_type()); - return 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionSolid::test_intersection_from_segment -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int CollisionSolid:: -test_intersection_from_segment(CollisionHandler *, - const CollisionEntry &) const { - report_undefined_intersection_test(CollisionSegment::get_class_type(), - get_type()); - return 0; -} - //////////////////////////////////////////////////////////////////// // Function: CollisionSolid::test_intersection_from_sphere // Access: Protected, Virtual @@ -244,75 +179,6 @@ report_undefined_intersection_test(TypeHandle from_type, TypeHandle into_type) { #endif } -//////////////////////////////////////////////////////////////////// -// Function: CollisionSolid::clear_viz_arcs -// Access: Protected -// Description: Removes all of the solids' visualization geometry and -// marks the viz as stale so it will be recomputed next -// time the solid is rendered. -//////////////////////////////////////////////////////////////////// -void CollisionSolid:: -clear_viz_arcs() { - VizArcs::iterator vi; - for (vi = _solid_viz_arcs.begin(); vi != _solid_viz_arcs.end(); ++vi) { - remove_arc(*vi); - } - for (vi = _wireframe_viz_arcs.begin(); vi != _wireframe_viz_arcs.end(); ++vi) { - remove_arc(*vi); - } - for (vi = _other_viz_arcs.begin(); vi != _other_viz_arcs.end(); ++vi) { - remove_arc(*vi); - } - _solid_viz_arcs.clear(); - _wireframe_viz_arcs.clear(); - _other_viz_arcs.clear(); - _viz_stale = true; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionSolid::add_solid_viz -// Access: Protected -// Description: -//////////////////////////////////////////////////////////////////// -void CollisionSolid:: -add_solid_viz(Node *parent, GeomNode *viz) { - RenderRelation *arc = new RenderRelation(parent, viz); - arc->set_transition(new CullFaceTransition(CullFaceProperty::M_cull_clockwise)); - arc->set_transition(new RenderModeTransition(RenderModeProperty::M_filled)); - arc->set_transition(new TextureTransition(TextureTransition::off())); - arc->set_transition(new TransparencyTransition(TransparencyProperty::M_alpha)); - - if (is_tangible()) { - arc->set_transition(new ColorTransition(1.0f, 1.0f, 1.0f, 0.5)); - } else { - arc->set_transition(new ColorTransition(1.0f, 0.3, 0.5, 0.5)); - } - - _solid_viz_arcs.push_back(arc); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionSolid::add_wireframe_viz -// Access: Protected -// Description: -//////////////////////////////////////////////////////////////////// -void CollisionSolid:: -add_wireframe_viz(Node *parent, GeomNode *viz) { - RenderRelation *arc = new RenderRelation(parent, viz); - arc->set_transition(new CullFaceTransition(CullFaceProperty::M_cull_none)); - arc->set_transition(new RenderModeTransition(RenderModeProperty::M_wireframe)); - arc->set_transition(new TextureTransition(TextureTransition::off())); - arc->set_transition(new TransparencyTransition(TransparencyProperty::M_none)); - float r,g,b; - if (is_tangible()) { - r=1.0f; g=1.0f; b=0.0f; - } else { - r=0.0f; g=0.0f; b=1.0f; - } - arc->set_transition(new ColorTransition(r,g,b,1.0f)); - _wireframe_viz_arcs.push_back(arc); -} - //////////////////////////////////////////////////////////////////// // Function: CollisionSolid::write_datagram // Access: Public @@ -340,22 +206,6 @@ fillin(DatagramIterator& scan, BamReader*) } -//////////////////////////////////////////////////////////////////// -// Function: CollisionSolid::add_other_viz -// Access: Protected -// Description: -//////////////////////////////////////////////////////////////////// -void CollisionSolid:: -add_other_viz(Node *parent, GeomNode *viz) { - RenderRelation *arc = new RenderRelation(parent, viz); - arc->set_transition(new CullFaceTransition(CullFaceProperty::M_cull_clockwise)); - arc->set_transition(new RenderModeTransition(RenderModeProperty::M_filled)); - arc->set_transition(new TextureTransition(TextureTransition::off())); - arc->set_transition(new TransparencyTransition(TransparencyProperty::M_alpha)); - - _other_viz_arcs.push_back(arc); -} - //////////////////////////////////////////////////////////////////// // Function: CollisionSolid::fill_viz_geom // Access: Protected, Virtual diff --git a/panda/src/collide/collisionSolid.h b/panda/src/collide/collisionSolid.h index 971cd5a67e..7be22f53ef 100644 --- a/panda/src/collide/collisionSolid.h +++ b/panda/src/collide/collisionSolid.h @@ -28,18 +28,10 @@ #include "renderState.h" #include "qpgeomNode.h" -#include "nodeRelation.h" -#include "node.h" -#include "vector_PT_NodeRelation.h" - -class CollisionHandler; class qpCollisionHandler; -class CollisionEntry; class qpCollisionEntry; class CollisionSphere; -class Node; -class GeomNode; -class CollisionNode; +class qpGeomNode; class qpCollisionNode; /////////////////////////////////////////////////////////////////// @@ -71,17 +63,12 @@ PUBLISHED: public: virtual int - test_intersection(CollisionHandler *record, - const CollisionEntry &entry, - const CollisionSolid *into) const=0; - virtual int test_intersection(qpCollisionHandler *record, const qpCollisionEntry &entry, const CollisionSolid *into) const=0; virtual void xform(const LMatrix4f &mat)=0; - void update_viz(Node *parent); qpGeomNode *get_viz(); PUBLISHED: @@ -90,15 +77,6 @@ PUBLISHED: protected: virtual int - test_intersection_from_sphere(CollisionHandler *record, - const CollisionEntry &entry) const; - virtual int - test_intersection_from_ray(CollisionHandler *record, - const CollisionEntry &entry) const; - virtual int - test_intersection_from_segment(CollisionHandler *record, - const CollisionEntry &entry) const; - virtual int test_intersection_from_sphere(qpCollisionHandler *record, const qpCollisionEntry &entry) const; virtual int @@ -113,25 +91,13 @@ protected: TypeHandle into_type); INLINE void mark_viz_stale(); - void clear_viz_arcs(); - void add_solid_viz(Node *parent, GeomNode *viz); - void add_wireframe_viz(Node *parent, GeomNode *viz); - void add_other_viz(Node *parent, GeomNode *viz); - - virtual void recompute_viz(Node *parent)=0; virtual void fill_viz_geom(); CPT(RenderState) get_solid_viz_state(); CPT(RenderState) get_wireframe_viz_state(); CPT(RenderState) get_other_viz_state(); - typedef vector_PT_NodeRelation VizArcs; - VizArcs _solid_viz_arcs; - VizArcs _wireframe_viz_arcs; - VizArcs _other_viz_arcs; PT(qpGeomNode) _viz_geom; - bool _viz_stale; - bool _viz_geom_stale; bool _tangible; diff --git a/panda/src/collide/collisionSphere.cxx b/panda/src/collide/collisionSphere.cxx index 3f34a6af22..eccb08dd2c 100644 --- a/panda/src/collide/collisionSphere.cxx +++ b/panda/src/collide/collisionSphere.cxx @@ -20,19 +20,15 @@ #include "collisionSphere.h" #include "collisionRay.h" #include "collisionSegment.h" -#include "collisionHandler.h" #include "qpcollisionHandler.h" -#include "collisionEntry.h" #include "qpcollisionEntry.h" #include "config_collide.h" #include "boundingSphere.h" -#include "geomNode.h" #include "datagram.h" #include "datagramIterator.h" #include "bamReader.h" #include "bamWriter.h" - #include "geomSphere.h" #include "nearly_zero.h" @@ -48,17 +44,6 @@ make_copy() { return new CollisionSphere(*this); } -//////////////////////////////////////////////////////////////////// -// Function: CollisionSphere::test_intersection -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int CollisionSphere:: -test_intersection(CollisionHandler *record, const CollisionEntry &entry, - const CollisionSolid *into) const { - return into->test_intersection_from_sphere(record, entry); -} - //////////////////////////////////////////////////////////////////// // Function: CollisionSphere::test_intersection // Access: Public, Virtual @@ -84,7 +69,7 @@ xform(const LMatrix4f &mat) { LVector3f radius_v = LVector3f(_radius, 0.0f, 0.0f) * mat; _radius = length(radius_v); - clear_viz_arcs(); + mark_viz_stale(); mark_bound_stale(); } @@ -127,146 +112,6 @@ recompute_bound() { return bound; } -//////////////////////////////////////////////////////////////////// -// Function: CollisionSphere::test_intersection_from_sphere -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int CollisionSphere:: -test_intersection_from_sphere(CollisionHandler *record, - const CollisionEntry &entry) const { - const CollisionSphere *sphere; - DCAST_INTO_R(sphere, entry.get_from(), 0); - - LPoint3f from_center = sphere->get_center() * entry.get_wrt_space(); - LVector3f from_radius_v = - LVector3f(sphere->get_radius(), 0.0f, 0.0f) * entry.get_wrt_space(); - float from_radius = length(from_radius_v); - - LPoint3f into_center = _center; - float into_radius = _radius; - - LVector3f vec = from_center - into_center; - float dist2 = dot(vec, vec); - if (dist2 > (into_radius + from_radius) * (into_radius + from_radius)) { - // No intersection. - return 0; - } - - if (collide_cat.is_debug()) { - collide_cat.debug() - << "intersection detected from " << *entry.get_from_node() << " into " - << entry.get_into_node_path() << "\n"; - } - PT(CollisionEntry) new_entry = new CollisionEntry(entry); - - float dist = sqrtf(dist2); - LVector3f into_normal = normalize(vec); - LPoint3f into_intersection_point = into_normal * (dist - from_radius); - float into_depth = into_radius + from_radius - dist; - - new_entry->set_into_surface_normal(into_normal * entry.get_inv_wrt_space()); - new_entry->set_into_intersection_point(into_intersection_point * entry.get_inv_wrt_space()); - new_entry->set_into_depth(into_depth); - - record->add_entry(new_entry); - return 1; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionSphere::test_intersection_from_ray -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int CollisionSphere:: -test_intersection_from_ray(CollisionHandler *record, - const CollisionEntry &entry) const { - const CollisionRay *ray; - DCAST_INTO_R(ray, entry.get_from(), 0); - - LPoint3f from_origin = ray->get_origin() * entry.get_wrt_space(); - LVector3f from_direction = ray->get_direction() * entry.get_wrt_space(); - - double t1, t2; - if (!intersects_line(t1, t2, from_origin, from_direction)) { - // No intersection. - return 0; - } - - if (t2 < 0.0) { - // Both intersection points are before the start of the ray. - return 0; - } - - if (collide_cat.is_debug()) { - collide_cat.debug() - << "intersection detected from " << *entry.get_from_node() << " into " - << entry.get_into_node_path() << "\n"; - } - PT(CollisionEntry) new_entry = new CollisionEntry(entry); - - LPoint3f into_intersection_point; - if (t1 < 0.0) { - into_intersection_point = from_origin + t2 * from_direction; - } else { - into_intersection_point = from_origin + t1 * from_direction; - } - new_entry->set_into_intersection_point(into_intersection_point); - - record->add_entry(new_entry); - return 1; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionSphere::test_intersection_from_segment -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int CollisionSphere:: -test_intersection_from_segment(CollisionHandler *record, - const CollisionEntry &entry) const { - const CollisionSegment *segment; - DCAST_INTO_R(segment, entry.get_from(), 0); - - LPoint3f from_a = segment->get_point_a() * entry.get_wrt_space(); - LPoint3f from_b = segment->get_point_b() * entry.get_wrt_space(); - LVector3f from_direction = from_b - from_a; - - double t1, t2; - if (!intersects_line(t1, t2, from_a, from_direction)) { - // No intersection. - return 0; - } - - if (t2 < 0.0 || t1 > 1.0) { - // Both intersection points are before the start of the segment or - // after the end of the segment. - return 0; - } - - if (collide_cat.is_debug()) { - collide_cat.debug() - << "intersection detected from " << *entry.get_from_node() << " into " - << entry.get_into_node_path() << "\n"; - } - PT(CollisionEntry) new_entry = new CollisionEntry(entry); - - LPoint3f into_intersection_point; - if (t1 < 0.0) { - // Point a is within the sphere. The first intersection point is - // point a itself. - into_intersection_point = from_a; - } else { - // Point a is outside the sphere, and point b is either inside the - // sphere or beyond it. The first intersection point is at t1. - into_intersection_point = from_a + t1 * from_direction; - } - new_entry->set_into_intersection_point(into_intersection_point); - - record->add_entry(new_entry); - return 1; -} - //////////////////////////////////////////////////////////////////// // Function: CollisionSphere::test_intersection_from_sphere // Access: Public, Virtual @@ -407,32 +252,6 @@ test_intersection_from_segment(qpCollisionHandler *record, return 1; } -//////////////////////////////////////////////////////////////////// -// Function: CollisionSphere::recompute_viz -// Access: Public, Virtual -// Description: Rebuilds the geometry that will be used to render a -// visible representation of the collision solid. -//////////////////////////////////////////////////////////////////// -void CollisionSphere:: -recompute_viz(Node *parent) { - if (collide_cat.is_debug()) { - collide_cat.debug() - << "Recomputing viz for " << *this << " on " << *parent << "\n"; - } - - GeomSphere *sphere = new GeomSphere; - PTA_Vertexf verts; - verts.push_back(_center); - verts.push_back(_center + LVector3f(_radius, 0.0f, 0.0f)); - sphere->set_coords(verts); - sphere->set_num_prims(1); - - GeomNode *viz = new GeomNode("viz-sphere"); - viz->add_geom(sphere); - add_solid_viz(parent, viz); - // add_wireframe_viz(parent, viz); -} - //////////////////////////////////////////////////////////////////// // Function: CollisionSphere::fill_viz_geom // Access: Protected, Virtual diff --git a/panda/src/collide/collisionSphere.h b/panda/src/collide/collisionSphere.h index e6bb035029..7f864f4c1e 100644 --- a/panda/src/collide/collisionSphere.h +++ b/panda/src/collide/collisionSphere.h @@ -36,11 +36,6 @@ public: INLINE CollisionSphere(const CollisionSphere ©); virtual CollisionSolid *make_copy(); - virtual int - test_intersection(CollisionHandler *record, - const CollisionEntry &entry, - const CollisionSolid *into) const; - virtual int test_intersection(qpCollisionHandler *record, const qpCollisionEntry &entry, @@ -65,15 +60,6 @@ protected: protected: virtual int - test_intersection_from_sphere(CollisionHandler *record, - const CollisionEntry &entry) const; - virtual int - test_intersection_from_ray(CollisionHandler *record, - const CollisionEntry &entry) const; - virtual int - test_intersection_from_segment(CollisionHandler *record, - const CollisionEntry &entry) const; - virtual int test_intersection_from_sphere(qpCollisionHandler *record, const qpCollisionEntry &entry) const; virtual int @@ -83,7 +69,6 @@ protected: test_intersection_from_segment(qpCollisionHandler *record, const qpCollisionEntry &entry) const; - virtual void recompute_viz(Node *parent); virtual void fill_viz_geom(); bool intersects_line(double &t1, double &t2, diff --git a/panda/src/collide/collisionTraverser.I b/panda/src/collide/collisionTraverser.I deleted file mode 100644 index a3b30fa7b1..0000000000 --- a/panda/src/collide/collisionTraverser.I +++ /dev/null @@ -1,17 +0,0 @@ -// Filename: collisionTraverser.I -// Created by: drose (24Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// diff --git a/panda/src/collide/collisionTraverser.cxx b/panda/src/collide/collisionTraverser.cxx deleted file mode 100644 index 83e6451cdc..0000000000 --- a/panda/src/collide/collisionTraverser.cxx +++ /dev/null @@ -1,633 +0,0 @@ -// Filename: collisionTraverser.cxx -// Created by: drose (24Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "collisionNode.h" -#include "collisionEntry.h" -#include "collisionPolygon.h" -#include "config_collide.h" - -#include -#include -#include - -#include "collisionTraverser.h" -#include -#include -#include -#include -#include - -#ifndef CPPPARSER -PStatCollector CollisionTraverser::_collisions_pcollector("App:Collisions"); -#endif - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -CollisionTraverser:: -CollisionTraverser(TypeHandle graph_type) : - _graph_type(graph_type) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -CollisionTraverser:: -~CollisionTraverser() { -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::add_collider -// Access: Public -// Description: Adds a new CollisionNode, representing an object that -// will be tested for collisions into other objects, -// along with the handler that will serve each detected -// collision. Each CollisionNode may be served by only -// one handler at a time, but a given handler may serve -// many CollisionNodes. -// -// The handler that serves a particular node may be -// changed from time to time by calling add_collider() -// again on the same node. -//////////////////////////////////////////////////////////////////// -void CollisionTraverser:: -add_collider(CollisionNode *node, CollisionHandler *handler) { - nassertv(_ordered_colliders.size() == _colliders.size()); - nassertv(node != (CollisionNode *)NULL); - nassertv(handler != (CollisionHandler *)NULL); - - Colliders::iterator ci = _colliders.find(node); - if (ci != _colliders.end()) { - // We already knew about this collider. - if ((*ci).second != handler) { - // Change the handler. - PT(CollisionHandler) old_handler = (*ci).second; - (*ci).second = handler; - - // Now update our own reference counts within our handler set. - Handlers::iterator hi = _handlers.find(old_handler); - nassertv(hi != _handlers.end()); - (*hi).second--; - nassertv((*hi).second >= 0); - if ((*hi).second == 0) { - _handlers.erase(hi); - } - - hi = _handlers.find(handler); - if (hi == _handlers.end()) { - _handlers.insert(Handlers::value_type(handler, 1)); - } else { - (*hi).second++; - } - } - - } else { - // We hadn't already known about this collider. - _colliders.insert(Colliders::value_type(node, handler)); - _ordered_colliders.push_back(node); - - Handlers::iterator hi = _handlers.find(handler); - if (hi == _handlers.end()) { - _handlers.insert(Handlers::value_type(handler, 1)); - } else { - (*hi).second++; - } - } - - nassertv(_ordered_colliders.size() == _colliders.size()); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::remove_collider -// Access: Public -// Description: Removes the collider (and its associated handler) -// from the set of CollisionNodes that will be tested -// each frame for collisions into other objects. -// Returns true if the definition was found and removed, -// false if it wasn't present to begin with. -//////////////////////////////////////////////////////////////////// -bool CollisionTraverser:: -remove_collider(CollisionNode *node) { - nassertr(_ordered_colliders.size() == _colliders.size(), false); - - Colliders::iterator ci = _colliders.find(node); - if (ci == _colliders.end()) { - // We didn't know about this node. - return false; - } - - CollisionHandler *handler = (*ci).second; - - // Update the set of handlers. - Handlers::iterator hi = _handlers.find(handler); - nassertr(hi != _handlers.end(), false); - (*hi).second--; - nassertr((*hi).second >= 0, false); - if ((*hi).second == 0) { - _handlers.erase(hi); - } - - _colliders.erase(ci); - - OrderedColliders::iterator oci = - find(_ordered_colliders.begin(), _ordered_colliders.end(), node); - nassertr(oci != _ordered_colliders.end(), false); - _ordered_colliders.erase(oci); - - nassertr(_ordered_colliders.size() == _colliders.size(), false); - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::has_collider -// Access: Public -// Description: Returns true if the indicated node is current in the -// set of nodes that will be tested each frame for -// collisions into other objects. -//////////////////////////////////////////////////////////////////// -bool CollisionTraverser:: -has_collider(CollisionNode *node) const { - Colliders::const_iterator ci = _colliders.find(node); - return (ci != _colliders.end()); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::get_num_colliders -// Access: Public -// Description: Returns the number of CollisionNodes that have been -// added to the traverser via add_collider(). -//////////////////////////////////////////////////////////////////// -int CollisionTraverser:: -get_num_colliders() const { - nassertr(_ordered_colliders.size() == _colliders.size(), 0); - return _ordered_colliders.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::get_collider -// Access: Public -// Description: Returns the nth CollisionNode that has been -// added to the traverser via add_collider(). -//////////////////////////////////////////////////////////////////// -CollisionNode *CollisionTraverser:: -get_collider(int n) const { - nassertr(_ordered_colliders.size() == _colliders.size(), NULL); - nassertr(n >= 0 && n < (int)_ordered_colliders.size(), NULL); - return _ordered_colliders[n]; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::get_handler -// Access: Public -// Description: Returns the handler that is currently assigned to -// serve the indicated collision node, or NULL if the -// node is not on the traverser's set of active nodes. -//////////////////////////////////////////////////////////////////// -CollisionHandler *CollisionTraverser:: -get_handler(CollisionNode *node) const { - Colliders::const_iterator ci = _colliders.find(node); - if (ci != _colliders.end()) { - return (*ci).second; - }; - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::clear_colliders -// Access: Public -// Description: Completely empties the set of collision nodes and -// their associated handlers. -//////////////////////////////////////////////////////////////////// -void CollisionTraverser:: -clear_colliders() { - _colliders.clear(); - _ordered_colliders.clear(); -} - - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::traverse -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void CollisionTraverser:: -traverse(Node *root) { - traverse(NodePath(root, _graph_type)); -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::traverse -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void CollisionTraverser:: -traverse(const NodePath &root) { - nassertv(root.get_graph_type() == _graph_type); - PStatTimer timer(_collisions_pcollector); - - CollisionLevelState level_state(root); - prepare_colliders(level_state); - - Handlers::iterator hi; - for (hi = _handlers.begin(); hi != _handlers.end(); ++hi) { - (*hi).first->begin_group(); - } - - df_traverse(root.node(), *this, NullTransitionWrapper(), - level_state, _graph_type); - - hi = _handlers.begin(); - while (hi != _handlers.end()) { - if (!(*hi).first->end_group()) { - // This handler wants to remove itself from the traversal list. - Handlers::iterator hnext = hi; - ++hnext; - _handlers.erase(hi); - hi = hnext; - } else { - ++hi; - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void CollisionTraverser:: -output(ostream &out) const { - out << "CollisionTraverser, " << _colliders.size() - << " colliders and " << _handlers.size() << " handlers.\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::write -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void CollisionTraverser:: -write(ostream &out, int indent_level) const { - indent(out, indent_level) - << "CollisionTraverser, " << _colliders.size() - << " colliders and " << _handlers.size() << " handlers:\n"; - Colliders::const_iterator ci; - for (ci = _colliders.begin(); ci != _colliders.end(); ++ci) { - CollisionNode *cnode = (*ci).first; - CollisionHandler *handler = (*ci).second; - nassertv(cnode != (CollisionNode *)NULL); - nassertv(handler != (CollisionHandler *)NULL); - - indent(out, indent_level + 2) - << *cnode << " handled by " << handler->get_type() << "\n"; - int num_solids = cnode->get_num_solids(); - for (int i = 0; i < num_solids; i++) { - cnode->get_solid(i)->write(out, indent_level + 4); - } - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::prepare_colliders -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -void CollisionTraverser:: -prepare_colliders(CollisionLevelState &level_state) { - level_state.clear(); - level_state.reserve(_colliders.size()); - - int i = 0; - while (i < (int)_ordered_colliders.size()) { - CollisionNode *cnode = _ordered_colliders[i]; - - CollisionLevelState::ColliderDef def; - def._node = cnode; - get_rel_mat(cnode, NULL, def._space, _graph_type); - def._inv_space.invert_from(def._space); - -#ifndef NDEBUG - if (def._space.is_nan()) { - collide_cat.error() - << "Collider " << *cnode - << " has become NaN. Dropping from traverser.\n"; - // This is safe to do while traversing the list of colliders, - // because we do not increment i in this case. - remove_collider(cnode); - } else -#endif - { - int num_solids = cnode->get_num_solids(); - for (int s = 0; s < num_solids; s++) { - CollisionSolid *collider = cnode->get_solid(s); - def._collider = collider; - level_state.prepare_collider(def); - } - i++; - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::reached_node -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -bool CollisionTraverser:: -reached_node(Node *node, NullTransitionWrapper &, - CollisionLevelState &level_state) { - if (node->is_of_type(CollisionNode::get_class_type())) { - level_state.reached_collision_node(); - - CollisionNode *cnode; - DCAST_INTO_R(cnode, node, false); - const BoundingVolume &node_bv = cnode->get_bound(); - const GeometricBoundingVolume *node_gbv = NULL; - if (node_bv.is_of_type(GeometricBoundingVolume::get_class_type())) { - DCAST_INTO_R(node_gbv, &node_bv, false); - } - - CollisionEntry entry; - entry._into_node = cnode; - entry._into_node_path = NodePath(level_state.get_arc_chain(), _graph_type); - entry._into_space = entry._into_node_path.get_mat(NodePath()); - - int num_colliders = level_state.get_num_colliders(); - for (int c = 0; c < num_colliders; c++) { - if (level_state.has_collider(c)) { - entry._from_node = level_state.get_node(c); - - if ((entry._from_node->get_from_collide_mask() & - cnode->get_into_collide_mask()) != 0) { - entry._from = level_state.get_collider(c); - entry._from_space = level_state.get_space(c); - - NodePath root; - LMatrix4f into_space_inv = root.get_mat(entry._into_node_path); - entry._wrt_space = entry._from_space * into_space_inv; - entry._inv_wrt_space = - entry._into_space * level_state.get_inv_space(c); - - const GeometricBoundingVolume *col_gbv = - level_state.get_local_bound(c); - - compare_collider_to_node(entry, col_gbv, node_gbv); - } - } - } - - } else if (node->is_of_type(GeomNode::get_class_type()) && - level_state.has_any_collide_geom()) { - GeomNode *gnode; - DCAST_INTO_R(gnode, node, false); - const BoundingVolume &node_bv = gnode->get_bound(); - const GeometricBoundingVolume *node_gbv = NULL; - if (node_bv.is_of_type(GeometricBoundingVolume::get_class_type())) { - DCAST_INTO_R(node_gbv, &node_bv, false); - } - - CollisionEntry entry; - entry._into_node = gnode; - get_rel_mat(node, NULL, entry._into_space, _graph_type); - - int num_colliders = level_state.get_num_colliders(); - for (int c = 0; c < num_colliders; c++) { - if (level_state.has_collider_with_geom(c)) { - entry._from_node = level_state.get_node(c); - - entry._from = level_state.get_collider(c); - entry._from_space = level_state.get_space(c); - - LMatrix4f into_space_inv; - get_rel_mat(NULL, node, into_space_inv, _graph_type); - entry._wrt_space = entry._from_space * into_space_inv; - entry._inv_wrt_space = - entry._into_space * level_state.get_inv_space(c); - - const GeometricBoundingVolume *col_gbv = - level_state.get_local_bound(c); - - compare_collider_to_geom_node(entry, col_gbv, node_gbv); - } - } - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::forward_arc -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -bool CollisionTraverser:: -forward_arc(NodeRelation *arc, NullTransitionWrapper &, - NullTransitionWrapper &, NullTransitionWrapper &, - CollisionLevelState &level_state) { - // Check the bounding volume on the arc against each of our - // colliders. - const BoundingVolume &arc_bv = arc->get_bound(); - if (arc_bv.is_of_type(GeometricBoundingVolume::get_class_type())) { - const GeometricBoundingVolume *arc_gbv; - DCAST_INTO_R(arc_gbv, &arc_bv, false); - - int num_colliders = level_state.get_num_colliders(); - for (int c = 0; c < num_colliders; c++) { - if (level_state.has_collider(c)) { - const GeometricBoundingVolume *col_gbv = - level_state.get_local_bound(c); - if (col_gbv != (GeometricBoundingVolume *)NULL) { - if (arc_gbv->contains(col_gbv) == 0) { - // This collider certainly does not intersect with any - // geometry at this arc or below. - level_state.omit_collider(c); - } - } - } - } - } - - if (!level_state.has_any_collider()) { - // No colliders intersect with the geometry at this arc or below, - // so don't bother traversing them. - return false; - } - - TransformTransition *tt; - if (get_transition_into(tt, arc)) { - // There's a transform on the arc; apply it to our colliders' - // bounding volumes. - LMatrix4f inv_mat; - inv_mat.invert_from(tt->get_matrix()); - level_state.xform(inv_mat); - } - - level_state.forward_arc(arc); - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::compare_collider_to_node -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -void CollisionTraverser:: -compare_collider_to_node(CollisionEntry &entry, - const GeometricBoundingVolume *from_node_gbv, - const GeometricBoundingVolume *into_node_gbv) { - bool within_node_bounds = true; - if (from_node_gbv != (GeometricBoundingVolume *)NULL && - into_node_gbv != (GeometricBoundingVolume *)NULL) { - within_node_bounds = (into_node_gbv->contains(from_node_gbv) != 0); - } - - if (within_node_bounds) { - CollisionNode *cnode; - DCAST_INTO_V(cnode, entry._into_node); - int num_solids = cnode->get_num_solids(); - for (int s = 0; s < num_solids; s++) { - entry._into = cnode->get_solid(s); - if (entry._from != entry._into) { - const BoundingVolume &solid_bv = entry._into->get_bound(); - const GeometricBoundingVolume *solid_gbv = NULL; - if (num_solids > 1 && - solid_bv.is_of_type(GeometricBoundingVolume::get_class_type())) { - // Only bother to test against each solid's bounding - // volume if we have more than one solid in the node, as a - // slight optimization. (If the node contains just one - // solid, then the node's bounding volume, which we just - // tested, is the same as the solid's bounding volume.) - DCAST_INTO_V(solid_gbv, &solid_bv); - } - - compare_collider_to_solid(entry, from_node_gbv, solid_gbv); - } - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::compare_collider_to_geom_node -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -void CollisionTraverser:: -compare_collider_to_geom_node(CollisionEntry &entry, - const GeometricBoundingVolume *from_node_gbv, - const GeometricBoundingVolume *into_node_gbv) { - bool within_node_bounds = true; - if (from_node_gbv != (GeometricBoundingVolume *)NULL && - into_node_gbv != (GeometricBoundingVolume *)NULL) { - within_node_bounds = (into_node_gbv->contains(from_node_gbv) != 0); - } - - if (within_node_bounds) { - GeomNode *gnode; - DCAST_INTO_V(gnode, entry._into_node); - int num_geoms = gnode->get_num_geoms(); - for (int s = 0; s < num_geoms; s++) { - entry._into = (CollisionSolid *)NULL; - Geom *geom = DCAST(Geom, gnode->get_geom(s)); - if (geom != (Geom *)NULL) { - const BoundingVolume &geom_bv = geom->get_bound(); - const GeometricBoundingVolume *geom_gbv = NULL; - if (num_geoms > 1 && - geom_bv.is_of_type(GeometricBoundingVolume::get_class_type())) { - // Only bother to test against each geom's bounding - // volume if we have more than one geom in the node, as a - // slight optimization. (If the node contains just one - // geom, then the node's bounding volume, which we just - // tested, is the same as the geom's bounding volume.) - DCAST_INTO_V(geom_gbv, &geom_bv); - } - - compare_collider_to_geom(entry, geom, from_node_gbv, geom_gbv); - } - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::compare_collider_to_solid -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -void CollisionTraverser:: -compare_collider_to_solid(CollisionEntry &entry, - const GeometricBoundingVolume *from_node_gbv, - const GeometricBoundingVolume *solid_gbv) { - bool within_solid_bounds = true; - if (from_node_gbv != (GeometricBoundingVolume *)NULL && - solid_gbv != (GeometricBoundingVolume *)NULL) { - within_solid_bounds = (solid_gbv->contains(from_node_gbv) != 0); - } - if (within_solid_bounds) { - Colliders::const_iterator ci; - ci = _colliders.find(entry.get_from_node()); - nassertv(ci != _colliders.end()); - entry.get_from()->test_intersection((*ci).second, entry, entry.get_into()); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CollisionTraverser::compare_collider_to_geom -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -void CollisionTraverser:: -compare_collider_to_geom(CollisionEntry &entry, Geom *geom, - const GeometricBoundingVolume *from_node_gbv, - const GeometricBoundingVolume *geom_gbv) { - bool within_geom_bounds = true; - if (from_node_gbv != (GeometricBoundingVolume *)NULL && - geom_gbv != (GeometricBoundingVolume *)NULL) { - within_geom_bounds = (geom_gbv->contains(from_node_gbv) != 0); - } - if (within_geom_bounds) { - Colliders::const_iterator ci; - ci = _colliders.find(entry.get_from_node()); - nassertv(ci != _colliders.end()); - - PTA_Vertexf coords; - PTA_ushort vindex; - geom->get_coords(coords, vindex); - PTA_ushort tris = geom->get_tris(); - - for (int i = 0; i < (int)tris.size(); i += 3) { - if (CollisionPolygon::verify_points(coords[tris[i]], - coords[tris[i + 1]], - coords[tris[i + 2]])) { - // Generate a temporary CollisionPolygon on the fly for each - // triangle in the Geom. - CollisionPolygon poly(coords[tris[i]], coords[tris[i + 1]], - coords[tris[i + 2]]); - if (entry.get_from()->test_intersection((*ci).second, entry, &poly) != 0) { - return; - } - } - } - } -} diff --git a/panda/src/collide/collisionTraverser.h b/panda/src/collide/collisionTraverser.h deleted file mode 100644 index 893d1014dd..0000000000 --- a/panda/src/collide/collisionTraverser.h +++ /dev/null @@ -1,116 +0,0 @@ -// Filename: collisionTraverser.h -// Created by: drose (24Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef COLLISIONTRAVERSER_H -#define COLLISIONTRAVERSER_H - -#include - -#include "collisionHandler.h" -#include "collisionLevelState.h" - -#include -#include -#include -#include -#include -#include - -#include "pset.h" - -class CollisionNode; -class Geom; -class NodePath; - -//////////////////////////////////////////////////////////////////// -// Class : CollisionTraverser -// Description : -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA CollisionTraverser : - public TraverserVisitor { -PUBLISHED: - CollisionTraverser(TypeHandle graph_type = RenderRelation::get_class_type()); - ~CollisionTraverser(); - - void add_collider(CollisionNode *node, CollisionHandler *handler); - bool remove_collider(CollisionNode *node); - bool has_collider(CollisionNode *node) const; - int get_num_colliders() const; - CollisionNode *get_collider(int n) const; - CollisionHandler *get_handler(CollisionNode *node) const; - void clear_colliders(); - - void traverse(Node *root); - void traverse(const NodePath &root); - - void output(ostream &out) const; - void write(ostream &out, int indent_level = 0) const; - -private: - void prepare_colliders(CollisionLevelState &state); - -public: - // These methods, from parent class TraverserVisitor, define the - // behavior of the CollisionTraverser as it traverses the graph. - // Normally you would never call these directly. - bool reached_node(Node *node, NullTransitionWrapper &render_state, - CollisionLevelState &level_state); - - bool forward_arc(NodeRelation *arc, NullTransitionWrapper &trans, - NullTransitionWrapper &pre, NullTransitionWrapper &post, - CollisionLevelState &level_state); - -private: - void compare_collider_to_node(CollisionEntry &entry, - const GeometricBoundingVolume *from_node_gbv, - const GeometricBoundingVolume *into_node_gbv); - void compare_collider_to_geom_node(CollisionEntry &entry, - const GeometricBoundingVolume *from_node_gbv, - const GeometricBoundingVolume *into_node_gbv); - void compare_collider_to_solid(CollisionEntry &entry, - const GeometricBoundingVolume *from_node_gbv, - const GeometricBoundingVolume *solid_gbv); - void compare_collider_to_geom(CollisionEntry &entry, Geom *geom, - const GeometricBoundingVolume *from_node_gbv, - const GeometricBoundingVolume *solid_gbv); - -private: - PT(CollisionHandler) _default_handler; - TypeHandle _graph_type; - - typedef pmap Colliders; - Colliders _colliders; - typedef pvector OrderedColliders; - OrderedColliders _ordered_colliders; - - typedef pmap Handlers; - Handlers _handlers; - - // Statistics - static PStatCollector _collisions_pcollector; -}; - -INLINE ostream &operator << (ostream &out, const CollisionTraverser &trav) { - trav.output(out); - return out; -} - -#include "collisionTraverser.I" - -#endif - diff --git a/panda/src/collide/config_collide.cxx b/panda/src/collide/config_collide.cxx index dc5c92ed3a..b60c31a5f7 100644 --- a/panda/src/collide/config_collide.cxx +++ b/panda/src/collide/config_collide.cxx @@ -17,21 +17,13 @@ //////////////////////////////////////////////////////////////////// #include "config_collide.h" -#include "collisionEntry.h" #include "qpcollisionEntry.h" -#include "collisionHandler.h" #include "qpcollisionHandler.h" -#include "collisionHandlerEvent.h" #include "qpcollisionHandlerEvent.h" -#include "collisionHandlerFloor.h" #include "qpcollisionHandlerFloor.h" -#include "collisionHandlerPhysical.h" #include "qpcollisionHandlerPhysical.h" -#include "collisionHandlerPusher.h" #include "qpcollisionHandlerPusher.h" -#include "collisionHandlerQueue.h" #include "qpcollisionHandlerQueue.h" -#include "collisionNode.h" #include "qpcollisionNode.h" #include "collisionPlane.h" #include "collisionPolygon.h" @@ -64,21 +56,13 @@ init_libcollide() { } initialized = true; - CollisionEntry::init_type(); qpCollisionEntry::init_type(); - CollisionHandler::init_type(); qpCollisionHandler::init_type(); - CollisionHandlerEvent::init_type(); qpCollisionHandlerEvent::init_type(); - CollisionHandlerFloor::init_type(); qpCollisionHandlerFloor::init_type(); - CollisionHandlerPhysical::init_type(); qpCollisionHandlerPhysical::init_type(); - CollisionHandlerPusher::init_type(); qpCollisionHandlerPusher::init_type(); - CollisionHandlerQueue::init_type(); qpCollisionHandlerQueue::init_type(); - CollisionNode::init_type(); qpCollisionNode::init_type(); CollisionPlane::init_type(); CollisionPolygon::init_type(); @@ -89,7 +73,6 @@ init_libcollide() { //Registration of writeable object's creation //functions with BamReader's factory - CollisionNode::register_with_read_factory(); qpCollisionNode::register_with_read_factory(); CollisionPlane::register_with_read_factory(); CollisionPolygon::register_with_read_factory(); diff --git a/panda/src/collide/qpcollisionLevelState.cxx b/panda/src/collide/qpcollisionLevelState.cxx index 10224126e7..f2a5b14bd7 100644 --- a/panda/src/collide/qpcollisionLevelState.cxx +++ b/panda/src/collide/qpcollisionLevelState.cxx @@ -18,6 +18,7 @@ #include "qpcollisionLevelState.h" #include "collisionSolid.h" +#include "dcast.h" //////////////////////////////////////////////////////////////////// // Function: qpCollisionLevelState::clear diff --git a/panda/src/collide/qpcollisionNode.cxx b/panda/src/collide/qpcollisionNode.cxx index 69be332b06..5295768256 100644 --- a/panda/src/collide/qpcollisionNode.cxx +++ b/panda/src/collide/qpcollisionNode.cxx @@ -16,7 +16,7 @@ // //////////////////////////////////////////////////////////////////// -#include "collisionNode.h" +#include "qpcollisionNode.h" #include "config_collide.h" #include "qpgeomNode.h" diff --git a/panda/src/collide/qpcollisionTraverser.h b/panda/src/collide/qpcollisionTraverser.h index 9fb56aaab9..213a62fa31 100644 --- a/panda/src/collide/qpcollisionTraverser.h +++ b/panda/src/collide/qpcollisionTraverser.h @@ -24,10 +24,6 @@ #include "qpcollisionHandler.h" #include "qpcollisionLevelState.h" -#include "traverserVisitor.h" -#include "nullTransitionWrapper.h" -#include "pointerTo.h" -#include "renderRelation.h" #include "pointerTo.h" #include "pStatCollector.h" diff --git a/panda/src/crgsg/Sources.pp b/panda/src/crgsg/Sources.pp index e87773fabc..551899b0ca 100644 --- a/panda/src/crgsg/Sources.pp +++ b/panda/src/crgsg/Sources.pp @@ -7,8 +7,8 @@ #begin lib_target #define TARGET crgsg #define LOCAL_LIBS \ - pandabase cull gsgmisc gsgbase gobj sgattrib sgraphutil graph display \ - putil linmath sgraph mathutil pnmimage + pandabase gsgmisc gsgbase gobj display \ + putil linmath mathutil pnmimage #define COMBINED_SOURCES $[TARGET]_composite1.cxx diff --git a/panda/src/crgsg/crGraphicsStateGuardian.cxx b/panda/src/crgsg/crGraphicsStateGuardian.cxx index 2ec5444351..74c975a336 100644 --- a/panda/src/crgsg/crGraphicsStateGuardian.cxx +++ b/panda/src/crgsg/crGraphicsStateGuardian.cxx @@ -41,28 +41,6 @@ #include "spotlight.h" #include "GL/glu.h" #include "lensNode.h" -#include "transformTransition.h" -#include "colorMatrixTransition.h" -#include "alphaTransformTransition.h" -#include "colorTransition.h" -#include "textureTransition.h" -#include "renderModeTransition.h" -#include "materialTransition.h" -#include "colorBlendTransition.h" -#include "colorMaskTransition.h" -#include "texMatrixTransition.h" -#include "texGenTransition.h" -#include "textureApplyTransition.h" -#include "clipPlaneTransition.h" -#include "transparencyTransition.h" -#include "fogTransition.h" -#include "linesmoothTransition.h" -#include "depthTestTransition.h" -#include "depthWriteTransition.h" -#include "cullFaceTransition.h" -#include "stencilTransition.h" -#include "pointShapeTransition.h" -#include "polygonOffsetTransition.h" #include "textureAttrib.h" #include "lightAttrib.h" #include "cullFaceAttrib.h" @@ -311,10 +289,10 @@ reset() { // Make sure the GL state matches all of our initial attribute // states. - PT(DepthTestTransition) dta = new DepthTestTransition; - PT(DepthWriteTransition) dwa = new DepthWriteTransition; - PT(CullFaceTransition) cfa = new CullFaceTransition; - PT(TextureTransition) ta = new TextureTransition; + CPT(RenderAttrib) dta = DepthTestAttrib::make(); + CPT(RenderAttrib) dwa = DepthWriteAttrib::make(); + CPT(RenderAttrib) cfa = CullFaceAttrib::make(); + CPT(renderAttrib) ta = TextureAttrib::make_off(); dta->issue(this); dwa->issue(this); @@ -360,14 +338,14 @@ clear(const RenderBuffer &buffer) { nassertv(buffer._gsg == this); int buffer_type = buffer._buffer_type; GLbitfield mask = 0; - NodeTransitions state; + CPT(RenderState) state = RenderState::make_identity(); if (buffer_type & RenderBuffer::T_color) { call_glClearColor(_color_clear_value[0], _color_clear_value[1], _color_clear_value[2], _color_clear_value[3]); - state.set_transition(new ColorMaskTransition); + state = state->set_attrib(ColorWriteAttrib::make(ColorWriteAttrib::M_on)); mask |= GL_COLOR_BUFFER_BIT; set_draw_buffer(buffer); @@ -380,7 +358,7 @@ clear(const RenderBuffer &buffer) { // In order to clear the depth buffer, the depth mask must enable // writing to the depth buffer. if (!_depth_mask) { - state.set_transition(new DepthWriteTransition); + state = state->set_attrib(DepthWriteAttrib::make(DepthWriteAttrib::M_on)); } } @@ -507,189 +485,6 @@ prepare_lens() { return true; } - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::render_frame -// Access: Public, Virtual -// Description: Renders an entire frame, including all display -// regions within the frame, and includes any necessary -// pre- and post-processing like swapping buffers. -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -render_frame() { -#ifdef GSG_VERBOSE - crgsg_cat.debug() - << "begin frame " << ClockObject::get_global_clock()->get_frame_count() - << " --------------------------------------------" << endl; -#endif - - activate(); - _win->begin_frame(); - report_errors(); - _decal_level = 0; - - _vertices_display_list_pcollector.clear_level(); - - // First, clear the entire window. - clear_framebuffer(); - - // Now render each of our layers in order. - int max_channel_index = _win->get_max_channel_index(); - for (int c = 0; c < max_channel_index; c++) { - if (_win->is_channel_defined(c)) { - GraphicsChannel *chan = _win->get_channel(c); - if (chan->is_active()) { - int num_layers = chan->get_num_layers(); - for (int l = 0; l < num_layers; l++) { - GraphicsLayer *layer = chan->get_layer(l); - if (layer->is_active()) { - int num_drs = layer->get_num_drs(); - for (int d = 0; d < num_drs; d++) { - DisplayRegion *dr = layer->get_dr(d); - nassertv(dr != (DisplayRegion *)NULL); - Camera *cam = dr->get_camera(); - - // For each display region, render from the camera's view. - if (dr->is_active() && cam != (Camera *)NULL && - cam->is_active() && cam->get_scene() != (Node *)NULL) { - DisplayRegionStack old_dr = push_display_region(dr); - prepare_display_region(); - render_scene(cam->get_scene(), cam); - pop_display_region(old_dr); - } - } - } - } - } - } - } - - // Now we're done with the frame processing. Clean up. - -#ifndef NDEBUG - report_errors(); -#endif - - _win->end_frame(); - -#ifdef GSG_VERBOSE - crgsg_cat.debug() - << "end frame ----------------------------------------------" << endl; -#endif -} - - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::render_scene -// Access: Public, Virtual -// Description: Renders an entire scene, from the root node of the -// scene graph, as seen from a particular LensNode -// and with a given initial state. This initial state -// may be modified during rendering. -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -render_scene(Node *root, LensNode *projnode) { -#ifdef GSG_VERBOSE - _pass_number = 0; - crgsg_cat.debug() - << "begin scene - - - - - - - - - - - - - - - - - - - - - - - - -" - << endl; -#endif - _current_root_node = root; - - render_subgraph(_render_traverser, root, projnode, - AllTransitionsWrapper()); - -#ifdef GSG_VERBOSE - crgsg_cat.debug() - << "done scene - - - - - - - - - - - - - - - - - - - - - - - - -" - << endl; -#endif -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::render_subgraph -// Access: Public, Virtual -// Description: Renders a subgraph of the scene graph as seen from a -// given lens node, and with a particular initial -// state. This state may be modified by the render -// process. -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -render_subgraph(RenderTraverser *traverser, - Node *subgraph, LensNode *projnode, - const AllTransitionsWrapper &net_trans) { - // Calling activate() frequently seems to be intolerably expensive - // on some platforms. We'll limit ourselves for now to calling it - // only in render_frame(). - - // activate(); - - Lens *lens = projnode->get_lens(); - LensNode *old_camera = _current_camera; - _current_camera = projnode; - - LensStack lens_stack = push_lens(lens); - if (!prepare_lens()) { - crgsg_cat.error() - << "Cannot render with a nonlinear lens!\n"; - return; - } - - // We infer the modelview matrix by doing a wrt on the lens - // node. - LMatrix4f modelview_mat; - get_rel_mat(subgraph, _current_camera, modelview_mat); - - if (_coordinate_system != CS_yup_right) { - // Now we build the coordinate system conversion into the - // modelview matrix (as described in the paragraph above). - modelview_mat = modelview_mat * - LMatrix4f::convert_mat(_coordinate_system, CS_yup_right); - } - - // The modelview matrix will be loaded as each geometry is - // encountered. So we set the supplied modelview matrix as an - // initial value instead of loading it now. - AllTransitionsWrapper sub_trans = net_trans; - sub_trans.set_transition(new TransformTransition(modelview_mat)); - - render_subgraph(traverser, subgraph, sub_trans); - - _current_camera = old_camera; - - pop_lens(lens_stack); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::render_subgraph -// Access: Public, Virtual -// Description: Renders a subgraph of the scene graph as seen from the -// current lens node, and with a particular -// initial state. This state may be modified during the -// render process. -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -render_subgraph(RenderTraverser *traverser, Node *subgraph, - const AllTransitionsWrapper &net_trans) { -#ifdef GSG_VERBOSE - crgsg_cat.debug() - << "begin subgraph (pass " << ++_pass_number - << ") - - - - - - - - - - - - - - - - - - - - - - - - -" << endl; -#endif - // activate(); - - nassertv(traverser != (RenderTraverser *)NULL); - traverser->traverse(subgraph, net_trans); - -#ifdef GSG_VERBOSE - crgsg_cat.debug() - << "end subgraph (pass " << _pass_number - << ") - - - - - - - - - - - - - - - - - - - - - - - - -" - << endl; -#endif -} - //////////////////////////////////////////////////////////////////// // Function: CRGraphicsStateGuardian::draw_point // Access: Public, Virtual @@ -1803,7 +1598,9 @@ release_texture(TextureContext *tc) { // contents of the node. //////////////////////////////////////////////////////////////////// GeomNodeContext *CRGraphicsStateGuardian:: -prepare_geom_node(GeomNode *node) { +prepare_geom_node(qpGeomNode *node) { +#if 0 // temporarily disabled until we bring to new scene graph + // Make sure we have at least some static Geoms in the GeomNode; // otherwise there's no point in building a display list. int num_geoms = node->get_num_geoms(); @@ -1887,6 +1684,8 @@ prepare_geom_node(GeomNode *node) { nassertr(inserted, NULL); return ggnc; +#endif // temporarily disabled until we bring to new scene graph + return NULL; } //////////////////////////////////////////////////////////////////// @@ -1896,7 +1695,9 @@ prepare_geom_node(GeomNode *node) { // prepare_geom_node(). //////////////////////////////////////////////////////////////////// void CRGraphicsStateGuardian:: -draw_geom_node(GeomNode *node, GeomNodeContext *gnc) { +draw_geom_node(qpGeomNode *node, const RenderState *state, + GeomNodeContext *gnc) { +#if 0 // temporarily disabled until we bring to new scene graph if (gnc == (GeomNodeContext *)NULL) { // We don't have a saved context; just draw the GeomNode in // immediate mode. @@ -1922,6 +1723,7 @@ draw_geom_node(GeomNode *node, GeomNodeContext *gnc) { ggnc->_dynamic_geoms[i]->draw(this); } } +#endif // temporarily disabled until we bring to new scene graph } //////////////////////////////////////////////////////////////////// @@ -2015,90 +1817,6 @@ copy_texture(TextureContext *tc, const DisplayRegion *dr, const RenderBuffer &rb copy_texture(tc, dr); } -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::draw_texture -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -draw_texture(TextureContext *tc, const DisplayRegion *dr) { - nassertv(tc != NULL && dr != NULL); - // activate(); - - Texture *tex = tc->_texture; - - DisplayRegionStack old_dr = push_display_region(dr); - prepare_display_region(); - - NodeTransitions state; - CullFaceTransition *cfa = new CullFaceTransition; - cfa->set_mode(CullFaceProperty::M_cull_none); - DepthTestTransition *dta = new DepthTestTransition; - dta->set_mode(DepthTestProperty::M_none); - DepthWriteTransition *dwa = new DepthWriteTransition; - dwa->set_off(); - TextureTransition *ta = new TextureTransition; - ta->set_on(tex); - TextureApplyTransition *taa = new TextureApplyTransition; - taa->set_mode(TextureApplyProperty::M_decal); - - state.set_transition(new ColorMaskTransition); - state.set_transition(new RenderModeTransition); - state.set_transition(new TexMatrixTransition); - state.set_transition(new TransformTransition); - state.set_transition(new ColorBlendTransition); - state.set_transition(cfa); - state.set_transition(dta); - state.set_transition(dwa); - state.set_transition(ta); - state.set_transition(taa); - modify_state(state); - - // We set up an orthographic projection that defines our entire - // viewport to the range [0..1] in both dimensions. Then, when we - // create a unit square polygon below, it will exactly fill the - // viewport (and thus exactly fill the display region). - chromium.MatrixMode(GL_PROJECTION); - chromium.PushMatrix(); - chromium.LoadIdentity(); - gluOrtho2D(0, 1, 0, 1); - - float txl, txr, tyt, tyb; - txl = tyb = 0.; - if (tex->_has_requested_size) { - txr = ((float)(tex->_requested_w)) / ((float)(tex->_pbuffer->get_xsize())); - tyt = ((float)(tex->_requested_h)) / ((float)(tex->_pbuffer->get_ysize())); - } else { - txr = tyt = 1.; - } - - // This two-triangle strip is actually a quad. But it's usually - // better to render quads as tristrips anyway. - chromium.Begin(GL_TRIANGLE_STRIP); - chromium.TexCoord2f(txl, tyb); chromium.Vertex2i(0, 0); - chromium.TexCoord2f(txr, tyb); chromium.Vertex2i(1, 0); - chromium.TexCoord2f(txl, tyt); chromium.Vertex2i(0, 1); - chromium.TexCoord2f(txr, tyt); chromium.Vertex2i(1, 1); - chromium.End(); - - chromium.MatrixMode(GL_PROJECTION); - chromium.PopMatrix(); - - pop_display_region(old_dr); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::draw_texture -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -draw_texture(TextureContext *tc, const DisplayRegion *dr, const RenderBuffer &rb) { - // activate(); - set_draw_buffer(rb); - draw_texture(tc, dr); -} - //////////////////////////////////////////////////////////////////// // Function: CRGraphicsStateGuardian::texture_to_pixel_buffer // Access: Public, Virtual @@ -2241,141 +1959,6 @@ copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, copy_pixel_buffer(pb, dr); } -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::draw_pixel_buffer -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, - const NodeTransitions& na) { - nassertv(pb != NULL && dr != NULL); - nassertv(!pb->_image.empty()); - // activate(); - - DisplayRegionStack old_dr = push_display_region(dr); - prepare_display_region(); - - NodeTransitions state(na); - state.set_transition(new TextureTransition); - state.set_transition(new TransformTransition); - //state.set_transition(new ColorBlendTransition); - state.set_transition(new StencilTransition); - - switch (pb->get_format()) { - case PixelBuffer::F_depth_component: - { - ColorMaskTransition *cma = new ColorMaskTransition(0); - DepthTestTransition *dta = new DepthTestTransition(DepthTestProperty::M_always); - DepthWriteTransition *dwa = new DepthWriteTransition; - state.set_transition(cma); - state.set_transition(dta); - state.set_transition(dwa); - } - break; - - case PixelBuffer::F_rgb: - case PixelBuffer::F_rgb5: - case PixelBuffer::F_rgb8: - case PixelBuffer::F_rgb12: - case PixelBuffer::F_rgba: - case PixelBuffer::F_rgbm: - case PixelBuffer::F_rgba4: - case PixelBuffer::F_rgba5: - case PixelBuffer::F_rgba8: - case PixelBuffer::F_rgba12: - { - ColorMaskTransition *cma = new ColorMaskTransition; - DepthTestTransition *dta = new DepthTestTransition(DepthTestProperty::M_none); - DepthWriteTransition *dwa = new DepthWriteTransition(DepthWriteTransition::off()); - state.set_transition(cma); - state.set_transition(dta); - state.set_transition(dwa); - } - break; - default: - crgsg_cat.error() - << "draw_pixel_buffer(): unknown buffer format" << endl; - break; - } - - modify_state(state); - - set_unpack_alignment(1); - - chromium.MatrixMode( GL_PROJECTION ); - chromium.PushMatrix(); - chromium.LoadIdentity(); - gluOrtho2D(0, _win->get_width(), - 0, _win->get_height()); - -#ifdef GSG_VERBOSE - crgsg_cat.debug() - << "crDrawPixels(" << pb->get_xsize() << ", " << pb->get_ysize() - << ", "; - switch (get_external_image_format(pb->get_format())) { - case GL_DEPTH_COMPONENT: - crgsg_cat.debug(false) << "GL_DEPTH_COMPONENT, "; - break; - case GL_RGB: - crgsg_cat.debug(false) << "GL_RGB, "; - break; - case GL_RGBA: - crgsg_cat.debug(false) << "GL_RGBA, "; - break; -#ifdef GL_BGR - case GL_BGR: - crgsg_cat.debug(false) << "GL_BGR, "; - break; - case GL_BGRA: - crgsg_cat.debug(false) << "GL_BGRA, "; - break; -#endif // GL_BGR - default: - crgsg_cat.debug(false) << "unknown, "; - break; - } - switch (get_image_type(pb->get_image_type())) { - case GL_UNSIGNED_BYTE: - crgsg_cat.debug(false) << "GL_UNSIGNED_BYTE, "; - break; - case GL_FLOAT: - crgsg_cat.debug(false) << "GL_FLOAT, "; - break; - default: - crgsg_cat.debug(false) << "unknown, "; - break; - } - crgsg_cat.debug(false) - << (void *)pb->_image.p() << ")" << endl; -#endif - - chromium.RasterPos2i( pb->get_xorg(), pb->get_yorg() ); - chromium.DrawPixels( pb->get_xsize(), pb->get_ysize(), - get_external_image_format(pb->get_format()), - get_image_type(pb->get_image_type()), - pb->_image.p() ); - - chromium.MatrixMode( GL_PROJECTION ); - chromium.PopMatrix(); - - pop_display_region(old_dr); - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::draw_pixel_buffer -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, - const RenderBuffer &rb, const NodeTransitions& na) { - // activate(); - set_draw_buffer(rb); - draw_pixel_buffer(pb, dr, na); -} - //////////////////////////////////////////////////////////////////// // Function: CRGraphicsStateGuardian::apply_material // Access: Public, Virtual @@ -2421,35 +2004,6 @@ void CRGraphicsStateGuardian::apply_material(const Material *material) { report_errors(); } -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::apply_fog -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -apply_fog(Fog *fog) { - Fog::Mode fmode = fog->get_mode(); - call_glFogMode(get_fog_mode_type(fmode)); - - if (fmode == Fog::M_linear) { - // Linear fog may be world-relative or camera-relative. The fog - // object knows how to decode its parameters into camera-relative - // properties. - float onset, opaque; - fog->compute_linear_range(onset, opaque, _current_camera, - _coordinate_system); - call_glFogStart(onset); - call_glFogEnd(opaque); - - } else { - // Exponential fog is always camera-relative. - call_glFogDensity(fog->get_exp_density()); - } - - call_glFogColor(fog->get_color()); - report_errors(); -} - //////////////////////////////////////////////////////////////////// // Function: CRGraphicsStateGuardian::apply_fog // Access: Public, Virtual @@ -2475,614 +2029,6 @@ apply_fog(qpFog *fog) { report_errors(); } -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_transform -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_transform(const TransformTransition *attrib) { - // activate(); -#ifdef GSG_VERBOSE - crgsg_cat.debug() - << "crLoadMatrix(GL_MODELVIEW): " << attrib->get_matrix() << endl; -#endif - chromium.MatrixMode(GL_MODELVIEW); - chromium.LoadMatrixf(attrib->get_matrix().get_data()); - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_color_transform -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_color_transform(const ColorMatrixTransition *attrib) { - _current_color_mat = attrib->get_matrix(); - - if (_current_color_mat == LMatrix4f::ident_mat()) { - _color_transform_enabled = false; - } else { - _color_transform_enabled = true; - } - - _scene_graph_color_stale = _has_scene_graph_color; -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_alpha_transform -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_alpha_transform(const AlphaTransformTransition *attrib) { - _current_alpha_offset= attrib->get_offset(); - _current_alpha_scale = attrib->get_scale(); - - if (_current_alpha_offset == 0 && _current_alpha_scale == 1) { - _alpha_transform_enabled = false; - } else { - _alpha_transform_enabled = true; - } - - _scene_graph_color_stale = _has_scene_graph_color; -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_matrix -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_tex_matrix(const TexMatrixTransition *attrib) { - // activate(); -#ifdef GSG_VERBOSE - crgsg_cat.debug() - << "crLoadMatrix(GL_TEXTURE): " << attrib->get_matrix() << endl; -#endif - chromium.MatrixMode(GL_TEXTURE); - chromium.LoadMatrixf(attrib->get_matrix().get_data()); - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_color -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_color(const ColorTransition *attrib) { - if (attrib->is_on()) { - if (attrib->is_real()) { - // The color attribute is "on" and "real": it specifies a scene - // graph color that overrides the vertex color. - _scene_graph_color = attrib->get_color(); - _has_scene_graph_color = true; - _vertex_colors_enabled = false; - _scene_graph_color_stale = true; - - } else { - // The color attribute is "on" but not "real": it specifies that - // no scene graph color is in effect, but vertex color is not - // important either. - _has_scene_graph_color = false; - _scene_graph_color_stale = false; - _vertex_colors_enabled = false; - } - } else { - // The color attribute is "off": it specifies that vertex color - // should be revealed. - _has_scene_graph_color = false; - _scene_graph_color_stale = false; - _vertex_colors_enabled = true; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_texture -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_texture(const TextureTransition *attrib) { - // activate(); - - if (attrib->is_on()) { - enable_texturing(true); - Texture *tex = attrib->get_texture(); - nassertv(tex != (Texture *)NULL); - tex->apply(this); - } else { - enable_texturing(false); - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_tex_gen -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_tex_gen(const TexGenTransition *attrib) { - // activate(); - TexGenProperty::Mode mode = attrib->get_mode(); - - switch (mode) { - case TexGenProperty::M_none: - chromium.Disable(GL_TEXTURE_GEN_S); - chromium.Disable(GL_TEXTURE_GEN_T); - chromium.Disable(GL_TEXTURE_GEN_Q); - chromium.Disable(GL_TEXTURE_GEN_R); - break; - - case TexGenProperty::M_texture_projector: - { - chromium.Enable(GL_TEXTURE_GEN_S); - chromium.Enable(GL_TEXTURE_GEN_T); - chromium.Enable(GL_TEXTURE_GEN_Q); - chromium.Enable(GL_TEXTURE_GEN_R); - const LMatrix4f &plane = attrib->get_plane(); - chromium.TexGenfv(GL_S, GL_OBJECT_PLANE, plane.get_row(0).get_data()); - chromium.TexGenfv(GL_T, GL_OBJECT_PLANE, plane.get_row(1).get_data()); - chromium.TexGenfv(GL_R, GL_OBJECT_PLANE, plane.get_row(2).get_data()); - chromium.TexGenfv(GL_Q, GL_OBJECT_PLANE, plane.get_row(3).get_data()); - chromium.TexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - chromium.TexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - chromium.TexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - chromium.TexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - } - break; - - case TexGenProperty::M_sphere_map: - chromium.Enable(GL_TEXTURE_GEN_S); - chromium.Enable(GL_TEXTURE_GEN_T); - chromium.Disable(GL_TEXTURE_GEN_Q); - chromium.Disable(GL_TEXTURE_GEN_R); - chromium.TexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); - chromium.TexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); - break; - - default: - crgsg_cat.error() - << "Unknown texgen mode " << (int)mode << endl; - break; - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_material -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_material(const MaterialTransition *attrib) { - // activate(); - if (attrib->is_on()) { - const Material *material = attrib->get_material(); - nassertv(material != (const Material *)NULL); - apply_material(material); - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_fog -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_fog(const FogTransition *attrib) { - // activate(); - - if (attrib->is_on()) { - enable_fog(true); - Fog *fog = attrib->get_fog(); - nassertv(fog != (Fog *)NULL); - fog->apply(this); - } else { - enable_fog(false); - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_render_mode -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_render_mode(const RenderModeTransition *attrib) { - // activate(); - - RenderModeProperty::Mode mode = attrib->get_mode(); - - switch (mode) { - case RenderModeProperty::M_filled: - call_glPolygonMode(GL_FILL); - break; - - case RenderModeProperty::M_wireframe: - // Make sure line width is back to default (1 pixel) - call_glLineWidth(attrib->get_line_width()); - call_glPolygonMode(GL_LINE); - break; - - default: - crgsg_cat.error() - << "Unknown render mode " << (int)mode << endl; - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_color_blend -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_color_blend(const ColorBlendTransition *attrib) { - // activate(); - ColorBlendProperty::Mode mode = attrib->get_mode(); - - switch (mode) { - case ColorBlendProperty::M_none: - enable_blend(false); - break; - case ColorBlendProperty::M_multiply: - enable_blend(true); - call_glBlendFunc(GL_DST_COLOR, GL_ZERO); - break; - case ColorBlendProperty::M_add: - enable_blend(true); - call_glBlendFunc(GL_ONE, GL_ONE); - break; - case ColorBlendProperty::M_multiply_add: - enable_blend(true); - call_glBlendFunc(GL_DST_COLOR, GL_ONE); - break; - case ColorBlendProperty::M_alpha: - enable_blend(true); - call_glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - break; - default: - crgsg_cat.error() - << "Unknown color blend mode " << (int)mode << endl; - break; - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_texture_apply -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_texture_apply(const TextureApplyTransition *attrib) { - // activate(); - GLint glmode = get_texture_apply_mode_type(attrib->get_mode()); - chromium.TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, glmode); - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_color_mask -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_color_mask(const ColorMaskTransition *attrib) { - // activate(); - chromium.ColorMask(attrib->is_write_r(), - attrib->is_write_g(), - attrib->is_write_b(), - attrib->is_write_a()); - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_depth_test -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_depth_test(const DepthTestTransition *attrib) { - // activate(); - - DepthTestProperty::Mode mode = attrib->get_mode(); - if (mode == DepthTestProperty::M_none) { - enable_depth_test(false); - } else { - enable_depth_test(true); - chromium.DepthFunc(get_depth_func_type(mode)); - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_depth_write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_depth_write(const DepthWriteTransition *attrib) { - // activate(); - chromium.DepthMask(attrib->is_on()); - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_stencil -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_stencil(const StencilTransition *attrib) { - StencilProperty::Mode mode = attrib->get_mode(); - if (mode == StencilProperty::M_none) { - enable_stencil_test(false); - - } else { - enable_stencil_test(true); - call_glStencilFunc(get_stencil_func_type(mode),attrib->get_reference_value(),attrib->get_func_mask()); - call_glStencilOp(get_stencil_action_type(attrib->get_fail_action()), - get_stencil_action_type(attrib->get_zfail_action()), - get_stencil_action_type(attrib->get_pass_action())); - #ifdef _DEBUG - if (attrib->get_write_mask() != 0xFFFFFFFF) - crgsg_cat.warning() << "OpenGL doesnt support stencil writemasks!\n"; - #endif - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_cull_transition -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_cull_face(const CullFaceTransition *attrib) { - // activate(); - CullFaceProperty::Mode mode = attrib->get_mode(); - - switch (mode) { - case CullFaceProperty::M_cull_none: - chromium.Disable(GL_CULL_FACE); - break; - case CullFaceProperty::M_cull_clockwise: - chromium.Enable(GL_CULL_FACE); - chromium.CullFace(GL_BACK); - break; - case CullFaceProperty::M_cull_counter_clockwise: - chromium.Enable(GL_CULL_FACE); - chromium.CullFace(GL_FRONT); - break; - case CullFaceProperty::M_cull_all: - chromium.Enable(GL_CULL_FACE); - chromium.CullFace(GL_FRONT_AND_BACK); - break; - default: - crgsg_cat.error() - << "invalid cull face mode " << (int)mode << endl; - break; - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_clip_plane -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_clip_plane(const ClipPlaneTransition *attrib) -{ - nassertv(attrib->get_default_dir() != TD_on); - // activate(); - - // Initialize the currently enabled clip plane list - int i; - for (i = 0; i < _max_clip_planes; i++) - _cur_clip_plane_enabled[i] = false; - - int num_enabled = 0; - ClipPlaneTransition::const_iterator pi; - for (pi = attrib->begin(); pi != attrib->end(); ++pi) { - PlaneNode *plane_node; - DCAST_INTO_V(plane_node, (*pi).first); - nassertv(plane_node != (PlaneNode *)NULL); - TransitionDirection dir = (*pi).second; - - if (dir == TD_on) { - _cur_clip_plane_id = -1; - num_enabled++; - - // Check to see if this clip plane has already been bound to an id - for (i = 0; i < _max_clip_planes; i++) { - if (_available_clip_plane_ids[i] == plane_node) { - // Clip plane has already been bound to an id, we only need - // to enable the clip plane, not apply it - _cur_clip_plane_id = -2; - enable_clip_plane(i, true); - _cur_clip_plane_enabled[i] = true; - break; - } - } - - // See if there are any unbound clip plane ids - if (_cur_clip_plane_id == -1) { - for (i = 0; i < _max_clip_planes; i++) { - if (_available_clip_plane_ids[i] == NULL) { - _available_clip_plane_ids[i] = plane_node; - _cur_clip_plane_id = i; - break; - } - } - } - - // If there were no unbound clip plane ids, see if we can replace - // a currently unused but previously bound id - if (_cur_clip_plane_id == -1) { - for (i = 0; i < _max_clip_planes; i++) { - if (attrib->is_off(_available_clip_plane_ids[i])) { - _available_clip_plane_ids[i] = plane_node; - _cur_clip_plane_id = i; - break; - } - } - } - - if (_cur_clip_plane_id >= 0) { - enable_clip_plane(_cur_clip_plane_id, true); - _cur_clip_plane_enabled[_cur_clip_plane_id] = true; - double equation[4]; - const Planef clip_plane = plane_node->get_plane(); - // Move us into the coordinate space of the plane - chromium.MatrixMode(GL_MODELVIEW); - chromium.PushMatrix(); - chromium.LoadMatrixf(clip_plane.get_reflection_mat().get_data()); - equation[0] = clip_plane._a; - equation[1] = clip_plane._b; - equation[2] = clip_plane._c; - equation[3] = clip_plane._d; - chromium.ClipPlane(get_clip_plane_id(_cur_clip_plane_id), equation); - chromium.PopMatrix(); - } else if (_cur_clip_plane_id == -1) { - crgsg_cat.error() - << "issue_clip_plane() - failed to bind clip plane to id" << endl; - } - } - } - - // Disable all unused clip planes - for (i = 0; i < _max_clip_planes; i++) { - if (_cur_clip_plane_enabled[i] == false) - enable_clip_plane(i, false); - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_transparency -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_transparency(const TransparencyTransition *attrib ) -{ - // activate(); - - TransparencyProperty::Mode mode = attrib->get_mode(); - - switch (mode) { - case TransparencyProperty::M_none: - enable_multisample_alpha_one(false); - enable_multisample_alpha_mask(false); - enable_blend(false); - enable_alpha_test(false); - break; - case TransparencyProperty::M_alpha: - case TransparencyProperty::M_alpha_sorted: - // Should we really have an "alpha" and an "alpha_sorted" mode, - // like Performer does? (The difference is that "alpha" is with - // the write to the depth buffer disabled.) Or should we just use - // the separate depth write transition to control this? Doing it - // implicitly requires a bit more logic here and in the state - // management; for now we require the user to explicitly turn off - // the depth write. - enable_multisample_alpha_one(false); - enable_multisample_alpha_mask(false); - enable_blend(true); - enable_alpha_test(false); - call_glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - break; - case TransparencyProperty::M_multisample: - enable_multisample_alpha_one(true); - enable_multisample_alpha_mask(true); - enable_blend(false); - enable_alpha_test(false); - break; - case TransparencyProperty::M_multisample_mask: - enable_multisample_alpha_one(false); - enable_multisample_alpha_mask(true); - enable_blend(false); - enable_alpha_test(false); - break; - case TransparencyProperty::M_binary: - enable_multisample_alpha_one(false); - enable_multisample_alpha_mask(false); - enable_blend(false); - enable_alpha_test(true); - call_glAlphaFunc(GL_EQUAL, 1); - break; - default: - crgsg_cat.error() - << "invalid transparency mode " << (int)mode << endl; - break; - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_linesmooth -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_linesmooth(const LinesmoothTransition *attrib) { - // activate(); - enable_line_smooth(attrib->is_on()); - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_point_shape -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_point_shape(const PointShapeTransition *attrib) { - // activate(); - - if (attrib->get_mode() == PointShapeProperty::M_square) - chromium.Disable(GL_POINT_SMOOTH); - else - chromium.Enable(GL_POINT_SMOOTH); - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::issue_polygon_offset -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -issue_polygon_offset(const PolygonOffsetTransition *attrib) { - // activate(); - //GL really wants to do a enable/disable of PolygonOffset, but it - //seems more intuitive to have a PolygonOffset "on" all the time, - //and have zero mean nothing is being done. So check for a zero - //offset to decide whether to enable or disable PolygonOffset - if(attrib->get_units() != 0 || attrib->get_factor() != 0) - { - // GLfloat newfactor=attrib->get_factor(); - GLfloat newfactor= 1.0f; - - GLfloat newunits=attrib->get_units(); - chromium.PolygonOffset(newfactor,newunits); - enable_polygon_offset(true); - } - else - { - enable_polygon_offset(false); - } - report_errors(); -} - //////////////////////////////////////////////////////////////////// // Function: CRGraphicsStateGuardian::issue_transform // Access: Public, Virtual @@ -3454,151 +2400,6 @@ wants_texcoords() const { return _texturing_enabled; } -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::begin_decal -// Access: Public, Virtual -// Description: This will be called to initiate decaling mode. It is -// passed the pointer to the GeomNode that will be the -// destination of the decals, which it is expected that -// the GSG will render normally; subsequent geometry -// rendered up until the next call of end_decal() should -// be rendered as decals of the base_geom. -// -// The transitions wrapper is the current state as of the -// base geometry node. It may or may not be modified by -// the GSG to reflect whatever rendering state is -// necessary to render the decals properly. -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -begin_decal(GeomNode *base_geom, AllTransitionsWrapper &attrib) { - nassertv(base_geom != (GeomNode *)NULL); - _decal_level++; - -#define POLYGON_OFFSET_MULTIPLIER -2 - - if (cr_decal_type == GDT_offset) { - // GL 1.1-style: use chromium.PolygonOffset to do decals. - - // Just draw the base geometry normally. - base_geom->draw(this); - chromium.PolygonOffset(0.0f,POLYGON_OFFSET_MULTIPLIER * _decal_level); - chromium.Enable(GL_POLYGON_OFFSET_FILL); - - } else { - // GL 1.0f-style: use three-step rendering to do decals. - - if (_decal_level > 1) { - // If we're already decaling, just draw the geometry. - base_geom->draw(this); - - } else { - // Turn off writing the depth buffer to render the base geometry. - chromium.DepthMask(false); - DepthWriteTransition *dwa = new DepthWriteTransition; - dwa->set_off(); - attrib.set_transition(dwa); - - // Now render the base geometry. - base_geom->draw(this); - - // Render all of the decal geometry, too. We'll keep the depth - // buffer write off during this. - - // Save the current transform within the GL state so we can - // restore it when we come back to draw the base geometry again. - chromium.MatrixMode(GL_MODELVIEW); - chromium.PushMatrix(); - } - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::end_decal -// Access: Public, Virtual -// Description: This will be called to terminate decaling mode. It -// is passed the same base_geom that was passed to -// begin_decal(). -//////////////////////////////////////////////////////////////////// -void CRGraphicsStateGuardian:: -end_decal(GeomNode *base_geom) { - nassertv(base_geom != (GeomNode *)NULL); - - _decal_level--; - - if (cr_decal_type == GDT_offset) { - // GL 1.1-style: use chromium.PolygonOffset to do decals. - chromium.PolygonOffset(0.0f,POLYGON_OFFSET_MULTIPLIER * _decal_level); - if (_decal_level == 0) { - chromium.Disable(GL_POLYGON_OFFSET_FILL); - } - - } else { - // GL 1.0f-style: use three-step rendering to do decals. - - if (_decal_level == 0) { - // Now we need to re-render the base geometry with the depth write - // on and the color mask off, so we update the depth buffer - // properly. - bool was_textured = _texturing_enabled; - bool was_blend = _blend_enabled; - GLenum old_blend_source_func = _blend_source_func; - GLenum old_blend_dest_func = _blend_dest_func; - - // First, we'd better restore the transform matrix in case our - // decals screwed it up. - chromium.MatrixMode(GL_MODELVIEW); - chromium.PopMatrix(); - - // Enable the writing to the depth buffer. - chromium.DepthMask(true); - - // Disable the writing to the color buffer, however we have to - // do this. - if (cr_decal_type == GDT_blend) { - // For the early nVidia Linux driver, at least, we don't seem - // to have a working chromium.ColorMask. So we have to disable the - // color writes through the use of a blend function. - // Expensive. - - enable_blend(true); - call_glBlendFunc(GL_ZERO, GL_ONE); - } else { - chromium.ColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - } - - // No need to have texturing on for this. - enable_texturing(false); - - base_geom->draw(this); - - // Finally, restore the depth write and color mask states to the - // way they're supposed to be. - DepthWriteTransition *depth_write; - if (get_attribute_into(depth_write, this)) { - issue_depth_write(depth_write); - } - - if (cr_decal_type == GDT_blend) { - enable_blend(was_blend); - if (was_blend) { - call_glBlendFunc(old_blend_source_func, old_blend_dest_func); - } - } else { - ColorMaskTransition *color_mask; - if (get_attribute_into(color_mask, this)) { - issue_color_mask(color_mask); - } else { - chromium.ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - } - } - - enable_texturing(was_textured); - } - } - report_errors(); -} - //////////////////////////////////////////////////////////////////// // Function: CRGraphicsStateGuardian::depth_offset_decals // Access: Public, Virtual @@ -4223,27 +3024,6 @@ get_internal_image_format(PixelBuffer::Format format) { } } -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::get_texture_apply_mode_type -// Access: Protected -// Description: Maps from the texture environment's mode types -// to the corresponding OpenGL ids -//////////////////////////////////////////////////////////////////// -GLint CRGraphicsStateGuardian:: -get_texture_apply_mode_type( TextureApplyProperty::Mode am ) const -{ - switch( am ) { - case TextureApplyProperty::M_modulate: return GL_MODULATE; - case TextureApplyProperty::M_decal: return GL_DECAL; - case TextureApplyProperty::M_blend: return GL_BLEND; - case TextureApplyProperty::M_replace: return GL_REPLACE; - case TextureApplyProperty::M_add: return GL_ADD; - } - crgsg_cat.error() - << "Invalid TextureApplyProperty::Mode value" << endl; - return GL_MODULATE; -} - //////////////////////////////////////////////////////////////////// // Function: CRGraphicsStateGuardian::get_texture_apply_mode_type // Access: Protected @@ -4264,31 +3044,6 @@ get_texture_apply_mode_type(TextureApplyAttrib::Mode am) const { return GL_MODULATE; } -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::get_depth_func_type -// Access: Protected -// Description: Maps from the depth func modes to gl version -//////////////////////////////////////////////////////////////////// -GLenum CRGraphicsStateGuardian:: -get_depth_func_type(DepthTestProperty::Mode m) const -{ - switch(m) { - case DepthTestProperty::M_never: return GL_NEVER; - case DepthTestProperty::M_less: return GL_LESS; - case DepthTestProperty::M_equal: return GL_EQUAL; - case DepthTestProperty::M_less_equal: return GL_LEQUAL; - case DepthTestProperty::M_greater: return GL_GREATER; - case DepthTestProperty::M_not_equal: return GL_NOTEQUAL; - case DepthTestProperty::M_greater_equal: return GL_GEQUAL; - case DepthTestProperty::M_always: return GL_ALWAYS; - - default: - crgsg_cat.error() - << "Invalid DepthTestProperty::Mode value" << endl; - return GL_LESS; - } -} - //////////////////////////////////////////////////////////////////// // Function: CRGraphicsStateGuardian::get_depth_func_type // Access: Protected @@ -4314,83 +3069,6 @@ get_depth_func_type(DepthTestAttrib::Mode m) const } } -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::get_stencil_func_type -// Access: Protected -// Description: Maps from the stencil func modes to gl version -//////////////////////////////////////////////////////////////////// -GLenum CRGraphicsStateGuardian:: -get_stencil_func_type(StencilProperty::Mode m) const -{ - // TODO: should do this with a table, not a switch - switch(m) { - case StencilProperty::M_never: return GL_NEVER; - case StencilProperty::M_less: return GL_LESS; - case StencilProperty::M_equal: return GL_EQUAL; - case StencilProperty::M_less_equal: return GL_LEQUAL; - case StencilProperty::M_greater: return GL_GREATER; - case StencilProperty::M_not_equal: return GL_NOTEQUAL; - case StencilProperty::M_greater_equal: return GL_GEQUAL; - case StencilProperty::M_always: return GL_ALWAYS; - - default: - crgsg_cat.error() - << "Invalid StencilProperty::Mode value" << endl; - return GL_LESS; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::get_stencil_action_type -// Access: Protected -// Description: Maps from the stencil action modes to gl version -//////////////////////////////////////////////////////////////////// -GLenum CRGraphicsStateGuardian:: -get_stencil_action_type(StencilProperty::Action a) const -{ - // TODO: should do this with a table, not a switch - switch(a) { - case StencilProperty::A_keep: return GL_KEEP; - case StencilProperty::A_zero: return GL_ZERO; - case StencilProperty::A_replace: return GL_REPLACE; - case StencilProperty::A_increment_clamp: return GL_INCR; - case StencilProperty::A_decrement_clamp: return GL_DECR; - case StencilProperty::A_invert: return GL_INVERT; - - case StencilProperty::A_increment: - case StencilProperty::A_decrement: - crgsg_cat.error() - << "wraparound incr/decr StencilProperty::Action not supported by OpenGL\n"; - return ((a == StencilProperty::A_increment) ? GL_INCR : GL_DECR); - } - crgsg_cat.error() - << "Invalid StencilProperty::Action value" << endl; - return GL_KEEP; -} - -//////////////////////////////////////////////////////////////////// -// Function: CRGraphicsStateGuardian::get_fog_mode_type -// Access: Protected -// Description: Maps from the fog types to gl version -//////////////////////////////////////////////////////////////////// -GLenum CRGraphicsStateGuardian:: -get_fog_mode_type(Fog::Mode m) const { - switch(m) { - case Fog::M_linear: return GL_LINEAR; - case Fog::M_exponential: return GL_EXP; - case Fog::M_exponential_squared: return GL_EXP2; - /* - #ifdef GL_FOG_FUNC_SGIS - case Fog::M_spline: return GL_FOG_FUNC_SGIS; - #endif - */ - - default: - crgsg_cat.error() << "Invalid Fog::Mode value" << endl; - return GL_EXP; - } -} - //////////////////////////////////////////////////////////////////// // Function: CRGraphicsStateGuardian::print_gfx_visual // Access: Public diff --git a/panda/src/crgsg/crGraphicsStateGuardian.h b/panda/src/crgsg/crGraphicsStateGuardian.h index 17bc7620aa..3bc2188a4d 100644 --- a/panda/src/crgsg/crGraphicsStateGuardian.h +++ b/panda/src/crgsg/crGraphicsStateGuardian.h @@ -29,10 +29,6 @@ #include "pixelBuffer.h" #include "displayRegion.h" #include "material.h" -#include "textureApplyProperty.h" -#include "depthTestProperty.h" -#include "stencilProperty.h" -#include "fog.h" #include "depthTestAttrib.h" #include "textureApplyAttrib.h" #include "pointerToArray.h" @@ -87,15 +83,6 @@ public: virtual void prepare_display_region(); virtual bool prepare_lens(); - virtual void render_frame(); - virtual void render_scene(Node *root, LensNode *projnode); - virtual void render_subgraph(RenderTraverser *traverser, - Node *subgraph, LensNode *projnode, - const AllTransitionsWrapper &net_trans); - virtual void render_subgraph(RenderTraverser *traverser, - Node *subgraph, - const AllTransitionsWrapper &net_trans); - virtual void draw_point(GeomPoint *geom, GeomContext *gc); virtual void draw_line(GeomLine *geom, GeomContext *gc); virtual void draw_linestrip(GeomLinestrip *geom, GeomContext *gc); @@ -111,16 +98,14 @@ public: virtual void apply_texture(TextureContext *tc); virtual void release_texture(TextureContext *tc); - virtual GeomNodeContext *prepare_geom_node(GeomNode *node); - virtual void draw_geom_node(GeomNode *node, GeomNodeContext *gnc); + virtual GeomNodeContext *prepare_geom_node(qpGeomNode *node); + virtual void draw_geom_node(qpGeomNode *node, const RenderState *state, + GeomNodeContext *gnc); virtual void release_geom_node(GeomNodeContext *gnc); virtual void copy_texture(TextureContext *tc, const DisplayRegion *dr); virtual void copy_texture(TextureContext *tc, const DisplayRegion *dr, const RenderBuffer &rb); - virtual void draw_texture(TextureContext *tc, const DisplayRegion *dr); - virtual void draw_texture(TextureContext *tc, const DisplayRegion *dr, - const RenderBuffer &rb); virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb); virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb, @@ -136,32 +121,8 @@ public: const NodeTransitions& na=NodeTransitions()); virtual void apply_material(const Material *material); - virtual void apply_fog(Fog *fog); void apply_fog(qpFog *fog); - virtual void issue_transform(const TransformTransition *attrib); - virtual void issue_color_transform(const ColorMatrixTransition *attrib); - virtual void issue_alpha_transform(const AlphaTransformTransition *attrib); - virtual void issue_tex_matrix(const TexMatrixTransition *attrib); - virtual void issue_color(const ColorTransition *attrib); - virtual void issue_texture(const TextureTransition *attrib); - virtual void issue_material(const MaterialTransition *attrib); - virtual void issue_render_mode(const RenderModeTransition *attrib); - virtual void issue_color_blend(const ColorBlendTransition *attrib); - virtual void issue_texture_apply(const TextureApplyTransition *attrib); - virtual void issue_color_mask(const ColorMaskTransition *attrib); - virtual void issue_depth_test(const DepthTestTransition *attrib); - virtual void issue_depth_write(const DepthWriteTransition *attrib); - virtual void issue_tex_gen(const TexGenTransition *attrib); - virtual void issue_cull_face(const CullFaceTransition *attrib); - virtual void issue_stencil(const StencilTransition *attrib); - virtual void issue_clip_plane(const ClipPlaneTransition *attrib); - virtual void issue_transparency(const TransparencyTransition *attrib); - virtual void issue_fog(const FogTransition *attrib); - virtual void issue_linesmooth(const LinesmoothTransition *attrib); - virtual void issue_point_shape(const PointShapeTransition *attrib); - virtual void issue_polygon_offset(const PolygonOffsetTransition *attrib); - virtual void issue_transform(const TransformState *transform); virtual void issue_tex_matrix(const TexMatrixAttrib *attrib); virtual void issue_texture(const TextureAttrib *attrib); @@ -185,9 +146,6 @@ public: virtual bool wants_normals(void) const; virtual bool wants_texcoords(void) const; - virtual void begin_decal(GeomNode *base_geom, AllTransitionsWrapper &attrib); - virtual void end_decal(GeomNode *base_geom); - virtual bool depth_offset_decals(); virtual CoordinateSystem get_internal_coordinate_system() const; diff --git a/panda/src/cull/Sources.pp b/panda/src/cull/Sources.pp deleted file mode 100644 index 0a42f64d23..0000000000 --- a/panda/src/cull/Sources.pp +++ /dev/null @@ -1,53 +0,0 @@ -#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \ - dtoolutil:c dtoolbase:c dtool:m - -#begin lib_target - #define TARGET cull - #define LOCAL_LIBS \ - gobj sgraphutil graph putil sgraph mathutil sgattrib display \ - pstatclient - - #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx - - #define SOURCES \ - config_cull.h cullState.I cullState.h cullStateLookup.I \ - cullStateLookup.h cullStateSubtree.I cullStateSubtree.h \ - cullTraverser.I cullTraverser.h directRenderTransition.I \ - directRenderTransition.h geomBin.I geomBin.h \ - geomBinBackToFront.I geomBinBackToFront.h geomBinFixed.I \ - geomBinFixed.h geomBinGroup.I geomBinGroup.h geomBinNormal.h \ - geomBinTransition.I geomBinTransition.h geomBinUnsorted.I \ - geomBinUnsorted.h - - #define INCLUDED_SOURCES \ - config_cull.cxx cullState.cxx cullStateLookup.cxx \ - cullStateSubtree.cxx cullTraverser.cxx \ - directRenderTransition.cxx geomBin.cxx \ - geomBinBackToFront.cxx geomBinFixed.cxx geomBinGroup.cxx \ - geomBinNormal.cxx geomBinTransition.cxx geomBinUnsorted.cxx - - #define INSTALL_HEADERS \ - config_cull.h cullLevelState.h cullState.I cullState.h \ - cullStateLookup.I cullStateLookup.h cullStateSubtree.I \ - cullStateSubtree.h cullTraverser.I cullTraverser.h \ - directRenderTransition.I directRenderTransition.h geomBin.I \ - geomBin.h \ - geomBinBackToFront.I geomBinBackToFront.h geomBinFixed.I \ - geomBinFixed.h geomBinGroup.I geomBinGroup.h geomBinNormal.h \ - geomBinTransition.I geomBinTransition.h geomBinUnsorted.I \ - geomBinUnsorted.h - - #define IGATESCAN all - -#end lib_target - -#begin test_bin_target - #define TARGET test_cull - #define LOCAL_LIBS \ - cull sgattrib - - #define SOURCES \ - test_cull.cxx - -#end test_bin_target - diff --git a/panda/src/cull/config_cull.cxx b/panda/src/cull/config_cull.cxx deleted file mode 100644 index ce0cfcd6ce..0000000000 --- a/panda/src/cull/config_cull.cxx +++ /dev/null @@ -1,55 +0,0 @@ -// Filename: config_cull.cxx -// Created by: drose (07Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "config_cull.h" -#include "cullTraverser.h" -#include "geomBin.h" -#include "geomBinUnsorted.h" -#include "geomBinBackToFront.h" -#include "geomBinGroup.h" -#include "geomBinNormal.h" -#include "geomBinTransition.h" -#include "geomBinFixed.h" -#include "directRenderTransition.h" - -#include - -ConfigureDef(config_cull); -NotifyCategoryDef(cull, ""); - -ConfigureFn(config_cull) { - CullTraverser::init_type(); - GeomBin::init_type(); - GeomBinUnsorted::init_type(); - GeomBinBackToFront::init_type(); - GeomBinGroup::init_type(); - GeomBinNormal::init_type(); - GeomBinTransition::init_type(); - GeomBinFixed::init_type(); - DirectRenderTransition::init_type(); - - //Registration of writeable object's creation - //functions with BamReader's factory - GeomBinTransition::register_with_read_factory(); -} - -// Set this true to force all of the caching to blow itself away every -// frame. Normally you would only do this during testing. -const bool cull_force_update = config_cull.GetBool("cull-force-update", false); - diff --git a/panda/src/cull/config_cull.h b/panda/src/cull/config_cull.h deleted file mode 100644 index 64cb0beef6..0000000000 --- a/panda/src/cull/config_cull.h +++ /dev/null @@ -1,31 +0,0 @@ -// Filename: config_cull.h -// Created by: drose (07Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CONFIG_CULL_H -#define CONFIG_CULL_H - -#include -#include -#include - -ConfigureDecl(config_cull, EXPCL_PANDA, EXPTP_PANDA); -NotifyCategoryDecl(cull, EXPCL_PANDA, EXPTP_PANDA); - -extern const bool cull_force_update; - -#endif diff --git a/panda/src/cull/cullLevelState.h b/panda/src/cull/cullLevelState.h deleted file mode 100644 index a01e925e72..0000000000 --- a/panda/src/cull/cullLevelState.h +++ /dev/null @@ -1,41 +0,0 @@ -// Filename: cullLevelState.h -// Created by: drose (17Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CULLLEVELSTATE_H -#define CULLLEVELSTATE_H - -#include - -#include "cullStateLookup.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : CullLevelState -// Description : This is the state information the -// CullTraverser retains for each level during -// traversal. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA CullLevelState { -public: - CullStateLookup *_lookup; - UpdateSeq _as_of; -}; - -#endif - diff --git a/panda/src/cull/cullState.I b/panda/src/cull/cullState.I deleted file mode 100644 index bce53466e8..0000000000 --- a/panda/src/cull/cullState.I +++ /dev/null @@ -1,263 +0,0 @@ -// Filename: cullState.I -// Created by: drose (14Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: CullState::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CullState:: -CullState(const AllTransitionsWrapper &trans) : - _trans(trans) -{ - _bin = (GeomBin *)NULL; - _empty_frames_count = 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CullState:: -~CullState() { - // This shouldn't be destructing while it's still assigned to a bin. - // If it is, something went screwy with the reference counts or with - // the bin logic somewhere. - nassertv(_bin == (GeomBin *)NULL); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::compare_to -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int CullState:: -compare_to(const CullState &other) const { - return _trans.compare_to(other._trans); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::mark_verified -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void CullState:: -mark_verified(Node *node, UpdateSeq now) { - _verified[node] = now; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::clear_current_nodes -// Access: Public -// Description: Called by the CullTraverser at the beginning of the -// frame to reset the list of GeomNodes currently -// visible, in preparation for building up a new list -// (via repeated calls to record_current_node()). -//////////////////////////////////////////////////////////////////// -INLINE void CullState:: -clear_current_nodes() { - if (_current_geom_nodes.empty() && _current_direct_nodes.empty()) { - _empty_frames_count++; - } - _current_geom_nodes.clear(); - _current_direct_nodes.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::record_current_geom_node -// Access: Public -// Description: Called by the CullTraverser to indicate a particular -// GeomNode, associated with this state, that is known to -// be visible this frame. -//////////////////////////////////////////////////////////////////// -INLINE void CullState:: -record_current_geom_node(const ArcChain &arc_chain) { - if (cull_cat.is_spam()) { - cull_cat.spam() - << "Recording geom node " << arc_chain << " with state " << (void *)this - << "\n"; - } - _current_geom_nodes.push_back(arc_chain); - _empty_frames_count = 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::record_current_direct_node -// Access: Public -// Description: Called by the CullTraverser to indicate a particular -// Node, to be directly rendered, that is known to be -// visible this frame. -//////////////////////////////////////////////////////////////////// -INLINE void CullState:: -record_current_direct_node(const ArcChain &arc_chain) { - _current_direct_nodes.push_back(arc_chain); - _empty_frames_count = 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::is_empty -// Access: Public -// Description: Returns true if the CullState has no current nodes to -// render (i.e. count_current_nodes() == 0), false -// otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool CullState:: -is_empty() const { - return _current_geom_nodes.empty() && _current_direct_nodes.empty(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::count_current_nodes -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int CullState:: -count_current_nodes() const { - return _current_geom_nodes.size() + _current_direct_nodes.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::get_empty_frames_count -// Access: Public -// Description: Returns the number of consecutive frames the state -// has been empty, i.e. has represented no visible -// nodes. -//////////////////////////////////////////////////////////////////// -INLINE int CullState:: -get_empty_frames_count() const { - return _empty_frames_count; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::apply_to -// Access: Public -// Description: Indicates the initial state this frame; this is -// applied to the net transitions indicated by the -// CullState and stored within the CullState object. -//////////////////////////////////////////////////////////////////// -INLINE void CullState:: -apply_to(const AllTransitionsWrapper &initial_state) { - _attrib.compose_from(initial_state, _trans); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::get_attributes -// Access: Public -// Description: Returns the current state indicated by the CullState -// object, based on the CullState's net transitions set -// and the initial state set by apply_to(). -//////////////////////////////////////////////////////////////////// -INLINE const AllTransitionsWrapper &CullState:: -get_attributes() const { - return _attrib; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::get_transitions -// Access: Public -// Description: Returns the net transitions indicated by the -// CullState object. -//////////////////////////////////////////////////////////////////// -INLINE const AllTransitionsWrapper &CullState:: -get_transitions() const { - return _trans; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::has_bin -// Access: Public -// Description: Returns true if the CullState has been assigned to a -// particular GeomBin. -//////////////////////////////////////////////////////////////////// -INLINE bool CullState:: -has_bin() const { - return _bin != (GeomBin *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::get_bin -// Access: Public -// Description: Returns the particular GeomBin the CullState has been -// assigned to, or NULL if it has not been assigned to a -// bin. -//////////////////////////////////////////////////////////////////// -INLINE GeomBin *CullState:: -get_bin() const { - return _bin; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::geom_size -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CullState::geom_size_type CullState:: -geom_size() const { - return _current_geom_nodes.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::geom_begin -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CullState::geom_iterator CullState:: -geom_begin() const { - return _current_geom_nodes.begin(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::geom_end -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CullState::geom_iterator CullState:: -geom_end() const { - return _current_geom_nodes.end(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::direct_size -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CullState::direct_size_type CullState:: -direct_size() const { - return _current_direct_nodes.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::direct_begin -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CullState::direct_iterator CullState:: -direct_begin() const { - return _current_direct_nodes.begin(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::direct_end -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CullState::direct_iterator CullState:: -direct_end() const { - return _current_direct_nodes.end(); -} diff --git a/panda/src/cull/cullState.cxx b/panda/src/cull/cullState.cxx deleted file mode 100644 index cda91901d4..0000000000 --- a/panda/src/cull/cullState.cxx +++ /dev/null @@ -1,115 +0,0 @@ -// Filename: cullState.cxx -// Created by: drose (07Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "cullState.h" -#include "config_cull.h" - -#include -#include - -//////////////////////////////////////////////////////////////////// -// Function: CullState::check_currency -// Access: Public -// Description: Returns true if the CullState is fresh enough to still -// apply to the indicated node and its associated cached -// transition, false if it should be recomputed. If -// false, the node entry is removed. -//////////////////////////////////////////////////////////////////// -bool CullState:: -check_currency(Node *node, const AllTransitionsWrapper &, - UpdateSeq as_of) { - // First, check the verified time stamp. - Verified::iterator vi; - vi = _verified.find(node); - if (vi == _verified.end()) { - // We have never seen this node before. - return false; - } - - UpdateSeq verified_stamp = (*vi).second; - - if (cull_cat.is_spam()) { - cull_cat.spam() - << "Checking currency for " << *node << ", verified_stamp = " - << verified_stamp << " as_of = " << as_of << "\n"; - } - - if (as_of <= verified_stamp && !verified_stamp.is_fresh()) { - return true; - } - - // Now we should verify the set of transitions individually. Skip - // that for now. - - // So we now know this node is no longer appropriate for this state. - // Remove any record we ever had of the node. - _verified.erase(vi); - - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void CullState:: -output(ostream &out) const { - out << count_current_nodes() << " nodes: { " << _trans << " }"; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullState::write -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void CullState:: -write(ostream &out, int indent_level) const { - indent(out, indent_level) - << _current_geom_nodes.size() << " geom nodes"; - - if (!_current_geom_nodes.empty()) { - CurrentGeomNodes::const_iterator ci; - ci = _current_geom_nodes.begin(); - out << " (" << (*ci); - ++ci; - while (ci != _current_geom_nodes.end()) { - out << ", " << (*ci); - ++ci; - } - out << ")"; - } - - out << ", " << _current_direct_nodes.size() << " direct nodes"; - - if (!_current_direct_nodes.empty()) { - CurrentDirectNodes::const_iterator ci; - ci = _current_direct_nodes.begin(); - out << " (" << (*ci); - ++ci; - while (ci != _current_direct_nodes.end()) { - out << ", " << (*ci); - ++ci; - } - out << ")"; - } - out << ":\n"; - - _trans.write(out, indent_level + 2); -} diff --git a/panda/src/cull/cullState.h b/panda/src/cull/cullState.h deleted file mode 100644 index cc78ebb148..0000000000 --- a/panda/src/cull/cullState.h +++ /dev/null @@ -1,127 +0,0 @@ -// Filename: cullState.h -// Created by: drose (07Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CULLSTATE_H -#define CULLSTATE_H - -#include - -#include "config_cull.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "pmap.h" -#include "pvector.h" - -class GraphicsStateGuardian; -class GeomBin; - -//////////////////////////////////////////////////////////////////// -// Class : CullState -// Description : This is the basic grouping unit of the CullTraverser. -// A single CullState object represents all of the -// GeomNodes throughout the scene graph that share an -// identical state. The CullTraverser collects these as -// it traverses, and tries to cache them between -// subsequent frames. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA CullState : public ReferenceCount { -public: - typedef pvector CurrentGeomNodes; - typedef pvector CurrentDirectNodes; - -public: - INLINE CullState(const AllTransitionsWrapper &trans); - INLINE ~CullState(); - - INLINE int compare_to(const CullState &other) const; - - bool check_currency(Node *node, - const AllTransitionsWrapper &trans, - UpdateSeq as_of); - - INLINE void mark_verified(Node *node, UpdateSeq now); - - INLINE void clear_current_nodes(); - INLINE void record_current_geom_node(const ArcChain &arc_chain); - INLINE void record_current_direct_node(const ArcChain &arc_chain); - INLINE bool is_empty() const; - INLINE int count_current_nodes() const; - INLINE int get_empty_frames_count() const; - - INLINE void apply_to(const AllTransitionsWrapper &initial_state); - INLINE const AllTransitionsWrapper &get_attributes() const; - INLINE const AllTransitionsWrapper &get_transitions() const; - - INLINE bool has_bin() const; - INLINE GeomBin *get_bin() const; - - void output(ostream &out) const; - void write(ostream &out, int indent_level = 0) const; - -public: - // Functions and typedefs to support treating the CullState as a - // read-only STL container of current nodes. Beware! This - // interface is not safe to use outside of PANDA.DLL. - typedef CurrentGeomNodes::const_iterator geom_iterator; - typedef CurrentGeomNodes::const_iterator geom_const_iterator; - typedef CurrentGeomNodes::value_type geom_value_type; - typedef CurrentGeomNodes::size_type geom_size_type; - - INLINE geom_size_type geom_size() const; - INLINE geom_iterator geom_begin() const; - INLINE geom_iterator geom_end() const; - - typedef CurrentDirectNodes::const_iterator direct_iterator; - typedef CurrentDirectNodes::const_iterator direct_const_iterator; - typedef CurrentDirectNodes::value_type direct_value_type; - typedef CurrentDirectNodes::size_type direct_size_type; - - INLINE direct_size_type direct_size() const; - INLINE direct_iterator direct_begin() const; - INLINE direct_iterator direct_end() const; - -private: - AllTransitionsWrapper _trans; - AllTransitionsWrapper _attrib; - - typedef pmap Verified; - Verified _verified; - - CurrentGeomNodes _current_geom_nodes; - CurrentDirectNodes _current_direct_nodes; - int _empty_frames_count; - - GeomBin *_bin; - friend class GeomBin; -}; - -INLINE ostream &operator << (ostream &out, const CullState &bs) { - bs.output(out); - return out; -} - -#include "cullState.I" - -#endif diff --git a/panda/src/cull/cullStateLookup.I b/panda/src/cull/cullStateLookup.I deleted file mode 100644 index 36084f7ec4..0000000000 --- a/panda/src/cull/cullStateLookup.I +++ /dev/null @@ -1,50 +0,0 @@ -// Filename: cullStateLookup.I -// Created by: drose (13Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "cullState.h" - -//////////////////////////////////////////////////////////////////// -// Function: CullStateLookup::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CullStateLookup:: -CullStateLookup() { -} - -//////////////////////////////////////////////////////////////////// -// Function: CullStateLookup::is_completely_empty -// Access: Public -// Description: Returns true if the lookup is completely empty; that -// is, it represents no Nodes, and no subtrees. -//////////////////////////////////////////////////////////////////// -INLINE bool CullStateLookup:: -is_completely_empty() const { - return _cull_states.empty() && _subtrees.empty(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullStateLookup::record_node -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void CullStateLookup:: -record_node(Node *node, CullState *cs, UpdateSeq now) { - _cull_states[node] = cs; - cs->mark_verified(node, now); -} diff --git a/panda/src/cull/cullStateLookup.cxx b/panda/src/cull/cullStateLookup.cxx deleted file mode 100644 index f5982fb06f..0000000000 --- a/panda/src/cull/cullStateLookup.cxx +++ /dev/null @@ -1,272 +0,0 @@ -// Filename: cullStateLookup.cxx -// Created by: drose (07Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "cullState.h" -#include "cullStateSubtree.h" - -#include - -#include "cullStateLookup.h" - -//////////////////////////////////////////////////////////////////// -// Function: CullStateLookup::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -CullStateLookup:: -~CullStateLookup() { - clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullStateLookup::clear -// Access: Public -// Description: Removes all of the data cached in the lookup. -//////////////////////////////////////////////////////////////////// -void CullStateLookup:: -clear() { - _cull_states.clear(); - - // We have to explicitly delete each of the subtrees created within - // this class. - Subtrees::iterator si; - for (si = _subtrees.begin(); si != _subtrees.end(); ++si) { - delete (*si).second; - } - _subtrees.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullStateLookup::find_node -// Access: Public -// Description: Looks up the indicated Node in the table, and -// determines if the associated CullState (if any) is -// fresh. If it is acceptable, returns its pointer; if -// there is no associated CullState or if the CullState -// is stale, removes the CullState and returns NULL. -//////////////////////////////////////////////////////////////////// -CullState *CullStateLookup:: -find_node(Node *node, - const AllTransitionsWrapper &trans, - UpdateSeq now) { - if (cull_cat.is_spam()) { - cull_cat.spam() - << "Looking up " << *node << " in lookup " << (void *)this << "\n"; - } - CullStates::iterator csi; - csi = _cull_states.find(node); - if (csi == _cull_states.end()) { - // No entry for the node. - if (cull_cat.is_spam()) { - cull_cat.spam() - << "No entry for the node.\n"; - } - return NULL; - } - - CullState *cs = (*csi).second; - if (cs->check_currency(node, trans, now)) { - // The entry is current enough to use. - if (cull_cat.is_spam()) { - cull_cat.spam() - << "The entry is found and current.\n"; - } - return cs; - } - - // The entry is stale; remove it and return NULL. - if (cull_cat.is_spam()) { - cull_cat.spam() - << "The entry is stale.\n"; - } - _cull_states.erase(csi); - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullStateLookup::get_subtree -// Access: Public -// Description: A subtree is declared for each arc that begins a new -// shared instance of a node within the scene graph; -// i.e. each arc that leads to a node with multiple -// parents. Each of the descendents of this arc is -// added only to the thus-defined subtree, and not -// directly to the parent CullStateLookup; this allows us -// to define a different cached value for each instance -// of a particular node. -// -// This function looks up the indicated NodeRelation in -// the table, and determines if the associated -// CullStateSubtree (if any) is fresh. If it is -// acceptable, returns its pointer; if there is no -// associated CullStateSubtree or if the -// CullStateSubtree is stale, creates and returns a new -// CullStateSubtree. In any case, a usable -// CullStateSubtree is always returned. -//////////////////////////////////////////////////////////////////// -CullStateSubtree *CullStateLookup:: -get_subtree(const PT_NodeRelation &arc, - const AllTransitionsWrapper &trans, - Node *top_subtree, - UpdateSeq now) { - if (cull_cat.is_spam()) { - cull_cat.spam() - << "Getting subtree for " << *arc << " in lookup " - << (void *)this << "\n"; - } - Subtrees::iterator si; - si = _subtrees.find(arc); - if (si == _subtrees.end()) { - // No entry for the arc. - if (cull_cat.is_spam()) { - cull_cat.spam() - << "No entry for the arc; creating new one.\n"; - } - CullStateSubtree *subtree = - new CullStateSubtree(this, trans, top_subtree, now); - _subtrees.insert(Subtrees::value_type(arc, subtree)); - return subtree; - } - - CullStateSubtree *subtree = (*si).second; - if (subtree->check_currency(trans, top_subtree, now)) { - // The entry is current enough to use. - if (cull_cat.is_spam()) { - cull_cat.spam() - << "The entry is found and current.\n"; - } - return subtree; - } - - // The entry is stale; update it. - if (cull_cat.is_spam()) { - cull_cat.spam() - << "The entry is stale.\n"; - } - subtree->update(trans, top_subtree, now); - return subtree; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullStateLookup::clean_out_top_nodes -// Access: Public -// Description: Walks through the list of nodes and arcs, and removes -// any pointers to CullStates that don't seem to be -// active any more. -//////////////////////////////////////////////////////////////////// -void CullStateLookup:: -clean_out_old_nodes() { - CullStates::iterator csi, csnext; - csi = _cull_states.begin(); - csnext = csi; - while (csi != _cull_states.end()) { - ++csnext; - - Node *node = (*csi).first; - CullState *cs = (*csi).second; - - if (node->get_ref_count() == 1) { - // If we've got the only outstanding pointer to this node, - // the node was deleted. Drop our reference. - _cull_states.erase(csi); - - } else if (!cs->has_bin() && cs->is_empty() && - cs->get_empty_frames_count() > 100) { - // If the CullState doesn't even have any nodes, delete it after - // 100 frames have elapsed. - _cull_states.erase(csi); - } - csi = csnext; - } - - Subtrees::iterator si, snext; - si = _subtrees.begin(); - snext = si; - while (si != _subtrees.end()) { - ++snext; - - CullStateSubtree *subtree = (*si).second; - subtree->clean_out_old_nodes(); - if (subtree->is_completely_empty()) { - _subtrees.erase(si); - } - si = snext; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CullStateLookup::get_top_subtree -// Access: Public, Virtual -// Description: Returns the node that represents the top of the -// subtree for this particular CullStateSubtree. In the -// case of the root CullStateLookup, this always returns -// NULL, indicating the root of the graph. -//////////////////////////////////////////////////////////////////// -Node *CullStateLookup:: -get_top_subtree() const { - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullStateLookup::compose_trans -// Access: Public, Virtual -// Description: Composes the transitions given in "from" with the net -// transitions that appear above the top node of this -// subtree, and returns the result in "to". This is a -// pass-thru for CullStateLookup; it has effect only for -// CullStateSubtree. -//////////////////////////////////////////////////////////////////// -void CullStateLookup:: -compose_trans(const AllTransitionsWrapper &from, - AllTransitionsWrapper &to) const { - to = from; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullStateLookup::write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void CullStateLookup:: -write(ostream &out, int indent_level) const { - indent(out, indent_level) << "CullStateLookup("; - bool is_first = true; - - CullStates::const_iterator csi; - for (csi = _cull_states.begin(); csi != _cull_states.end(); ++csi) { - if (!is_first) { - out << ", "; - } - is_first = false; - out << *(*csi).first; - } - out << ") {\n"; - - Subtrees::const_iterator si; - for (si = _subtrees.begin(); si != _subtrees.end(); ++si) { - const NodeRelation *arc = (*si).first; - const CullStateSubtree *subtree = (*si).second; - - indent(out, indent_level + 2) << *arc << " {\n"; - subtree->write(out, indent_level + 4); - indent(out, indent_level + 2) << "}\n"; - } - - indent(out, indent_level) << "}\n"; -} diff --git a/panda/src/cull/cullStateLookup.h b/panda/src/cull/cullStateLookup.h deleted file mode 100644 index 73f6b85b0f..0000000000 --- a/panda/src/cull/cullStateLookup.h +++ /dev/null @@ -1,86 +0,0 @@ -// Filename: cullStateLookup.h -// Created by: drose (07Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CULLSTATELOOKUP_H -#define CULLSTATELOOKUP_H - -#include - -#include -#include -#include -#include - -#include "pmap.h" - -class CullState; -class CullStateSubtree; - -//////////////////////////////////////////////////////////////////// -// Class : CullStateLookup -// Description : This object stores a set of CullState pointers, one -// for each unique state encountered in the scene graph. -// It can combine two identical states encountered at -// different parts of the scene graph into the same -// CullState pointer. -// -// It also supports instancing by maintaining a tree of -// instanced nodes: for each node in the scene graph -// with multiple parents, a new CullStateLookup object -// (actually, a CullStateSubtree object) is kept which -// tracks the state changes below that node. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA CullStateLookup { -public: - CullStateLookup(); - virtual ~CullStateLookup(); - - void clear(); - INLINE bool is_completely_empty() const; - - CullState *find_node(Node *node, - const AllTransitionsWrapper &trans, - UpdateSeq now); - CullStateSubtree *get_subtree(const PT_NodeRelation &arc, - const AllTransitionsWrapper &trans, - Node *top_subtree, - UpdateSeq now); - - INLINE void record_node(Node *node, CullState *cs, - UpdateSeq now); - - void clean_out_old_nodes(); - - virtual Node *get_top_subtree() const; - - virtual void compose_trans(const AllTransitionsWrapper &from, - AllTransitionsWrapper &to) const; - - virtual void write(ostream &out, int indent_level = 0) const; - -private: - typedef pmap CullStates; - CullStates _cull_states; - - typedef pmap Subtrees; - Subtrees _subtrees; -}; - -#include "cullStateLookup.I" - -#endif diff --git a/panda/src/cull/cullStateSubtree.I b/panda/src/cull/cullStateSubtree.I deleted file mode 100644 index 32007c45c5..0000000000 --- a/panda/src/cull/cullStateSubtree.I +++ /dev/null @@ -1,57 +0,0 @@ -// Filename: cullStateSubtree.I -// Created by: drose (13Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: CullStateSubtree::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CullStateSubtree:: -CullStateSubtree(CullStateLookup *parent, - const AllTransitionsWrapper &trans, - Node *top_subtree, - UpdateSeq now) : - _parent(parent), - _trans(trans), - _top_subtree(top_subtree), - _verified(now) -{ - _parent->compose_trans(_trans, _trans_from_root); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullStateSubtree::update -// Access: Public -// Description: Indicates a possibly new set of transitions for the -// top node of this subtree. Updates all internal state -// to reflect the new set, or does nothing if the set is -// unchanged. -//////////////////////////////////////////////////////////////////// -INLINE void CullStateSubtree:: -update(const AllTransitionsWrapper &trans, Node *top_subtree, UpdateSeq now) { - // We shouldn't *need* to call clear(). This will unnecessarily - // blow out the cache for all of our children. We do it for now - // just to cut down on things that can go wrong, but this should - // come out of here before long. - // clear(); - - _trans = trans; - _parent->compose_trans(_trans, _trans_from_root); - _top_subtree = top_subtree; - _verified = now; -} diff --git a/panda/src/cull/cullStateSubtree.cxx b/panda/src/cull/cullStateSubtree.cxx deleted file mode 100644 index 7dee76f630..0000000000 --- a/panda/src/cull/cullStateSubtree.cxx +++ /dev/null @@ -1,90 +0,0 @@ -// Filename: cullStateSubtree.cxx -// Created by: drose (09Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "cullStateSubtree.h" -#include "config_cull.h" - - -//////////////////////////////////////////////////////////////////// -// Function: CullStateSubtree::Constructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -CullStateSubtree:: -~CullStateSubtree() { -} - -//////////////////////////////////////////////////////////////////// -// Function: CullStateSubtree::check_currency -// Access: Public -// Description: Returns true if the CullStateSubtree is fresh enough to -// still apply to the indicated cached transition, false -// if it should be recomputed. -//////////////////////////////////////////////////////////////////// -bool CullStateSubtree:: -check_currency(const AllTransitionsWrapper &, Node *top_subtree, - UpdateSeq as_of) { - if (cull_cat.is_spam()) { - cull_cat.spam() - << "Checking currency for subtree " << (void *)this - << ", _verified = " << _verified << " as_of = " << as_of << "\n"; - } - - // Make sure we've still got the same top_subtree node. - if (_top_subtree != top_subtree) { - return false; - } - - // First, check the verified time stamp. - if (as_of <= _verified && !_verified.is_fresh()) { - return true; - } - - // Now we should verify the set of transitions individually. Skip - // that for now. - - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullStateLookup::get_top_subtree -// Access: Public, Virtual -// Description: Returns the node that represents the top of the -// subtree for this particular CullStateSubtree. -//////////////////////////////////////////////////////////////////// -Node *CullStateSubtree:: -get_top_subtree() const { - return _top_subtree; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullStateSubtree::compose_trans -// Access: Public, Virtual -// Description: Composes the transitions given in "from" with the net -// transitions that appear above the top node of this -// subtree, and returns the result in "to". This is a -// pass-thru for CullStateLookup; it has effect only for -// CullStateSubtree. -//////////////////////////////////////////////////////////////////// -void CullStateSubtree:: -compose_trans(const AllTransitionsWrapper &from, - AllTransitionsWrapper &to) const { - to = _trans_from_root; - to.compose_in_place(from); -} diff --git a/panda/src/cull/cullStateSubtree.h b/panda/src/cull/cullStateSubtree.h deleted file mode 100644 index 2405974c62..0000000000 --- a/panda/src/cull/cullStateSubtree.h +++ /dev/null @@ -1,68 +0,0 @@ -// Filename: cullStateSubtree.h -// Created by: drose (07Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CULLSTATESUBTREE_H -#define CULLSTATESUBTREE_H - -#include - -#include "cullStateLookup.h" - -#include -#include -#include - -class CullStateLookup; - -//////////////////////////////////////////////////////////////////// -// Class : CullStateSubtree -// Description : A specialization of CullStateLookup for tracking the -// state at and below an instanced node in the scene -// graph. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA CullStateSubtree : public CullStateLookup { -public: - INLINE CullStateSubtree(CullStateLookup *parent, - const AllTransitionsWrapper &trans, - Node *top_subtree, - UpdateSeq now); - virtual ~CullStateSubtree(); - - bool check_currency(const AllTransitionsWrapper &trans, - Node *top_subtree, - UpdateSeq as_of); - INLINE void update(const AllTransitionsWrapper &trans, - Node *top_subtree, - UpdateSeq now); - - virtual Node *get_top_subtree() const; - - virtual void compose_trans(const AllTransitionsWrapper &from, - AllTransitionsWrapper &to) const; - -private: - CullStateLookup *_parent; - AllTransitionsWrapper _trans; - AllTransitionsWrapper _trans_from_root; - Node *_top_subtree; - UpdateSeq _verified; -}; - -#include "cullStateSubtree.I" - -#endif diff --git a/panda/src/cull/cullTraverser.I b/panda/src/cull/cullTraverser.I deleted file mode 100644 index fbe92ef5d1..0000000000 --- a/panda/src/cull/cullTraverser.I +++ /dev/null @@ -1,151 +0,0 @@ -// Filename: cullTraverser.I -// Created by: drose (13Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "cullStateSubtree.h" -#include "config_cull.h" - -#include -#include - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::draw_geom -// Access: Public -// Description: Sets up the GSG to draw the indicated GeomNode in the -// indicated state. If the state so demands it and the -// GeomNode has children, draws the rest of the -// hierarchy below it immediately. -//////////////////////////////////////////////////////////////////// -INLINE void CullTraverser:: -draw_geom(GeomNode *geom_node, const AllTransitionsWrapper &initial_state) { - if (cull_cat.is_spam()) { - cull_cat.spam() - << "Drawing " << *geom_node << " with state: " << initial_state << "\n"; - } - nassertv(geom_node != (GeomNode *)NULL); - _gsg->set_state(initial_state); - _gsg->prepare_display_region(); - geom_node->draw(_gsg); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::draw_geom -// Access: Public -// Description: Sets up the GSG to draw the indicated GeomNode in the -// indicated state. If the state so demands it and the -// GeomNode has children, draws the rest of the -// hierarchy below it immediately. -//////////////////////////////////////////////////////////////////// -INLINE void CullTraverser:: -draw_geom(const ArcChain &arc_chain, const AllTransitionsWrapper &initial_state) { - nassertv(!arc_chain.empty()); - GeomNode *geom_node; - DCAST_INTO_V(geom_node, arc_chain.back()->get_child()); - draw_geom(geom_node, initial_state); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::draw_direct -// Access: Public -// Description: Draws the indicated subtree beginning at the -// indicated node, and including all nested nodes below. -//////////////////////////////////////////////////////////////////// -INLINE void CullTraverser:: -draw_direct(const ArcChain &arc_chain, - const AllTransitionsWrapper &initial_state) { - nassertv(!arc_chain.empty()); - Node *node = arc_chain.back()->get_child(); - if (cull_cat.is_spam()) { - cull_cat.spam() - << "Drawing " << *node << " in direct mode.\n"; - } - nassertv(node != (Node *)NULL); - DirectRenderTraverser drt(_gsg, _graph_type, arc_chain); - drt.traverse(node, initial_state); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::add_instance -// Access: Private -// Description: This function should be called for each arc that -// leads to a multiply-instanced node in the graph; that -// is, each arc that points to a node with multiple -// parents. It will return a suitable CullStateLookup -// pointer that should be passed to subsequent -// add_geom_node() and add_instance() calls for nodes -// that descend from this arc. -//////////////////////////////////////////////////////////////////// -INLINE CullStateLookup *CullTraverser:: -add_instance(NodeRelation *arc, const AllTransitionsWrapper &trans, - Node *top_subtree, const CullLevelState &level_state) { - return level_state._lookup->get_subtree - (arc, trans, top_subtree, level_state._as_of); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::find_bin_state -// Access: Private -// Description: Looks for a CullState in the set that corresponds to -// the indicated set of transitions; if one is found, -// returns its pointer; otherwise, creates a new one and -// returns it. -//////////////////////////////////////////////////////////////////// -INLINE CullState *CullTraverser:: -find_bin_state(const AllTransitionsWrapper &trans) { - PT(CullState) cs = new CullState(trans); - - // The insert operation will either succeed or fail, depending on - // whether a matching CullState was already in the set. It doesn't - // matter; in either case, the return value represents the - // corresponding CullState that is (now) stored in the set. - pair result = _states.insert(cs); - -#ifdef NOTIFY_DEBUG - if (cull_cat.is_spam()) { - if (result.second) { - // The insert succeeded, so the CullState was not there - // previously. - cull_cat.spam() - << "Created CullState " << (void *)cs << " for:\n"; - trans.write(cull_cat.spam(false), 2); - } else { - CullState *found_cs = *result.first; - cull_cat.spam() - << "Found existing CullState " << (void *)found_cs - << " which has:\n"; - found_cs->get_transitions().write(cull_cat.spam(false), 2); - cull_cat.spam(false) - << "for:\n"; - trans.write(cull_cat.spam(false), 2); - } - } -#endif - - return *result.first; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::backward_arc -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void CullTraverser:: -backward_arc(NodeRelation *arc, NullTransitionWrapper &, - NullTransitionWrapper &, NullTransitionWrapper &, - const CullLevelState &) { - mark_backward_arc(arc); -} diff --git a/panda/src/cull/cullTraverser.cxx b/panda/src/cull/cullTraverser.cxx deleted file mode 100644 index a2351c8d9d..0000000000 --- a/panda/src/cull/cullTraverser.cxx +++ /dev/null @@ -1,876 +0,0 @@ -// Filename: cullTraverser.cxx -// Created by: drose (07Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "cullTraverser.h" -#include "geomBinTransition.h" -#include "cullStateSubtree.h" -#include "geomBinNormal.h" -#include "geomBinFixed.h" -#include "directRenderTransition.h" -#include "config_cull.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include // for implicit_app_traversal -#include // for support_decals -#include - - -TypeHandle CullTraverser::_type_handle; - -#ifndef CPPPARSER -PStatCollector CullTraverser::_cull_pcollector("Cull"); -PStatCollector CullTraverser::_draw_pcollector("Draw:Cull"); -PStatCollector CullTraverser::_cull_traverse_pcollector("Cull:Traverse"); -PStatCollector CullTraverser::_cull_geom_node_pcollector("Cull:Geom node"); -PStatCollector CullTraverser::_cull_direct_node_pcollector("Cull:Direct node"); -PStatCollector CullTraverser::_cull_draw_get_bin_pcollector("Cull:Apply initial"); -PStatCollector CullTraverser::_cull_draw_pcollector("Cull:Draw"); -PStatCollector CullTraverser::_cull_clean_pcollector("Cull:Clean"); -PStatCollector CullTraverser::_cull_bins_unsorted_pcollector("Cull:Bins:Unsorted"); -PStatCollector CullTraverser::_cull_bins_fixed_pcollector("Cull:Bins:Fixed"); -PStatCollector CullTraverser::_cull_bins_btf_pcollector("Cull:Bins:BTF"); -#endif - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -CullTraverser:: -CullTraverser(GraphicsStateGuardian *gsg, TypeHandle graph_type, - const ArcChain &arc_chain) : - RenderTraverser(gsg, graph_type, arc_chain) -{ - _nested_count = 0; - - setup_initial_bins(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -CullTraverser:: -~CullTraverser() { - // We should detach each of our associated bins when we destruct. - clear_bins(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::has_bin -// Access: Public -// Description: Returns true if a bin by the given name has been -// attached to the CullTraverser, false otherwise. -//////////////////////////////////////////////////////////////////// -bool CullTraverser:: -has_bin(const string &name) const { - return (_toplevel_bins.count(name) != 0); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::get_bin -// Access: Public -// Description: Returns the GeomBin that was previously attached to -// the CullTraverser that shares the indicated name, or -// NULL if no GeomBin with a matching name was added. -//////////////////////////////////////////////////////////////////// -GeomBin *CullTraverser:: -get_bin(const string &name) const { - ToplevelBins::const_iterator tbi; - tbi = _toplevel_bins.find(name); - if (tbi == _toplevel_bins.end()) { - return NULL; - } - return (*tbi).second; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::clear_bins -// Access: Public -// Description: Disassociates all the GeomBins previously associated -// with this traverser (and deletes them, if they have -// no other references). You must add new GeomBins -// before rendering by calling set_traverser() on the -// appropriate bins. -//////////////////////////////////////////////////////////////////// -void CullTraverser:: -clear_bins() { - // We can't just run a for loop, because this is a self-modifying - // operation. - while (!_toplevel_bins.empty()) { - GeomBin *bin = (*_toplevel_bins.begin()).second; - nassertv(bin != (GeomBin *)NULL); - nassertv(bin->get_traverser() == this); - bin->clear_traverser(); - } - - nassertv(_sub_bins.empty()); - nassertv(_default_bin == (GeomBin *)NULL); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::clear_state -// Access: Public -// Description: Removes all the cached state information stored -// within the CullTraverser, and forces it to rebuild -// this state from scratch the next frame. -// -// This can be used to clear out state that has gone -// bad, as well as to free up memory pointers that -// otherwise may be held for another frame. -//////////////////////////////////////////////////////////////////// -void CullTraverser:: -clear_state() { - _states.clear(); - _lookup.clear(); - - ToplevelBins::const_iterator tbi; - for (tbi = _toplevel_bins.begin(); tbi != _toplevel_bins.end(); ++tbi) { - (*tbi).second->clear_current_states(); - } - SubBins::const_iterator sbi; - for (sbi = _sub_bins.begin(); sbi != _sub_bins.end(); ++sbi) { - (*sbi).second->clear_current_states(); - } - _default_bin->clear_current_states(); - - _initial_state = AllTransitionsWrapper(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void CullTraverser:: -output(ostream &out) const { - int node_count = 0; - int used_states = 0; - - States::const_iterator si; - for (si = _states.begin(); si != _states.end(); ++si) { - const CullState *cs = (*si); - int c = cs->count_current_nodes(); - if (c != 0) { - node_count += c; - used_states++; - } - } - - out << node_count << " nodes with " << used_states << " states; " - << _states.size() - used_states << " unused states."; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void CullTraverser:: -write(ostream &out, int indent_level) const { - /* - States::const_iterator si; - for (si = _states.begin(); si != _states.end(); ++si) { - const CullState *cs = (*si); - cs->write(out, indent_level); - out << "\n"; - } - */ - - ToplevelBins::const_iterator tbi; - for (tbi = _toplevel_bins.begin(); tbi != _toplevel_bins.end(); ++tbi) { - (*tbi).second->write(out, indent_level); - } - _lookup.write(out, indent_level); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::traverse -// Access: Public, Virtual -// Description: This performs a normal, complete cull-and-render -// traversal using this CullTraverser object. State is -// saved within the CullTraverser object so that the -// next frame will be processed much more quickly than -// the first frame. -//////////////////////////////////////////////////////////////////// -void CullTraverser:: -traverse(Node *root, - const AllTransitionsWrapper &initial_state) { - // Statistics - PStatTimer timer(_cull_pcollector); - - if (cull_cat.is_debug()) { - cull_cat.debug() - << "Beginning level " << _nested_count << " cull traversal at " - << *root << "\n"; - } - - bool is_initial = (_nested_count == 0); - if (is_initial) { - if (cull_force_update) { - _as_of = UpdateSeq::fresh(); - } else { - _as_of = UpdateSeq::initial(); - } - } - _now = last_graph_update(_graph_type); - _nested_count++; - - if (is_initial) { - _initial_state = initial_state; - - States::iterator si; - for (si = _states.begin(); si != _states.end(); ++si) { - (*si)->clear_current_nodes(); - } - } - - CullLevelState level_state; - level_state._lookup = &_lookup; - level_state._as_of = _as_of; - - // Determine the relative transform matrix from the camera to our - // starting node. This is important for proper view-frustum - // culling. - LMatrix4f rel_from_camera; - NodeTransitionWrapper ntw(TransformTransition::get_class_type()); - const DisplayRegion *dr = _gsg->get_current_display_region(); - LensNode *camera = dr->get_cull_frustum(); - wrt(camera, root, begin(), end(), ntw, get_graph_type()); - const TransformTransition *tt; - if (get_transition_into(tt, ntw)) { - rel_from_camera = tt->get_matrix(); - } else { - // No relative transform. - rel_from_camera = LMatrix4f::ident_mat(); - } - - fc_traverse(_arc_chain, root, rel_from_camera, *this, - NullTransitionWrapper(), level_state, _gsg, _graph_type); - - if (is_initial) { - draw(); - clean_out_old_states(); - } - - _nested_count--; - - if (cull_cat.is_debug()) { - cull_cat.debug() - << "Ending level " << _nested_count << " cull traversal at " - << *root << "\n"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::setup_initial_bins -// Access: Private -// Description: Creates all the appropriate rendering bins as -// requested from the Configrc file. -//////////////////////////////////////////////////////////////////// -void CullTraverser:: -setup_initial_bins() { - // We always have "default", "background", and "fixed" hardcoded in, - // although these may be overridden by specifing a new bin with the - // same name in the Configrc file. - - GeomBinNormal *default_bin = new GeomBinNormal("default"); - GeomBinFixed *background = new GeomBinFixed("background"); - GeomBinFixed *fixed = new GeomBinFixed("fixed"); - background->set_sort(10); - fixed->set_sort(40); - - default_bin->set_traverser(this); - background->set_traverser(this); - fixed->set_traverser(this); - - - // Now get the config options. - Config::ConfigTable::Symbol cull_bins; - config_cull.GetAll("cull-bin", cull_bins); - - Config::ConfigTable::Symbol::iterator bi; - for (bi = cull_bins.begin(); bi != cull_bins.end(); ++bi) { - ConfigString def = (*bi).Val(); - - // This is a string in three tokens, separated by whitespace: - // bin_name sort type - - vector_string words; - extract_words(def, words); - - if (words.size() != 3) { - cull_cat.error() - << "Invalid cull-bin definition: " << def << "\n" - << "Definition should be three words: bin_name sort type\n"; - } else { - int sort; - if (!string_to_int(words[1], sort)) { - cull_cat.error() - << "Invalid cull-bin definition: " << def << "\n" - << "Sort token " << words[1] << " is not an integer.\n"; - - } else { - TypeHandle type = GeomBin::parse_bin_type(words[2]); - if (type == TypeHandle::none()) { - cull_cat.error() - << "Invalid cull-bin definition: " << def << "\n" - << "Bin type " << words[2] << " is not known.\n"; - } else { - PT(GeomBin) bin = GeomBin::make_bin(type, words[0]); - nassertv(bin != (GeomBin *)NULL); - bin->set_sort(sort); - bin->set_traverser(this); - } - } - } - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::draw -// Access: Private -// Description: Puts all of the renderable geometry into the -// appropriate bins, and renders the bins. -//////////////////////////////////////////////////////////////////// -void CullTraverser:: -draw() { - PStatTimer timer(_cull_draw_pcollector); - - if (cull_cat.is_debug()) { - // Count up the nonempty states for debug output. - int num_states = 0; - States::iterator si; - for (si = _states.begin(); si != _states.end(); ++si) { - CullState *cs = (*si); - if (!cs->is_empty()) { - num_states++; - } - } - - cull_cat.debug() - << "Initiating draw with " << num_states - << " nonempty states of " << _states.size() << " total.\n"; - } - - SubBins::const_iterator sbi; - { - PStatTimer timer(_cull_clean_pcollector); - for (sbi = _sub_bins.begin(); sbi != _sub_bins.end(); ++sbi) { - (*sbi).second->clear_current_states(); - } - } - - States::iterator si; - for (si = _states.begin(); si != _states.end(); ++si) { - CullState *cs = (*si); - if (!cs->is_empty()) { - { - PStatTimer timer(_cull_draw_get_bin_pcollector); - cs->apply_to(_initial_state); - } - - static string default_bin_name = "default"; - string bin_name = default_bin_name; - GeomBin *requested_bin = _default_bin; - int draw_order = 0; - - // Check the requested bin for the Geoms in this state. - const GeomBinTransition *bin_attrib; - if (get_transition_into(bin_attrib, cs->get_attributes())) { - draw_order = bin_attrib->get_draw_order(); - bin_name = bin_attrib->get_bin(); - requested_bin = get_bin(bin_name); - } - - if (requested_bin == (GeomBin *)NULL) { - // If we don't have a bin by this name, create one. - cull_cat.warning() - << "Bin " << bin_name << " is unknown; creating a default bin.\n"; - - requested_bin = new GeomBinNormal(bin_name); - requested_bin->set_traverser(this); - } - requested_bin->record_current_state(_gsg, cs, draw_order, this); - } - } - - if (_gsg != (GraphicsStateGuardian *)NULL) { - if (cull_cat.is_debug()) { - cull_cat.debug() - << "Drawing " << _sub_bins.size() << " bins.\n"; - } - for (sbi = _sub_bins.begin(); sbi != _sub_bins.end(); ++sbi) { - GeomBin *bin = (*sbi).second; - if (bin->is_active()) { - bin->draw(this); - } - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::clean_out_old_states -// Access: Private -// Description: Walks through the list of CullStates after a frame -// has been completely rendered and drawn, and removes -// any from the list that don't seem to be in use any -// more. -//////////////////////////////////////////////////////////////////// -void CullTraverser:: -clean_out_old_states() { - PStatTimer timer(_cull_clean_pcollector); - - _lookup.clean_out_old_nodes(); - - States::iterator si, snext; - si = _states.begin(); - snext = si; - while (si != _states.end()) { - ++snext; - - CullState *cs = (*si); - if (cs->get_ref_count() == 1 && cs->is_empty() && !cs->has_bin()) { - // This CullState doesn't seem to be used anywhere else. - _states.erase(si); - } - si = snext; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::add_geom_node -// Access: Private -// Description: Records the indicated GeomNode as one that is visible -// this frame with the indicated state, setting up an -// appropriate CullState node and adding it to the -// appropriate bin. -//////////////////////////////////////////////////////////////////// -void CullTraverser:: -add_geom_node(GeomNode *node, const AllTransitionsWrapper &trans, - const CullLevelState &level_state) { - // Using the PStatTimer here to start and stop the collector - // implicitly gives VC++ a headache and an internal compiler error, - // but explicitly starting and stopping it is ok. - //PStatTimer timer(_cull_geom_node_pcollector); - _cull_geom_node_pcollector.start(); - - nassertv(node != (GeomNode *)NULL); - const ArcChain &arc_chain = get_arc_chain(); - nassertv(!arc_chain.empty()); - nassertv(arc_chain.back()->get_child() == node); - - AllTransitionsWrapper complete_trans; - level_state._lookup->compose_trans(trans, complete_trans); - - // Actually, there should be no need to remove this transition - // explicitly, as we should never encounter it--we'll never traverse - // below a DirectRenderTransition in the CullTraverser. We try to - // remove it here just to be paranoid. - complete_trans.clear_transition(DirectRenderTransition::get_class_type()); - - CullState *cs = level_state._lookup->find_node - (node, complete_trans, level_state._as_of); - if (cs == (CullState *)NULL) { - if (cull_cat.is_spam()) { - cull_cat.spam() - << "Finding a new bin state\n"; - } - - // The node didn't have a previously-associated CullState that we - // could use, so determine a new one for it. - cs = find_bin_state(complete_trans); - nassertv(cs != (CullState *)NULL); - - level_state._lookup->record_node(node, cs, level_state._as_of); - } - - cs->record_current_geom_node(arc_chain); - _cull_geom_node_pcollector.stop(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::add_direct_node -// Access: Private -// Description: Records the indicated Node as one that is immediately -// under a DirectRenderTransition, and thus it and its -// subtree should be rendered directly, in a depth-first -// traversal. This is usually done when the render order -// is very important within a small subtree of nodes. -//////////////////////////////////////////////////////////////////// -void CullTraverser:: -add_direct_node(Node *node, const AllTransitionsWrapper &trans, - const CullLevelState &level_state) { - // This causes an internal compiler error with VC++. Instead of - // using the timer, we'll work around this by explicitly starting - // and stopping the collector. - // PStatTimer timer(_cull_direct_node_pcollector); - _cull_direct_node_pcollector.start(); - - nassertv(node != (Node *)NULL); - const ArcChain &arc_chain = get_arc_chain(); - nassertv(!arc_chain.empty()); - nassertv(arc_chain.back()->get_child() == node); - - AllTransitionsWrapper complete_trans; - level_state._lookup->compose_trans(trans, complete_trans); - - // Remove this, just so we won't clutter up the state unnecessarily - // and interfere with state-sorting. - complete_trans.clear_transition(DirectRenderTransition::get_class_type()); - - CullState *cs = level_state._lookup->find_node - (node, complete_trans, level_state._as_of); - if (cs == (CullState *)NULL) { - // The node didn't have a previously-associated CullState that we - // could use, so determine a new one for it. - cs = find_bin_state(complete_trans); - nassertv(cs != (CullState *)NULL); - - level_state._lookup->record_node(node, cs, level_state._as_of); - } - - cs->record_current_direct_node(arc_chain); - _cull_direct_node_pcollector.stop(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::forward_arc -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -bool CullTraverser:: -forward_arc(NodeRelation *arc, NullTransitionWrapper &, - NullTransitionWrapper &, NullTransitionWrapper &, - CullLevelState &level_state) { - nassertr(level_state._lookup != (CullStateLookup *)NULL, false); - - if (arc->has_transition(PruneTransition::get_class_type())) { - return false; - } - - PStatTimer timer(_cull_traverse_pcollector); - - Node *node = arc->get_child(); - - if (implicit_app_traversal) { - node->app_traverse(_arc_chain); - } - node->draw_traverse(_arc_chain); - - // We have to get a new _now timestamp, just in case either of the - // above traversals changed it. - _now = last_graph_update(_graph_type); - - AllTransitionsWrapper trans; - - UpdateSeq last_update = arc->get_last_update(); - if (level_state._as_of < last_update) { - level_state._as_of = last_update; - } - - bool is_instanced = (node->get_num_parents(_graph_type) > 1); - bool is_geom = node->is_of_type(GeomNode::get_class_type()); - bool node_has_sub_render = node->has_sub_render(); - int arc_num_sub_render = arc->get_num_sub_render_trans(); - bool has_decal = arc->has_transition(DecalTransition::get_class_type()); - - _gsg->_nodes_pcollector.add_level(1); - if (is_geom) { - _gsg->_geom_nodes_pcollector.add_level(1); - } - - if (has_decal) { - // For the purposes of cull, we don't consider a DecalTransition - // to be a sub_render transition. - arc_num_sub_render--; - } - - bool has_direct_render = - arc->has_transition(DirectRenderTransition::get_class_type()); - -#ifndef NDEBUG - if (support_decals != SD_on) { - has_direct_render = has_direct_render && !has_decal; - } else -#endif - { - has_direct_render = has_direct_render || has_decal; - } - -#ifndef NDEBUG - if (support_subrender == SD_off) { - node_has_sub_render = false; - arc_num_sub_render = 0; - - } else if (support_subrender == SD_hide) { - if ((node_has_sub_render || arc_num_sub_render != 0) && - !arc->has_transition(DecalTransition::get_class_type())) { - return false; - } - node_has_sub_render = false; - arc_num_sub_render = 0; - } -#endif - -#ifndef NDEBUG - if (support_direct == SD_off) { - has_direct_render = false; - - } else if (support_direct == SD_hide) { - if (has_direct_render) { - return false; - } - } -#endif - - if (arc_num_sub_render != 0) { - level_state._as_of = UpdateSeq::fresh(); - } - _as_of = level_state._as_of; - - mark_forward_arc(arc); - - if (cull_cat.is_spam()) { - cull_cat.spam() - << "Reached " << *node << ":\n" - << " as_of = " << level_state._as_of - << " now = " << _now - << " is_instanced = " << is_instanced - << " is_geom = " << is_geom - << " node_has_sub_render = " << node_has_sub_render - << " arc_num_sub_render = " << arc_num_sub_render - << " has_direct_render = " << has_direct_render - << "\n"; - } - - if (is_instanced || is_geom || node_has_sub_render || - arc_num_sub_render != 0 || has_direct_render) { - // In any of these cases, we'll need to determine the net - // transition to this node. - wrt_subtree(arc, level_state._lookup->get_top_subtree(), - level_state._as_of, _now, - trans, _graph_type); - } - - if (arc_num_sub_render != 0 || node_has_sub_render) { - if (_gsg != (GraphicsStateGuardian *)NULL) { - AllTransitionsWrapper complete_trans; - level_state._lookup->compose_trans(trans, complete_trans); - AllTransitionsWrapper attrib; - attrib.compose_from(_initial_state, complete_trans); - - AllTransitionsWrapper modify_trans; - if (!arc->sub_render_trans(attrib, modify_trans, this) || - !node->sub_render(attrib, modify_trans, this)) { - mark_backward_arc(arc); - return false; - } - trans.compose_in_place(modify_trans); - } - } - - if (has_direct_render) { - add_direct_node(node, trans, level_state); - // Since we're adding the node to be rendered directly, we won't - // traverse any further beyond it--the rest of the subgraph - // beginning at this node will be traversed when the node is - // rendered. - mark_backward_arc(arc); - return false; - } - - if (is_instanced || arc_num_sub_render != 0) { - // This node is multiply instanced; thus, it begins a subtree. - level_state._lookup = add_instance(arc, trans, node, level_state); - if (cull_cat.is_spam()) { - cull_cat.spam() - << "Added " << *node << " as instance.\n"; - } - - // It might also be an instanced GeomNode. - if (is_geom) { - if (cull_cat.is_spam()) { - cull_cat.spam() - << "Added " << *node << "\n"; - } - add_geom_node(DCAST(GeomNode, node), AllTransitionsWrapper(), level_state); - } - - } else if (is_geom) { - if (cull_cat.is_spam()) { - cull_cat.spam() - << "Added " << *node << "\n"; - } - add_geom_node(DCAST(GeomNode, node), trans, level_state); - } - -#ifndef NDEBUG - if (support_decals == SD_hide && - arc->has_transition(DecalTransition::get_class_type())) { - mark_backward_arc(arc); - return false; - } -#endif - - if (node->is_of_type(SwitchNode::get_class_type())) { - SwitchNode *swnode = DCAST(SwitchNode, node); - swnode->compute_switch(this); - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::attach_toplevel_bin -// Access: Private -// Description: This is intended to be called only by -// GeomBin::attach(). It stores the bin in the -// appropriate structures within the traverser, as a -// toplevel bin, e.g. a bin that may be referenced by -// name from outside the traverser, or one that geometry -// may be explicitly assigned to by name. -//////////////////////////////////////////////////////////////////// -void CullTraverser:: -attach_toplevel_bin(GeomBin *bin) { - if (cull_cat.is_debug()) { - cull_cat.debug() - << "Attaching toplevel bin " << *bin << "\n"; - } - - const string &bin_name = bin->get_name(); - - // Insert the new bin by name. - pair result = - _toplevel_bins.insert(ToplevelBins::value_type(bin_name, bin)); - - if (!result.second) { - // There was already a bin by the same name name in this - // traverser. We should therefore detach this bin. - GeomBin *other_bin = (*result.first).second; - if (other_bin != bin) { - other_bin->clear_traverser(); - } - - result = - _toplevel_bins.insert(ToplevelBins::value_type(bin_name, bin)); - nassertv(result.second); - } - - if (bin_name == "default") { - _default_bin = bin; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::attach_sub_bin -// Access: Private -// Description: This is intended to be called only by -// GeomBin::attach(). It stores the bin in the -// appropriate structures within the traverser, as a -// sub bin, e.g. a bin that may have geometry assigned -// to it, and may therefore be rendered. -// -// In most cases, a toplevel bin is the same as a sub -// bin, except in the case of a GeomBinGroup, which is a -// toplevel bin that contains a number of sub bins. -//////////////////////////////////////////////////////////////////// -void CullTraverser:: -attach_sub_bin(GeomBin *bin) { - if (cull_cat.is_debug()) { - cull_cat.debug() - << "Attaching sub bin " << *bin << "\n"; - } - - _sub_bins.insert(SubBins::value_type(bin->get_sort(), bin)); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::detach_toplevel_bin -// Access: Private -// Description: This is intended to be called only by -// GeomBin::detach(). It removes the bin from the -// appropriate structures within the traverser, as a -// toplevel bin. See attach_toplevel_bin(). -//////////////////////////////////////////////////////////////////// -void CullTraverser:: -detach_toplevel_bin(GeomBin *bin) { - if (cull_cat.is_debug()) { - cull_cat.debug() - << "Detaching toplevel bin " << *bin << "\n"; - } - - const string &bin_name = bin->get_name(); - - ToplevelBins::iterator tbi = _toplevel_bins.find(bin_name); - nassertv(tbi != _toplevel_bins.end()); - _toplevel_bins.erase(tbi); - - if (bin_name == "default") { - _default_bin = (GeomBin *)NULL; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CullTraverser::detach_sub_bin -// Access: Private -// Description: This is intended to be called only by -// GeomBin::detach(). It removes the bin from the -// appropriate structures within the traverser, as a -// sub bin. See attach_sub_bin(). -//////////////////////////////////////////////////////////////////// -void CullTraverser:: -detach_sub_bin(GeomBin *bin) { - if (cull_cat.is_debug()) { - cull_cat.debug() - << "Detaching sub bin " << *bin << "\n"; - } - - // Remove the bin from its place in the sort order list. This will - // be one of the (possibly several) entries in the multimap with the - // same sort value. - pair range; - range = _sub_bins.equal_range(bin->get_sort()); - - SubBins::iterator sbi; - for (sbi = range.first; sbi != range.second; ++sbi) { - GeomBin *consider_bin = (*sbi).second; - nassertv(consider_bin->get_sort() == bin->get_sort()); - - if (consider_bin == bin) { - // Here's the position! - _sub_bins.erase(sbi); - return; - } - } - nassertv(false); -} diff --git a/panda/src/cull/cullTraverser.h b/panda/src/cull/cullTraverser.h deleted file mode 100644 index fd503fd0c2..0000000000 --- a/panda/src/cull/cullTraverser.h +++ /dev/null @@ -1,172 +0,0 @@ -// Filename: cullTraverser.h -// Created by: drose (07Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CULLTRAVERSER_H -#define CULLTRAVERSER_H - -#include - -#include "cullLevelState.h" -#include "geomBin.h" - -#include -#include -#include -#include -#include - -#include "plist.h" -#include "pset.h" - -class GraphicsStateGuardian; -class CullStateLookup; -class CullState; -class AllTransitionsWrapper; - -//////////////////////////////////////////////////////////////////// -// Class : CullTraverser -// Description : A special kind of RenderTraverser that makes a -// complete "cull" pass over the scene graph, grouping -// the geometry by state and adding it to individual -// GeomBins, and then renders the GeomBins in sequence. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA CullTraverser : - public RenderTraverser, - public TraverserVisitor { -public: - CullTraverser(GraphicsStateGuardian *gsg, TypeHandle graph_type, - const ArcChain &arc_chain = ArcChain()); - virtual ~CullTraverser(); - -PUBLISHED: - bool has_bin(const string &name) const; - GeomBin *get_bin(const string &name) const; - void clear_bins(); - - void clear_state(); - - void output(ostream &out) const; - void write(ostream &out, int indent_level = 0) const; - -public: - - virtual void traverse(Node *root, - const AllTransitionsWrapper &initial_state); - - INLINE void draw_geom(GeomNode *geom_node, - const AllTransitionsWrapper &initial_state); - INLINE void draw_geom(const ArcChain &arc_chain, - const AllTransitionsWrapper &initial_state); - INLINE void draw_direct(const ArcChain &arc_chain, - const AllTransitionsWrapper &initial_state); - -private: - void setup_initial_bins(); - - void draw(); - void clean_out_old_states(); - - void add_geom_node(GeomNode *node, - const AllTransitionsWrapper &trans, - const CullLevelState &level_state); - void add_direct_node(Node *node, - const AllTransitionsWrapper &trans, - const CullLevelState &level_state); - - INLINE CullStateLookup *add_instance(NodeRelation *arc, - const AllTransitionsWrapper &trans, - Node *top_subtree, - const CullLevelState &level_state); - - INLINE CullState *find_bin_state(const AllTransitionsWrapper &trans); - - -public: - // These methods, from parent class TraverserVisitor, define the - // behavior of the RenderTraverser as it traverses the graph. - // Normally you would never call these directly. - bool forward_arc(NodeRelation *arc, NullTransitionWrapper &trans, - NullTransitionWrapper &pre, NullTransitionWrapper &post, - CullLevelState &level_state); - - INLINE void - backward_arc(NodeRelation *arc, NullTransitionWrapper &trans, - NullTransitionWrapper &pre, NullTransitionWrapper &post, - const CullLevelState &level_state); - -private: - void attach_toplevel_bin(GeomBin *bin); - void attach_sub_bin(GeomBin *bin); - void detach_toplevel_bin(GeomBin *bin); - void detach_sub_bin(GeomBin *bin); - - AllTransitionsWrapper _initial_state; - - typedef pmap ToplevelBins; - typedef pmultimap SubBins; - ToplevelBins _toplevel_bins; - SubBins _sub_bins; - PT(GeomBin) _default_bin; - - typedef pset > States; - States _states; - - CullStateLookup _lookup; - int _nested_count; - UpdateSeq _as_of; - UpdateSeq _now; - -public: - // Statistics - static PStatCollector _cull_pcollector; - static PStatCollector _draw_pcollector; - static PStatCollector _cull_traverse_pcollector; - static PStatCollector _cull_geom_node_pcollector; - static PStatCollector _cull_direct_node_pcollector; - static PStatCollector _cull_draw_get_bin_pcollector; - static PStatCollector _cull_draw_pcollector; - static PStatCollector _cull_clean_pcollector; - static PStatCollector _cull_bins_unsorted_pcollector; - static PStatCollector _cull_bins_fixed_pcollector; - static PStatCollector _cull_bins_btf_pcollector; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - RenderTraverser::init_type(); - register_type(_type_handle, "CullTraverser", - RenderTraverser::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; - - friend class GeomBin; - friend class GeomBinGroup; -}; - -#include "cullTraverser.I" - -#endif - diff --git a/panda/src/cull/cull_composite1.cxx b/panda/src/cull/cull_composite1.cxx deleted file mode 100644 index 6ea64f04af..0000000000 --- a/panda/src/cull/cull_composite1.cxx +++ /dev/null @@ -1,8 +0,0 @@ - -#include "config_cull.cxx" -#include "cullState.cxx" -#include "cullStateLookup.cxx" -#include "cullStateSubtree.cxx" -#include "cullTraverser.cxx" -#include "directRenderTransition.cxx" - diff --git a/panda/src/cull/cull_composite2.cxx b/panda/src/cull/cull_composite2.cxx deleted file mode 100644 index 510620bd53..0000000000 --- a/panda/src/cull/cull_composite2.cxx +++ /dev/null @@ -1,9 +0,0 @@ - -#include "geomBin.cxx" -#include "geomBinBackToFront.cxx" -#include "geomBinFixed.cxx" -#include "geomBinGroup.cxx" -#include "geomBinNormal.cxx" -#include "geomBinTransition.cxx" -#include "geomBinUnsorted.cxx" - diff --git a/panda/src/cull/directRenderTransition.I b/panda/src/cull/directRenderTransition.I deleted file mode 100644 index 566a0014a9..0000000000 --- a/panda/src/cull/directRenderTransition.I +++ /dev/null @@ -1,26 +0,0 @@ -// Filename: directRenderTransition.I -// Created by: drose (17Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: DirectRenderTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE DirectRenderTransition:: -DirectRenderTransition() { -} diff --git a/panda/src/cull/directRenderTransition.cxx b/panda/src/cull/directRenderTransition.cxx deleted file mode 100644 index 41f9076007..0000000000 --- a/panda/src/cull/directRenderTransition.cxx +++ /dev/null @@ -1,48 +0,0 @@ -// Filename: directRenderTransition.cxx -// Created by: drose (17Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "directRenderTransition.h" - -#include - -TypeHandle DirectRenderTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: DirectRenderTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated DirectRenderTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *DirectRenderTransition:: -make_copy() const { - return new DirectRenderTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: DirectRenderTransition::has_sub_render -// Access: Public, Virtual -// Description: DirectRenderTransition doesn't actually have a -// sub_render() function, but it might as well, because -// it's treated as a special case. We set this function -// to return true so GraphReducer will behave correctly. -//////////////////////////////////////////////////////////////////// -bool DirectRenderTransition:: -has_sub_render() const { - return true; -} diff --git a/panda/src/cull/directRenderTransition.h b/panda/src/cull/directRenderTransition.h deleted file mode 100644 index bef7e8c78a..0000000000 --- a/panda/src/cull/directRenderTransition.h +++ /dev/null @@ -1,74 +0,0 @@ -// Filename: directRenderTransition.h -// Created by: drose (17Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DIRECTRENDERTRANSITION_H -#define DIRECTRENDERTRANSITION_H - -#include - -#include - -//////////////////////////////////////////////////////////////////// -// Class : DirectRenderTransition -// Description : When this transition is attached to an arc, it -// indicates that the node below this arc, and all -// subsequent nodes below, should be treated as a single -// binnable unit. All the nodes at this point and below -// will be placed into the same bin, according to the -// state as of the top node, and when rendered, they -// will be rendered using a depth-first traversal rooted -// at this top node. -// -// This can be a way to establish a local draw-order -// within a few related nodes. It does not, however, -// affect view-frustum culling. -// -// This is the only way to achieve certain special -// effects that depend on scene-graph relationships, for -// instance decalling, while using the CullTraverser. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA DirectRenderTransition : public ImmediateTransition { -PUBLISHED: - INLINE DirectRenderTransition(); - -public: - virtual NodeTransition *make_copy() const; - - virtual bool has_sub_render() const; - -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() { - ImmediateTransition::init_type(); - register_type(_type_handle, "DirectRenderTransition", - ImmediateTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "directRenderTransition.I" - -#endif diff --git a/panda/src/cull/geomBin.I b/panda/src/cull/geomBin.I deleted file mode 100644 index ae808e373e..0000000000 --- a/panda/src/cull/geomBin.I +++ /dev/null @@ -1,151 +0,0 @@ -// Filename: geomBin.I -// Created by: drose (13Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE GeomBin:: -GeomBin(const string &name) : - Namable(name) -{ - _traverser = (CullTraverser *)NULL; - _is_attached = false; - _sort = 0; - _active = true; - _parent = (GeomBin *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::get_sort -// Access: Public -// Description: Returns the sort index associated with this -// particular bin. The CullTraverser will render bins -// in order according to their sort index. -//////////////////////////////////////////////////////////////////// -INLINE int GeomBin:: -get_sort() const { - return _sort; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::get_active -// Access: Public -// Description: Returns the active flag of this particular bin. If -// the flag is false, the contents of the bin are not -// rendered. -//////////////////////////////////////////////////////////////////// -INLINE bool GeomBin:: -is_active() const { - return _active; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::has_traverser -// Access: Public -// Description: Returns true if the GeomBin is currently attached to -// a traverser, false otherwise. If this is false, and -// the bin is not attached to a parent bin -// (i.e. has_parent() is also false), don't expect the -// bin to be rendered. -//////////////////////////////////////////////////////////////////// -INLINE bool GeomBin:: -has_traverser() const { - return (_traverser != (CullTraverser *)NULL); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::get_traverser -// Access: Public -// Description: Returns a pointer to the CullTraverser this bin is -// currently attached to, or NULL if it is not attached. -//////////////////////////////////////////////////////////////////// -INLINE CullTraverser *GeomBin:: -get_traverser() const { - return _traverser; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::has_parent -// Access: Public -// Description: Returns true if the bin is a child of some -// GeomBinGroup, false if it is a toplevel bin in its -// own right. See GeomBinGroup. -//////////////////////////////////////////////////////////////////// -INLINE bool GeomBin:: -has_parent() const { - return _parent != (GeomBin *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::get_parent -// Access: Public -// Description: Returns the parent pointer of the GeomBin if the bin -// is a child of some GeomBinGropu, or NULL if the bin -// does not have a parent. See GeomBinGroup. -//////////////////////////////////////////////////////////////////// -INLINE GeomBin *GeomBin:: -get_parent() const { - return _parent; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::is_attached -// Access: Public -// Description: Returns true if the bin is currently attached to a -// CullTraverser, false otherwise. This should always -// be tree if has_traverser() is true, and false if -// has_traverser() is false. -//////////////////////////////////////////////////////////////////// -INLINE bool GeomBin:: -is_attached() const { - return _is_attached; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::claim_cull_state -// Access: Protected -// Description: Marks the indicated CullState as being assigned to -// this bin, presumably in preparation to storing its -// pointer within the bin. -//////////////////////////////////////////////////////////////////// -INLINE void GeomBin:: -claim_cull_state(CullState *cs) { - nassertv(cs != (CullState *)NULL); - - if (cs->_bin != (GeomBin *)NULL && cs->_bin != this) { - cs->_bin->remove_state(cs); - } - - cs->_bin = this; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::claim_cull_state -// Access: Protected -// Description: Marks the indicated CullState as being assigned to -// no particular bin, presumably in preparation to -// removing it from the bin. -//////////////////////////////////////////////////////////////////// -INLINE void GeomBin:: -disclaim_cull_state(CullState *cs) { - nassertv(cs != (CullState *)NULL); - nassertv(cs->_bin == this); - cs->_bin = (GeomBin *)NULL; -} diff --git a/panda/src/cull/geomBin.cxx b/panda/src/cull/geomBin.cxx deleted file mode 100644 index c2e9f80f2e..0000000000 --- a/panda/src/cull/geomBin.cxx +++ /dev/null @@ -1,345 +0,0 @@ -// Filename: geomBin.cxx -// Created by: drose (07Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "geomBin.h" -#include "cullTraverser.h" -#include "config_cull.h" -#include "geomBinNormal.h" -#include "geomBinUnsorted.h" -#include "geomBinFixed.h" -#include "geomBinBackToFront.h" - -#include -#include -#include - -TypeHandle GeomBin::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -GeomBin:: -~GeomBin() { - // We shouldn't be attached to anything when we destruct. If we - // are, something went screwy in the reference counting. - nassertv(!_is_attached); - nassertv(_traverser == (CullTraverser *)NULL); - - // We also shouldn't be part of any parent bin. - nassertv(_parent == (GeomBin *)NULL); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::set_name -// Access: Public -// Description: Changes the name of the GeomBin, correctly updating -// the CullTraverser it's attached to. -//////////////////////////////////////////////////////////////////// -void GeomBin:: -set_name(const string &name) { - if (name == get_name()) { - return; - } - - // If we're currently attached, we need to need to be unattached - // while we change the name--but only if we're a toplevel bin. A - // nested bin doesn't matter. - if (is_attached() && !has_parent()) { - PT(GeomBin) keep = this; - - nassertv(_traverser != (CullTraverser *)NULL); - _traverser->detach_toplevel_bin(this); - Namable::set_name(name); - _traverser->attach_toplevel_bin(this); - - } else { - Namable::set_name(name); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::clear_name -// Access: Public -// Description: Removes the name of the GeomBin. This also detaches -// it (if it is a toplevel bin), and may therefore -// inadvertently delete it! Be very careful. -//////////////////////////////////////////////////////////////////// -void GeomBin:: -clear_name() { - PT(GeomBin) keep; - - if (is_attached() && !has_parent()) { - cull_cat.warning() - << "GeomBin::clear_name() called on an attached GeomBin.\n"; - keep = detach(); - } - - Namable::clear_name(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::set_sort -// Access: Public -// Description: Changes the sort index associated with this -// particular bin. The CullTraverser will render bins -// in order according to their sort index. -//////////////////////////////////////////////////////////////////// -void GeomBin:: -set_sort(int sort) { - if (sort == _sort) { - return; - } - - // If we're currently attached, even if we're a nested bin, we need - // to be unattached while we adjust the sorting order. - if (is_attached()) { - PT(GeomBin) keep = this; - - nassertv(_traverser != (CullTraverser *)NULL); - _traverser->detach_sub_bin(this); - _sort = sort; - _traverser->attach_sub_bin(this); - - } else { - _sort = sort; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::set_active -// Access: Public, Virtual -// Description: Sets the active flag of this particular bin. If the -// flag is false, the contents of the bin are not -// rendered. -//////////////////////////////////////////////////////////////////// -void GeomBin:: -set_active(bool active) { - _active = active; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::set_traverser -// Access: Public -// Description: Associates the GeomBin with the indicated -// CullTraverser. A particular bin may only be -// associated with one traverser at a time. This is -// normally done only after initially creating the -// GeomBin; it is an error to call set_traverser() more -// than once on the same bin (without calling -// clear_traverser() first). -// -// It is also not necessary (and is an error) to assign -// child bins of a GeomBinGroup to a traverser; just -// assign the parent bin. -// -// This must be called before the GeomBin can be -// rendered; it will thereafter be rendered by the -// indicated traverser. -//////////////////////////////////////////////////////////////////// -void GeomBin:: -set_traverser(CullTraverser *traverser) { - if (traverser == (CullTraverser *)NULL) { - clear_traverser(); - } - - nassertv(!is_attached()); - nassertv(_traverser == (CullTraverser *)NULL); - - _traverser = traverser; - attach(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::clear_traverser -// Access: Public -// Description: Disassociates the GeomBin with its current traverser. -// The bin will no longer be rendered, and may even be -// deleted if you do not immediately save the returned -// pointer. -//////////////////////////////////////////////////////////////////// -PT(GeomBin) GeomBin:: -clear_traverser() { - PT(GeomBin) keep = this; - - if (is_attached()) { - detach(); - _traverser = (CullTraverser *)NULL; - } - - return keep; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::parse_bin_type -// Access: Public, Static -// Description: Converts from the given string representation to one -// of the derived GeomBin type handles. Returns -// TypeHandle::none() if the string does not match any -// known bin type. -//////////////////////////////////////////////////////////////////// -TypeHandle GeomBin:: -parse_bin_type(const string &bin_type) { - if (cmp_nocase_uh(bin_type, "normal") == 0) { - return GeomBinNormal::get_class_type(); - - } else if (cmp_nocase_uh(bin_type, "unsorted") == 0) { - return GeomBinUnsorted::get_class_type(); - - } else if (cmp_nocase_uh(bin_type, "state_sorted") == 0) { - // For now, GeomBinUnsorted stands in surprisingly well for - // GeomBinStateSorted. This is because the states are already - // reasonably sorted as they come out of the CullTraverser, so it - // doesn't matter much whether the bin sorts it further. - return GeomBinUnsorted::get_class_type(); - - } else if (cmp_nocase_uh(bin_type, "statesorted") == 0) { - return GeomBinUnsorted::get_class_type(); - - } else if (cmp_nocase_uh(bin_type, "fixed") == 0) { - return GeomBinFixed::get_class_type(); - - } else if (cmp_nocase_uh(bin_type, "back_to_front") == 0) { - return GeomBinBackToFront::get_class_type(); - - } else if (cmp_nocase_uh(bin_type, "backtofront") == 0) { - return GeomBinBackToFront::get_class_type(); - - } else { - return TypeHandle::none(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::make_bin -// Access: Public, Static -// Description: Creates and returns a new GeomBin of the appropriate -// type as indicated by the TypeHandle. Returns NULL if -// the TypeHandle does not reflect a known GeomBin type. -//////////////////////////////////////////////////////////////////// -PT(GeomBin) GeomBin:: -make_bin(TypeHandle type, const string &name) { - if (type == GeomBinNormal::get_class_type()) { - return new GeomBinNormal(name); - - } else if (type == GeomBinUnsorted::get_class_type()) { - return new GeomBinUnsorted(name); - - } else if (type == GeomBinFixed::get_class_type()) { - return new GeomBinFixed(name); - - } else if (type == GeomBinBackToFront::get_class_type()) { - return new GeomBinBackToFront(name); - - } else { - return NULL; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::attach -// Access: Protected, Virtual -// Description: Formally adds the GeomBin to its indicated Traverser. -//////////////////////////////////////////////////////////////////// -void GeomBin:: -attach() { - nassertv(has_name()); - nassertv(_traverser != (CullTraverser *)NULL); - nassertv(!_is_attached); - - // In the ordinary case, a bin is both a toplevel bin (visible by - // name from the CullTraverser) and a sub bin (directly renderable). - if (!has_parent()) { - _traverser->attach_toplevel_bin(this); - } - _traverser->attach_sub_bin(this); - - _is_attached = true; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::detach -// Access: Protected, Virtual -// Description: Detaches the bin from whichever CullTraverser it is -// currently attached to. The bin will no longer be -// rendered. The return value is a PT(GeomBin) that -// refers to the GeomBin itself; the caller should save -// this pointer in a local PT variable to avoid possibly -// destructing the GeomBin (since detaching it may -// remove the last outstanding reference count). -//////////////////////////////////////////////////////////////////// -PT(GeomBin) GeomBin:: -detach() { - nassertr(_is_attached, NULL); - nassertr(_traverser != (CullTraverser *)NULL, NULL); - - PT(GeomBin) keep = this; - - if (!has_parent()) { - _traverser->detach_toplevel_bin(this); - } - _traverser->detach_sub_bin(this); - - _is_attached = false; - - return keep; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GeomBin:: -output(ostream &out) const { - out << get_type() << " " << get_name(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GeomBin:: -write(ostream &out, int indent_level) const { - indent(out, indent_level) << *this << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBin::remove_state -// Access: Public, Virtual -// Description: Disassociates the indicated state from the bin, if it -// was previously associated; presumably because a -// change in the scene's initial attributes as resulted -// in the indicated CullState switching to a new bin. -// -// Since the initial attributes will remain constant -// throughout a given frame, this function will only be -// called for GeomBins that save CullStates between -// frames; simple GeomBins that empty the entire list of -// CullStates upon a call to clear_current_states() -// should never see this function. -//////////////////////////////////////////////////////////////////// -void GeomBin:: -remove_state(CullState *) { - cull_cat.error() - << "remove_state() unexpectedly called for " << get_type() << "\n"; - nassertv(false); -} diff --git a/panda/src/cull/geomBin.h b/panda/src/cull/geomBin.h deleted file mode 100644 index 795cdd2dbf..0000000000 --- a/panda/src/cull/geomBin.h +++ /dev/null @@ -1,131 +0,0 @@ -// Filename: geomBin.h -// Created by: drose (07Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef GEOMBIN_H -#define GEOMBIN_H - -#include - -#include "cullState.h" -#include "cullStateLookup.h" - -#include -#include -#include -#include -#include -#include - -#include "pset.h" - -class GeomNode; -class CullTraverser; - -//////////////////////////////////////////////////////////////////// -// Class : GeomBin -// Description : This is an abstract class that defines the interface -// for a number of different kinds of bins that may be -// assigned to a CullTraverser. The traverser will -// assign GeomNodes to the bins according to the various -// GeomBinTransitions encountered in the scene graph; -// the individual GeomBins are then responsible for -// sorting and rendering the geometry. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA GeomBin : public TypedReferenceCount, public Namable { -public: - INLINE GeomBin(const string &name); - virtual ~GeomBin(); - -PUBLISHED: - void set_name(const string &name); - void clear_name(); - - INLINE int get_sort() const; - void set_sort(int sort); - - virtual void set_active(bool active); - INLINE bool is_active() const; - - void set_traverser(CullTraverser *traverser); - INLINE bool has_traverser() const; - INLINE CullTraverser *get_traverser() const; - PT(GeomBin) clear_traverser(); - - INLINE bool has_parent() const; - INLINE GeomBin *get_parent() const; - - virtual void output(ostream &out) const; - virtual void write(ostream &out, int indent_level = 0) const; - -public: - INLINE bool is_attached() const; - - virtual void clear_current_states()=0; - virtual void record_current_state(GraphicsStateGuardian *gsg, - CullState *cs, int draw_order, - CullTraverser *trav)=0; - virtual void remove_state(CullState *cs); - - virtual void draw(CullTraverser *trav)=0; - - static TypeHandle parse_bin_type(const string &bin_type); - static PT(GeomBin) make_bin(TypeHandle type, const string &name); - -protected: - INLINE void claim_cull_state(CullState *cs); - INLINE void disclaim_cull_state(CullState *cs); - - virtual void attach(); - virtual PT(GeomBin) detach(); - - CullTraverser *_traverser; - bool _is_attached; - int _sort; - bool _active; - GeomBin *_parent; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - TypedReferenceCount::init_type(); - Namable::init_type(); - register_type(_type_handle, "GeomBin", - TypedReferenceCount::get_class_type(), - Namable::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; - - friend class GeomBinGroup; -}; - -INLINE ostream &operator << (ostream &out, const GeomBin &bin) { - bin.output(out); - return out; -} - -#include "geomBin.I" - -#endif diff --git a/panda/src/cull/geomBinBackToFront.I b/panda/src/cull/geomBinBackToFront.I deleted file mode 100644 index addf1bf222..0000000000 --- a/panda/src/cull/geomBinBackToFront.I +++ /dev/null @@ -1,96 +0,0 @@ -// Filename: geomBinBackToFront.I -// Created by: drose (13Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "cullTraverser.h" - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinBackToFront::NodeEntry::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE GeomBinBackToFront::NodeEntry:: -NodeEntry(float distance, const PT(CullState) &state, - const ArcChain &arc_chain, bool is_direct) : - _distance(distance), - _state(state), - _arc_chain(arc_chain), - _is_direct(is_direct) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinBackToFront::NodeEntry::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE GeomBinBackToFront::NodeEntry:: -NodeEntry(const GeomBinBackToFront::NodeEntry ©) : - _distance(copy._distance), - _state(copy._state), - _arc_chain(copy._arc_chain), - _is_direct(copy._is_direct) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinBackToFront::NodeEntry::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void GeomBinBackToFront::NodeEntry:: -operator = (const NodeEntry ©) { - _distance = copy._distance; - _state = copy._state; - _arc_chain = copy._arc_chain; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinBackToFront::NodeEntry::Ordering Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool GeomBinBackToFront::NodeEntry:: -operator < (const NodeEntry &other) const { - return _distance > other._distance; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinBackToFront::NodeEntry::draw -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void GeomBinBackToFront::NodeEntry:: -draw(CullTraverser *trav) const { - nassertv(!_arc_chain.empty()); - if (_is_direct) { - trav->draw_direct(_arc_chain, _state->get_attributes()); - } else { - trav->draw_geom(_arc_chain, _state->get_attributes()); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinBackToFront::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE GeomBinBackToFront:: -GeomBinBackToFront(const string &name) : - GeomBin(name) -{ -} diff --git a/panda/src/cull/geomBinBackToFront.cxx b/panda/src/cull/geomBinBackToFront.cxx deleted file mode 100644 index 3931bd623f..0000000000 --- a/panda/src/cull/geomBinBackToFront.cxx +++ /dev/null @@ -1,167 +0,0 @@ -// Filename: geomBinBackToFront.cxx -// Created by: drose (13Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "geomBinBackToFront.h" -#include "cullTraverser.h" - -#include -#include -#include -#include -#include - -TypeHandle GeomBinBackToFront::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinBackToFront::clear_current_states -// Access: Public, Virtual -// Description: Called each frame by the CullTraverser to reset the -// list of CullStates that were added last frame, in -// preparation for defining a new set of CullStates -// visible this frame. -//////////////////////////////////////////////////////////////////// -void GeomBinBackToFront:: -clear_current_states() { - _node_entries.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinBackToFront::record_current_state -// Access: Public, Virtual -// Description: Called each frame by the CullTraverser to indicate -// that the given CullState (and all of its current -// GeomNodes) is visible this frame. -//////////////////////////////////////////////////////////////////// -void GeomBinBackToFront:: -record_current_state(GraphicsStateGuardian *gsg, CullState *cs, int, - CullTraverser *trav) { - // PStatTimer timer(CullTraverser::_cull_bins_btf_pcollector); - // Using the PStatTimer may cause a compiler fault. - CullTraverser::_cull_bins_btf_pcollector.start(); - - // Get the transform matrix from the state. - TransformTransition *trans_attrib = NULL; - get_transition_into(trans_attrib, cs->get_attributes()); - - CullState::geom_const_iterator gi; - for (gi = cs->geom_begin(); gi != cs->geom_end(); ++gi) { - const ArcChain &arc_chain = (*gi); - nassertv(!arc_chain.empty()); - GeomNode *node; - DCAST_INTO_V(node, arc_chain.back()->get_child()); - nassertv(node != (GeomNode *)NULL); - const BoundingVolume &volume = node->get_bound(); - - if (!volume.is_empty() && - volume.is_of_type(GeometricBoundingVolume::get_class_type())) { - const GeometricBoundingVolume *gbv; - DCAST_INTO_V(gbv, &volume); - - LPoint3f center = gbv->get_approx_center(); - if (trans_attrib != (TransformTransition *)NULL) { - center = center * trans_attrib->get_matrix(); - } - - float distance = gsg->compute_distance_to(center); - - _node_entries.insert(NodeEntry(distance, cs, arc_chain, false)); - } - } - - CullState::direct_const_iterator di; - for (di = cs->direct_begin(); di != cs->direct_end(); ++di) { - const ArcChain &arc_chain = (*di); - nassertv(!arc_chain.empty()); - Node *node = arc_chain.back()->get_child(); - nassertv(node != (Node *)NULL); - - const BoundingVolume &volume = node->get_bound(); - float distance = 0.0; - bool got_distance = false; - - if (!volume.is_empty() && - volume.is_of_type(GeometricBoundingVolume::get_class_type())) { - const GeometricBoundingVolume *gbv; - DCAST_INTO_V(gbv, &volume); - - LPoint3f center = gbv->get_approx_center(); - if (trans_attrib != (TransformTransition *)NULL) { - center = center * trans_attrib->get_matrix(); - } - - distance = gsg->compute_distance_to(center); - got_distance = true; - } - - if (!got_distance) { - // Choose the average center of all of our children. - LPoint3f avg(0.0, 0.0, 0.0); - int num_points = 0; - - TypeHandle graph_type = trav->get_graph_type(); - int num_children = node->get_num_children(graph_type); - for (int i = 0; i < num_children; i++) { - NodeRelation *arc = node->get_child(graph_type, i); - - const BoundingVolume &volume = arc->get_bound(); - if (!volume.is_empty() && - volume.is_of_type(GeometricBoundingVolume::get_class_type())) { - const GeometricBoundingVolume *gbv; - DCAST_INTO_V(gbv, &volume); - - LPoint3f center = gbv->get_approx_center(); - avg += center; - num_points++; - } - } - - if (num_points > 0) { - avg /= (float)num_points; - if (trans_attrib != (TransformTransition *)NULL) { - avg = avg * trans_attrib->get_matrix(); - } - distance = gsg->compute_distance_to(avg); - got_distance = true; - } - } - - _node_entries.insert(NodeEntry(distance, cs, arc_chain, true)); - } - - CullTraverser::_cull_bins_btf_pcollector.stop(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinBackToFront::draw -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GeomBinBackToFront:: -draw(CullTraverser *trav) { - PStatTimer timer(CullTraverser::_draw_pcollector); - - if (cull_cat.is_spam()) { - cull_cat.spam() - << "GeomBinBackToFront drawing " << _node_entries.size() << " entries.\n"; - } - NodeEntries::iterator nei; - for (nei = _node_entries.begin(); nei != _node_entries.end(); ++nei) { - (*nei).draw(trav); - } -} diff --git a/panda/src/cull/geomBinBackToFront.h b/panda/src/cull/geomBinBackToFront.h deleted file mode 100644 index 4aec343626..0000000000 --- a/panda/src/cull/geomBinBackToFront.h +++ /dev/null @@ -1,93 +0,0 @@ -// Filename: geomBinBackToFront.h -// Created by: drose (13Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef GEOMBINBACKTOFRONT_H -#define GEOMBINBACKTOFRONT_H - -#include - -#include "geomBin.h" - -#include - -#include "pset.h" - -//////////////////////////////////////////////////////////////////// -// Class : GeomBinBackToFront -// Description : This kind of GeomBin renders its GeomNodes in order -// according to distance from the camera plane, -// beginning with the farthest away. It's particularly -// appropriate for rendering transparent geometry, but -// it may also be useful for rendering simple scenes -// without a Z-buffer. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA GeomBinBackToFront : public GeomBin { -PUBLISHED: - INLINE GeomBinBackToFront(const string &name); - -public: - virtual void clear_current_states(); - virtual void record_current_state(GraphicsStateGuardian *gsg, - CullState *cs, int draw_order, - CullTraverser *trav); - - virtual void draw(CullTraverser *trav); - -private: - class NodeEntry { - public: - INLINE NodeEntry(float distance, const PT(CullState) &state, - const ArcChain &arc_chain, bool is_direct); - INLINE NodeEntry(const NodeEntry ©); - INLINE void operator = (const NodeEntry ©); - - INLINE bool operator < (const NodeEntry &other) const; - - INLINE void draw(CullTraverser *trav) const; - - private: - float _distance; - PT(CullState) _state; - ArcChain _arc_chain; - bool _is_direct; - }; - - typedef pmultiset NodeEntries; - NodeEntries _node_entries; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - GeomBin::init_type(); - register_type(_type_handle, "GeomBinBackToFront", - GeomBin::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "geomBinBackToFront.I" - -#endif diff --git a/panda/src/cull/geomBinFixed.I b/panda/src/cull/geomBinFixed.I deleted file mode 100644 index fc69933dbe..0000000000 --- a/panda/src/cull/geomBinFixed.I +++ /dev/null @@ -1,97 +0,0 @@ -// Filename: geomBinFixed.I -// Created by: drose (14Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "cullTraverser.h" - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinFixed::NodeEntry::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE GeomBinFixed::NodeEntry:: -NodeEntry(int draw_order, const PT(CullState) &state, - const ArcChain &arc_chain, bool is_direct) : - _draw_order(draw_order), - _state(state), - _arc_chain(arc_chain), - _is_direct(is_direct) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinFixed::NodeEntry::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE GeomBinFixed::NodeEntry:: -NodeEntry(const GeomBinFixed::NodeEntry ©) : - _draw_order(copy._draw_order), - _state(copy._state), - _arc_chain(copy._arc_chain), - _is_direct(copy._is_direct) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinFixed::NodeEntry::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void GeomBinFixed::NodeEntry:: -operator = (const NodeEntry ©) { - _draw_order = copy._draw_order; - _state = copy._state; - _arc_chain = copy._arc_chain; - _is_direct = copy._is_direct; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinFixed::NodeEntry::Ordering Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool GeomBinFixed::NodeEntry:: -operator < (const NodeEntry &other) const { - return _draw_order < other._draw_order; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinFixed::NodeEntry::draw -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void GeomBinFixed::NodeEntry:: -draw(CullTraverser *trav) const { - nassertv(!_arc_chain.empty()); - if (_is_direct) { - trav->draw_direct(_arc_chain, _state->get_attributes()); - } else { - trav->draw_geom(_arc_chain, _state->get_attributes()); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinFixed::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE GeomBinFixed:: -GeomBinFixed(const string &name) : - GeomBin(name) -{ -} diff --git a/panda/src/cull/geomBinFixed.cxx b/panda/src/cull/geomBinFixed.cxx deleted file mode 100644 index c270d4aad2..0000000000 --- a/panda/src/cull/geomBinFixed.cxx +++ /dev/null @@ -1,88 +0,0 @@ -// Filename: geomBinFixed.cxx -// Created by: drose (14Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "geomBinFixed.h" -#include "cullTraverser.h" - -#include -#include -#include -#include -#include - -#include - -TypeHandle GeomBinFixed::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinFixed::clear_current_states -// Access: Public, Virtual -// Description: Called each frame by the CullTraverser to reset the -// list of CullStates that were added last frame, in -// preparation for defining a new set of CullStates -// visible this frame. -//////////////////////////////////////////////////////////////////// -void GeomBinFixed:: -clear_current_states() { - _node_entries.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinFixed::record_current_state -// Access: Public, Virtual -// Description: Called each frame by the CullTraverser to indicate -// that the given CullState (and all of its current -// GeomNodes) is visible this frame. -//////////////////////////////////////////////////////////////////// -void GeomBinFixed:: -record_current_state(GraphicsStateGuardian *, CullState *cs, - int draw_order, CullTraverser *) { - PStatTimer timer(CullTraverser::_cull_bins_fixed_pcollector); - - // Get the transform matrix from the state. - TransformTransition *trans_attrib = NULL; - get_transition_into(trans_attrib, cs->get_attributes()); - - CullState::geom_const_iterator gi; - for (gi = cs->geom_begin(); gi != cs->geom_end(); ++gi) { - const ArcChain &arc_chain = (*gi); - _node_entries.insert(NodeEntry(draw_order, cs, arc_chain, false)); - } - - CullState::direct_const_iterator di; - for (di = cs->direct_begin(); di != cs->direct_end(); ++di) { - const ArcChain &arc_chain = (*di); - _node_entries.insert(NodeEntry(draw_order, cs, arc_chain, true)); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinFixed::draw -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GeomBinFixed:: -draw(CullTraverser *trav) { - PStatTimer timer(CullTraverser::_draw_pcollector); - - NodeEntries::iterator nei; - for (nei = _node_entries.begin(); nei != _node_entries.end(); ++nei) { - (*nei).draw(trav); - } -} diff --git a/panda/src/cull/geomBinFixed.h b/panda/src/cull/geomBinFixed.h deleted file mode 100644 index 861a6c9188..0000000000 --- a/panda/src/cull/geomBinFixed.h +++ /dev/null @@ -1,90 +0,0 @@ -// Filename: geomBinFixed.h -// Created by: drose (14Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef GEOMBINFIXED_H -#define GEOMBINFIXED_H - -#include - -#include "geomBin.h" - -#include - -#include "pset.h" - -//////////////////////////////////////////////////////////////////// -// Class : GeomBinFixed -// Description : This kind of GeomBin renders its GeomNodes in a -// user-specified order according to the draw_order -// specified at each GeomBinTransition. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA GeomBinFixed : public GeomBin { -PUBLISHED: - INLINE GeomBinFixed(const string &name); - -public: - virtual void clear_current_states(); - virtual void record_current_state(GraphicsStateGuardian *gsg, - CullState *cs, int draw_order, - CullTraverser *trav); - - virtual void draw(CullTraverser *trav); - -private: - class NodeEntry { - public: - INLINE NodeEntry(int draw_order, const PT(CullState) &state, - const ArcChain &arc_chain, bool is_direct); - INLINE NodeEntry(const NodeEntry ©); - INLINE void operator = (const NodeEntry ©); - - INLINE bool operator < (const NodeEntry &other) const; - - INLINE void draw(CullTraverser *trav) const; - - private: - int _draw_order; - PT(CullState) _state; - ArcChain _arc_chain; - bool _is_direct; - }; - - typedef pmultiset NodeEntries; - NodeEntries _node_entries; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - GeomBin::init_type(); - register_type(_type_handle, "GeomBinFixed", - GeomBin::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "geomBinFixed.I" - -#endif diff --git a/panda/src/cull/geomBinGroup.I b/panda/src/cull/geomBinGroup.I deleted file mode 100644 index 614fd55bf8..0000000000 --- a/panda/src/cull/geomBinGroup.I +++ /dev/null @@ -1,49 +0,0 @@ -// Filename: geomBinGroup.I -// Created by: drose (13Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinGroup::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE GeomBinGroup:: -GeomBinGroup(const string &name) : - GeomBin(name) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinGroup::get_num_bins -// Access: Public -// Description: Returns the number of available sub bins. -//////////////////////////////////////////////////////////////////// -INLINE int GeomBinGroup:: -get_num_bins() const { - return _sub_bins.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinGroup::get_bin -// Access: Public -// Description: Returns the nth sub bin. -//////////////////////////////////////////////////////////////////// -INLINE GeomBin *GeomBinGroup:: -get_bin(int n) { - nassertr(n >= 0 && n < (int)_sub_bins.size(), NULL); - return _sub_bins[n]; -} diff --git a/panda/src/cull/geomBinGroup.cxx b/panda/src/cull/geomBinGroup.cxx deleted file mode 100644 index 079497a758..0000000000 --- a/panda/src/cull/geomBinGroup.cxx +++ /dev/null @@ -1,263 +0,0 @@ -// Filename: geomBinGroup.cxx -// Created by: drose (13Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "geomBinGroup.h" -#include "cullTraverser.h" -#include -#include - -TypeHandle GeomBinGroup::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinGroup::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -GeomBinGroup:: -~GeomBinGroup() { - nassertv(!is_attached()); - - // Disassociate all of our children before we destruct. - SubBins::iterator sbi; - for (sbi = _sub_bins.begin(); sbi != _sub_bins.end(); ++sbi) { - GeomBin *sub_bin = (*sbi); - sub_bin->_parent = (GeomBin *)NULL; - } - _sub_bins.clear(); -} - - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinGroup::add_sub_bin -// Access: Public -// Description: Appends the indicated bin to the end of the sub_bin -// list, and returns the new index. -//////////////////////////////////////////////////////////////////// -int GeomBinGroup:: -add_sub_bin(GeomBin *sub_bin) { - nassertr(!sub_bin->has_parent(), -1); - nassertr(!sub_bin->is_attached(), -1); - nassertr(sub_bin->has_name(), -1); - - sub_bin->_parent = this; - _sub_bins.push_back(sub_bin); - - if (is_attached()) { - sub_bin->_traverser = _traverser; - _traverser->attach_sub_bin(sub_bin); - } - - return _sub_bins.size() - 1; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinGroup::remove_bin -// Access: Public -// Description: Removes the nth bin. All subsequent index numbers -// shift down by one. The return value is the -// just-removed bin, which may be deleted if it is not -// immediately saved. -//////////////////////////////////////////////////////////////////// -PT(GeomBin) GeomBinGroup:: -remove_bin(int n) { - nassertr(n >= 0 && n < (int)_sub_bins.size(), NULL); - PT(GeomBin) sub_bin = get_bin(n); - nassertr(sub_bin->get_parent() == this, NULL); - - if (is_attached()) { - nassertr(sub_bin->is_attached(), NULL); - nassertr(sub_bin->_traverser == _traverser, NULL); - _traverser->detach_sub_bin(sub_bin); - sub_bin->_traverser = (CullTraverser *)NULL; - } - - _sub_bins.erase(_sub_bins.begin() + n); - sub_bin->_parent = (GeomBin *)NULL; - - return sub_bin; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinGroup::set_active -// Access: Public, Virtual -// Description: Sets the active flag of this particular bin, and all -// of its child bins. If the flag is false, the -// contents of the bin are not rendered. -//////////////////////////////////////////////////////////////////// -void GeomBinGroup:: -set_active(bool active) { - GeomBin::set_active(active); - - SubBins::iterator sbi; - for (sbi = _sub_bins.begin(); sbi != _sub_bins.end(); ++sbi) { - (*sbi)->set_active(active); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinGroup::clear_current_states -// Access: Public, Virtual -// Description: Called each frame by the CullTraverser to reset the -// list of CullStates that were added last frame, in -// preparation for defining a new set of CullStates -// visible this frame. -//////////////////////////////////////////////////////////////////// -void GeomBinGroup:: -clear_current_states() { - // This should never be called for toplevel bins, only sub bins--and - // a GeomBinGroup should never be a sub bin. The function will do - // the right thing even if it is called, but this is probably a - // mistake. - cull_cat.warning() - << "GeomBinGroup::clear_current_states() called\n"; - - SubBins::iterator sbi; - for (sbi = _sub_bins.begin(); sbi != _sub_bins.end(); ++sbi) { - (*sbi)->clear_current_states(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinUnsorted::record_current_state -// Access: Public, Virtual -// Description: Called each frame by the CullTraverser to indicate -// that the given CullState (and all of its current -// GeomNodes) is visible this frame. -//////////////////////////////////////////////////////////////////// -void GeomBinGroup:: -record_current_state(GraphicsStateGuardian *gsg, CullState *cs, - int draw_order, CullTraverser *trav) { - int index = choose_bin(cs); - if (index >= 0 && index < get_num_bins()) { - get_bin(index)->record_current_state(gsg, cs, draw_order, trav); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinGroup::draw -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GeomBinGroup:: -draw(CullTraverser *trav) { - // This should never be called for toplevel bins, only sub bins--and - // a GeomBinGroup should never be a sub bin. The function will do - // the right thing even if it is called, but this is probably a - // mistake. - cull_cat.warning() - << "GeomBinGroup::draw() called\n"; - - SubBins::iterator sbi; - for (sbi = _sub_bins.begin(); sbi != _sub_bins.end(); ++sbi) { - (*sbi)->draw(trav); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinGroup::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GeomBinGroup:: -output(ostream &out) const { - out << get_type() << " " << get_name() - << ", " << _sub_bins.size() << " bins."; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinGroup::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GeomBinGroup:: -write(ostream &out, int indent_level) const { - indent(out, indent_level) << get_type() << " " << get_name() << " {\n"; - - SubBins::const_iterator sbi; - for (sbi = _sub_bins.begin(); sbi != _sub_bins.end(); ++sbi) { - (*sbi)->write(out, indent_level + 2); - } - - indent(out, indent_level) << "}\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinGroup::attach -// Access: Protected, Virtual -// Description: Formally adds the GeomBin to its indicated Traverser. -//////////////////////////////////////////////////////////////////// -void GeomBinGroup:: -attach() { - nassertv(has_name()); - nassertv(_traverser != (CullTraverser *)NULL); - nassertv(!_is_attached); - - // In the case of a GeomBinGroup, the bin is only a toplevel bin - // (visible by name from the CullTraverser), and not a sub bin - // (directly renderable). - if (!has_parent()) { - _traverser->attach_toplevel_bin(this); - } - - _is_attached = true; - - // Now attach each of our sub bins. - SubBins::const_iterator sbi; - for (sbi = _sub_bins.begin(); sbi != _sub_bins.end(); ++sbi) { - GeomBin *sub_bin = (*sbi); - nassertv(!sub_bin->is_attached()); - sub_bin->_traverser = _traverser; - sub_bin->attach(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinGroup::detach -// Access: Protected, Virtual -// Description: Detaches the bin from whichever CullTraverser it is -// currently attached to. The bin will no longer be -// rendered. The return value is a PT(GeomBin) that -// refers to the GeomBin itself; the caller should save -// this pointer in a local PT variable to avoid possibly -// destructing the GeomBin (since detaching it may -// remove the last outstanding reference count). -//////////////////////////////////////////////////////////////////// -PT(GeomBin) GeomBinGroup:: -detach() { - nassertr(_is_attached, NULL); - nassertr(_traverser != (CullTraverser *)NULL, NULL); - - PT(GeomBin) keep = this; - - if (!has_parent()) { - _traverser->detach_toplevel_bin(this); - } - - _is_attached = false; - - // Now detach each of our sub bins. - SubBins::const_iterator sbi; - for (sbi = _sub_bins.begin(); sbi != _sub_bins.end(); ++sbi) { - GeomBin *sub_bin = (*sbi); - sub_bin->detach(); - sub_bin->_traverser = (CullTraverser *)NULL; - } - - return keep; -} diff --git a/panda/src/cull/geomBinGroup.h b/panda/src/cull/geomBinGroup.h deleted file mode 100644 index aae9505865..0000000000 --- a/panda/src/cull/geomBinGroup.h +++ /dev/null @@ -1,91 +0,0 @@ -// Filename: geomBinGroup.h -// Created by: drose (13Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef GEOMBINGROUP_H -#define GEOMBINGROUP_H - -#include - -#include "geomBin.h" - -#include - -#include "pvector.h" - -//////////////////////////////////////////////////////////////////// -// Class : GeomBinGroup -// Description : A special kind of abstract GeomBin that assigns its -// CullState objects to any of a number of sub-bins. -// This class is abstract because it does not define the -// function choose_bin(), which should identity the bin -// a given CullState should be assigned to. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA GeomBinGroup : public GeomBin { -PUBLISHED: - INLINE GeomBinGroup(const string &name); - virtual ~GeomBinGroup(); - - int add_sub_bin(GeomBin *sub_bin); - INLINE int get_num_bins() const; - INLINE GeomBin *get_bin(int n); - PT(GeomBin) remove_bin(int n); - - virtual void set_active(bool active); - -public: - virtual int choose_bin(CullState *cs) const=0; - - virtual void clear_current_states(); - virtual void record_current_state(GraphicsStateGuardian *gsg, - CullState *cs, int draw_order, - CullTraverser *trav); - - virtual void draw(CullTraverser *trav); - - virtual void output(ostream &out) const; - virtual void write(ostream &out, int indent_level = 0) const; - -protected: - virtual void attach(); - virtual PT(GeomBin) detach(); - -private: - typedef pvector< PT(GeomBin) > SubBins; - SubBins _sub_bins; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - GeomBin::init_type(); - register_type(_type_handle, "GeomBinGroup", - GeomBin::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "geomBinGroup.I" - -#endif diff --git a/panda/src/cull/geomBinNormal.cxx b/panda/src/cull/geomBinNormal.cxx deleted file mode 100644 index 6383aac682..0000000000 --- a/panda/src/cull/geomBinNormal.cxx +++ /dev/null @@ -1,65 +0,0 @@ -// Filename: geomBinNormal.cxx -// Created by: drose (13Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "geomBinNormal.h" -#include "geomBinUnsorted.h" -#include "geomBinBackToFront.h" - -#include - -#include - -TypeHandle GeomBinNormal::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinNormal::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -GeomBinNormal:: -GeomBinNormal(const string &name) : - GeomBinGroup(name) -{ - GeomBinUnsorted *opaque = new GeomBinUnsorted("opaque"); - GeomBinBackToFront *transparent = new GeomBinBackToFront("transparent"); - opaque->set_sort(20); - transparent->set_sort(30); - - add_sub_bin(opaque); - add_sub_bin(transparent); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinNormal::Constructor -// Access: Public, Virtual -// Description: Identifies the particular sub-bin the indicated -// CullState should be assigned to. -//////////////////////////////////////////////////////////////////// -int GeomBinNormal:: -choose_bin(CullState *cs) const { - bool is_transparent = false; - - TransparencyTransition *trans_attrib; - if (get_transition_into(trans_attrib, cs->get_attributes())) { - is_transparent = - (trans_attrib->get_mode() != TransparencyProperty::M_none); - } - - return is_transparent ? 1 : 0; -} diff --git a/panda/src/cull/geomBinNormal.h b/panda/src/cull/geomBinNormal.h deleted file mode 100644 index d6b91dae4a..0000000000 --- a/panda/src/cull/geomBinNormal.h +++ /dev/null @@ -1,62 +0,0 @@ -// Filename: geomBinNormal.h -// Created by: drose (13Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef GEOMBINNORMAL_H -#define GEOMBINNORMAL_H - -#include - -#include "geomBinGroup.h" - -#include - -#include "pset.h" - -//////////////////////////////////////////////////////////////////// -// Class : GeomBinNormal -// Description : This is the most typical kind of GeomBin: it renders -// nontransparent geometry in state-sorted order, -// followed by transparent geometry sorted -// back-to-front. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA GeomBinNormal : public GeomBinGroup { -PUBLISHED: - GeomBinNormal(const string &name); - -public: - virtual int choose_bin(CullState *cs) const; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - GeomBinGroup::init_type(); - register_type(_type_handle, "GeomBinNormal", - GeomBinGroup::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#endif diff --git a/panda/src/cull/geomBinTransition.I b/panda/src/cull/geomBinTransition.I deleted file mode 100644 index 086dc614fd..0000000000 --- a/panda/src/cull/geomBinTransition.I +++ /dev/null @@ -1,94 +0,0 @@ -// Filename: geomBinTransition.I -// Created by: drose (07Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE GeomBinTransition:: -GeomBinTransition() { -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE GeomBinTransition:: -GeomBinTransition(const string &bin, int draw_order) : - OnOffTransition(TD_on), - _value(bin), - _draw_order(draw_order) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinTransition::off -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE GeomBinTransition GeomBinTransition:: -off() { - GeomBinTransition result; - result.set_off(); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinTransition::set_on -// Access: Public -// Description: Changes the GeomBinTransition to render the particular -// bin. -//////////////////////////////////////////////////////////////////// -INLINE void GeomBinTransition:: -set_on(const string &bin, int draw_order) { - nassertv(!bin.empty()); - _value = bin; - _draw_order = draw_order; - OnOffTransition::set_on(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinTransition::get_bin -// Access: Public -// Description: Returns the bin name that the GeomBinTransition -// represents. It is only valid to call this if is_on() -// has returned true. -//////////////////////////////////////////////////////////////////// -INLINE const string &GeomBinTransition:: -get_bin() const { - nassertr(is_on(), _value); - return _value; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinTransition::get_draw_order -// Access: Public -// Description: Returns the draw order associated with the -// GeomBinTransition. It is only valid to call this if -// is_on() has returned true. This draw order has -// meaning only if the associated bin (see get_bin()) is -// of type GeomBinFixed. -//////////////////////////////////////////////////////////////////// -INLINE int GeomBinTransition:: -get_draw_order() const { - nassertr(is_on(), 0); - return _draw_order; -} - diff --git a/panda/src/cull/geomBinTransition.cxx b/panda/src/cull/geomBinTransition.cxx deleted file mode 100644 index 1a3784d270..0000000000 --- a/panda/src/cull/geomBinTransition.cxx +++ /dev/null @@ -1,151 +0,0 @@ -// Filename: geomBinTransition.cxx -// Created by: drose (07Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "geomBinTransition.h" -#include -#include - -TypeHandle GeomBinTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated GeomBinTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *GeomBinTransition:: -make_copy() const { - return new GeomBinTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated GeomBinTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *GeomBinTransition:: -make_initial() const { - return new GeomBinTransition; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinTransition::set_value_from -// Access: Protected, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another GeomBinTransition. -//////////////////////////////////////////////////////////////////// -void GeomBinTransition:: -set_value_from(const OnOffTransition *other) { - const GeomBinTransition *ot; - DCAST_INTO_V(ot, other); - _value = ot->_value; - _draw_order = ot->_draw_order; - nassertv(!_value.empty()); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinTransition::compare_values -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int GeomBinTransition:: -compare_values(const OnOffTransition *other) const { - const GeomBinTransition *ot; - DCAST_INTO_R(ot, other, false); - if (_value != ot->_value) { - return strcmp(_value.c_str(), ot->_value.c_str()); - } - return _draw_order - ot->_draw_order; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -void GeomBinTransition:: -output_value(ostream &out) const { - out << _value << ":" << _draw_order; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -void GeomBinTransition:: -write_value(ostream &out, int indent_level) const { - indent(out, indent_level) << _value << ":" << _draw_order << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinTransition::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a GeomBinTransition object -//////////////////////////////////////////////////////////////////// -void GeomBinTransition:: -register_with_read_factory() { - BamReader::get_factory()->register_factory(get_class_type(), make_GeomBinTransition); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinTransition::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void GeomBinTransition:: -write_datagram(BamWriter *manager, Datagram &me) { - OnOffTransition::write_datagram(manager, me); - me.add_string(_value); - me.add_int32(_draw_order); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinTransition::make_GeomBinTransition -// Access: Public -// Description: Factory method to generate a GeomBinTransition object -//////////////////////////////////////////////////////////////////// -TypedWritable *GeomBinTransition:: -make_GeomBinTransition(const FactoryParams ¶ms) { - GeomBinTransition *me = new GeomBinTransition; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinTransition::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void GeomBinTransition:: -fillin(DatagramIterator &scan, BamReader *manager) { - OnOffTransition::fillin(scan, manager); - _value = scan.get_string(); - _draw_order = scan.get_int32(); -} diff --git a/panda/src/cull/geomBinTransition.h b/panda/src/cull/geomBinTransition.h deleted file mode 100644 index c51c21ffef..0000000000 --- a/panda/src/cull/geomBinTransition.h +++ /dev/null @@ -1,83 +0,0 @@ -// Filename: geomBinTransition.h -// Created by: drose (07Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef GEOMBINTRANSITION_H -#define GEOMBINTRANSITION_H - -#include - -#include -#include "geomBin.h" - -//////////////////////////////////////////////////////////////////// -// Class : GeomBinTransition -// Description : -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA GeomBinTransition : public OnOffTransition { -PUBLISHED: - INLINE GeomBinTransition(); - INLINE GeomBinTransition(const string &bin, int draw_order); - INLINE static GeomBinTransition off(); - - INLINE void set_on(const string &bin, int draw_order); - INLINE const string &get_bin() const; - INLINE int get_draw_order() const; - -public: - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - -protected: - virtual void set_value_from(const OnOffTransition *other); - virtual int compare_values(const OnOffTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - - string _value; - int _draw_order; - -public: - static void register_with_read_factory(); - virtual void write_datagram(BamWriter* manager, Datagram &me); - - static TypedWritable *make_GeomBinTransition(const FactoryParams ¶ms); - -protected: - 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() { - OnOffTransition::init_type(); - register_type(_type_handle, "GeomBinTransition", - OnOffTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "geomBinTransition.I" - -#endif diff --git a/panda/src/cull/geomBinUnsorted.I b/panda/src/cull/geomBinUnsorted.I deleted file mode 100644 index 1f2e8abaed..0000000000 --- a/panda/src/cull/geomBinUnsorted.I +++ /dev/null @@ -1,28 +0,0 @@ -// Filename: geomBinUnsorted.I -// Created by: drose (13Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinUnsorted::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE GeomBinUnsorted:: -GeomBinUnsorted(const string &name) : - GeomBin(name) -{ -} diff --git a/panda/src/cull/geomBinUnsorted.cxx b/panda/src/cull/geomBinUnsorted.cxx deleted file mode 100644 index 2829966d49..0000000000 --- a/panda/src/cull/geomBinUnsorted.cxx +++ /dev/null @@ -1,159 +0,0 @@ -// Filename: geomBinUnsorted.cxx -// Created by: drose (13Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "geomBinUnsorted.h" -#include "cullTraverser.h" -#include -#include -#include - -TypeHandle GeomBinUnsorted::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinUnsorted::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -GeomBinUnsorted:: -~GeomBinUnsorted() { - clear_current_states(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinUnsorted::clear_current_states -// Access: Public, Virtual -// Description: Called each frame by the CullTraverser to reset the -// list of CullStates that were added last frame, in -// preparation for defining a new set of CullStates -// visible this frame. -//////////////////////////////////////////////////////////////////// -void GeomBinUnsorted:: -clear_current_states() { - CullStates::iterator csi; - for (csi = _cull_states.begin(); csi != _cull_states.end(); ++csi) { - disclaim_cull_state(*csi); - } - - _cull_states.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinUnsorted::record_current_state -// Access: Public, Virtual -// Description: Called each frame by the CullTraverser to indicate -// that the given CullState (and all of its current -// GeomNodes) is visible this frame. -//////////////////////////////////////////////////////////////////// -void GeomBinUnsorted:: -record_current_state(GraphicsStateGuardian *, CullState *cs, int, - CullTraverser *) { - PStatTimer timer(CullTraverser::_cull_bins_unsorted_pcollector); - - // This shouldn't be called twice for a particular CullState on this - // bin, since we don't preserve any CullStates between frames. - nassertv(cs->get_bin() != this); - - claim_cull_state(cs); - _cull_states.push_back(cs); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinUnsorted::draw -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GeomBinUnsorted:: -draw(CullTraverser *trav) { - // PStatTimer timer(CullTraverser::_draw_pcollector); - // Using the PStatTimer may cause a compiler fault. - CullTraverser::_draw_pcollector.start(); - - GraphicsStateGuardian *gsg = trav->get_gsg(); - - if (cull_cat.is_spam()) { - cull_cat.spam() - << "GeomBinUnsorted drawing " << _cull_states.size() << " states.\n"; - } - - CullStates::const_iterator csi; - for (csi = _cull_states.begin(); csi != _cull_states.end(); ++csi) { - const CullState *cs = (*csi); - if (cull_cat.is_spam()) { - cull_cat.spam() - << "GeomBinUnsorted state with " << cs->geom_size() << " geoms and " - << cs->direct_size() << " direct nodes.\n" - << "setting state " << cs->get_attributes() << "\n"; - } - - if (cs->geom_size() != 0) { - gsg->set_state(cs->get_attributes()); - gsg->prepare_display_region(); - - CullState::geom_iterator gi; - for (gi = cs->geom_begin(); gi != cs->geom_end(); ++gi) { - const ArcChain &arc_chain = (*gi); - nassertv(!arc_chain.empty()); - GeomNode *geom_node; - DCAST_INTO_V(geom_node, arc_chain.back()->get_child()); - if (cull_cat.is_spam()) { - cull_cat.spam() - << "Drawing " << *geom_node << "\n"; - } - geom_node->draw(gsg); - } - } - - CullState::direct_iterator di; - for (di = cs->direct_begin(); di != cs->direct_end(); ++di) { - const ArcChain &arc_chain = (*di); - nassertv(!arc_chain.empty()); - - trav->draw_direct(arc_chain, cs->get_attributes()); - } - } - CullTraverser::_draw_pcollector.stop(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinUnsorted::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GeomBinUnsorted:: -output(ostream &out) const { - out << get_type() << " " << get_name() - << ", " << _cull_states.size() << " states."; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomBinUnsorted::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GeomBinUnsorted:: -write(ostream &out, int indent_level) const { - indent(out, indent_level) << get_type() << " " << get_name() << " {\n"; - - CullStates::const_iterator csi; - for (csi = _cull_states.begin(); csi != _cull_states.end(); ++csi) { - const CullState *cs = (*csi); - cs->write(out, indent_level + 2); - } - - indent(out, indent_level) << "}\n"; -} diff --git a/panda/src/cull/geomBinUnsorted.h b/panda/src/cull/geomBinUnsorted.h deleted file mode 100644 index dd1e68db85..0000000000 --- a/panda/src/cull/geomBinUnsorted.h +++ /dev/null @@ -1,78 +0,0 @@ -// Filename: geomBinUnsorted.h -// Created by: drose (13Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef GEOMBINUNSORTED_H -#define GEOMBINUNSORTED_H - -#include - -#include "geomBin.h" - -#include - -#include "pvector.h" - -//////////////////////////////////////////////////////////////////// -// Class : GeomBinUnsorted -// Description : This kind of GeomBin will group the GeomNodes -// together by state (since that's how they come from -// the CullTraverser, anyway), but won't attempt to -// render the various different states in any particular -// order. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA GeomBinUnsorted : public GeomBin { -PUBLISHED: - INLINE GeomBinUnsorted(const string &name); - virtual ~GeomBinUnsorted(); - -public: - virtual void clear_current_states(); - virtual void record_current_state(GraphicsStateGuardian *gsg, - CullState *cs, int draw_order, - CullTraverser *trav); - - virtual void draw(CullTraverser *trav); - - virtual void output(ostream &out) const; - virtual void write(ostream &out, int indent_level = 0) const; - -private: - typedef pvector< PT(CullState) > CullStates; - CullStates _cull_states; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - GeomBin::init_type(); - register_type(_type_handle, "GeomBinUnsorted", - GeomBin::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "geomBinUnsorted.I" - -#endif diff --git a/panda/src/cull/test_cull.cxx b/panda/src/cull/test_cull.cxx deleted file mode 100644 index 75d0e02c82..0000000000 --- a/panda/src/cull/test_cull.cxx +++ /dev/null @@ -1,153 +0,0 @@ -// Filename: test_cull.cxx -// Created by: drose (07Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "cullTraverser.h" -#include "directRenderTransition.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -class PrintNodes : public TraverserVisitor { -public: - PrintNodes() { - _indent_level = 0; - } - bool reached_node(Node *node, TransitionWrapper &state, NullLevelState &) { - indent(nout, _indent_level) - << *node << ", state is:\n"; - state.write(nout, _indent_level); - return true; - } - bool forward_arc(NodeRelation *arc, TransitionWrapper &trans, - TransitionWrapper &pre, TransitionWrapper &post, - NullLevelState &) { - _indent_level += 2; - return true; - } - void backward_arc(NodeRelation *arc, TransitionWrapper &trans, - TransitionWrapper &pre, TransitionWrapper &post, - const NullLevelState &) { - _indent_level -= 2; - } - int _indent_level; -}; - - -int -main(int argc, char *argv[]) { - PT_NamedNode r = new NamedNode("r"); - - PT_NamedNode a = new NamedNode("a"); - PT_NamedNode b = new NamedNode("b"); - - PT(GeomNode) aa = new GeomNode("aa"); - PT(GeomNode) aaa = new GeomNode("aaa"); - PT(GeomNode) ab = new GeomNode("ab"); - PT(GeomNode) ba = new GeomNode("ba"); - PT(GeomNode) bb = new GeomNode("bb"); - - PT_NamedNode m = new GeomNode("m"); - PT(GeomNode) ma = new GeomNode("ma"); - PT(GeomNode) mb = new GeomNode("mb"); - - NodeRelation *r_a = - new NodeRelation(r, a, 0, NodeRelation::get_class_type()); - NodeRelation *r_b = - new NodeRelation(r, b, 0, NodeRelation::get_class_type()); - - NodeRelation *a_aa = - new NodeRelation(a, aa, 0, NodeRelation::get_class_type()); - NodeRelation *a_ab = - new NodeRelation(a, ab, 0, NodeRelation::get_class_type()); - NodeRelation *b_ba = - new NodeRelation(b, ba, 0, NodeRelation::get_class_type()); - NodeRelation *b_bb = - new NodeRelation(b, bb, 0, NodeRelation::get_class_type()); - - NodeRelation *aa_aaa = - new NodeRelation(aa, aaa, 0, NodeRelation::get_class_type()); - - NodeRelation *a_m = - new NodeRelation(a, m, 0, NodeRelation::get_class_type()); - - NodeRelation *b_m = - new NodeRelation(b, m, 0, NodeRelation::get_class_type()); - - NodeRelation *m_ma = - new NodeRelation(m, ma, 0, NodeRelation::get_class_type()); - NodeRelation *m_mb = - new NodeRelation(m, mb, 0, NodeRelation::get_class_type()); - - - PT(Texture) alpha = new Texture; - alpha->set_name("alpha"); - PT(Texture) beta = new Texture; - beta->set_name("beta"); - - r_a->set_transition(new ColorTransition(1.0, 1.0, 1.0, 1.0)); - r_a->set_transition(new TextureTransition(alpha)); - a_aa->set_transition(new ColorTransition(0.5, 1.0, 0.5, 0.2)); - a_ab->set_transition(new TextureTransition(beta)); - - a_m->set_transition(new BillboardTransition); - b_m->set_transition(new ColorTransition(0.0, 0.0, 1.0, 1.0)); - m_ma->set_transition(new TextureTransition(alpha)); - - // r_a->set_transition(new DirectRenderTransition); - - nout << "\nr to a has:\n"; - r_a->write_transitions(nout, 2); - nout << "\nr to b has:\n"; - r_b->write_transitions(nout, 2); - nout << "\na to aa has:\n"; - a_aa->write_transitions(nout, 2); - nout << "\na to ab has:\n"; - a_ab->write_transitions(nout, 2); - nout << "\nb to ba has:\n"; - b_ba->write_transitions(nout, 2); - nout << "\n"; - - nout << "\n"; - PrintNodes pn; - df_traverse(r, pn, - AllTransitionsWrapper(), NullLevelState(), - NodeRelation::get_class_type()); - nout << "\n"; - - CullTraverser ct(NULL, NodeRelation::get_class_type()); - - ct.traverse(r, AllTransitionsWrapper(), AllTransitionsWrapper()); - ct.write(nout, 0); - - nout << "\nframe 2:\n"; - ct.traverse(r, AllTransitionsWrapper(), AllTransitionsWrapper()); - ct.write(nout, 0); - - return (0); -} - diff --git a/panda/src/device/Sources.pp b/panda/src/device/Sources.pp index e798347b74..813e62b7d2 100644 --- a/panda/src/device/Sources.pp +++ b/panda/src/device/Sources.pp @@ -4,34 +4,26 @@ #begin lib_target #define TARGET device #define LOCAL_LIBS \ - dgraph display gobj sgraph graph gsgbase ipc mathutil linmath putil + dgraph display gobj gsgbase ipc mathutil linmath putil #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx #define SOURCES \ - analogNode.I analogNode.h \ qpanalogNode.I qpanalogNode.h \ - buttonNode.I buttonNode.h \ qpbuttonNode.I qpbuttonNode.h \ clientAnalogDevice.I clientAnalogDevice.h clientBase.I \ clientBase.h clientButtonDevice.I clientButtonDevice.h \ clientDevice.I clientDevice.h clientDialDevice.I \ clientDialDevice.h clientTrackerDevice.I \ clientTrackerDevice.h config_device.h \ - dialNode.I dialNode.h \ qpdialNode.I qpdialNode.h \ - mouse.h \ mouseAndKeyboard.h \ trackerData.I trackerData.h \ - trackerNode.I trackerNode.h \ qptrackerNode.I qptrackerNode.h \ - virtualMouse.h \ qpvirtualMouse.h #define INCLUDED_SOURCES \ - analogNode.cxx \ qpanalogNode.cxx \ - buttonNode.cxx \ qpbuttonNode.cxx \ clientAnalogDevice.cxx \ clientBase.cxx clientButtonDevice.cxx clientDevice.cxx \ @@ -39,18 +31,13 @@ config_device.cxx \ dialNode.cxx \ qpdialNode.cxx \ - mouse.cxx \ mouseAndKeyboard.cxx \ trackerData.cxx \ - trackerNode.cxx \ qptrackerNode.cxx \ - virtualMouse.cxx \ qpvirtualMouse.cxx #define INSTALL_HEADERS \ - analogNode.I analogNode.h \ qpanalogNode.I qpanalogNode.h \ - buttonNode.I buttonNode.h \ qpbuttonNode.I qpbuttonNode.h \ clientAnalogDevice.I clientAnalogDevice.h \ clientBase.I clientBase.h \ @@ -58,14 +45,11 @@ clientDevice.I clientDevice.h \ clientDialDevice.I clientDialDevice.h \ clientTrackerDevice.I clientTrackerDevice.h \ - config_device.h mouse.h \ + config_device.h \ mouseAndKeyboard.h \ - dialNode.I dialNode.h \ qpdialNode.I qpdialNode.h \ trackerData.I trackerData.h \ - trackerNode.I trackerNode.h \ qptrackerNode.I qptrackerNode.h \ - virtualMouse.h \ qpvirtualMouse.h #define IGATESCAN all diff --git a/panda/src/device/analogNode.I b/panda/src/device/analogNode.I deleted file mode 100644 index 1f3ddb08f7..0000000000 --- a/panda/src/device/analogNode.I +++ /dev/null @@ -1,141 +0,0 @@ -// Filename: analogNode.I -// Created by: drose (26Jan01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: AnalogNode::OutputData::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE AnalogNode::OutputData:: -OutputData() { - _index = -1; - _flip = false; -} - -//////////////////////////////////////////////////////////////////// -// Function: AnalogNode::is_valid -// Access: Public -// Description: Returns true if the AnalogNode is valid and -// connected to a server, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool AnalogNode:: -is_valid() const { - return (_analog != (ClientAnalogDevice *)NULL) && _analog->is_connected(); -} - -//////////////////////////////////////////////////////////////////// -// Function: AnalogNode::get_num_controls -// Access: Public -// Description: Returns the number of analog controls known to the -// AnalogNode. This number may change as more controls -// are discovered. -//////////////////////////////////////////////////////////////////// -INLINE int AnalogNode:: -get_num_controls() const { - _analog->lock(); - int result = _analog->get_num_controls(); - _analog->unlock(); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: AnalogNode::get_control_state -// Access: Public -// Description: Returns the current position of indicated analog -// control identified by its index number, or 0.0 if -// the control is unknown. The normal range of a single -// control is -1.0 to 1.0. -//////////////////////////////////////////////////////////////////// -INLINE double AnalogNode:: -get_control_state(int index) const { - _analog->lock(); - double result = _analog->get_control_state(index); - _analog->unlock(); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: AnalogNode::is_control_known -// Access: Public -// Description: Returns true if the state of the indicated analog -// control is known, or false if we have never heard -// anything about this particular control. -//////////////////////////////////////////////////////////////////// -INLINE bool AnalogNode:: -is_control_known(int index) const { - _analog->lock(); - bool result = _analog->is_control_known(index); - _analog->unlock(); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: AnalogNode::set_output -// Access: Public -// Description: Causes a particular analog control to be placed in -// the data graph for the indicated channel. Normally, -// a mouse uses channels 0 and 1 for the X and Y -// information, respectively; channels 0, 1, and 2 are -// available. If flip is true, the analog control value -// will be reversed before outputting it. -//////////////////////////////////////////////////////////////////// -INLINE void AnalogNode:: -set_output(int channel, int index, bool flip) { - nassertv(channel >= 0 && channel < max_outputs); - _outputs[channel]._index = index; - _outputs[channel]._flip = flip; -} - -//////////////////////////////////////////////////////////////////// -// Function: AnalogNode::clear_output -// Access: Public -// Description: Removes the output to the data graph associated with -// the indicated channel. See set_output(). -//////////////////////////////////////////////////////////////////// -INLINE void AnalogNode:: -clear_output(int channel) { - nassertv(channel >= 0 && channel < max_outputs); - _outputs[channel]._index = -1; -} - -//////////////////////////////////////////////////////////////////// -// Function: AnalogNode::get_output -// Access: Public -// Description: Returns the analog control index that is output to -// the data graph on the indicated channel, or -1 if no -// control is output on that channel. See set_output(). -//////////////////////////////////////////////////////////////////// -INLINE int AnalogNode:: -get_output(int channel) const { - nassertr(channel >= 0 && channel < max_outputs, -1); - return _outputs[channel]._index; -} - -//////////////////////////////////////////////////////////////////// -// Function: AnalogNode::is_output_flipped -// Access: Public -// Description: Returns true if the analog control index that is -// output to the data graph on the indicated channel is -// flipped. See set_output(). -//////////////////////////////////////////////////////////////////// -INLINE bool AnalogNode:: -is_output_flipped(int channel) const { - nassertr(channel >= 0 && channel < max_outputs, false); - return _outputs[channel]._flip; -} diff --git a/panda/src/device/analogNode.cxx b/panda/src/device/analogNode.cxx deleted file mode 100644 index 9f3703dae2..0000000000 --- a/panda/src/device/analogNode.cxx +++ /dev/null @@ -1,135 +0,0 @@ -// Filename: analogNode.cxx -// Created by: drose (26Jan01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "analogNode.h" -#include "config_device.h" - -//////////////////////////////////////////////////////////////////// -// Static variables -//////////////////////////////////////////////////////////////////// -TypeHandle AnalogNode::_type_handle; - -TypeHandle AnalogNode::_xyz_type; - -//////////////////////////////////////////////////////////////////// -// Function: AnalogNode::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -AnalogNode:: -AnalogNode(ClientBase *client, const string &device_name) : - DataNode(device_name) -{ - nassertv(client != (ClientBase *)NULL); - PT(ClientDevice) device = - client->get_device(ClientAnalogDevice::get_class_type(), device_name); - - if (device == (ClientDevice *)NULL) { - device_cat.warning() - << "Unable to open analog device " << device_name << "\n"; - return; - } - - if (!device->is_of_type(ClientAnalogDevice::get_class_type())) { - device_cat.error() - << "Inappropriate device type " << device->get_type() - << " created; expected a ClientAnalogDevice.\n"; - return; - } - - _analog = DCAST(ClientAnalogDevice, device); - - _xyz = new Vec3DataTransition(LPoint3f(0.0f, 0.0f, 0.0f)); - _attrib.set_transition(_xyz_type, _xyz); -} - -//////////////////////////////////////////////////////////////////// -// Function: AnalogNode::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -AnalogNode:: -~AnalogNode() { - // When the _analog pointer destructs, the ClientAnalogDevice - // disconnects itself from the ClientBase, and everything that needs - // to get turned off does. Magic. -} - -//////////////////////////////////////////////////////////////////// -// Function: AnalogNode::write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void AnalogNode:: -write(ostream &out, int indent_level) const { - DataNode::write(out, indent_level); - - if (_analog != (ClientAnalogDevice *)NULL) { - _analog->lock(); - _analog->write_controls(out, indent_level + 2); - _analog->unlock(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: AnalogNode::transmit_data -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void AnalogNode:: -transmit_data(AllTransitionsWrapper &data) { - if (is_valid()) { - _analog->poll(); - - LPoint3f out(0.0f, 0.0f, 0.0f); - - _analog->lock(); - for (int i = 0; i < max_outputs; i++) { - if (_outputs[i]._index >= 0 && - _analog->is_control_known(_outputs[i]._index)) { - if (_outputs[i]._flip) { - out[i] = -_analog->get_control_state(_outputs[i]._index); - } else { - out[i] = _analog->get_control_state(_outputs[i]._index); - } - } - } - _analog->unlock(); - _xyz->set_value(out); - } - - data = _attrib; -} - -//////////////////////////////////////////////////////////////////// -// Function: AnalogNode::init_type -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void AnalogNode:: -init_type() { - DataNode::init_type(); - register_type(_type_handle, "AnalogNode", - DataNode::get_class_type()); - - Vec3DataTransition::init_type(); - register_data_transition(_xyz_type, "XYZ", - Vec3DataTransition::get_class_type()); -} - diff --git a/panda/src/device/analogNode.h b/panda/src/device/analogNode.h deleted file mode 100644 index ba068c415e..0000000000 --- a/panda/src/device/analogNode.h +++ /dev/null @@ -1,114 +0,0 @@ -// Filename: analogNode.h -// Created by: drose (26Jan01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef ANALOGNODE_H -#define ANALOGNODE_H - -#include - -#include "clientBase.h" -#include "clientAnalogDevice.h" - -#include -#include -#include -#include - - -//////////////////////////////////////////////////////////////////// -// Class : AnalogNode -// Description : This is the primary interface to analog controls like -// sliders and joysticks associated with a ClientBase. -// This creates a node that connects to the named analog -// device, if it exists, and provides hooks to the user -// to read the state of any of the sequentially numbered -// controls associated with that device. -// -// Each control can return a value ranging from -1 to 1, -// reflecting the current position of the control within -// its total range of motion. -// -// The user may choose up to three analog controls to -// place on the data graph as the three channels of an -// XYZ datagram, similarly to the way a mouse places its -// position data. In this way, an AnalogNode may be -// used in place of a mouse. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA AnalogNode : public DataNode { -PUBLISHED: - AnalogNode(ClientBase *client, const string &device_name); - virtual ~AnalogNode(); - - INLINE bool is_valid() const; - - INLINE int get_num_controls() const; - - INLINE double get_control_state(int index) const; - INLINE bool is_control_known(int index) const; - - INLINE void set_output(int channel, int index, bool flip); - INLINE void clear_output(int channel); - INLINE int get_output(int channel) const; - INLINE bool is_output_flipped(int channel) const; - -public: - virtual void write(ostream &out, int indent_level = 0) const; - -private: - class OutputData { - public: - INLINE OutputData(); - int _index; - bool _flip; - }; - - enum { max_outputs = 3 }; - OutputData _outputs[max_outputs]; - -//////////////////////////////////////////////////////////////////// -// From parent class DataNode -//////////////////////////////////////////////////////////////////// -public: - virtual void - transmit_data(AllTransitionsWrapper &data); - - AllTransitionsWrapper _attrib; - PT(Vec3DataTransition) _xyz; - - static TypeHandle _xyz_type; - -private: - PT(ClientAnalogDevice) _analog; - -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(); - -private: - static TypeHandle _type_handle; -}; - -#include "analogNode.I" - -#endif diff --git a/panda/src/device/buttonNode.I b/panda/src/device/buttonNode.I deleted file mode 100644 index 33a9c27119..0000000000 --- a/panda/src/device/buttonNode.I +++ /dev/null @@ -1,114 +0,0 @@ -// Filename: buttonNode.I -// Created by: drose (31Dec69) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: ButtonNode::is_valid -// Access: Public -// Description: Returns true if the ButtonNode is valid and -// connected to a server, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool ButtonNode:: -is_valid() const { - return (_button != (ClientButtonDevice *)NULL) && _button->is_connected(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonNode::get_num_buttons -// Access: Public -// Description: Returns the number of buttons known to the -// ButtonNode. This includes those buttons whose state -// has been seen, as well as buttons that have been -// associated with a ButtonHandle even if their state is -// unknown. This number may change as more buttons are -// discovered. -//////////////////////////////////////////////////////////////////// -INLINE int ButtonNode:: -get_num_buttons() const { - _button->lock(); - int result = _button->get_num_buttons(); - _button->unlock(); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonNode::set_button_map -// Access: Public -// Description: Associates the indicated ButtonHandle with the button -// of the indicated index number. When the given button -// index changes state, a corresponding ButtonEvent will -// be generated with the given ButtonHandle. Pass -// ButtonHandle::none() to turn off any association. -// -// It is not necessary to call this if you simply want -// to query the state of the various buttons by index -// number; this is only necessary in order to generate -// ButtonEvents when the buttons change state. -//////////////////////////////////////////////////////////////////// -INLINE void ButtonNode:: -set_button_map(int index, ButtonHandle button) { - _button->lock(); - _button->set_button_map(index, button); - _button->unlock(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonNode::get_button_map -// Access: Public -// Description: Returns the ButtonHandle that was previously -// associated with the given index number by -// a call to set_button_map(), or ButtonHandle::none() -// if no button was associated. -//////////////////////////////////////////////////////////////////// -INLINE ButtonHandle ButtonNode:: -get_button_map(int index) const { - _button->lock(); - ButtonHandle result = _button->get_button_map(index); - _button->unlock(); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonNode::get_button_state -// Access: Public -// Description: Returns true if the indicated button (identified by -// its index number) is currently known to be down, or -// false if it is up or unknown. -//////////////////////////////////////////////////////////////////// -INLINE bool ButtonNode:: -get_button_state(int index) const { - _button->lock(); - bool result = _button->get_button_state(index); - _button->unlock(); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonNode::is_button_known -// Access: Public -// Description: Returns true if the state of the indicated button is -// known, or false if we have never heard anything about -// this particular button. -//////////////////////////////////////////////////////////////////// -INLINE bool ButtonNode:: -is_button_known(int index) const { - _button->lock(); - bool result = _button->is_button_known(index); - _button->unlock(); - return result; -} diff --git a/panda/src/device/buttonNode.cxx b/panda/src/device/buttonNode.cxx deleted file mode 100644 index 6c9a79372d..0000000000 --- a/panda/src/device/buttonNode.cxx +++ /dev/null @@ -1,153 +0,0 @@ -// Filename: buttonNode.cxx -// Created by: drose (31Dec69) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "buttonNode.h" -#include "config_device.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Static variables -//////////////////////////////////////////////////////////////////// -TypeHandle ButtonNode::_type_handle; - -TypeHandle ButtonNode::_button_events_type; - -//////////////////////////////////////////////////////////////////// -// Function: ButtonNode::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -ButtonNode:: -ButtonNode(ClientBase *client, const string &device_name) : - DataNode(device_name) -{ - nassertv(client != (ClientBase *)NULL); - PT(ClientDevice) device = - client->get_device(ClientButtonDevice::get_class_type(), device_name); - - if (device == (ClientDevice *)NULL) { - device_cat.warning() - << "Unable to open button device " << device_name << "\n"; - return; - } - - if (!device->is_of_type(ClientButtonDevice::get_class_type())) { - device_cat.error() - << "Inappropriate device type " << device->get_type() - << " created; expected a ClientButtonDevice.\n"; - return; - } - - _button = DCAST(ClientButtonDevice, device); - - if (_button != (ClientButtonDevice *)NULL) { - _button_events = new ButtonEventDataTransition(); - _attrib.set_transition(_button_events_type, _button_events); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonNode::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -ButtonNode:: -~ButtonNode() { - // When the _button pointer destructs, the ClientButtonDevice - // disconnects itself from the ClientBase, and everything that needs - // to get turned off does. Magic. -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonNode::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void ButtonNode:: -output(ostream &out) const { - DataNode::output(out); - - if (_button != (ClientButtonDevice *)NULL) { - out << " ("; - _button->lock(); - _button->output_buttons(out); - _button->unlock(); - out << ")"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonNode::write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void ButtonNode:: -write(ostream &out, int indent_level) const { - DataNode::write(out, indent_level); - - if (_button != (ClientButtonDevice *)NULL) { - _button->lock(); - _button->write_buttons(out, indent_level + 2); - _button->unlock(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonNode::transmit_data -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void ButtonNode:: -transmit_data(AllTransitionsWrapper &data) { - if (is_valid()) { - _button->poll(); - _button->lock(); - - // We can no longer copy these in the old scene graph. - // (*_button_events) = (*_button->get_button_events()); - - _button->get_button_events()->clear(); - _button->unlock(); - - if (device_cat.is_debug()) { - device_cat.debug() << "ButtonNode:transitions" << endl; - _attrib.write(device_cat.debug(false), 3); - } - } - - data = _attrib; -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonNode::init_type -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void ButtonNode:: -init_type() { - DataNode::init_type(); - register_type(_type_handle, "ButtonNode", - DataNode::get_class_type()); - - ButtonEventDataTransition::init_type(); - register_data_transition(_button_events_type, "ButtonEvents", - ButtonEventDataTransition::get_class_type()); -} - diff --git a/panda/src/device/buttonNode.h b/panda/src/device/buttonNode.h deleted file mode 100644 index 3d576a5a55..0000000000 --- a/panda/src/device/buttonNode.h +++ /dev/null @@ -1,98 +0,0 @@ -// Filename: buttonNode.h -// Created by: drose (31Dec69) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef BUTTONNODE_H -#define BUTTONNODE_H - -#include - -#include "clientBase.h" -#include "clientButtonDevice.h" - -#include -#include -#include - - -//////////////////////////////////////////////////////////////////// -// Class : ButtonNode -// Description : This is the primary interface to on/off button -// devices associated with a ClientBase. This creates a -// node that connects to the named button device, if it -// exists, and provides hooks to the user to read the -// state of any of the sequentially numbered buttons -// associated with that device. -// -// It also can associate an arbitrary ButtonHandle with -// each button; when buttons are associated with -// ButtonHandles, this node will put appropriate up and -// down events on the data graph for each button state -// change. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ButtonNode : public DataNode { -PUBLISHED: - ButtonNode(ClientBase *client, const string &device_name); - virtual ~ButtonNode(); - - INLINE bool is_valid() const; - - INLINE int get_num_buttons() const; - - INLINE void set_button_map(int index, ButtonHandle button); - INLINE ButtonHandle get_button_map(int index) const; - - INLINE bool get_button_state(int index) const; - INLINE bool is_button_known(int index) const; - -public: - virtual void output(ostream &out) const; - virtual void write(ostream &out, int indent_level = 0) const; - -//////////////////////////////////////////////////////////////////// -// From parent class DataNode -//////////////////////////////////////////////////////////////////// -public: - virtual void - transmit_data(AllTransitionsWrapper &data); - - AllTransitionsWrapper _attrib; - PT(ButtonEventDataTransition) _button_events; - - // outputs - static TypeHandle _button_events_type; - -private: - PT(ClientButtonDevice) _button; - -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(); - -private: - static TypeHandle _type_handle; -}; - -#include "buttonNode.I" - -#endif diff --git a/panda/src/device/config_device.cxx b/panda/src/device/config_device.cxx index b0be34c3bd..7696920ab8 100644 --- a/panda/src/device/config_device.cxx +++ b/panda/src/device/config_device.cxx @@ -18,9 +18,7 @@ #include "config_device.h" -#include "analogNode.h" #include "qpanalogNode.h" -#include "buttonNode.h" #include "qpbuttonNode.h" #include "clientAnalogDevice.h" #include "clientBase.h" @@ -28,13 +26,9 @@ #include "clientDevice.h" #include "clientDialDevice.h" #include "clientTrackerDevice.h" -#include "dialNode.h" #include "qpdialNode.h" -#include "mouse.h" #include "mouseAndKeyboard.h" -#include "trackerNode.h" #include "qptrackerNode.h" -#include "virtualMouse.h" #include "qpvirtualMouse.h" #include @@ -64,9 +58,7 @@ init_libdevice() { } initialized = true; - AnalogNode::init_type(); qpAnalogNode::init_type(); - ButtonNode::init_type(); qpButtonNode::init_type(); ClientAnalogDevice::init_type(); ClientBase::init_type(); @@ -74,12 +66,8 @@ init_libdevice() { ClientDevice::init_type(); ClientDialDevice::init_type(); ClientTrackerDevice::init_type(); - DialNode::init_type(); qpDialNode::init_type(); - MouseAndKeyboard::init_type(); qpMouseAndKeyboard::init_type(); - TrackerNode::init_type(); qpTrackerNode::init_type(); - VirtualMouse::init_type(); qpVirtualMouse::init_type(); } diff --git a/panda/src/device/device_composite2.cxx b/panda/src/device/device_composite2.cxx index 8c4a0a2992..59d25823f2 100644 --- a/panda/src/device/device_composite2.cxx +++ b/panda/src/device/device_composite2.cxx @@ -1,16 +1,10 @@ #include "config_device.cxx" -#include "analogNode.cxx" #include "qpanalogNode.cxx" -#include "buttonNode.cxx" #include "qpbuttonNode.cxx" -#include "dialNode.cxx" #include "qpdialNode.cxx" -#include "mouse.cxx" #include "mouseAndKeyboard.cxx" #include "trackerData.cxx" -#include "trackerNode.cxx" #include "qptrackerNode.cxx" -#include "virtualMouse.cxx" #include "qpvirtualMouse.cxx" diff --git a/panda/src/device/dialNode.I b/panda/src/device/dialNode.I deleted file mode 100644 index a6928e84a4..0000000000 --- a/panda/src/device/dialNode.I +++ /dev/null @@ -1,74 +0,0 @@ -// Filename: dialNode.I -// Created by: drose (26Jan01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: DialNode::is_valid -// Access: Public -// Description: Returns true if the DialNode is valid and -// connected to a server, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool DialNode:: -is_valid() const { - return (_dial != (ClientDialDevice *)NULL) && _dial->is_connected(); -} - -//////////////////////////////////////////////////////////////////// -// Function: DialNode::get_num_dials -// Access: Public -// Description: Returns the number of dial dials known to the -// DialNode. This number may change as more dials -// are discovered. -//////////////////////////////////////////////////////////////////// -INLINE int DialNode:: -get_num_dials() const { - _dial->lock(); - int result = _dial->get_num_dials(); - _dial->unlock(); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: DialNode::read_dial -// Access: Public -// Description: Returns the number of complete revolutions of the -// dial since the last time read_dial() was called. -// This is a destructive operation; it is not possible -// to read the dial without resetting the counter. -//////////////////////////////////////////////////////////////////// -INLINE double DialNode:: -read_dial(int index) { - _dial->lock(); - double result = _dial->read_dial(index); - _dial->unlock(); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: DialNode::is_dial_known -// Access: Public -// Description: Returns true if the state of the indicated dial -// dial is known, or false if we have never heard -// anything about this particular dial. -//////////////////////////////////////////////////////////////////// -INLINE bool DialNode:: -is_dial_known(int index) const { - _dial->lock(); - bool result = _dial->is_dial_known(index); - _dial->unlock(); - return result; -} diff --git a/panda/src/device/dialNode.cxx b/panda/src/device/dialNode.cxx deleted file mode 100644 index 8b1eb7b5d0..0000000000 --- a/panda/src/device/dialNode.cxx +++ /dev/null @@ -1,96 +0,0 @@ -// Filename: dialNode.cxx -// Created by: drose (26Jan01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "dialNode.h" -#include "config_device.h" - -//////////////////////////////////////////////////////////////////// -// Static variables -//////////////////////////////////////////////////////////////////// -TypeHandle DialNode::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: DialNode::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -DialNode:: -DialNode(ClientBase *client, const string &device_name) : - DataNode(device_name) -{ - nassertv(client != (ClientBase *)NULL); - PT(ClientDevice) device = - client->get_device(ClientDialDevice::get_class_type(), device_name); - - if (device == (ClientDevice *)NULL) { - device_cat.warning() - << "Unable to open dial device " << device_name << "\n"; - return; - } - - if (!device->is_of_type(ClientDialDevice::get_class_type())) { - device_cat.error() - << "Inappropriate device type " << device->get_type() - << " created; expected a ClientDialDevice.\n"; - return; - } - - _dial = DCAST(ClientDialDevice, device); -} - -//////////////////////////////////////////////////////////////////// -// Function: DialNode::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -DialNode:: -~DialNode() { - // When the _dial pointer destructs, the ClientDialDevice - // disconnects itself from the ClientBase, and everything that needs - // to get turned off does. Magic. -} - -//////////////////////////////////////////////////////////////////// -// Function: DialNode::transmit_data -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DialNode:: -transmit_data(AllTransitionsWrapper &data) { - if (is_valid()) { - _dial->poll(); - - // Not clear yet what we should be transmitting. - } - - data = _attrib; -} - -//////////////////////////////////////////////////////////////////// -// Function: DialNode::init_type -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void DialNode:: -init_type() { - DataNode::init_type(); - register_type(_type_handle, "DialNode", - DataNode::get_class_type()); -} - diff --git a/panda/src/device/dialNode.h b/panda/src/device/dialNode.h deleted file mode 100644 index 217ea17df2..0000000000 --- a/panda/src/device/dialNode.h +++ /dev/null @@ -1,85 +0,0 @@ -// Filename: dialNode.h -// Created by: drose (26Jan01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DIALNODE_H -#define DIALNODE_H - -#include - -#include "clientBase.h" -#include "clientDialDevice.h" - -#include -#include - - -//////////////////////////////////////////////////////////////////// -// Class : DialNode -// Description : This is the primary interface to infinite dial type -// devices associated with a ClientBase. This creates a -// node that connects to the named dial device, if it -// exists, and provides hooks to the user to read the -// state of any of the sequentially numbered dial -// controls associated with that device. -// -// A dial is a rotating device that does not have -// stops--it can keep rotating any number of times. -// Therefore it does not have a specific position at any -// given time, unlike an AnalogDevice. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA DialNode : public DataNode { -PUBLISHED: - DialNode(ClientBase *client, const string &device_name); - virtual ~DialNode(); - - INLINE bool is_valid() const; - - INLINE int get_num_dials() const; - - INLINE double read_dial(int index); - INLINE bool is_dial_known(int index) const; - -//////////////////////////////////////////////////////////////////// -// From parent class DataNode -//////////////////////////////////////////////////////////////////// -public: - virtual void - transmit_data(AllTransitionsWrapper &data); - - AllTransitionsWrapper _attrib; - -private: - PT(ClientDialDevice) _dial; - -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(); - -private: - static TypeHandle _type_handle; -}; - -#include "dialNode.I" - -#endif diff --git a/panda/src/device/mouse.cxx b/panda/src/device/mouse.cxx deleted file mode 100644 index c8e0988883..0000000000 --- a/panda/src/device/mouse.cxx +++ /dev/null @@ -1,118 +0,0 @@ -// Filename: mouse.cxx -// Created by: mike (09Jan97) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "mouse.h" - -#include -#include -#include - -//////////////////////////////////////////////////////////////////// -// Static variables -//////////////////////////////////////////////////////////////////// -TypeHandle MouseAndKeyboard::_type_handle; - -TypeHandle MouseAndKeyboard::_pixel_xyz_type; -TypeHandle MouseAndKeyboard::_xyz_type; -TypeHandle MouseAndKeyboard::_button_events_type; - - -//////////////////////////////////////////////////////////////////// -// Function: MouseAndKeyboard::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -MouseAndKeyboard:: -MouseAndKeyboard(GraphicsWindow *window, int device, const string& name) : - DataNode(name), - _window(window), - _device(device) -{ - _pixel_xyz = new Vec3DataTransition(LPoint3f(0.0f, 0.0f, 0.0f)); - _xyz = new Vec3DataTransition(LPoint3f(0.0f, 0.0f, 0.0f)); - _button_events = new ButtonEventDataTransition(); - - _got_mouse_attrib.set_transition(_pixel_xyz_type, _pixel_xyz); - _got_mouse_attrib.set_transition(_xyz_type, _xyz); - _got_mouse_attrib.set_transition(_button_events_type, _button_events); - - _no_mouse_attrib.set_transition(_button_events_type, _button_events); -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseAndKeyboard::transmit_data -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void MouseAndKeyboard:: -transmit_data(AllTransitionsWrapper &data) { - // Fill up the button events. - _button_events->clear(); - while (_window->has_button_event(_device)) { - ButtonEvent be = _window->get_button_event(_device); - _button_events->push_back(be); - } - - if (_window->has_pointer(_device)) { - const MouseData &mdata = _window->get_mouse_data(_device); - - if (mdata._in_window) { - // Get motion - _pixel_xyz->set_value(LPoint3f(mdata._xpos, mdata._ypos, 0.0f)); - - int w = _window->get_width(); - int h = _window->get_height(); - - // Scale to range [-1,1] - float xf = (float)(2 * mdata._xpos) / (float)w - 1.0f; - float yf = 1.0f - (float)(2 * mdata._ypos) / (float)h; - - _xyz->set_value(LPoint3f(xf, yf, 0.0f)); - data = _got_mouse_attrib; - - } else { - // The mouse isn't within the window right now. - data = _no_mouse_attrib; - } - - } else { - // We don't have a mouse device. - data = _no_mouse_attrib; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseAndKeyboard::init_type -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void MouseAndKeyboard:: -init_type() { - DataNode::init_type(); - register_type(_type_handle, "MouseAndKeyboard", - DataNode::get_class_type()); - - Vec3DataTransition::init_type(); - register_data_transition(_pixel_xyz_type, "PixelXYZ", - Vec3DataTransition::get_class_type()); - register_data_transition(_xyz_type, "XYZ", - Vec3DataTransition::get_class_type()); - ButtonEventDataTransition::init_type(); - register_data_transition(_button_events_type, "ButtonEvents", - ButtonEventDataTransition::get_class_type()); -} diff --git a/panda/src/device/mouse.h b/panda/src/device/mouse.h deleted file mode 100644 index 543d437538..0000000000 --- a/panda/src/device/mouse.h +++ /dev/null @@ -1,89 +0,0 @@ -// Filename: mouse.h -// Created by: mike (09Jan97) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// -#ifndef MOUSE_H -#define MOUSE_H - -#include "pandabase.h" - -#include "dataNode.h" -#include "vec3DataTransition.h" -#include "buttonEventDataTransition.h" -#include "graphicsWindow.h" -#include "pointerTo.h" -#include "allTransitionsWrapper.h" - - -//////////////////////////////////////////////////////////////////// -// Class : MouseAndKeyboard -// Description : Reads the mouse and/or keyboard data sent from a -// GraphicsWindow, and transmits it down the data graph. -// -// The mouse and keyboard devices are bundled together -// into one device here, because they interrelate so -// much. A mouse might be constrained by the holding -// down of the shift key, for instance, or the clicking -// of the mouse button might be handled in much the same -// way as a keyboard key. -// -// Mouse data is sent down the data graph as an x,y -// position as well as the set of buttons currently -// being held down; keyboard data is sent down as a set -// of keypress events in an EventDataTransition. To -// throw these events to the system, you must child an -// EventThrower to the MouseAndKeyboard object; -// otherwise, the events will be discarded. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA MouseAndKeyboard : public DataNode { -PUBLISHED: - MouseAndKeyboard(GraphicsWindow *window, int device, - const string& name = ""); - -public: - virtual void transmit_data(AllTransitionsWrapper &data); - -public: - AllTransitionsWrapper _got_mouse_attrib; - AllTransitionsWrapper _no_mouse_attrib; - PT(Vec3DataTransition) _pixel_xyz; - PT(Vec3DataTransition) _xyz; - PT(ButtonEventDataTransition) _button_events; - - static TypeHandle _mods_type; - static TypeHandle _pixel_xyz_type; - static TypeHandle _xyz_type; - static TypeHandle _button_events_type; - -protected: - PT(GraphicsWindow) _window; - int _device; - -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(); - -private: - static TypeHandle _type_handle; -}; - -#endif diff --git a/panda/src/device/mouseAndKeyboard.cxx b/panda/src/device/mouseAndKeyboard.cxx index 55c3f6c210..9f60030737 100644 --- a/panda/src/device/mouseAndKeyboard.cxx +++ b/panda/src/device/mouseAndKeyboard.cxx @@ -21,6 +21,7 @@ #include "buttonHandle.h" #include "buttonEvent.h" #include "dataNodeTransmit.h" +#include "graphicsWindow.h" TypeHandle qpMouseAndKeyboard::_type_handle; diff --git a/panda/src/device/mouseAndKeyboard.h b/panda/src/device/mouseAndKeyboard.h index b54ea9d523..e95968f4b6 100644 --- a/panda/src/device/mouseAndKeyboard.h +++ b/panda/src/device/mouseAndKeyboard.h @@ -24,7 +24,8 @@ #include "qpdataNode.h" #include "buttonEventList.h" #include "linmath_events.h" - +#include "pointerTo.h" +#include "graphicsWindow.h" //////////////////////////////////////////////////////////////////// // Class : MouseAndKeyboard diff --git a/panda/src/device/qpanalogNode.cxx b/panda/src/device/qpanalogNode.cxx index 3bca0626e8..218cd277ec 100644 --- a/panda/src/device/qpanalogNode.cxx +++ b/panda/src/device/qpanalogNode.cxx @@ -19,6 +19,7 @@ #include "qpanalogNode.h" #include "config_device.h" #include "dataNodeTransmit.h" +#include "dcast.h" TypeHandle qpAnalogNode::_type_handle; diff --git a/panda/src/device/qpbuttonNode.cxx b/panda/src/device/qpbuttonNode.cxx index c61c4b13e3..a6f2df8a59 100644 --- a/panda/src/device/qpbuttonNode.cxx +++ b/panda/src/device/qpbuttonNode.cxx @@ -20,6 +20,7 @@ #include "config_device.h" #include "dataNodeTransmit.h" #include "buttonEventList.h" +#include "dcast.h" TypeHandle qpButtonNode::_type_handle; diff --git a/panda/src/device/qpdialNode.cxx b/panda/src/device/qpdialNode.cxx index 9707e7645d..5664307e9c 100644 --- a/panda/src/device/qpdialNode.cxx +++ b/panda/src/device/qpdialNode.cxx @@ -19,6 +19,7 @@ #include "qpdialNode.h" #include "config_device.h" #include "dataNodeTransmit.h" +#include "dcast.h" TypeHandle qpDialNode::_type_handle; diff --git a/panda/src/device/trackerNode.I b/panda/src/device/trackerNode.I deleted file mode 100644 index f23205cc4e..0000000000 --- a/panda/src/device/trackerNode.I +++ /dev/null @@ -1,119 +0,0 @@ -// Filename: trackerNode.I -// Created by: drose (25Jan01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: TrackerNode::is_valid -// Access: Public -// Description: Returns true if the TrackerNode is valid and -// connected to a server, false otherwise. -//////////////////////////////////////////////////////////////////// -bool TrackerNode:: -is_valid() const { - return (_tracker != (ClientTrackerDevice *)NULL) && _tracker->is_connected(); -} - - -//////////////////////////////////////////////////////////////////// -// Function: TrackerNode::get_pos -// Access: Public -// Description: Returns the current position of the tracker, if it is -// available. -//////////////////////////////////////////////////////////////////// -const LPoint3f &TrackerNode:: -get_pos() const { - return _data.get_pos(); -} - -//////////////////////////////////////////////////////////////////// -// Function: TrackerNode::get_orient -// Access: Public -// Description: Returns the current orientation of the tracker, if it -// is available. -//////////////////////////////////////////////////////////////////// -const LOrientationf &TrackerNode:: -get_orient() const { - return _data.get_orient(); -} - -//////////////////////////////////////////////////////////////////// -// Function: TrackerNode::get_transform -// Access: Public -// Description: Returns the current position and orientation of the -// tracker, as a combined matrix. -//////////////////////////////////////////////////////////////////// -const LMatrix4f &TrackerNode:: -get_transform() const { - return _transform; -} - - -//////////////////////////////////////////////////////////////////// -// Function: TrackerNode::set_tracker_coordinate_system -// Access: Published -// Description: Specifies the coordinate system that the tracker -// associated with this node will operate in. Normally, -// this is set from the ClientBase that's used to create -// the TrackerNode, so it should not need to be set on -// an individual tracker basis. -//////////////////////////////////////////////////////////////////// -void TrackerNode:: -set_tracker_coordinate_system(CoordinateSystem cs) { - _tracker_cs = cs; - if (_tracker_cs == CS_default) { - _tracker_cs = default_coordinate_system; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TrackerNode::get_tracker_coordinate_system -// Access: Published -// Description: Returns the coordinate system that the tracker -// associated with this node will operate in. -//////////////////////////////////////////////////////////////////// -INLINE CoordinateSystem TrackerNode:: -get_tracker_coordinate_system() const { - return _tracker_cs; -} - -//////////////////////////////////////////////////////////////////// -// Function: TrackerNode::set_graph_coordinate_system -// Access: Published -// Description: Specifies the coordinate system that the TrackerNode -// will convert its transform into for passing down the -// data graph. Normally, this is CS_default. -//////////////////////////////////////////////////////////////////// -void TrackerNode:: -set_graph_coordinate_system(CoordinateSystem cs) { - _graph_cs = cs; - if (_graph_cs == CS_default) { - _graph_cs = default_coordinate_system; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TrackerNode::get_graph_coordinate_system -// Access: Published -// Description: Returns the coordinate system that the TrackerNode -// will convert its transform into for passing down the -// data graph. Normally, this is CS_default. -//////////////////////////////////////////////////////////////////// -INLINE CoordinateSystem TrackerNode:: -get_graph_coordinate_system() const { - return _graph_cs; -} diff --git a/panda/src/device/trackerNode.cxx b/panda/src/device/trackerNode.cxx deleted file mode 100644 index 10143bc399..0000000000 --- a/panda/src/device/trackerNode.cxx +++ /dev/null @@ -1,125 +0,0 @@ -// Filename: trackerNode.cxx -// Created by: jason (07Aug00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "trackerNode.h" -#include "config_device.h" - -//////////////////////////////////////////////////////////////////// -// Static variables -//////////////////////////////////////////////////////////////////// -TypeHandle TrackerNode::_type_handle; - -TypeHandle TrackerNode::_transform_type; - -//////////////////////////////////////////////////////////////////// -// Function: TrackerNode::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -TrackerNode:: -TrackerNode(ClientBase *client, const string &device_name) : - DataNode(device_name) -{ - nassertv(client != (ClientBase *)NULL); - set_tracker_coordinate_system(client->get_coordinate_system()); - set_graph_coordinate_system(CS_default); - - PT(ClientDevice) device = - client->get_device(ClientTrackerDevice::get_class_type(), device_name); - - if (device == (ClientDevice *)NULL) { - device_cat.warning() - << "Unable to open tracker device " << device_name << "\n"; - return; - } - - if (!device->is_of_type(ClientTrackerDevice::get_class_type())) { - device_cat.error() - << "Inappropriate device type " << device->get_type() - << " created; expected a ClientTrackerDevice.\n"; - return; - } - - _tracker = DCAST(ClientTrackerDevice, device); - - if (_tracker != (ClientTrackerDevice *)NULL) { - _transform_attrib = new MatrixDataTransition; - _attrib.set_transition(_transform_type, _transform_attrib); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TrackerNode::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -TrackerNode:: -~TrackerNode() { - // When the _tracker pointer destructs, the ClientTrackerDevice - // disconnects itself from the ClientBase, and everything that needs - // to get turned off does. Magic. -} - -//////////////////////////////////////////////////////////////////// -// Function: TrackerNode::transmit_data -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void TrackerNode:: -transmit_data(AllTransitionsWrapper &data) { - if (is_valid()) { - _tracker->poll(); - _tracker->lock(); - _data = _tracker->get_data(); - _tracker->unlock(); - - _data.get_orient().extract_to_matrix(_transform); - if (_tracker_cs != _graph_cs) { - // Convert the rotation for passing down the data graph. - _transform = _transform * LMatrix4f::convert_mat(_tracker_cs, _graph_cs); - } - _transform.set_row(3, _data.get_pos()); - - _transform_attrib->set_value(_transform); - - if (device_cat.is_debug()) { - device_cat.debug() << "TrackerNode:transitions" << endl; - _attrib.write(device_cat.debug(false), 3); - } - } - - data = _attrib; -} - -//////////////////////////////////////////////////////////////////// -// Function: TrackerNode::init_type -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void TrackerNode:: -init_type() { - DataNode::init_type(); - register_type(_type_handle, "TrackerNode", - DataNode::get_class_type()); - - MatrixDataTransition::init_type(); - register_data_transition(_transform_type, "Transform", - MatrixDataTransition::get_class_type()); -} - diff --git a/panda/src/device/trackerNode.h b/panda/src/device/trackerNode.h deleted file mode 100644 index 49ba5c12ea..0000000000 --- a/panda/src/device/trackerNode.h +++ /dev/null @@ -1,96 +0,0 @@ -// Filename: trackerNode.h -// Created by: jason (07Aug00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef TRACKERNODE_H -#define TRACKERNODE_H - -#include - -#include "clientBase.h" -#include "trackerData.h" -#include "clientTrackerDevice.h" - -#include -#include -#include -#include -#include -#include -#include - -//////////////////////////////////////////////////////////////////// -// Class : TrackerNode -// Description : This is the primary interface to a Tracker object -// associated with a ClientBase. It reads the position -// and orientation information from the tracker and -// makes it available as a transformation on the data -// graph. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA TrackerNode : public DataNode { -PUBLISHED: - TrackerNode(ClientBase *client, const string &device_name); - virtual ~TrackerNode(); - - INLINE bool is_valid() const; - - INLINE const LPoint3f &get_pos() const; - INLINE const LOrientationf &get_orient() const; - INLINE const LMatrix4f &get_transform() const; - - INLINE void set_tracker_coordinate_system(CoordinateSystem cs); - INLINE CoordinateSystem get_tracker_coordinate_system() const; - - INLINE void set_graph_coordinate_system(CoordinateSystem cs); - INLINE CoordinateSystem get_graph_coordinate_system() const; - -//////////////////////////////////////////////////////////////////// -// From parent class DataNode -//////////////////////////////////////////////////////////////////// -public: - virtual void - transmit_data(AllTransitionsWrapper &data); - - AllTransitionsWrapper _attrib; - PT(MatrixDataTransition) _transform_attrib; - - // outputs - static TypeHandle _transform_type; - -private: - PT(ClientTrackerDevice) _tracker; - TrackerData _data; - LMatrix4f _transform; - CoordinateSystem _tracker_cs, _graph_cs; - -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(); - -private: - static TypeHandle _type_handle; -}; - -#include "trackerNode.I" - -#endif diff --git a/panda/src/device/virtualMouse.cxx b/panda/src/device/virtualMouse.cxx deleted file mode 100644 index 38dfbfa6a7..0000000000 --- a/panda/src/device/virtualMouse.cxx +++ /dev/null @@ -1,164 +0,0 @@ -// Filename: virtualMouse.cxx -// Created by: drose (13Dec01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "virtualMouse.h" - -TypeHandle VirtualMouse::_type_handle; - -TypeHandle VirtualMouse::_pixel_xyz_type; -TypeHandle VirtualMouse::_xyz_type; -TypeHandle VirtualMouse::_button_events_type; - - -//////////////////////////////////////////////////////////////////// -// Function: VirtualMouse::Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -VirtualMouse:: -VirtualMouse(const string &name) : - DataNode(name) -{ - _pixel_xyz = new Vec3DataTransition(LPoint3f(0.0f, 0.0f, 0.0f)); - _xyz = new Vec3DataTransition(LPoint3f(0.0f, 0.0f, 0.0f)); - _button_events = new ButtonEventDataTransition(); - - _got_mouse_attrib.set_transition(_pixel_xyz_type, _pixel_xyz); - _got_mouse_attrib.set_transition(_xyz_type, _xyz); - _got_mouse_attrib.set_transition(_button_events_type, _button_events); - - _no_mouse_attrib.set_transition(_button_events_type, _button_events); - - _mouse_x = 0; - _mouse_y = 0; - _win_width = 100; - _win_height = 100; - _mouse_on = false; - _next_button_events = new ButtonEventDataTransition(); -} - -//////////////////////////////////////////////////////////////////// -// Function: VirtualMouse::set_mouse_pos -// Access: Published -// Description: Sets the current mouse pixel location, where (0,0) is -// the upper left, and (width-1, height-1) is the lower -// right pixel of the virtual window. -//////////////////////////////////////////////////////////////////// -void VirtualMouse:: -set_mouse_pos(int x, int y) { - _mouse_x = x; - _mouse_y = y; -} - -//////////////////////////////////////////////////////////////////// -// Function: VirtualMouse::set_window_size -// Access: Published -// Description: Sets the size of the "window" in which the mouse -// rolls. This changes the meaning of the values passed -// to set_mouse_pos(). -//////////////////////////////////////////////////////////////////// -void VirtualMouse:: -set_window_size(int width, int height) { - _win_width = width; - _win_height = height; -} - -//////////////////////////////////////////////////////////////////// -// Function: VirtualMouse::set_mouse_on -// Access: Published -// Description: Sets whether the mouse should appear to be within the -// window or not. If this is true, the mouse is within -// the window; if false, the mouse is not within the -// window (and set_mouse_pos() means nothing). -//////////////////////////////////////////////////////////////////// -void VirtualMouse:: -set_mouse_on(bool flag) { - _mouse_on = flag; -} - -//////////////////////////////////////////////////////////////////// -// Function: VirtualMouse::press_button -// Access: Published -// Description: Simulates a mouse or keyboard button being depressed. -// This should be followed up by a call to -// release_button() sometime later (possibly -// immediately). -//////////////////////////////////////////////////////////////////// -void VirtualMouse:: -press_button(ButtonHandle button) { - _next_button_events->push_back(ButtonEvent(button, ButtonEvent::T_down)); -} - -//////////////////////////////////////////////////////////////////// -// Function: VirtualMouse::release_button -// Access: Published -// Description: Simulates the button being released. This should -// follow a previous call to press_button(). -//////////////////////////////////////////////////////////////////// -void VirtualMouse:: -release_button(ButtonHandle button) { - _next_button_events->push_back(ButtonEvent(button, ButtonEvent::T_up)); -} - -//////////////////////////////////////////////////////////////////// -// Function: VirtualMouse::transmit_data -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void VirtualMouse:: -transmit_data(AllTransitionsWrapper &data) { - // Swap in the button events, and clear them for next time. - _button_events->swap(_next_button_events); - _next_button_events->clear(); - - if (_mouse_on) { - // The mouse is within the window. - _pixel_xyz->set_value(LPoint3f(_mouse_x, _mouse_y, 0.0f)); - - // Scale to range [-1,1] - float xf = (2.0f * (float)_mouse_x) / (float)_win_width - 1.0f; - float yf = 1.0f - (2.0f * (float)_mouse_y) / (float)_win_height; - _xyz->set_value(LPoint3f(xf, yf, 0.0f)); - data = _got_mouse_attrib; - - } else { - // The mouse isn't within the window. - data = _no_mouse_attrib; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: VirtualMouse::init_type -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void VirtualMouse:: -init_type() { - DataNode::init_type(); - register_type(_type_handle, "VirtualMouse", - DataNode::get_class_type()); - - Vec3DataTransition::init_type(); - register_data_transition(_pixel_xyz_type, "PixelXYZ", - Vec3DataTransition::get_class_type()); - register_data_transition(_xyz_type, "XYZ", - Vec3DataTransition::get_class_type()); - ButtonEventDataTransition::init_type(); - register_data_transition(_button_events_type, "ButtonEvents", - ButtonEventDataTransition::get_class_type()); -} diff --git a/panda/src/device/virtualMouse.h b/panda/src/device/virtualMouse.h deleted file mode 100644 index 9241890587..0000000000 --- a/panda/src/device/virtualMouse.h +++ /dev/null @@ -1,87 +0,0 @@ -// Filename: virtualMouse.h -// Created by: drose (13Dec01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef VIRTUALMOUSE_H -#define VIRTUALMOUSE_H - -#include "pandabase.h" - -#include "dataNode.h" -#include "buttonHandle.h" -#include "buttonEvent.h" -#include "vec3DataTransition.h" -#include "buttonEventDataTransition.h" -#include "pointerTo.h" -#include "allTransitionsWrapper.h" - -//////////////////////////////////////////////////////////////////// -// Class : VirtualMouse -// Description : Poses as a MouseAndKeyboard object in the datagraph, -// but accepts input from user calls, rather than -// reading the actual mouse and keyboard from an input -// device. The user can write high-level code to put -// the mouse wherever he/she wants, and to insert -// keypresses on demand. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA VirtualMouse : public DataNode { -PUBLISHED: - VirtualMouse(const string &name = ""); - - void set_mouse_pos(int x, int y); - void set_window_size(int width, int height); - void set_mouse_on(bool flag); - - void press_button(ButtonHandle button); - void release_button(ButtonHandle button); - -public: - virtual void transmit_data(AllTransitionsWrapper &data); - -public: - AllTransitionsWrapper _got_mouse_attrib; - AllTransitionsWrapper _no_mouse_attrib; - PT(Vec3DataTransition) _pixel_xyz; - PT(Vec3DataTransition) _xyz; - PT(ButtonEventDataTransition) _button_events; - - static TypeHandle _mods_type; - static TypeHandle _pixel_xyz_type; - static TypeHandle _xyz_type; - static TypeHandle _button_events_type; - -private: - int _mouse_x, _mouse_y; - int _win_width, _win_height; - bool _mouse_on; - PT(ButtonEventDataTransition) _next_button_events; - -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(); - -private: - static TypeHandle _type_handle; -}; - -#endif diff --git a/panda/src/dgraph/Sources.pp b/panda/src/dgraph/Sources.pp index 142e4aa606..f8a66ddd3a 100644 --- a/panda/src/dgraph/Sources.pp +++ b/panda/src/dgraph/Sources.pp @@ -4,73 +4,29 @@ #begin lib_target #define TARGET dgraph #define LOCAL_LIBS \ - pstatclient sgraph graph putil sgattrib mathutil event + pstatclient pgraph putil mathutil event #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx #define SOURCES \ - buttonEventDataTransition.I buttonEventDataTransition.h \ - config_dgraph.h dataGraphTraversal.h dataGraphTraverser.I \ - dataGraphTraverser.h \ + config_dgraph.h \ qpdataGraphTraverser.I qpdataGraphTraverser.h \ - dataNode.h \ qpdataNode.I qpdataNode.h \ - dataNodeTransmit.I dataNodeTransmit.h \ - dataRelation.I \ - dataRelation.N dataRelation.h describe_data_verbose.h \ - doubleDataTransition.I doubleDataTransition.h \ - intDataTransition.I intDataTransition.h \ - matrixDataTransition.I matrixDataTransition.h \ - numericDataTransition.I numericDataTransition.h \ - vec3DataTransition.I vec3DataTransition.h \ - vec4DataTransition.I vec4DataTransition.h \ - vectorDataTransition.I vectorDataTransition.h + dataNodeTransmit.I dataNodeTransmit.h #define INCLUDED_SOURCES \ - buttonEventDataTransition.cxx \ - config_dgraph.cxx dataGraphTraversal.cxx \ - dataGraphTraverser.cxx \ + config_dgraph.cxx \ qpdataGraphTraverser.cxx \ - dataNode.cxx \ qpdataNode.cxx \ - dataNodeTransmit.cxx \ - dataRelation.cxx \ - describe_data_verbose.cxx \ - doubleDataTransition.cxx \ - intDataTransition.cxx \ - matrixDataTransition.cxx \ - vec3DataTransition.cxx \ - vec4DataTransition.cxx + dataNodeTransmit.cxx #define INSTALL_HEADERS \ - buttonEventDataTransition.I buttonEventDataTransition.h \ - dataGraphTraversal.h \ + config_dgraph.h \ qpdataGraphTraverser.I qpdataGraphTraverser.h \ - dataNode.h \ qpdataNode.I qpdataNode.h \ - dataNodeTransmit.I dataNodeTransmit.h \ - dataRelation.I dataRelation.h \ - describe_data_verbose.h \ - doubleDataTransition.I doubleDataTransition.h \ - intDataTransition.I intDataTransition.h \ - matrixDataTransition.I matrixDataTransition.h \ - numericDataTransition.I numericDataTransition.h \ - vec3DataTransition.I vec3DataTransition.h \ - vec4DataTransition.I vec4DataTransition.h \ - vectorDataTransition.I vectorDataTransition.h + dataNodeTransmit.I dataNodeTransmit.h #define IGATESCAN \ all #end lib_target - -#begin test_bin_target - #define TARGET test_dgraph - #define LOCAL_LIBS \ - dgraph - - #define SOURCES \ - test_dgraph.cxx - -#end test_bin_target - diff --git a/panda/src/dgraph/buttonEventDataTransition.I b/panda/src/dgraph/buttonEventDataTransition.I deleted file mode 100644 index 43a2f651cf..0000000000 --- a/panda/src/dgraph/buttonEventDataTransition.I +++ /dev/null @@ -1,89 +0,0 @@ -// Filename: buttonEventDataTransition.I -// Created by: drose (27Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: ButtonEventDataTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ButtonEventDataTransition:: -ButtonEventDataTransition() { -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonEventDataTransition::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ButtonEventDataTransition:: -ButtonEventDataTransition(const ButtonEventDataTransition ©) : - NodeTransition(copy), - _buttons(copy._buttons) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonEventDataTransition::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void ButtonEventDataTransition:: -operator = (const ButtonEventDataTransition ©) { - NodeTransition::operator = (copy); - _buttons = copy._buttons; -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonEventDataTransition::begin -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ButtonEventDataTransition::const_iterator ButtonEventDataTransition:: -begin() const { - return _buttons.begin(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonEventDataTransition::end -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ButtonEventDataTransition::const_iterator ButtonEventDataTransition:: -end() const { - return _buttons.end(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonEventDataTransition::clear -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void ButtonEventDataTransition:: -clear() { - _buttons.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonEventDataTransition::clear -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void ButtonEventDataTransition:: -push_back(const ButtonEvent &event) { - _buttons.push_back(event); -} diff --git a/panda/src/dgraph/buttonEventDataTransition.cxx b/panda/src/dgraph/buttonEventDataTransition.cxx deleted file mode 100644 index 83106cf0b1..0000000000 --- a/panda/src/dgraph/buttonEventDataTransition.cxx +++ /dev/null @@ -1,160 +0,0 @@ -// Filename: buttonEventDataTransition.cxx -// Created by: drose (27Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "buttonEventDataTransition.h" -#include "buttonEventDataTransition.h" - -#include "indent.h" -#include "modifierButtons.h" -#include "dcast.h" - -#include - -TypeHandle ButtonEventDataTransition::_type_handle; - - -//////////////////////////////////////////////////////////////////// -// Function: ButtonEventDataTransition::swap -// Access: Public -// Description: Swaps the data in the queue with that in the other. -//////////////////////////////////////////////////////////////////// -void ButtonEventDataTransition:: -swap(ButtonEventDataTransition *other) { - _buttons.swap(other->_buttons); -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonEventDataTransition::update_mods -// Access: Public -// Description: Updates the indicated ModifierButtons object with all -// of the button up/down transitions indicated in the -// queue. -//////////////////////////////////////////////////////////////////// -void ButtonEventDataTransition:: -update_mods(ModifierButtons &mods) const { - Buttons::const_iterator bi; - for (bi = _buttons.begin(); bi != _buttons.end(); ++bi) { - mods.add_event(*bi); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonEventDataTransition::make_copy -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -NodeTransition *ButtonEventDataTransition:: -make_copy() const { - return new ButtonEventDataTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonEventDataTransition::compose -// Access: Public, Virtual -// Description: Attempts to compose this transition with the other one, -// if that makes sense to do. Returns a new -// NodeTransition pointer that represents the compose, or -// if the compose is not possible, returns the "other" -// pointer unchanged (which is the result of the compose). -//////////////////////////////////////////////////////////////////// -NodeTransition *ButtonEventDataTransition:: -compose(const NodeTransition *other) const { - const ButtonEventDataTransition *oa; - DCAST_INTO_R(oa, other, NULL); - - if (_buttons.empty()) { - return (ButtonEventDataTransition *)oa; - - } else if (oa->_buttons.empty()) { - return (ButtonEventDataTransition *)this; - - } else { - // We have to create a new data transition that includes both sets - // of buttons. - ButtonEventDataTransition *new_attrib = - new ButtonEventDataTransition(*this); - - new_attrib->_buttons.insert(new_attrib->_buttons.end(), - oa->_buttons.begin(), oa->_buttons.end()); - return new_attrib; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonEventDataTransition::invert -// Access: Public, Virtual -// Description: Returns a new transition that corresponds to the -// inverse of this transition. If the transition was -// identity, this may return the same pointer. Returns -// NULL if the transition cannot be inverted. -//////////////////////////////////////////////////////////////////// -NodeTransition *ButtonEventDataTransition:: -invert() const { - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonEventDataTransition::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void ButtonEventDataTransition:: -output(ostream &out) const { - Buttons::const_iterator bi; - for (bi = _buttons.begin(); bi != _buttons.end(); ++bi) { - if (bi != _buttons.begin()) { - out << ", "; - } - out << *bi; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonEventDataTransition::write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void ButtonEventDataTransition:: -write(ostream &out, int indent_level) const { - indent(out, indent_level) << (*this) << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonEventDataTransition::internal_compare_to -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int ButtonEventDataTransition:: -internal_compare_to(const NodeTransition *other) const { - const ButtonEventDataTransition *ot; - DCAST_INTO_R(ot, other, false); - -#ifdef WIN32_VC - if (ot->_buttons == _buttons) - return 0; - else if (lexicographical_compare(_buttons.begin(), _buttons.end(), - ot->_buttons.begin(), ot->_buttons.end())) - return -1; - else - return 1; -#else - return lexicographical_compare_3way(_buttons.begin(), _buttons.end(), - ot->_buttons.begin(), ot->_buttons.end()); -#endif -} diff --git a/panda/src/dgraph/buttonEventDataTransition.h b/panda/src/dgraph/buttonEventDataTransition.h deleted file mode 100644 index f4df11eced..0000000000 --- a/panda/src/dgraph/buttonEventDataTransition.h +++ /dev/null @@ -1,96 +0,0 @@ -// Filename: buttonEventDataTransition.h -// Created by: drose (27Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef BUTTONEVENTDATATRANSITION_H -#define BUTTONEVENTDATATRANSITION_H - -#include "pandabase.h" - -#include "nodeTransition.h" -#include "buttonEvent.h" - -#include "pvector.h" - -class ModifierButtons; - -//////////////////////////////////////////////////////////////////// -// Class : ButtonEventDataTransition -// Description : This data graph transition stores a collection of -// button events that have been generated by the user -// since the last time the data graph pulsed, in the -// order they were generated. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ButtonEventDataTransition : public NodeTransition { -private: - typedef pvector Buttons; - -public: - INLINE ButtonEventDataTransition(); - INLINE ButtonEventDataTransition(const ButtonEventDataTransition ©); - INLINE void operator = (const ButtonEventDataTransition ©); - -public: - // Functions to access and manipulate the set of buttons. - typedef Buttons::const_iterator const_iterator; - typedef Buttons::const_iterator iterator; - - INLINE const_iterator begin() const; - INLINE const_iterator end() const; - - INLINE void clear(); - INLINE void push_back(const ButtonEvent &event); - void swap(ButtonEventDataTransition *other); - - void update_mods(ModifierButtons &mods) const; - -public: - virtual NodeTransition *make_copy() const; - - virtual NodeTransition *compose(const NodeTransition *other) const; - virtual NodeTransition *invert() const; - - virtual void output(ostream &out) const; - virtual void write(ostream &out, int indent_level = 0) const; - -protected: - virtual int internal_compare_to(const NodeTransition *other) const; - -private: - Buttons _buttons; - -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() { - NodeTransition::init_type(); - register_type(_type_handle, "ButtonEventDataTransition", - NodeTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "buttonEventDataTransition.I" - -#endif diff --git a/panda/src/dgraph/config_dgraph.cxx b/panda/src/dgraph/config_dgraph.cxx index 5ca354b615..2f873af3f8 100644 --- a/panda/src/dgraph/config_dgraph.cxx +++ b/panda/src/dgraph/config_dgraph.cxx @@ -17,14 +17,7 @@ //////////////////////////////////////////////////////////////////// #include "config_dgraph.h" -#include "dataNode.h" #include "qpdataNode.h" -#include "dataRelation.h" -#include "intDataTransition.h" -#include "doubleDataTransition.h" -#include "vec3DataTransition.h" -#include "matrixDataTransition.h" -#include "buttonEventDataTransition.h" #include @@ -32,14 +25,5 @@ Configure(config_dgraph); NotifyCategoryDef(dgraph, ""); ConfigureFn(config_dgraph) { - DataNode::init_type(); qpDataNode::init_type(); - DataRelation::init_type(); - IntDataTransition::init_type(); - DoubleDataTransition::init_type(); - Vec3DataTransition::init_type(); - MatrixDataTransition::init_type(); - ButtonEventDataTransition::init_type(); - - DataRelation::register_with_factory(); } diff --git a/panda/src/dgraph/dataGraphTraversal.cxx b/panda/src/dgraph/dataGraphTraversal.cxx deleted file mode 100644 index 22e81b7976..0000000000 --- a/panda/src/dgraph/dataGraphTraversal.cxx +++ /dev/null @@ -1,43 +0,0 @@ -// Filename: dataGraphTraversal.cxx -// Created by: drose (26Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "dataGraphTraversal.h" -#include "dataGraphTraverser.h" - -#include "pStatTimer.h" -#include "pStatCollector.h" - -#ifndef CPPPARSER -PStatCollector _dgraph_pcollector("App:Data graph"); -#endif - -//////////////////////////////////////////////////////////////////// -// Function: traverse_data_graph -// Description: Initiates a traversal of the data graph given the -// indicated root node, with no initial data. Data -// generated by the nodes encountered will be propagated -// downwards. -//////////////////////////////////////////////////////////////////// -void traverse_data_graph(Node *root) { - PStatTimer timer(_dgraph_pcollector); - { - DataGraphTraverser dgt; - dgt.traverse(root); - } -} diff --git a/panda/src/dgraph/dataGraphTraversal.h b/panda/src/dgraph/dataGraphTraversal.h deleted file mode 100644 index 7a8cc995b9..0000000000 --- a/panda/src/dgraph/dataGraphTraversal.h +++ /dev/null @@ -1,53 +0,0 @@ -// Filename: dataGraphTraversal.h -// Created by: drose (26Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DATAGRAPHTRAVERSAL_H -#define DATAGRAPHTRAVERSAL_H - -//////////////////////////////////////////////////////////////////// -// -// DataGraphTraversal -// -// This header file exists mainly to define the function -// traverse_data_graph(), which initiates a traversal of the data -// graph. -// -// This is the main interface to the data graph. Traversing the data -// graph transmits data down the graph--reading data from devices and -// sending it to the DataNodes that want it. -// -//////////////////////////////////////////////////////////////////// - -#include "pandabase.h" - -class Node; - -BEGIN_PUBLISH - -//////////////////////////////////////////////////////////////////// -// Function: traverse_data_graph -// Description: Initiates a traversal of the data graph given the -// indicated root node, with no initial data. Data -// generated by the nodes encountered will be propagated -// downwards. -//////////////////////////////////////////////////////////////////// -void EXPCL_PANDA traverse_data_graph(Node *root); - -END_PUBLISH - -#endif diff --git a/panda/src/dgraph/dataGraphTraverser.I b/panda/src/dgraph/dataGraphTraverser.I deleted file mode 100644 index 89ae2d7e2d..0000000000 --- a/panda/src/dgraph/dataGraphTraverser.I +++ /dev/null @@ -1,59 +0,0 @@ -// Filename: dataGraphTraverser.I -// Created by: drose (05Feb01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: DataGraphTraverser::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE DataGraphTraverser:: -DataGraphTraverser() { -} - -//////////////////////////////////////////////////////////////////// -// Function: DataGraphTraverser::traverse -// Access: Public -// Description: Fires off the traversal, beginning at the indicated -// node. -//////////////////////////////////////////////////////////////////// -INLINE void DataGraphTraverser:: -traverse(Node *node) { - AllTransitionsWrapper empty; - r_traverse(node, empty, false); - resume_all(); -} - -//////////////////////////////////////////////////////////////////// -// Function: DataGraphTraverser::traverse_below -// Access: Public -// Description: Fires off the traversal, beginning *below* the -// indicated node. The transmit_data() function is not -// called on the starting node; instead, the indicated -// data transitions are taken as the output of that node. -// -// If the node defines transmit_data_per_child(), that -// function is still called, once for each child as -// usual. -//////////////////////////////////////////////////////////////////// -INLINE void DataGraphTraverser:: -traverse_below(Node *node, const AllTransitionsWrapper &data) { - AllTransitionsWrapper copy = data; - r_traverse_below(node, copy, false); - resume_all(); -} diff --git a/panda/src/dgraph/dataGraphTraverser.cxx b/panda/src/dgraph/dataGraphTraverser.cxx deleted file mode 100644 index 1810f0d4b1..0000000000 --- a/panda/src/dgraph/dataGraphTraverser.cxx +++ /dev/null @@ -1,238 +0,0 @@ -// Filename: dataGraphTraverser.cxx -// Created by: drose (05Feb01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "dataGraphTraverser.h" -#include "dataRelation.h" -#include "dataNode.h" -#include "config_dgraph.h" -#include "describe_data_verbose.h" - - - -//////////////////////////////////////////////////////////////////// -// Function: DataGraphTraverser::r_traverse -// Access: Private -// Description: The recursive implementation of traverse(). -//////////////////////////////////////////////////////////////////// -void DataGraphTraverser:: -r_traverse(Node *node, AllTransitionsWrapper &data, bool has_spam_mode) { - DataNode *data_node = (DataNode *)NULL; - if (node->is_of_type(DataNode::get_class_type())) { - DCAST_INTO_V(data_node, node); - -#ifdef NOTIFY_DEBUG - has_spam_mode = has_spam_mode || data_node->get_spam_mode(); -#endif - } - - int num_parents = node->get_num_parents(DataRelation::get_class_type()); - - if (num_parents > 1) { - // This node is multiply parented, so we must save it for later. - save(node, data, has_spam_mode, num_parents); - - } else { - - // Now ask the node to transmit its overall data. - if (data_node != (DataNode *)NULL) { -#ifdef NOTIFY_DEBUG - if (has_spam_mode && dgraph_cat.is_info()) { - dgraph_cat.info() << "Sending into " << *node << " {\n"; - describe_data_verbose(dgraph_cat.info(false), data, 2); - dgraph_cat.info(false) << "}\n"; - - } else if (dgraph_cat.is_spam()) { - dgraph_cat.spam() << "Sending into " << *node << " {\n"; - describe_data_verbose(dgraph_cat.spam(false), data, 2); - dgraph_cat.spam(false) << "}\n"; - } -#endif - - data_node->transmit_data(data); - } - - r_traverse_below(node, data, has_spam_mode); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DataGraphTraverser::r_traverse_below -// Access: Private -// Description: Resumes the traversal below the indicated node, given -// the output from a previous call to -// Node::transmit_data(). -//////////////////////////////////////////////////////////////////// -void DataGraphTraverser:: -r_traverse_below(Node *node, AllTransitionsWrapper &data, bool has_spam_mode) { - DataNode *data_node = (DataNode *)NULL; - if (node->is_of_type(DataNode::get_class_type())) { - DCAST_INTO_V(data_node, node); - -#ifdef NOTIFY_DEBUG - has_spam_mode = has_spam_mode || data_node->get_spam_mode(); -#endif - } - - int num_children = node->get_num_children(DataRelation::get_class_type()); - - if (num_children > 0) { - // For the first n - 1 children need to make a copy of our - // AllTransitionsWrapper for each one--this allows our children to - // modify the set freely without affecting its siblings. - - // Note that this is so far just a pointer copy. The contents - // themselves are not necessarily copied, until the data node - // attempts to modify the data, which will then cause a - // copy-on-write. - - for (int i = 0; i < num_children - 1; i++) { - AllTransitionsWrapper copy(data); - if (data_node != (DataNode *)NULL) { - data_node->transmit_data_per_child(copy, i); - } - - NodeRelation *arc = - node->get_child(DataRelation::get_class_type(), i); - r_traverse(arc->get_child(), copy, has_spam_mode); - } - - // For the last child, we don't have to bother making a copy since - // no one cares any more. This is a slight optimization. - if (data_node != (DataNode *)NULL) { - data_node->transmit_data_per_child(data, num_children - 1); - } - - NodeRelation *arc = - node->get_child(DataRelation::get_class_type(), num_children - 1); - - r_traverse(arc->get_child(), data, has_spam_mode); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DataGraphTraverser::save -// Access: Private -// Description: Saves the current state for later, until we have -// extracted the data from all the parents of this node. -// When the last parent is accounted for, resumes the -// traversal for this node and removes it from the saved -// queue. -//////////////////////////////////////////////////////////////////// -void DataGraphTraverser:: -save(Node *node, const AllTransitionsWrapper &data, bool has_spam_mode, - int num_parents) { - - States::iterator si; - si = _saved_states.find(node); - - if (si != _saved_states.end()) { - SavedState &state = (*si).second; - state._data.compose_from(state._data, data); - state._has_spam_mode = state._has_spam_mode || has_spam_mode; - state._num_parents_so_far++; - - if (dgraph_cat.is_spam()) { - dgraph_cat.spam() - << "Encountered " << *node << " with " << num_parents - << " parents; " << state._num_parents_so_far - << " processed so far.\n"; - } - - nassertv(state._num_parents_so_far <= num_parents); - if (state._num_parents_so_far == num_parents) { - // All parents are accounted for, so resume traversal! - resume(node, state); - _saved_states.erase(si); - } - return; - } - - // This node has not been encountered before, so save an entry for - // it. - if (dgraph_cat.is_spam()) { - dgraph_cat.spam() - << "Encountered " << *node << " with " << num_parents - << " parents.\n"; - } - - SavedState &state = _saved_states[node]; - state._data = data; - state._has_spam_mode = has_spam_mode; - state._num_parents_so_far = 1; -} - -//////////////////////////////////////////////////////////////////// -// Function: DataGraphTraverser::resume -// Access: Private -// Description: Resumes traversal from a previously-saved state. -//////////////////////////////////////////////////////////////////// -void DataGraphTraverser:: -resume(Node *node, DataGraphTraverser::SavedState &state) { - DataNode *data_node = (DataNode *)NULL; - if (node->is_of_type(DataNode::get_class_type())) { - DCAST_INTO_V(data_node, node); - -#ifdef NOTIFY_DEBUG - if (state._has_spam_mode && dgraph_cat.is_info()) { - dgraph_cat.info() << "Sending into " << *node << " {\n"; - describe_data_verbose(dgraph_cat.info(false), state._data, 2); - dgraph_cat.info(false) << "}\n"; - - } else if (dgraph_cat.is_spam()) { - dgraph_cat.spam() << "Sending into " << *node << " {\n"; - describe_data_verbose(dgraph_cat.spam(false), state._data, 2); - dgraph_cat.spam(false) << "}\n"; - } -#endif - data_node->transmit_data(state._data); - } - - r_traverse_below(node, state._data, state._has_spam_mode); -} - -//////////////////////////////////////////////////////////////////// -// Function: DataGraphTraverser::resume_all -// Access: Private -// Description: Called after the traversal has completed, this -// resumes all of the unresumed saved states. There -// shouldn't actually be any such things, unless a node -// is multiply parented to a node outside of the data -// graph. -//////////////////////////////////////////////////////////////////// -void DataGraphTraverser:: -resume_all() { - while (!_saved_states.empty()) { - States::iterator si = _saved_states.begin(); - Node *node = (*si).first; - SavedState &state = (*si).second; - - dgraph_cat.warning() - << *node << " is parented both inside and outside of the data graph:\n"; - int num_parents = node->get_num_parents(DataRelation::get_class_type()); - for (int i = 0; i < num_parents; i++) { - NodeRelation *arc = node->get_parent(DataRelation::get_class_type(), i); - dgraph_cat.warning(false) - << " " << *arc << "\n"; - } - - resume(node, state); - _saved_states.erase(si); - } -} - diff --git a/panda/src/dgraph/dataGraphTraverser.h b/panda/src/dgraph/dataGraphTraverser.h deleted file mode 100644 index 746c623d00..0000000000 --- a/panda/src/dgraph/dataGraphTraverser.h +++ /dev/null @@ -1,68 +0,0 @@ -// Filename: dataGraphTraverser.h -// Created by: drose (05Feb01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DATAGRAPHTRAVERSER_H -#define DATAGRAPHTRAVERSER_H - -#include "pandabase.h" - -#include "allTransitionsWrapper.h" - -class Node; - -//////////////////////////////////////////////////////////////////// -// Class : DataGraphTraverser -// Description : This class manages the traversal of the data graph, -// so that all data transitions generated by nodes in the -// graph are transmitted to nodes below them. -// -// A bit of logic is employed to ensure that if a node -// is assigned to two parents, the data from both -// parents is merged before passing it to the child. -// -// This class need not be exported from PANDA.DLL. -//////////////////////////////////////////////////////////////////// -class DataGraphTraverser { -public: - INLINE DataGraphTraverser(); - - INLINE void traverse(Node *node); - INLINE void traverse_below(Node *node, const AllTransitionsWrapper &data); - -private: - class SavedState { - public: - AllTransitionsWrapper _data; - bool _has_spam_mode; - int _num_parents_so_far; - }; - - void r_traverse(Node *node, AllTransitionsWrapper &data, bool has_spam_mode); - void r_traverse_below(Node *node, AllTransitionsWrapper &data, bool has_spam_mode); - void save(Node *node, const AllTransitionsWrapper &data, bool has_spam_mode, - int num_parents); - void resume(Node *node, SavedState &state); - void resume_all(); - - typedef pmap States; - States _saved_states; -}; - -#include "dataGraphTraverser.I" - -#endif diff --git a/panda/src/dgraph/dataNode.cxx b/panda/src/dgraph/dataNode.cxx deleted file mode 100644 index 1bc507d374..0000000000 --- a/panda/src/dgraph/dataNode.cxx +++ /dev/null @@ -1,110 +0,0 @@ -// Filename: dataNode.cxx -// Created by: drose (26Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "dataNode.h" - -TypeHandle DataNode::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: DataNode::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -DataNode:: -DataNode(const string &name) : NamedNode(name) { - _spam_mode = false; -} - -//////////////////////////////////////////////////////////////////// -// Function: DataNode::transmit_data_per_child -// Access: Public, Virtual -// Description: Should be overridden in a derived class that wants to -// send a different data stream to each child. -// Normally, a node only overrides transmit_data(), -// which takes a set of input data transitions and -// generates a set of output data transitions. A node -// may also override transmit_data_per_child(), which is -// called after transmit_data(), once per child; this -// function may be used to send individual data -// transitions to each child. -//////////////////////////////////////////////////////////////////// -void DataNode:: -transmit_data_per_child(AllTransitionsWrapper &, int) { -} - -//////////////////////////////////////////////////////////////////// -// Function: DataNode::set_spam_mode -// Access: Public -// Description: Sets the "spam" flag, which if set indicates that all -// data produced from this DataNode, along with all data -// derived from it downstream, should be reported to the -// user. Handy for figuring out where things are going -// wrong. -//////////////////////////////////////////////////////////////////// -void DataNode:: -set_spam_mode(bool flag) { - _spam_mode = flag; -} - -//////////////////////////////////////////////////////////////////// -// Function: DataNode::get_spam_mode -// Access: Public -// Description: Gets the current state of the "spam" flag. See -// set_spam_mode. -//////////////////////////////////////////////////////////////////// -bool DataNode:: -get_spam_mode() const { - return _spam_mode; -} - - - -//////////////////////////////////////////////////////////////////// -// Function: register_data_transition -// Description: Defines a new data transition of the indicated name -// and inheriting from the indicated transition type. -// This will represent a channel of data, for instance a -// 3-component position from a tracker. -// -// All data transitions that have a common name and base -// class will share the same TypeHandle. This makes it -// possible to unify data producers and consumers based -// on the TypeHandle of the data they share. -//////////////////////////////////////////////////////////////////// -void -register_data_transition(TypeHandle &type_handle, const string &name, - TypeHandle derived_from) { - // Make sure the user gave us a transition type as the base. - - // We won't do this assertion for now, since it causes the - // derivation tree to get rebuilt repeatedly (since this runs at - // static init, before the whole tree is set up). This isn't really - // a problem, but it seems messy to me. - - // nassertv(derived_from.is_derived_from(NodeTransition::get_class_type())); - - string actual_name = name + "_" + derived_from.get_name(); - type_handle = TypeRegistry::ptr()->find_type(actual_name); - - if (type_handle == TypeHandle::none()) { - register_type(type_handle, actual_name, derived_from); - } -} - - diff --git a/panda/src/dgraph/dataNode.h b/panda/src/dgraph/dataNode.h deleted file mode 100644 index 6a33ebd972..0000000000 --- a/panda/src/dgraph/dataNode.h +++ /dev/null @@ -1,134 +0,0 @@ -// Filename: dataNode.h -// Created by: drose (25Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DATANODE_H -#define DATANODE_H - -//////////////////////////////////////////////////////////////////// -// -// The Data Graph. -// -// The data graph is intended to hook up devices and their inputs -// and/or outputs in a clean interface. It uses the same graph -// relationship that is used to construct the scene graph, with the -// same nodes and arcs. -// -// In a data graph, each node may potentially produce and/or consume -// data, and the arcs transmit data downward, from the root of the -// graph to its leaves. Thus, an input device such as a mouse might -// be added to the graph near the root, and a tformer-style object -// that interprets the mouse data as a trackball motion and outputs a -// matrix might be the immediate child of the mouse, followed by an -// object that accepts a matrix and sets it on some particular arc in -// the scene graph. -// -// In a normal scene graph, the arcs transmit state, and each node -// inherits a collection of NodeTransition values that are defined by -// the total set of arcs above it. In a data graph, the arcs transmit -// data instead of state, and each piece of data is stored in a -// NodeTransition value. Thus, each data node still inherits a -// collection of NodeTransition values, but now those values contain -// data instead of state information. In addition, a data node may -// retransmit a different set of NodeTransition values further down the -// chain. This is implemented via the transmit_data() function, below. -// -// Each data node may define its own set of input values and output -// values, each with its own unique transition type. This could be -// done by subclassing a different kind of NodeTransition for each -// different input or output value, but this quickly gets unwieldy. -// Instead, you may find it convenient to use the function -// register_data_transition(), below, which creates a new TypeHandle -// associated with some existing NodeTransition type, based on the -// unique name you give it. This allows producers and consumers to -// match their corresponding data values up by TypeHandle number (and -// hence by name); this matching happens more or less transparently by -// the graph traversal logic. -// -//////////////////////////////////////////////////////////////////// - -#include - -#include - -class AllTransitionsWrapper; - -//////////////////////////////////////////////////////////////////// -// Class : DataNode -// Description : The main node of the data graph. This could -// represent a device that produces data, or an object -// that operates on data received from a device. -// -// The main difference between this and a normal node is -// the transmit_data() function. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA DataNode : public NamedNode { -public: - DataNode(const string &name = ""); - - virtual void - transmit_data(AllTransitionsWrapper &data)=0; - - virtual void - transmit_data_per_child(AllTransitionsWrapper &data, int child_index); - -PUBLISHED: - void set_spam_mode(bool flag); - bool get_spam_mode() const; - - -private: - bool _spam_mode; - - -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() { - NamedNode::init_type(); - register_type(_type_handle, "DataNode", - NamedNode::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - - -//////////////////////////////////////////////////////////////////// -// Function: register_data_transition -// Description: Defines a new data transition of the indicated name -// and inheriting from the indicated transition type. -// This will represent a channel of data, for instance a -// 3-component position from a tracker. -// -// All data transitions that have a common name and base -// class will share the same TypeHandle. This makes it -// possible to unify data producers and consumers based -// on the TypeHandle of the data they share. -//////////////////////////////////////////////////////////////////// -void EXPCL_PANDA -register_data_transition(TypeHandle &type_handle, const string &name, - TypeHandle derived_from); - -#endif - diff --git a/panda/src/dgraph/dataRelation.I b/panda/src/dgraph/dataRelation.I deleted file mode 100644 index ffc0c4bc28..0000000000 --- a/panda/src/dgraph/dataRelation.I +++ /dev/null @@ -1,55 +0,0 @@ -// Filename: dataRelation.I -// Created by: drose (08Jun00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: DataRelation::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE DataRelation:: -DataRelation(Node *from, Node *to, int sort) : - NodeRelation(from, to, sort, get_class_type()) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: DataRelation::Constructor -// Access: Protected -// Description: Creates a new, unattached arc. This constructor is -// only intended for passing through the factory to -// create an arc based on a particular type using -// create_typed_arc(), below. You shouldn't, in -// general, attempt to create an unattached arc. -//////////////////////////////////////////////////////////////////// -INLINE DataRelation:: -DataRelation() : - NodeRelation(get_class_type()) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: DataRelation::register_with_factory -// Access: Public, Static -// Description: Registers the type DataRelation with the factory. -// This is only intended to be called at initialization -// time; don't call it directly. -//////////////////////////////////////////////////////////////////// -INLINE void DataRelation:: -register_with_factory() { - get_factory().register_factory(get_class_type(), make_arc); -} diff --git a/panda/src/dgraph/dataRelation.N b/panda/src/dgraph/dataRelation.N deleted file mode 100644 index 4899282a65..0000000000 --- a/panda/src/dgraph/dataRelation.N +++ /dev/null @@ -1 +0,0 @@ -ignoremember register_with_factory diff --git a/panda/src/dgraph/dataRelation.cxx b/panda/src/dgraph/dataRelation.cxx deleted file mode 100644 index 27b58d8cd5..0000000000 --- a/panda/src/dgraph/dataRelation.cxx +++ /dev/null @@ -1,36 +0,0 @@ -// Filename: dataRelation.cxx -// Created by: drose (08Jun00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "dataRelation.h" - -#include "transformTransition.h" - -TypeHandle DataRelation::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: DataRelation::make_arc -// Access: Public, Static -// Description: This function is passed to the Factory to make a new -// DataRelation by type. Don't try to call this -// function directly. -//////////////////////////////////////////////////////////////////// -NodeRelation *DataRelation:: -make_arc(const FactoryParams &) { - return new DataRelation; -} diff --git a/panda/src/dgraph/dataRelation.h b/panda/src/dgraph/dataRelation.h deleted file mode 100644 index b473207a3b..0000000000 --- a/panda/src/dgraph/dataRelation.h +++ /dev/null @@ -1,69 +0,0 @@ -// Filename: dataRelation.h -// Created by: drose (08Jun00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DATARELATION_H -#define DATARELATION_H - -#include - -#include - -/////////////////////////////////////////////////////////////////// -// Class : DataRelation -// Description : The arc type specific to data graphs. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA DataRelation : public NodeRelation { -public: - INLINE DataRelation(Node *from, Node *to, int sort = 0); - -protected: - // Normally, this should only be used for passing to the factory. - // Don't attempt to create an unattached arc directly. - INLINE DataRelation(); - -public: - // This is just to be called at initialization time; don't try to - // call this directly. - INLINE static void register_with_factory(); - -private: - static NodeRelation *make_arc(const FactoryParams ¶ms); - -PUBLISHED: - static TypeHandle get_class_type() { - return _type_handle; - } - -public: - static void init_type() { - NodeRelation::init_type(); - register_type(_type_handle, "DataRelation", - NodeRelation::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "dataRelation.I" - -#endif diff --git a/panda/src/dgraph/describe_data_verbose.cxx b/panda/src/dgraph/describe_data_verbose.cxx deleted file mode 100644 index 972def94eb..0000000000 --- a/panda/src/dgraph/describe_data_verbose.cxx +++ /dev/null @@ -1,71 +0,0 @@ -// Filename: describe_data_verbose.cxx -// Created by: drose (27Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "dataGraphTraversal.h" -#include "describe_data_verbose.h" - -#include "indent.h" -#include "allTransitionsWrapper.h" - -// The number of columns in from the start of the name to print the -// data value. -static const int data_indent_level = 12; - -//////////////////////////////////////////////////////////////////// -// Function: describe_data_verbose -// Description: Writes to the indicated output stream a -// nicely-formatted, multi-line description of all the -// data values included in the indicated state. -//////////////////////////////////////////////////////////////////// -void -describe_data_verbose(ostream &out, const AllTransitionsWrapper &state, - int indent_level) { - AllTransitionsWrapper::const_iterator nai; - - for (nai = state.begin(); nai != state.end(); ++nai) { - const PT(NodeTransition) &attrib = (*nai).second; - if (attrib != (NodeTransition *)NULL) { - // Now extract the type name out of the type flag. - TypeHandle type = (*nai).first; - string actual_name = type.get_name(); - string::size_type underscore = actual_name.rfind('_'); - string name; - if (underscore == string::npos) { - // There was no underscore, so this name wasn't created via - // register_data_transition(). Huh. Well, that's legitimate - // (if unexpected), so just print the whole name. - name = actual_name; - } else { - // Assume that, if the name was created via - // register_data_transition(), the original name was the part - // before the last underscore. - name = actual_name.substr(0, underscore); - } - - indent(out, indent_level) << name; - if ((int)name.length() < data_indent_level) { - indent(out, data_indent_level - name.length()); - } else { - out << " "; - } - out << *attrib << "\n"; - } - } -} - diff --git a/panda/src/dgraph/describe_data_verbose.h b/panda/src/dgraph/describe_data_verbose.h deleted file mode 100644 index 26df64e8d4..0000000000 --- a/panda/src/dgraph/describe_data_verbose.h +++ /dev/null @@ -1,35 +0,0 @@ -// Filename: describe_data_verbose.h -// Created by: drose (27Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DESCRIBE_DATA_VERBOSE_H -#define DESCRIBE_DATA_VERBOSE_H - -#include "pandabase.h" - -class AllTransitionsWrapper; - -//////////////////////////////////////////////////////////////////// -// Function: describe_data_verbose -// Description: Writes to the indicated output stream a -// nicely-formatted, multi-line description of all the -// data values included in the indicated state. -//////////////////////////////////////////////////////////////////// -void describe_data_verbose(ostream &out, const AllTransitionsWrapper &state, - int indent_level = 0); - -#endif diff --git a/panda/src/dgraph/dgraph_composite1.cxx b/panda/src/dgraph/dgraph_composite1.cxx index 8c0cc4cb87..e776c7d9ff 100644 --- a/panda/src/dgraph/dgraph_composite1.cxx +++ b/panda/src/dgraph/dgraph_composite1.cxx @@ -1,6 +1,2 @@ - -#include "buttonEventDataTransition.cxx" #include "config_dgraph.cxx" -#include "matrixDataTransition.cxx" -#include "vec3DataTransition.cxx" -#include "vec4DataTransition.cxx" +#include "qpdataGraphTraverser.cxx" diff --git a/panda/src/dgraph/dgraph_composite2.cxx b/panda/src/dgraph/dgraph_composite2.cxx index 3b2d232a4a..f9d063d042 100644 --- a/panda/src/dgraph/dgraph_composite2.cxx +++ b/panda/src/dgraph/dgraph_composite2.cxx @@ -1,13 +1,3 @@ - -#include "dataGraphTraversal.cxx" -#include "dataGraphTraverser.cxx" -#include "qpdataGraphTraverser.cxx" -#include "dataNode.cxx" #include "qpdataNode.cxx" #include "dataNodeTransmit.cxx" -#include "dataRelation.cxx" -#include "describe_data_verbose.cxx" -#include "doubleDataTransition.cxx" -#include "intDataTransition.cxx" - diff --git a/panda/src/dgraph/doubleDataTransition.I b/panda/src/dgraph/doubleDataTransition.I deleted file mode 100644 index ae3f456e07..0000000000 --- a/panda/src/dgraph/doubleDataTransition.I +++ /dev/null @@ -1,30 +0,0 @@ -// Filename: doubleDataTransition.I -// Created by: drose (27Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: DoubleDataTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE DoubleDataTransition:: -DoubleDataTransition(double value) : - NumericDataTransition(value) -{ -} - diff --git a/panda/src/dgraph/doubleDataTransition.cxx b/panda/src/dgraph/doubleDataTransition.cxx deleted file mode 100644 index 7a66a1670a..0000000000 --- a/panda/src/dgraph/doubleDataTransition.cxx +++ /dev/null @@ -1,37 +0,0 @@ -// Filename: doubleDataTransition.cxx -// Created by: drose (27Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "doubleDataTransition.h" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif - -TypeHandle DoubleDataTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: DoubleDataTransition::make_copy -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -NodeTransition *DoubleDataTransition:: -make_copy() const { - return new DoubleDataTransition(*this); -} diff --git a/panda/src/dgraph/doubleDataTransition.h b/panda/src/dgraph/doubleDataTransition.h deleted file mode 100644 index c1113a9075..0000000000 --- a/panda/src/dgraph/doubleDataTransition.h +++ /dev/null @@ -1,64 +0,0 @@ -// Filename: doubleDataTransition.h -// Created by: drose (27Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DOUBLEDATATRANSITION_H -#define DOUBLEDATATRANSITION_H - -#include - -#include "numericDataTransition.h" - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, NumericDataTransition); - -//////////////////////////////////////////////////////////////////// -// Class : DoubleDataTransition -// Description : A NumericDataTransition templated on double types. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA DoubleDataTransition : - public NumericDataTransition { -public: - INLINE DoubleDataTransition(double value = 0.0); - - virtual NodeTransition *make_copy() const; - -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() { - NumericDataTransition::init_type(); - register_type(_type_handle, "DoubleDataTransition", - NumericDataTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "doubleDataTransition.I" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/dgraph/intDataTransition.I b/panda/src/dgraph/intDataTransition.I deleted file mode 100644 index 38f356f011..0000000000 --- a/panda/src/dgraph/intDataTransition.I +++ /dev/null @@ -1,29 +0,0 @@ -// Filename: intDataTransition.I -// Created by: drose (27Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: IntDataTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE IntDataTransition:: -IntDataTransition(int value) : - NumericDataTransition(value) -{ -} - diff --git a/panda/src/dgraph/intDataTransition.cxx b/panda/src/dgraph/intDataTransition.cxx deleted file mode 100644 index 3722b3b70b..0000000000 --- a/panda/src/dgraph/intDataTransition.cxx +++ /dev/null @@ -1,37 +0,0 @@ -// Filename: intDataTransition.cxx -// Created by: drose (27Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "intDataTransition.h" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif - -TypeHandle IntDataTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: IntDataTransition::make_copy -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -NodeTransition *IntDataTransition:: -make_copy() const { - return new IntDataTransition(*this); -} diff --git a/panda/src/dgraph/intDataTransition.h b/panda/src/dgraph/intDataTransition.h deleted file mode 100644 index e1335bccd9..0000000000 --- a/panda/src/dgraph/intDataTransition.h +++ /dev/null @@ -1,64 +0,0 @@ -// Filename: intDataTransition.h -// Created by: drose (27Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef INTDATATRANSITION_H -#define INTDATATRANSITION_H - -#include - -#include "numericDataTransition.h" - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, NumericDataTransition); - -//////////////////////////////////////////////////////////////////// -// Class : IntDataTransition -// Description : A NumericDataTransition templated on integer types. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA IntDataTransition : - public NumericDataTransition { -public: - INLINE IntDataTransition(int value = 0); - - virtual NodeTransition *make_copy() const; - -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() { - NumericDataTransition::init_type(); - register_type(_type_handle, "IntDataTransition", - NumericDataTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "intDataTransition.I" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/dgraph/matrixDataTransition.I b/panda/src/dgraph/matrixDataTransition.I deleted file mode 100644 index bd7c1b9f6b..0000000000 --- a/panda/src/dgraph/matrixDataTransition.I +++ /dev/null @@ -1,30 +0,0 @@ -// Filename: matrixDataTransition.I -// Created by: drose (27Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: MatrixDataTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE MatrixDataTransition:: -MatrixDataTransition(const LMatrix4f &value) : - VectorDataTransition(value) -{ -} - diff --git a/panda/src/dgraph/matrixDataTransition.cxx b/panda/src/dgraph/matrixDataTransition.cxx deleted file mode 100644 index fcbee940a2..0000000000 --- a/panda/src/dgraph/matrixDataTransition.cxx +++ /dev/null @@ -1,37 +0,0 @@ -// Filename: matrixDataTransition.cxx -// Created by: drose (27Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "matrixDataTransition.h" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif - -TypeHandle MatrixDataTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: MatrixDataTransition::make_copy -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -NodeTransition *MatrixDataTransition:: -make_copy() const { - return new MatrixDataTransition(*this); -} diff --git a/panda/src/dgraph/matrixDataTransition.h b/panda/src/dgraph/matrixDataTransition.h deleted file mode 100644 index 10f4ca9ea9..0000000000 --- a/panda/src/dgraph/matrixDataTransition.h +++ /dev/null @@ -1,69 +0,0 @@ -// Filename: matrixDataTransition.h -// Created by: drose (27Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef MATRIXDATATRANSITION_H -#define MATRIXDATATRANSITION_H - -#include - -#include "vectorDataTransition.h" - -#include - -// We need to define this temporary macro so we can pass a parameter -// containing a comma through the macro. -#define VECTORDATATRANSITION_LMATRIX4F VectorDataTransition -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, VECTORDATATRANSITION_LMATRIX4F); - -//////////////////////////////////////////////////////////////////// -// Class : MatrixDataTransition -// Description : A VectorDataTransition templated on LMatrix4f. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA MatrixDataTransition : - public VectorDataTransition { -public: - INLINE MatrixDataTransition(const LMatrix4f &value = LMatrix4f::ident_mat()); - - virtual NodeTransition *make_copy() const; - -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() { - VectorDataTransition::init_type(); - register_type(_type_handle, "MatrixDataTransition", - VectorDataTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "matrixDataTransition.I" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/dgraph/numericDataTransition.I b/panda/src/dgraph/numericDataTransition.I deleted file mode 100644 index b1ee587296..0000000000 --- a/panda/src/dgraph/numericDataTransition.I +++ /dev/null @@ -1,136 +0,0 @@ -// Filename: numericDataTransition.I -// Created by: drose (25Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -template -TypeHandle NumericDataTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: NumericDataTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumericDataTransition:: -NumericDataTransition(NumType value) : - _value(value) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: NumericDataTransition::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumericDataTransition:: -NumericDataTransition(const NumericDataTransition ©) : - OnTransition(copy), - _value(copy._value) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: NumericDataTransition::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void NumericDataTransition:: -operator = (const NumericDataTransition ©) { - OnTransition::operator = (copy); - _value = copy._value; -} - -//////////////////////////////////////////////////////////////////// -// Function: NumericDataTransition::set_value -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void NumericDataTransition:: -set_value(NumType value) { - _value = value; - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NumericDataTransition::get_value -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE NumType NumericDataTransition:: -get_value() const { - return _value; -} - -//////////////////////////////////////////////////////////////////// -// Function: NumericDataTransition::set_value_from -// Access: Public, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another NumericDataTransition. -//////////////////////////////////////////////////////////////////// -template -void NumericDataTransition:: -set_value_from(const OnTransition *other) { - const NumericDataTransition *ot; - DCAST_INTO_V(ot, other); - _value = ot->_value; -} - -//////////////////////////////////////////////////////////////////// -// Function: NumericDataTransition::compare_values -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -int NumericDataTransition:: -compare_values(const OnTransition *other) const { - const NumericDataTransition *ot; - DCAST_INTO_R(ot, other, false); - if (_value < ot->_value) { - return -1; - } else if (ot->_value < _value) { - return 1; - } else { - return 0; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NumericDataTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -template -void NumericDataTransition:: -output_value(ostream &out) const { - out << _value; -} - -//////////////////////////////////////////////////////////////////// -// Function: NumericDataTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -template -void NumericDataTransition:: -write_value(ostream &out, int indent_level) const { - indent(out, indent_level) << _value << "\n"; -} diff --git a/panda/src/dgraph/numericDataTransition.h b/panda/src/dgraph/numericDataTransition.h deleted file mode 100644 index 2b250d1eff..0000000000 --- a/panda/src/dgraph/numericDataTransition.h +++ /dev/null @@ -1,75 +0,0 @@ -// Filename: numericDataTransition.h -// Created by: drose (25Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef NUMERICDATATRANSITION_H -#define NUMERICDATATRANSITION_H - -#include "pandabase.h" - -#include "onTransition.h" -#include "indent.h" - -//////////////////////////////////////////////////////////////////// -// Class : NumericDataTransition -// Description : A NumericDataTransition is a special data graph -// attribute that is used to pass around a single -// number. -//////////////////////////////////////////////////////////////////// -template -class NumericDataTransition : public OnTransition { -public: - INLINE NumericDataTransition(NumType value); - INLINE NumericDataTransition(const NumericDataTransition ©); - INLINE void operator = (const NumericDataTransition ©); - -public: - INLINE void set_value(NumType value); - INLINE NumType get_value() const; - -protected: - virtual void set_value_from(const OnTransition *other); - virtual int compare_values(const OnTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - NumType _value; - -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() { - OnTransition::init_type(); - register_type(_type_handle, - string("NumericDataTransition<") + - get_type_handle(NumType).get_name() + ">", - OnTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "numericDataTransition.I" - -#endif diff --git a/panda/src/dgraph/qpdataGraphTraverser.cxx b/panda/src/dgraph/qpdataGraphTraverser.cxx index 9d810b2069..f3fa11cba7 100644 --- a/panda/src/dgraph/qpdataGraphTraverser.cxx +++ b/panda/src/dgraph/qpdataGraphTraverser.cxx @@ -19,6 +19,7 @@ #include "qpdataGraphTraverser.h" #include "qpdataNode.h" #include "config_dgraph.h" +#include "dcast.h" //////////////////////////////////////////////////////////////////// diff --git a/panda/src/dgraph/qpdataNode.cxx b/panda/src/dgraph/qpdataNode.cxx index 67335bb2a4..665a59d228 100644 --- a/panda/src/dgraph/qpdataNode.cxx +++ b/panda/src/dgraph/qpdataNode.cxx @@ -19,6 +19,7 @@ #include "qpdataNode.h" #include "dataNodeTransmit.h" #include "config_dgraph.h" +#include "dcast.h" TypeHandle qpDataNode::_type_handle; diff --git a/panda/src/dgraph/test_dgraph.cxx b/panda/src/dgraph/test_dgraph.cxx deleted file mode 100644 index 42c1c632ad..0000000000 --- a/panda/src/dgraph/test_dgraph.cxx +++ /dev/null @@ -1,197 +0,0 @@ -// Filename: test_dgraph.cxx -// Created by: drose (25Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include - -#include "dataNode.h" -#include "dataRelation.h" -#include "dataGraphTraversal.h" -#include "doubleDataTransition.h" -#include "vec3DataTransition.h" - -#include - - -//////////////////////////////////////////////////////////////////// -// Class : Producer -// Description : Simulates some data-generating device, such as a -// mouse. -//////////////////////////////////////////////////////////////////// - -class Producer : public DataNode { -public: - Producer(const string &name); - - virtual void - transmit_data(AllTransitionsWrapper &data); - - AllTransitionsWrapper _attrib; - PT(DoubleDataTransition) _t; - PT(Vec3DataTransition) _xyz; - - static TypeHandle _t_type; - static TypeHandle _xyz_type; - - -public: - virtual TypeHandle get_type() const { - return get_class_type(); - } - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - DataNode::init_type(); - register_type(_type_handle, "Producer", - DataNode::get_class_type()); - - DoubleDataTransition::init_type(); - register_data_transition(_t_type, "t", - DoubleDataTransition::get_class_type()); - Vec3DataTransition::init_type(); - register_data_transition(_xyz_type, "xyz", - Vec3DataTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - - -TypeHandle Producer::_type_handle; - -TypeHandle Producer::_t_type; -TypeHandle Producer::_xyz_type; - -Producer:: -Producer(const string &name) : DataNode(name) { - _t = new DoubleDataTransition(0.0); - _xyz = new Vec3DataTransition(LPoint3f(0.0f, 0.0f, 0.0f)); - - // Set up our _attrib member to directly reference our data members. - // This way we can simply return a reference to our _attrib member, - // without bothering to construct a new one each time. - _attrib.set_transition(_t_type, _t); - _attrib.set_transition(_xyz_type, _xyz); -} - -void Producer:: -transmit_data(AllTransitionsWrapper &data) { - nout << get_name() << " sending xyz " << *_xyz << " t " << *_t << "\n"; - data = _attrib; -} - - - - -//////////////////////////////////////////////////////////////////// -// Class : Consumer -// Description : Simulates some data-consuming object, such as a mouse -// Tformer. -//////////////////////////////////////////////////////////////////// - -class Consumer : public DataNode { -public: - Consumer(const string &name) : DataNode(name) { } - - virtual void - transmit_data(AllTransitionsWrapper &data); - - - static TypeHandle _s_type; - static TypeHandle _t_type; - static TypeHandle _xyz_type; - - -public: - virtual TypeHandle get_type() const { - return get_class_type(); - } - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - DataNode::init_type(); - register_type(_type_handle, "Consumer", - DataNode::get_class_type()); - - DoubleDataTransition::init_type(); - register_data_transition(_s_type, "s", - DoubleDataTransition::get_class_type()); - register_data_transition(_t_type, "t", - DoubleDataTransition::get_class_type()); - Vec3DataTransition::init_type(); - register_data_transition(_xyz_type, "xyz", - Vec3DataTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - - -TypeHandle Consumer::_type_handle; - -TypeHandle Consumer::_s_type; -TypeHandle Consumer::_t_type; -TypeHandle Consumer::_xyz_type; - -void Consumer:: -transmit_data(AllTransitionsWrapper &data) { - const DoubleDataTransition *s; - const DoubleDataTransition *t; - const Vec3DataTransition *xyz; - - if (get_transition_into(s, data, _s_type) && - get_transition_into(t, data, _t_type) && - get_transition_into(xyz, data, _xyz_type)) { - nout << get_name() << " got xyz " << *xyz << " s " << *s - << " t " << *t << "\n"; - } else { - nout << get_name() << " didn't get all data.\n"; - } -} - - - -//////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// - -int -main() { - Producer::init_type(); - Consumer::init_type(); - PT_NamedNode root = new NamedNode("root"); - - PT(Producer) producer = new Producer("a"); - PT(Consumer) consumer = new Consumer("b"); - new DataRelation(root, producer); - DataRelation *arc1 = new DataRelation(producer, consumer); - - producer->_t->set_value(10.0f); - producer->_xyz->set_value(LPoint3f(1.0f, 2.0f, 3.0f)); - - arc1->set_transition(Producer::_xyz_type, - new Vec3DataTransition(LMatrix4f::scale_mat(2.0f))); - - producer->set_spam_mode(true); - - traverse_data_graph(root); - - return (0); -} diff --git a/panda/src/dgraph/vec3DataTransition.I b/panda/src/dgraph/vec3DataTransition.I deleted file mode 100644 index 8d03bc96bd..0000000000 --- a/panda/src/dgraph/vec3DataTransition.I +++ /dev/null @@ -1,29 +0,0 @@ -// Filename: vec3DataTransition.I -// Created by: drose (27Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: Vec3DataTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE Vec3DataTransition:: -Vec3DataTransition(const LPoint3f &value) : - VectorDataTransition(value) -{ -} - diff --git a/panda/src/dgraph/vec3DataTransition.cxx b/panda/src/dgraph/vec3DataTransition.cxx deleted file mode 100644 index 9c9bb8f9e6..0000000000 --- a/panda/src/dgraph/vec3DataTransition.cxx +++ /dev/null @@ -1,37 +0,0 @@ -// Filename: vec3DataTransition.cxx -// Created by: drose (27Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -#include "vec3DataTransition.h" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif - -TypeHandle Vec3DataTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: Vec3DataTransition::make_copy -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -NodeTransition *Vec3DataTransition:: -make_copy() const { - return new Vec3DataTransition(*this); -} diff --git a/panda/src/dgraph/vec3DataTransition.h b/panda/src/dgraph/vec3DataTransition.h deleted file mode 100644 index 2767123e99..0000000000 --- a/panda/src/dgraph/vec3DataTransition.h +++ /dev/null @@ -1,69 +0,0 @@ -// Filename: vec3DataTransition.h -// Created by: drose (27Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef VEC3DATATRANSITION_H -#define VEC3DATATRANSITION_H - -#include - -#include "vectorDataTransition.h" - -#include - -// We need to define this temporary macro so we can pass a parameter -// containing a comma through the macro. -#define VECTORDATATRANSITION_LPOINT3F VectorDataTransition -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, VECTORDATATRANSITION_LPOINT3F); - -//////////////////////////////////////////////////////////////////// -// Class : Vec3DataTransition -// Description : A VectorDataTransition templated on LPoint3f. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA Vec3DataTransition : - public VectorDataTransition { -public: - INLINE Vec3DataTransition(const LPoint3f &value = LPoint3f(0.0, 0.0, 0.0)); - - virtual NodeTransition *make_copy() const; - -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() { - VectorDataTransition::init_type(); - register_type(_type_handle, "Vec3DataTransition", - VectorDataTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "vec3DataTransition.I" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/dgraph/vec4DataTransition.I b/panda/src/dgraph/vec4DataTransition.I deleted file mode 100644 index f271a966af..0000000000 --- a/panda/src/dgraph/vec4DataTransition.I +++ /dev/null @@ -1,28 +0,0 @@ -// Filename: vec4DataTransition.I -// Created by: jason (03Aug00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: Vec4DataTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE Vec4DataTransition:: -Vec4DataTransition(const LPoint4f &value) : - VectorDataTransition(value) -{ -} diff --git a/panda/src/dgraph/vec4DataTransition.cxx b/panda/src/dgraph/vec4DataTransition.cxx deleted file mode 100644 index 721b927c7b..0000000000 --- a/panda/src/dgraph/vec4DataTransition.cxx +++ /dev/null @@ -1,36 +0,0 @@ -// Filename: vec4DataTransition.cxx -// Created by: jason (03Aug00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "vec4DataTransition.h" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif - -TypeHandle Vec4DataTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: Vec4DataTransition::make_copy -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -NodeTransition *Vec4DataTransition:: -make_copy() const { - return new Vec4DataTransition(*this); -} diff --git a/panda/src/dgraph/vec4DataTransition.h b/panda/src/dgraph/vec4DataTransition.h deleted file mode 100644 index c277e6b94f..0000000000 --- a/panda/src/dgraph/vec4DataTransition.h +++ /dev/null @@ -1,69 +0,0 @@ -// Filename: vec4DataTransition.h -// Created by: jason (03Aug00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef VEC4DATATRANSITION_H -#define VEC4DATATRANSITION_H - -#include - -#include "vectorDataTransition.h" - -#include - -// We need to define this temporary macro so we can pass a parameter -// containing a comma through the macro. -#define VECTORDATATRANSITION_LPOINT4F VectorDataTransition -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, VECTORDATATRANSITION_LPOINT4F); - -//////////////////////////////////////////////////////////////////// -// Class : Vec4DataTransition -// Description : A VectorDataTransition templated on LPoint4f. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA Vec4DataTransition : - public VectorDataTransition { -public: - INLINE Vec4DataTransition(const LPoint4f &value = LPoint4f(0.0, 0.0, 0.0, 0.0)); - - virtual NodeTransition *make_copy() const; - -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() { - VectorDataTransition::init_type(); - register_type(_type_handle, "Vec4DataTransition", - VectorDataTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "vec4DataTransition.I" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/dgraph/vectorDataTransition.I b/panda/src/dgraph/vectorDataTransition.I deleted file mode 100644 index 6980d2bf73..0000000000 --- a/panda/src/dgraph/vectorDataTransition.I +++ /dev/null @@ -1,132 +0,0 @@ -// Filename: vectorDataTransition.I -// Created by: drose (25Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -template -TypeHandle VectorDataTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: VectorDataTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE VectorDataTransition:: -VectorDataTransition(const VecType &value) : - _value(value) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: VectorDataTransition::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE VectorDataTransition:: -VectorDataTransition(const VectorDataTransition ©) : - OnTransition(copy), - _value(copy._value) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: VectorDataTransition::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void VectorDataTransition:: -operator = (const VectorDataTransition ©) { - OnTransition::operator = (copy); - _value = copy._value; -} - -//////////////////////////////////////////////////////////////////// -// Function: VectorDataTransition::set_value -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE void VectorDataTransition:: -set_value(const VecType &value) { - _value = value; - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: VectorDataTransition::get_value -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE const VecType &VectorDataTransition:: -get_value() const { - return _value; -} - -//////////////////////////////////////////////////////////////////// -// Function: VectorDataTransition::set_value_from -// Access: Public, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another VectorDataTransition. -//////////////////////////////////////////////////////////////////// -template -void VectorDataTransition:: -set_value_from(const OnTransition *other) { - const VectorDataTransition *ot; - DCAST_INTO_V(ot, other); - _value = ot->_value; -} - -//////////////////////////////////////////////////////////////////// -// Function: VectorDataTransition::compare_values -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -int VectorDataTransition:: -compare_values(const OnTransition *other) const { - const VectorDataTransition *ot; - DCAST_INTO_R(ot, other, false); - return _value.compare_to(ot->_value); -} - -//////////////////////////////////////////////////////////////////// -// Function: VectorDataTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -template -void VectorDataTransition:: -output_value(ostream &out) const { - out << _value; -} - -//////////////////////////////////////////////////////////////////// -// Function: VectorDataTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -template -void VectorDataTransition:: -write_value(ostream &out, int indent_level) const { - // Oops, this isn't defined for vectors. - // _value.write(out, indent_level); - indent(out, indent_level) << _value << "\n"; -} diff --git a/panda/src/dgraph/vectorDataTransition.h b/panda/src/dgraph/vectorDataTransition.h deleted file mode 100644 index 5d440b27ef..0000000000 --- a/panda/src/dgraph/vectorDataTransition.h +++ /dev/null @@ -1,79 +0,0 @@ -// Filename: vectorDataTransition.h -// Created by: drose (25Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef VECTORDATATRANSITION_H -#define VECTORDATATRANSITION_H - -#include "pandabase.h" - -#include "onTransition.h" -#include "luse.h" -#include "indent.h" -#include "pointerTo.h" - -//////////////////////////////////////////////////////////////////// -// Class : VectorDataTransition -// Description : A VectorDataTransition is a special data graph -// attribute that is used to pass around a complex -// number like a vector or a matrix. Matrices do not -// accumulate; each matrix replaces the one before. -//////////////////////////////////////////////////////////////////// -template -class VectorDataTransition : public OnTransition { -public: - INLINE VectorDataTransition(const VecType &value); - INLINE VectorDataTransition(const VectorDataTransition ©); - INLINE void operator = (const VectorDataTransition ©); - -public: - INLINE void set_value(const VecType &value); - INLINE const VecType &get_value() const; - -protected: - virtual void set_value_from(const OnTransition *other); - virtual int compare_values(const OnTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - VecType _value; - -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() { - OnTransition::init_type(); - do_init_type(VecType); - register_type(_type_handle, - string("VectorDataTransition<") + - get_type_handle(VecType).get_name() + ">", - OnTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "vectorDataTransition.I" - -#endif diff --git a/panda/src/display/Sources.pp b/panda/src/display/Sources.pp index 82beb4d09c..54dd8a630a 100644 --- a/panda/src/display/Sources.pp +++ b/panda/src/display/Sources.pp @@ -4,7 +4,7 @@ #begin lib_target #define TARGET display #define LOCAL_LIBS \ - pgraph putil gsgbase gobj linmath graph mathutil sgraph \ + pgraph putil gsgbase gobj linmath mathutil \ pstatclient #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx diff --git a/panda/src/display/displayRegion.I b/panda/src/display/displayRegion.I index 3eb65bb515..02f4597b8b 100644 --- a/panda/src/display/displayRegion.I +++ b/panda/src/display/displayRegion.I @@ -91,17 +91,6 @@ get_layer() const { return _layer; } -//////////////////////////////////////////////////////////////////// -// Function: DisplayRegion::get_camera -// Access: Public -// Description: Returns the camera associated with this -// DisplayRegion, or NULL if no camera is associated. -//////////////////////////////////////////////////////////////////// -INLINE Camera *DisplayRegion:: -get_camera() const { - return _camera; -} - //////////////////////////////////////////////////////////////////// // Function: DisplayRegion::get_qpcamera // Access: Public @@ -113,35 +102,6 @@ get_qpcamera() const { return _qpcamera; } -//////////////////////////////////////////////////////////////////// -// Function: DisplayRegion::set_cull_frustum -// Access: Public -// Description: Sets the LensNode that will be used to perform -// view-frustum culling for this particular -// DisplayRegion. Normally, this is the same as the -// camera (and is implicitly set when set_camera() is -// called). However, it may be useful to occasionally -// set it to a different node, particularly to enable a -// debugging mode where the culling effectiveness can be -// observed from a third-person perspective. -//////////////////////////////////////////////////////////////////// -INLINE void DisplayRegion:: -set_cull_frustum(LensNode *cull_frustum) { - _cull_frustum = cull_frustum; -} - -//////////////////////////////////////////////////////////////////// -// Function: DisplayRegion::get_cull_frustum -// Access: Public -// Description: Returns the LensNode that will be used to -// perform view-frustum culling for this particular -// DisplayRegion. See set_cull_frustum(). -//////////////////////////////////////////////////////////////////// -INLINE LensNode *DisplayRegion:: -get_cull_frustum() const { - return _cull_frustum; -} - //////////////////////////////////////////////////////////////////// // Function: DisplayRegion::set_active // Access: Public diff --git a/panda/src/display/displayRegion.cxx b/panda/src/display/displayRegion.cxx index c640cc7f85..236282baae 100644 --- a/panda/src/display/displayRegion.cxx +++ b/panda/src/display/displayRegion.cxx @@ -23,6 +23,7 @@ #include "config_display.h" #include "displayRegion.h" #include "qpcamera.h" +#include "dcast.h" //////////////////////////////////////////////////////////////////// @@ -159,31 +160,6 @@ get_pipe() const { return (_layer != (GraphicsLayer *)NULL) ? _layer->get_pipe() : NULL; } -//////////////////////////////////////////////////////////////////// -// Function: DisplayRegion::set_camera -// Access: Public -// Description: Sets the camera that is associated with this -// DisplayRegion. Each DisplayRegion may have zero or -// one cameras associated. (If it has no camera, -// nothing is rendered.) A given camera may be shared -// between multiple DisplayRegions. -//////////////////////////////////////////////////////////////////// -void DisplayRegion:: -set_camera(Camera *camera) { - if (camera != _camera) { - if (_camera != (Camera *)NULL) { - // We need to tell the old camera we're not using him anymore. - _camera->remove_display_region(this); - } - _camera = camera; - if (_camera != (Camera *)NULL) { - // Now tell the new camera we are using him. - _camera->add_display_region(this); - } - } - set_cull_frustum(camera); -} - //////////////////////////////////////////////////////////////////// // Function: DisplayRegion::set_qpcamera // Access: Public diff --git a/panda/src/display/displayRegion.h b/panda/src/display/displayRegion.h index c9d2bdd010..a42478d047 100644 --- a/panda/src/display/displayRegion.h +++ b/panda/src/display/displayRegion.h @@ -21,7 +21,6 @@ #include "pandabase.h" #include "referenceCount.h" -#include "camera.h" #include "qpnodePath.h" #include "cullResult.h" #include "pointerTo.h" @@ -66,15 +65,9 @@ PUBLISHED: GraphicsWindow *get_window() const; GraphicsPipe *get_pipe() const; - void set_camera(Camera *camera); - INLINE Camera *get_camera() const; - void set_qpcamera(const qpNodePath &camera); INLINE const qpNodePath &get_qpcamera() const; - INLINE void set_cull_frustum(LensNode *cull_frustum); - INLINE LensNode *get_cull_frustum() const; - INLINE void set_active(bool active); INLINE bool is_active() const; @@ -103,10 +96,8 @@ protected: int _pt; GraphicsLayer *_layer; - PT(Camera) _camera; qpNodePath _qpcamera; qpCamera *_camera_node; - PT(LensNode) _cull_frustum; bool _active; diff --git a/panda/src/display/geomNodeContext.I b/panda/src/display/geomNodeContext.I index ab10ebd808..dd4703f1d2 100644 --- a/panda/src/display/geomNodeContext.I +++ b/panda/src/display/geomNodeContext.I @@ -23,7 +23,7 @@ // Description: //////////////////////////////////////////////////////////////////// INLINE GeomNodeContext:: -GeomNodeContext(GeomNode *node) : +GeomNodeContext(qpGeomNode *node) : _node(node) { } diff --git a/panda/src/display/geomNodeContext.h b/panda/src/display/geomNodeContext.h index b3a6e1869e..d7842ee9cc 100644 --- a/panda/src/display/geomNodeContext.h +++ b/panda/src/display/geomNodeContext.h @@ -23,7 +23,7 @@ #include "savedContext.h" -class GeomNode; +class qpGeomNode; //////////////////////////////////////////////////////////////////// // Class : GeomNodeContext @@ -44,12 +44,12 @@ class GeomNode; //////////////////////////////////////////////////////////////////// class EXPCL_PANDA GeomNodeContext : public SavedContext { public: - INLINE GeomNodeContext(GeomNode *node); + INLINE GeomNodeContext(qpGeomNode *node); // This cannot be a PT(GeomNode), because the geomNode and the GSG // both own their GeomNodeContexts! That would create a circular // reference count. - GeomNode *_node; + qpGeomNode *_node; public: static TypeHandle get_class_type() { diff --git a/panda/src/display/graphicsStateGuardian.I b/panda/src/display/graphicsStateGuardian.I index c1b9d393eb..4e24bd4760 100644 --- a/panda/src/display/graphicsStateGuardian.I +++ b/panda/src/display/graphicsStateGuardian.I @@ -17,49 +17,6 @@ //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::StateInfo::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE GraphicsStateGuardian::StateInfo:: -StateInfo(TypeHandle type) : - _type(type) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::StateInfo::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE GraphicsStateGuardian::StateInfo:: -StateInfo(const NodeTransitions::value_type &value) : - _type(value.first), _trans(value.second) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::StateInfo::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE GraphicsStateGuardian::StateInfo:: -StateInfo(const NodeTransitionCache::value_type &value) : - _type(value.first), _trans(value.second) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::StateInfo::Ordering operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool GraphicsStateGuardian::StateInfo:: -operator < (const StateInfo &other) const { - return _type < other._type; -} - //////////////////////////////////////////////////////////////////// // Function: GraphicsStateGuardian::LightInfo::Constructor // Access: Public @@ -72,29 +29,6 @@ LightInfo() { } -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::set_render_traverser -// Access: Published -// Description: Sets the traverser that will be used to render the -// scene graph. If this is unset, nothing will be -// rendered. -//////////////////////////////////////////////////////////////////// -INLINE void GraphicsStateGuardian:: -set_render_traverser(RenderTraverser *rt) { - _render_traverser = rt; -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::get_render_traverser -// Access: Published -// Description: Returns the traverser that will be used to render the -// scene graph. -//////////////////////////////////////////////////////////////////// -INLINE RenderTraverser *GraphicsStateGuardian:: -get_render_traverser() const { - return _render_traverser; -} - //////////////////////////////////////////////////////////////////// // Function: GraphicsStateGuardian::is_closed // Access: Public @@ -129,23 +63,6 @@ get_scene() const { return _scene_setup; } -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::set_state -// Access: Public -// Description: Applies the transitions indicated in the state set to -// the current state, and issues the changes to the -// graphics hardware. -// -// The state is taken to be a complete description of -// what the graphics state should be; any transitions -// not mentioned in new_state are implicitly reset to -// their initial values. -//////////////////////////////////////////////////////////////////// -INLINE void GraphicsStateGuardian:: -set_state(const AllTransitionsWrapper &new_state) { - set_state(new_state.get_transitions()); -} - //////////////////////////////////////////////////////////////////// // Function: GraphicsStateGuardian::modify_state // Access: Public @@ -193,46 +110,6 @@ set_transform(const TransformState *transform) { } } -/* -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::get_state -// Access: Public -// Description: Returns the current state of the GSG. This state may -// be saved and used to restore the GSG to its current -// state later. -//////////////////////////////////////////////////////////////////// -INLINE const NodeTransitionCache *GraphicsStateGuardian:: -get_state() const { - return _state; -} -*/ - -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::get_current_camera -// Access: Public -// Description: Returns the node currently being used as the -// camera for this scene, as set by the last call to -// render_subgraph(). This actually might be any kind -// of LensNode, not specifically a Camera node, although -// it will usually be a Camera. -//////////////////////////////////////////////////////////////////// -INLINE LensNode *GraphicsStateGuardian:: -get_current_camera(void) const { - return _current_camera; -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::get_current_root_node -// Access: Public -// Description: Returns the root node of the entire scene graph (not -// the current subgraph) currently being rendered, as -// set by the last call to render_scene(). -//////////////////////////////////////////////////////////////////// -INLINE const Node *GraphicsStateGuardian:: -get_current_root_node(void) const { - return _current_root_node; -} - //////////////////////////////////////////////////////////////////// // Function: GraphicsStateGuardian::get_current_display_region // Access: Public @@ -433,21 +310,3 @@ get_light(int light_id) const { nassertr(light_id >= 0 && light_id < _max_lights, (Light *)NULL); return _light_info[light_id]._light; } - -//////////////////////////////////////////////////////////////////// -// Function: get_attribute_into -// Description: This external template function is handy for -// extracting a transition of a particular type from the -// gsg's state. It works like get_transition_into(). -//////////////////////////////////////////////////////////////////// -template -INLINE bool -get_attribute_into(Transition *&ptr, const GraphicsStateGuardian *gsg) { - NodeTransition *nt = gsg->get_attribute(Transition::get_class_type()); - if (nt == (NodeTransition *)NULL) { - ptr = (Transition *)NULL; - return false; - } - DCAST_INTO_R(ptr, nt, false); - return true; -} diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 2e2828264f..d706208f56 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -34,7 +34,6 @@ #include "ambientLight.h" #include "clockObject.h" -#include "geomNode.h" #include "pStatTimer.h" #include @@ -134,7 +133,6 @@ reset() { _frame_buffer_stack_level = 0; _lens_stack_level = 0; - _state.clear(); _qpstate = RenderState::make_empty(); _transform = TransformState::make_identity(); @@ -165,360 +163,6 @@ reset() { _lighting_enabled_this_frame = false; } -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::modify_state -// Access: Public -// Description: Applies the transitions indicated in the state set to -// the current state, and issues the changes to the -// graphics hardware. -// -// Any transitions not mentioned in new_state are left -// unchanged. -//////////////////////////////////////////////////////////////////// -void GraphicsStateGuardian:: -modify_state(const NodeTransitions &new_state) { - PStatTimer timer(_set_state_pcollector); - - if (gsg_cat.is_debug()) { - gsg_cat.debug() << "\n"; - gsg_cat.debug() - << "Frame " << ClockObject::get_global_clock()->get_frame_count() - << ", setting via NodeTransitions\n"; - new_state.write(gsg_cat.debug(false), 10); - } - - NodeTransitions::const_iterator new_i; - State::iterator current_i; - - new_i = new_state.begin(); - current_i = _state.begin(); - - while (new_i != new_state.end() && current_i != _state.end()) { - TypeHandle new_type = (*new_i).first; - NodeTransition *new_trans = (*new_i).second; - TypeHandle current_type = (*current_i)._type; - PT(NodeTransition) ¤t_trans = (*current_i)._trans; - - if (new_type < current_type) { - // The user requested setting an attribute that we've never set - // before. Issue the command. - - if (new_trans != (NodeTransition *)NULL) { - if (gsg_cat.is_debug()) { - gsg_cat.debug() - << "Issuing new attrib " << *new_trans << "\n"; - } - record_state_change(new_type); - new_trans->issue(this); - - // And store the new value. This is a terribly slow way to - // insert an element into a vector, but it happens only very - // rarely. - current_i = _state.insert(current_i, *new_i); - ++current_i; - } - - ++new_i; - - } else if (current_type < new_type) { - // Here's an attribute that we've set previously, but the user - // didn't specify this time. - ++current_i; - - } else { // current_type == new_type - - if (new_trans == (NodeTransition *)NULL) { - // Here's an attribute that we've set previously, which - // appears in the new list, but is NULL indicating it should - // be removed. - ++current_i; - ++new_i; - - } else if (current_trans == (NodeTransition *)NULL) { - // Here's a new attribute which we had previously set NULL, - // indicating the initial attribute. - if (gsg_cat.is_debug()) { - gsg_cat.debug() - << "Issuing previously NULL attrib " << *new_trans << "\n"; - } - record_state_change(new_type); - new_trans->issue(this); - - // And store the new value. - current_trans = new_trans; - - } else { - // Here's an attribute that we've set previously, and the user - // asked us to set it again. Issue the command only if the new - // attribute is different from that which we'd set before. - if (new_trans != current_trans) { - if (!compare_state_by_pointer && - new_trans->compare_to_ignore_priority(*current_trans) == 0) { - // Oops, different pointers, same value. - - // Get an assignable reference to the source. We modify - // the source in this way in a trivial manner--we replace - // the transition in the source with an identical one--in - // the hopes that this will reduce the need for future - // comparisons. - PT(NodeTransition) &new_trans_assign = - (PT(NodeTransition) &)(*new_i).second; - new_trans_assign = current_trans; - - if (gsg_cat.is_debug()) { - gsg_cat.debug() - << "Updating pointer for attrib " << *new_trans << "\n"; - } - - } else { - if (gsg_cat.is_debug()) { - gsg_cat.debug() - << "Reissuing attrib " << *new_trans << "\n"; - gsg_cat.debug() - << "Previous was " << *current_trans << "\n"; - } - record_state_change(new_type); - new_trans->issue(this); - - // And store the new value. - current_trans = new_trans; - } - - } else if (gsg_cat.is_debug()) { - gsg_cat.debug() - << "Not reissuing unchanged attrib " << *new_trans << "\n"; - } - - ++current_i; - ++new_i; - } - } - } - - while (new_i != new_state.end()) { - // The user requested setting an attribute that we've never set - // before. Issue the command. - TypeHandle new_type = (*new_i).first; - NodeTransition *new_trans = (*new_i).second; - - if (new_trans != (NodeTransition *)NULL) { - if (gsg_cat.is_debug()) { - gsg_cat.debug() - << "Issuing new attrib " << *new_trans << "\n"; - } - record_state_change(new_type); - - new_trans->issue(this); - - // And store the new value. - _state.push_back(*new_i); - } - ++new_i; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::set_state -// Access: Public -// Description: Applies the transitions indicated in the state set to -// the current state, and issues the changes to the -// graphics hardware. -// -// The state is taken to be a complete description of -// what the graphics state should be; any transitions -// not mentioned in new_state are implicitly reset to -// their initial values. -//////////////////////////////////////////////////////////////////// -void GraphicsStateGuardian:: -set_state(const NodeTransitionCache &new_state) { - PStatTimer timer(_set_state_pcollector); - - if (gsg_cat.is_debug()) { - gsg_cat.debug() << "\n"; - gsg_cat.debug() - << "Frame " << ClockObject::get_global_clock()->get_frame_count() - << ", setting to\n"; - new_state.write(gsg_cat.debug(false), 10); - } - - NodeTransitionCache::const_iterator new_i; - State::iterator current_i; - - new_i = new_state.begin(); - current_i = _state.begin(); - - while (new_i != new_state.end() && current_i != _state.end()) { - TypeHandle new_type = (*new_i).first; - NodeTransition *new_trans = (*new_i).second.get_trans(); - TypeHandle current_type = (*current_i)._type; - PT(NodeTransition) ¤t_trans = (*current_i)._trans; - - if (new_type < current_type) { - // The user requested setting an attribute that we've never set - // before. Issue the command. - - if (new_trans != (NodeTransition *)NULL) { - if (gsg_cat.is_debug()) { - gsg_cat.debug() - << "Issuing new attrib " << *new_trans << "\n"; - } - record_state_change(new_type); - new_trans->issue(this); - - // And store the new value. This is a terribly slow way to - // insert an element into a vector, but it happens only very - // rarely. - current_i = _state.insert(current_i, *new_i); - ++current_i; - } - - ++new_i; - - } else if (current_type < new_type) { - // Here's an attribute that we've set previously, but the user - // didn't specify this time. - - if (current_trans != (NodeTransition *)NULL) { - // This attribute should now get the default initial value. - - if (gsg_cat.is_debug()) { - gsg_cat.debug() - << "Unissuing attrib " << *current_trans - << " (previously set, not now)\n"; - } - record_state_change(current_type); - - PT(NodeTransition) initial = current_trans->make_initial(); - initial->issue(this); - - current_trans = NULL; - } - - ++current_i; - - } else { // current_type == new_type - - if (new_trans == (NodeTransition *)NULL) { - // Here's an attribute that we've set previously, which - // appears in the new list, but is NULL indicating it should - // be removed. - if (current_trans != (NodeTransition *)NULL) { - if (gsg_cat.is_debug()) { - gsg_cat.debug() - << "Unissuing attrib " << *current_trans - << " (previously set, now NULL)\n"; - } - record_state_change(current_type); - - // Issue the initial attribute before clearing the state. - PT(NodeTransition) initial = current_trans->make_initial(); - initial->issue(this); - - current_trans = NULL; - } - - } else if (current_trans == (NodeTransition *)NULL) { - // Here's a new attribute which we had previously set NULL, - // indicating the initial attribute. - if (gsg_cat.is_debug()) { - gsg_cat.debug() - << "Issuing previously NULL attrib " << *new_trans << "\n"; - } - record_state_change(new_type); - new_trans->issue(this); - - // And store the new value. - current_trans = new_trans; - - } else { - // Here's an attribute that we've set previously, and the user - // asked us to set it again. Issue the command only if the new - // attribute is different from that which we'd set before. - if (new_trans != current_trans) { - if (!compare_state_by_pointer && - new_trans->compare_to_ignore_priority(*current_trans) == 0) { - // Oops, different pointers, same value. - - // Get an assignable reference to the source. We modify - // the source in this way in a trivial manner--we replace - // the transition in the source with an identical one--in - // the hopes that this will reduce the need for future - // comparisons. - NodeTransitionCacheEntry &new_trans_assign = - (NodeTransitionCacheEntry &)(*new_i).second; - new_trans_assign.set_trans(current_trans); - - } else { - if (gsg_cat.is_debug()) { - gsg_cat.debug() - << "Reissuing attrib " << *new_trans << "\n"; - gsg_cat.debug() - << "Previous was " << *current_trans << "\n"; - } - record_state_change(new_type); - new_trans->issue(this); - - // And store the new value. - current_trans = new_trans; - } - - } else if (gsg_cat.is_debug()) { - gsg_cat.debug() - << "Not reissuing unchanged attrib " << *new_trans << "\n"; - } - } - - ++current_i; - ++new_i; - } - } - - while (current_i != _state.end()) { - // Here's an attribute that we've set previously, but the user - // didn't specify this time. - TypeHandle current_type = (*current_i)._type; - PT(NodeTransition) ¤t_trans = (*current_i)._trans; - - if (current_trans != (NodeTransition *)NULL) { - if (gsg_cat.is_debug()) { - gsg_cat.debug() - << "Unissuing attrib " << *current_trans - << " (previously set, end of list)\n"; - } - record_state_change(current_type); - - // This attribute should now get the default initial value. - PT(NodeTransition) initial = current_trans->make_initial(); - initial->issue(this); - - current_trans = NULL; - } - - ++current_i; - } - - while (new_i != new_state.end()) { - // The user requested setting an attribute that we've never set - // before. Issue the command. - TypeHandle new_type = (*new_i).first; - NodeTransition *new_trans = (*new_i).second.get_trans(); - - if (new_trans != (NodeTransition *)NULL) { - if (gsg_cat.is_debug()) { - gsg_cat.debug() - << "Issuing new attrib " << *new_trans << "\n"; - } - record_state_change(new_type); - - new_trans->issue(this); - - // And store the new value. - _state.push_back(*new_i); - } - ++new_i; - } -} - //////////////////////////////////////////////////////////////////// // Function: GraphicsStateGuardian::get_render_buffer // Access: Public @@ -652,54 +296,6 @@ release_all_geoms() { nassertv(_prepared_geom_nodes.empty()); } -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::clear_attribute -// Access: Public -// Description: Explicitly clear the indicated attribute, specified -// by the TypeHandle of its associated transition. If -// the attribute is not set already, this does nothing; -// if it is set, it resets it to its default value. -//////////////////////////////////////////////////////////////////// -void GraphicsStateGuardian:: -clear_attribute(TypeHandle type) { - // Look for the transition in our state vector. We'll use STL's - // binary search functions to do this. - - State::iterator si = - lower_bound(_state.begin(), _state.end(), StateInfo(type)); - - if (si != _state.end() && (*si)._type == type) { - // We found it. - PT(NodeTransition) ¤t_trans = (*si)._trans; - - if (current_trans != (NodeTransition *)NULL) { - // The state was already set; get the initial value and reset it. - PT(NodeTransition) initial = current_trans->make_initial(); - initial->issue(this); - current_trans = (NodeTransition *)NULL; - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::get_attribute -// Access: Public -// Description: Returns the NodeTransition from the current state -// associated with the indicated type, or NULL if there -// is no such transition set. -//////////////////////////////////////////////////////////////////// -NodeTransition *GraphicsStateGuardian:: -get_attribute(TypeHandle type) const { - State::const_iterator si = - lower_bound(_state.begin(), _state.end(), StateInfo(type)); - - if (si != _state.end() && (*si)._type == type) { - return (*si)._trans; - } - - return (NodeTransition *)NULL; -} - //////////////////////////////////////////////////////////////////// // Function: GraphicsStateGuardian::prepare_texture // Access: Public, Virtual @@ -746,7 +342,7 @@ release_texture(TextureContext *) { // contents of the node. //////////////////////////////////////////////////////////////////// GeomNodeContext *GraphicsStateGuardian:: -prepare_geom_node(GeomNode *) { +prepare_geom_node(qpGeomNode *) { return (GeomNodeContext *)NULL; } @@ -757,11 +353,14 @@ prepare_geom_node(GeomNode *) { // prepare_geom_node(). //////////////////////////////////////////////////////////////////// void GraphicsStateGuardian:: -draw_geom_node(GeomNode *node, GeomNodeContext *) { +draw_geom_node(qpGeomNode *node, const RenderState *state, + GeomNodeContext *) { +#if 0 // temporarily disabled until ported to new scene graph int num_geoms = node->get_num_geoms(); for (int i = 0; i < num_geoms; i++) { node->get_geom(i)->draw(this); } +#endif // temporarily disabled until ported to new scene graph } //////////////////////////////////////////////////////////////////// @@ -937,37 +536,6 @@ wants_colors() const { return _vertex_colors_enabled; } -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::begin_decal -// Access: Public, Virtual -// Description: This will be called to initiate decaling mode. It is -// passed the pointer to the GeomNode that will be the -// destination of the decals, which it is expected that -// the GSG will render normally; subsequent geometry -// rendered up until the next call of end_decal() should -// be rendered as decals of the base_geom. -// -// The attributes wrapper is the current state as of the -// base geometry node. It may or may not be modified by -// the GSG to reflect whatever rendering state is -// necessary to render the decals properly. -//////////////////////////////////////////////////////////////////// -void GraphicsStateGuardian:: -begin_decal(GeomNode *base_geom, AllTransitionsWrapper &attrib) { - base_geom->draw(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphicsStateGuardian::end_decal -// Access: Public, Virtual -// Description: This will be called to terminate decaling mode. It -// is passed the same base_geom that was passed to -// begin_decal(). -//////////////////////////////////////////////////////////////////// -void GraphicsStateGuardian:: -end_decal(GeomNode *) { -} - //////////////////////////////////////////////////////////////////// // Function: GraphicsStateGuardian::depth_offset_decals // Access: Public, Virtual diff --git a/panda/src/display/graphicsStateGuardian.h b/panda/src/display/graphicsStateGuardian.h index 36f00bdf60..43bd54fca3 100644 --- a/panda/src/display/graphicsStateGuardian.h +++ b/panda/src/display/graphicsStateGuardian.h @@ -28,14 +28,10 @@ #include "graphicsStateGuardianBase.h" #include "sceneSetup.h" -#include "nodeTransition.h" -#include "nodeTransitionCache.h" #include "luse.h" #include "coordinateSystem.h" #include "factory.h" -#include "renderTraverser.h" #include "pStatCollector.h" -#include "allTransitionsWrapper.h" #include "transformState.h" #include "renderState.h" #include "light.h" @@ -46,8 +42,6 @@ #include "notify.h" #include "pvector.h" -class AllTransitionsWrapper; - //////////////////////////////////////////////////////////////////// // Class : GraphicsStateGuardian // Description : Encapsulates all the communication with a particular @@ -67,9 +61,6 @@ public: virtual ~GraphicsStateGuardian(); PUBLISHED: - INLINE void set_render_traverser(RenderTraverser *rt); - INLINE RenderTraverser *get_render_traverser() const; - virtual void set_color_clear_value(const Colorf& value); virtual void set_depth_clear_value(const float value); virtual void set_stencil_clear_value(const bool value); @@ -91,9 +82,6 @@ PUBLISHED: void release_all_textures(); void release_all_geoms(); - void clear_attribute(TypeHandle type); - NodeTransition *get_attribute(TypeHandle type) const; - public: INLINE bool is_closed() const; @@ -104,8 +92,9 @@ public: virtual void apply_texture(TextureContext *tc); virtual void release_texture(TextureContext *tc); - virtual GeomNodeContext *prepare_geom_node(GeomNode *node); - virtual void draw_geom_node(GeomNode *node, GeomNodeContext *gnc); + virtual GeomNodeContext *prepare_geom_node(qpGeomNode *node); + virtual void draw_geom_node(qpGeomNode *node, const RenderState *state, + GeomNodeContext *gnc); virtual void release_geom_node(GeomNodeContext *gnc); virtual GeomContext *prepare_geom(Geom *geom); @@ -121,15 +110,6 @@ public: virtual void prepare_display_region()=0; virtual bool prepare_lens(); - virtual void render_frame()=0; - virtual void render_scene(Node *root, LensNode *projnode)=0; - virtual void render_subgraph(RenderTraverser *traverser, - Node *subgraph, LensNode *projnode, - const AllTransitionsWrapper &net_trans)=0; - virtual void render_subgraph(RenderTraverser *traverser, - Node *subgraph, - const AllTransitionsWrapper &net_trans)=0; - INLINE void enable_normals(bool val) { _normals_enabled = val; } virtual void begin_frame(); @@ -142,9 +122,6 @@ public: virtual bool wants_texcoords() const; virtual bool wants_colors() const; - virtual void begin_decal(GeomNode *base_geom, AllTransitionsWrapper &attrib); - virtual void end_decal(GeomNode *base_geom); - virtual bool depth_offset_decals(); virtual CPT(RenderState) begin_decal_base_first(); virtual CPT(RenderState) begin_decal_nested(); @@ -153,22 +130,12 @@ public: virtual void reset(); - // *** QP - void modify_state(const NodeTransitions &new_state); - // void modify_state(const NodeTransitionCache &new_state); - void set_state(const NodeTransitionCache &new_state); - INLINE void set_state(const AllTransitionsWrapper &new_state); - // INLINE const NodeTransitionCache *get_state() const; - INLINE void modify_state(const RenderState *state); INLINE void set_state(const RenderState *state); INLINE void set_transform(const TransformState *transform); RenderBuffer get_render_buffer(int buffer_type); - INLINE LensNode *get_current_camera(void) const ; - INLINE const Node* get_current_root_node(void) const; - INLINE const DisplayRegion *get_current_display_region(void) const; INLINE const Lens *get_current_lens() const; @@ -186,8 +153,6 @@ public: INLINE CoordinateSystem get_coordinate_system() const; virtual CoordinateSystem get_internal_coordinate_system() const; - INLINE void clear_cached_state(void) { _state.clear(); }; - virtual void issue_transform(const TransformState *transform); virtual void issue_color_scale(const ColorScaleAttrib *attrib); virtual void issue_color(const ColorAttrib *attrib); @@ -252,19 +217,6 @@ protected: protected: PT(SceneSetup) _scene_setup; - class StateInfo { - public: - INLINE StateInfo(TypeHandle type); - INLINE StateInfo(const NodeTransitions::value_type &value); - INLINE StateInfo(const NodeTransitionCache::value_type &value); - INLINE bool operator < (const StateInfo &other) const; - - TypeHandle _type; - PT(NodeTransition) _trans; - }; - typedef pvector State; - State _state; - CPT(RenderState) _qpstate; CPT(TransformState) _transform; @@ -280,13 +232,8 @@ protected: int _lens_stack_level; GraphicsWindow *_win; - PT(RenderTraverser) _render_traverser; - // These must be set by render_scene(). - Node *_current_root_node; - LensNode *_current_camera; CPT(DisplayRegion) _current_display_region; - CPT(Lens) _current_lens; // This is used by wants_normals() @@ -417,10 +364,6 @@ private: friend class GraphicsWindow; }; -template -INLINE bool -get_attribute_into(Transition *&ptr, const GraphicsStateGuardian *gsg); - #include "graphicsStateGuardian.I" #endif diff --git a/panda/src/display/graphicsWindow.I b/panda/src/display/graphicsWindow.I index a51d69f488..135b275f31 100644 --- a/panda/src/display/graphicsWindow.I +++ b/panda/src/display/graphicsWindow.I @@ -417,20 +417,6 @@ get_button_event(int device) { return _input_devices[device].get_button_event(); } -//////////////////////////////////////////////////////////////////// -// Function: GraphicsWindow::render_and_update -// Access: Published -// Description: Renders the scene associated with the window and -// updates the window. -//////////////////////////////////////////////////////////////////// -INLINE void GraphicsWindow:: -render_and_update() { - if (_gsg != (GraphicsStateGuardian *)NULL) { - _gsg->render_frame(); - } - update(); -} - //////////////////////////////////////////////////////////////////// // Function: GraphicsWindow::win_display_regions_changed // Access: Public diff --git a/panda/src/display/graphicsWindow.cxx b/panda/src/display/graphicsWindow.cxx index 2aa2faf035..07903ae835 100644 --- a/panda/src/display/graphicsWindow.cxx +++ b/panda/src/display/graphicsWindow.cxx @@ -411,49 +411,6 @@ register_idle_function(GraphicsWindow::vfn f) { _idle_function = f; } -//////////////////////////////////////////////////////////////////// -// Function: GraphicsWindow::main_loop -// Access: Public, Virtual -// Description: Yields the application over to the window entirely -// for rendering. The window will wait for keyboard and -// mouse input, and repeatedly call update() on itself. -// For some kinds of window API's (notably glut), this -// is the only way to use the window--see -// supports_update(). -// -// This function does not return. -//////////////////////////////////////////////////////////////////// -void GraphicsWindow:: -main_loop() { - while (true) { - update(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphicsWindow::supports_update -// Access: Public, Virtual -// Description: Returns true if this particular kind of -// GraphicsWindow supports use of the update() function -// to update the graphics one frame at a time, so that -// the window does not need to be the program's main -// loop. Returns false if the only way to update the -// window is to call main_loop(). -//////////////////////////////////////////////////////////////////// -bool GraphicsWindow:: -supports_update() const { - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphicsWindow::update -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GraphicsWindow:: -update() { -} - //////////////////////////////////////////////////////////////////// // Function: GraphicsWindow::begin_frame // Access: Public, Virtual diff --git a/panda/src/display/graphicsWindow.h b/panda/src/display/graphicsWindow.h index 27ecdaf6d5..7e19ea453b 100644 --- a/panda/src/display/graphicsWindow.h +++ b/panda/src/display/graphicsWindow.h @@ -193,12 +193,6 @@ PUBLISHED: virtual void register_draw_function(GraphicsWindow::vfn); virtual void register_idle_function(GraphicsWindow::vfn); - // Old-style scene graph rendering (will be phased out eventually). - virtual void main_loop(); - virtual bool supports_update() const; - virtual void update(); - INLINE void render_and_update(); - public: virtual void begin_frame(); void clear(); diff --git a/panda/src/distort/Sources.pp b/panda/src/distort/Sources.pp index 7af9977e1d..f3a5279cd2 100644 --- a/panda/src/distort/Sources.pp +++ b/panda/src/distort/Sources.pp @@ -4,7 +4,7 @@ #begin lib_target #define TARGET distort #define LOCAL_LIBS \ - sgraphutil sgraph sgattrib gobj linmath + display pgraph gobj linmath #define COMBINED_SOURCES $[TARGET]_composite1.cxx diff --git a/panda/src/distort/nonlinearImager.I b/panda/src/distort/nonlinearImager.I index 2d5f4b28ea..a7f8a8b813 100644 --- a/panda/src/distort/nonlinearImager.I +++ b/panda/src/distort/nonlinearImager.I @@ -26,7 +26,7 @@ // establish a relative coordinate system with them. //////////////////////////////////////////////////////////////////// INLINE void NonlinearImager:: -set_camera(LensNode *camera) { +set_camera(qpLensNode *camera) { _camera = camera; _stale = true; } @@ -37,7 +37,7 @@ set_camera(LensNode *camera) { // Description: Returns the virtual camera that will be used to // view the various ProjectionScreens. //////////////////////////////////////////////////////////////////// -INLINE LensNode *NonlinearImager:: +INLINE qpLensNode *NonlinearImager:: get_camera() const { return _camera; } @@ -49,7 +49,7 @@ get_camera() const { // scene graph, which is used to render all of the // screen meshes. //////////////////////////////////////////////////////////////////// -INLINE Node *NonlinearImager:: +INLINE qpNodePath NonlinearImager:: get_internal_scene() const { - return _internal_scene_top; + return _internal_scene; } diff --git a/panda/src/distort/nonlinearImager.cxx b/panda/src/distort/nonlinearImager.cxx index 5be3cf933a..fab92b4f26 100644 --- a/panda/src/distort/nonlinearImager.cxx +++ b/panda/src/distort/nonlinearImager.cxx @@ -20,11 +20,9 @@ #include "config_distort.h" #include "graphicsStateGuardian.h" -#include "textureTransition.h" #include "matrixLens.h" -#include "renderRelation.h" #include "graphicsWindow.h" -#include "cullFaceTransition.h" +#include "dcast.h" //////////////////////////////////////////////////////////////////// // Function: NonlinearImager::Constructor @@ -39,21 +37,19 @@ NonlinearImager:: NonlinearImager(DisplayRegion *dr) { _dr = dr; - _internal_camera = new Camera("NonlinearImager"); + _internal_camera = new qpCamera("NonlinearImager"); _internal_camera->set_lens(new MatrixLens); - _internal_scene_top = new NamedNode("NonlinearImager"); - _internal_scene = new NamedNode("screens"); - _internal_camera->set_scene(_internal_scene_top); - _dr->set_camera(_internal_camera); + _internal_scene_node = new PandaNode("screens"); + _internal_scene = qpNodePath(_internal_scene_node); + _internal_camera->set_scene(_internal_scene); - RenderRelation *top_arc = - new RenderRelation(_internal_scene_top, _internal_scene); + qpNodePath camera_np = _internal_scene.attach_new_node(_internal_camera); + _dr->set_qpcamera(camera_np); // Enable face culling on the wireframe mesh. This will help us to // cull out invalid polygons that result from vertices crossing a // singularity (for instance, at the back of a fisheye lens). - CullFaceTransition *cfa = new CullFaceTransition(CullFaceProperty::M_cull_clockwise); - top_arc->set_transition(cfa); + _internal_scene.set_two_sided(0); _stale = true; } @@ -65,8 +61,8 @@ NonlinearImager(DisplayRegion *dr) { //////////////////////////////////////////////////////////////////// NonlinearImager:: ~NonlinearImager() { - _internal_camera->set_scene((Node *)NULL); - _dr->set_camera((Camera *)NULL); + _internal_camera->set_scene(qpNodePath()); + _dr->set_qpcamera(qpNodePath()); remove_all_screens(); } @@ -100,7 +96,6 @@ add_screen(ProjectionScreen *screen) { _screens.push_back(Screen()); Screen &new_screen = _screens.back(); new_screen._screen = screen; - new_screen._mesh_arc = (NodeRelation *)NULL; new_screen._texture = (Texture *)NULL; new_screen._tex_width = 256; new_screen._tex_height = 256; @@ -110,9 +105,9 @@ add_screen(ProjectionScreen *screen) { // If the LensNode associated with the ProjectionScreen is an actual // Camera, then it has a scene associated. Otherwise, the user will // have to specify the scene later. - LensNode *projector = screen->get_projector(); - if (projector->is_of_type(Camera::get_class_type())) { - Camera *camera = DCAST(Camera, projector); + qpLensNode *projector = screen->get_projector(); + if (projector->is_of_type(qpCamera::get_class_type())) { + qpCamera *camera = DCAST(qpCamera, projector); new_screen._scene = camera->get_scene(); } @@ -148,9 +143,7 @@ void NonlinearImager:: remove_screen(int index) { nassertv_always(index >= 0 && index < (int)_screens.size()); Screen &screen = _screens[index]; - if (screen._mesh_arc != (NodeRelation *)NULL) { - remove_arc(screen._mesh_arc); - } + screen._mesh.remove_node(); _screens.erase(_screens.begin() + index); } @@ -164,9 +157,7 @@ remove_all_screens() { Screens::iterator si; for (si = _screens.begin(); si != _screens.end(); ++si) { Screen &screen = (*si); - if (screen._mesh_arc != (NodeRelation *)NULL) { - remove_arc(screen._mesh_arc); - } + screen._mesh.remove_node(); } _screens.clear(); @@ -221,7 +212,7 @@ set_size(int index, int width, int height) { // screen. //////////////////////////////////////////////////////////////////// void NonlinearImager:: -set_source(int index, LensNode *source, Node *scene) { +set_source(int index, qpLensNode *source, const qpNodePath &scene) { nassertv(index >= 0 && index < (int)_screens.size()); _screens[index]._source = source; _screens[index]._scene = scene; @@ -239,7 +230,7 @@ set_source(int index, LensNode *source, Node *scene) { // Camera itself. //////////////////////////////////////////////////////////////////// void NonlinearImager:: -set_source(int index, Camera *source) { +set_source(int index, qpCamera *source) { nassertv(index >= 0 && index < (int)_screens.size()); _screens[index]._source = source; _screens[index]._scene = source->get_scene(); @@ -260,10 +251,7 @@ set_active(int index, bool active) { if (!active) { Screen &screen = _screens[index]; // If we've just made this screen inactive, remove its mesh. - if (screen._mesh_arc != (NodeRelation *)NULL) { - remove_arc(screen._mesh_arc); - screen._mesh_arc = (NodeRelation *)NULL; - } + screen._mesh.remove_node(); screen._texture.clear(); } else { // If we've just made it active, it needs to be recomputed. @@ -296,7 +284,7 @@ recompute() { } } - if (_camera != (LensNode *)NULL && _camera->get_lens() != (Lens *)NULL) { + if (_camera != (qpLensNode *)NULL && _camera->get_lens() != (Lens *)NULL) { _camera_lens_change = _camera->get_lens()->get_last_change(); } _stale = false; @@ -331,7 +319,7 @@ render() { //////////////////////////////////////////////////////////////////// void NonlinearImager:: recompute_if_stale() { - if (_camera != (LensNode *)NULL && + if (_camera != (qpLensNode *)NULL && _camera->get_lens() != (Lens *)NULL) { UpdateSeq lens_change = _camera->get_lens()->get_last_change(); if (_stale || lens_change != _camera_lens_change) { @@ -359,18 +347,15 @@ recompute_if_stale() { //////////////////////////////////////////////////////////////////// void NonlinearImager:: recompute_screen(NonlinearImager::Screen &screen) { - if (screen._mesh_arc != (NodeRelation *)NULL) { - remove_arc(screen._mesh_arc); - screen._mesh_arc = (NodeRelation *)NULL; - } + screen._mesh.remove_node(); screen._texture.clear(); - if (_camera == (LensNode *)NULL || !screen._active) { + if (_camera == (qpLensNode *)NULL || !screen._active) { // Not much we can do without a camera. return; } - PT_Node mesh = screen._screen->make_flat_mesh(_camera); - screen._mesh_arc = new RenderRelation(_internal_scene, mesh); + PT(PandaNode) mesh = screen._screen->make_flat_mesh(_camera); + screen._mesh = _internal_scene.attach_new_node(mesh); PT(Texture) texture = new Texture; texture->set_minfilter(Texture::FT_linear); @@ -381,7 +366,7 @@ recompute_screen(NonlinearImager::Screen &screen) { texture->_pbuffer->set_ysize(screen._tex_height); screen._texture = texture; - screen._mesh_arc->set_transition(new TextureTransition(texture)); + screen._mesh.set_texture(texture); screen._last_screen = screen._screen->get_last_screen(); } @@ -393,20 +378,23 @@ recompute_screen(NonlinearImager::Screen &screen) { //////////////////////////////////////////////////////////////////// void NonlinearImager:: render_screen(NonlinearImager::Screen &screen) { - if (screen._source == (LensNode *)NULL) { + if (screen._source == (qpLensNode *)NULL) { distort_cat.error() << "No source lens specified for screen " << screen._screen->get_name() << "\n"; return; } - if (screen._scene == (Node *)NULL) { + if (screen._scene.is_empty()) { distort_cat.error() << "No scene specified for screen " << screen._screen->get_name() << "\n"; return; } + // Got to update this to new scene graph. + + /* GraphicsStateGuardian *gsg = _dr->get_window()->get_gsg(); // Make a display region of the proper size and clear it to prepare for @@ -428,4 +416,5 @@ render_screen(NonlinearImager::Screen &screen) { // Restore the original display region. gsg->pop_display_region(old_dr); + */ } diff --git a/panda/src/distort/nonlinearImager.h b/panda/src/distort/nonlinearImager.h index 815d3beb49..dce63f65f8 100644 --- a/panda/src/distort/nonlinearImager.h +++ b/panda/src/distort/nonlinearImager.h @@ -23,8 +23,11 @@ #include "projectionScreen.h" #include "displayRegion.h" -#include "camera.h" +#include "qpcamera.h" #include "texture.h" +#include "pandaNode.h" +#include "qpnodePath.h" +#include "pointerTo.h" #include "pvector.h" //////////////////////////////////////////////////////////////////// @@ -58,16 +61,16 @@ PUBLISHED: int get_num_screens() const; ProjectionScreen *get_screen(int index) const; void set_size(int index, int width, int height); - void set_source(int index, LensNode *source, Node *scene); - void set_source(int index, Camera *source); + void set_source(int index, qpLensNode *source, const qpNodePath &scene); + void set_source(int index, qpCamera *source); void set_active(int index, bool active); bool get_active(int index) const; - INLINE void set_camera(LensNode *camera); - INLINE LensNode *get_camera() const; + INLINE void set_camera(qpLensNode *camera); + INLINE qpLensNode *get_camera() const; - INLINE Node *get_internal_scene() const; + INLINE qpNodePath get_internal_scene() const; void recompute(); void render(); @@ -76,10 +79,10 @@ private: class Screen { public: PT(ProjectionScreen) _screen; - NodeRelation *_mesh_arc; + qpNodePath _mesh; PT(Texture) _texture; - PT(LensNode) _source; - PT_Node _scene; + PT(qpLensNode) _source; + qpNodePath _scene; int _tex_width, _tex_height; UpdateSeq _last_screen; bool _active; @@ -94,11 +97,11 @@ private: typedef pvector Screens; Screens _screens; - PT(LensNode) _camera; + PT(qpLensNode) _camera; - PT(Camera) _internal_camera; - PT_Node _internal_scene_top; - PT_Node _internal_scene; + PT(qpCamera) _internal_camera; + qpNodePath _internal_scene; + PT(PandaNode) _internal_scene_node; bool _stale; UpdateSeq _camera_lens_change; diff --git a/panda/src/distort/projectionScreen.I b/panda/src/distort/projectionScreen.I index f2366d79bb..228173ddc5 100644 --- a/panda/src/distort/projectionScreen.I +++ b/panda/src/distort/projectionScreen.I @@ -28,7 +28,7 @@ // geometry within the ProjectionScreen. //////////////////////////////////////////////////////////////////// INLINE void ProjectionScreen:: -set_projector(LensNode *projector) { +set_projector(qpLensNode *projector) { _projector = projector; _stale = true; } @@ -41,7 +41,7 @@ set_projector(LensNode *projector) { // projector for this screen, or NULL if no LensNode is // associated. //////////////////////////////////////////////////////////////////// -INLINE LensNode *ProjectionScreen:: +INLINE qpLensNode *ProjectionScreen:: get_projector() const { return _projector; } diff --git a/panda/src/distort/projectionScreen.cxx b/panda/src/distort/projectionScreen.cxx index 8333f12379..9f00cf3ca7 100644 --- a/panda/src/distort/projectionScreen.cxx +++ b/panda/src/distort/projectionScreen.cxx @@ -17,12 +17,10 @@ //////////////////////////////////////////////////////////////////// #include "projectionScreen.h" -#include "geomNode.h" +#include "qpgeomNode.h" #include "geom.h" #include "geomTristrip.h" -#include "renderRelation.h" -#include "transformTransition.h" -#include "get_rel_pos.h" +#include "transformState.h" TypeHandle ProjectionScreen::_type_handle; @@ -32,7 +30,7 @@ TypeHandle ProjectionScreen::_type_handle; // Description: //////////////////////////////////////////////////////////////////// ProjectionScreen:: -ProjectionScreen(const string &name) : NamedNode(name) +ProjectionScreen(const string &name) : PandaNode(name) { _vignette_on = false; _vignette_color.set(0.0f, 0.0f, 0.0f, 1.0f); @@ -52,12 +50,12 @@ ProjectionScreen:: //////////////////////////////////////////////////////////////////// // Function: ProjectionScreen::Copy Constructor -// Access: Public +// Access: Protected // Description: //////////////////////////////////////////////////////////////////// ProjectionScreen:: ProjectionScreen(const ProjectionScreen ©) : - NamedNode(copy), + PandaNode(copy), _projector(copy._projector), _vignette_on(copy._vignette_on), _vignette_color(copy._vignette_color), @@ -67,33 +65,20 @@ ProjectionScreen(const ProjectionScreen ©) : _stale = true; } -//////////////////////////////////////////////////////////////////// -// Function: ProjectionScreen::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void ProjectionScreen:: -operator = (const ProjectionScreen ©) { - NamedNode::operator = (copy); - _projector = copy._projector; - _vignette_on = copy._vignette_on; - _vignette_color = copy._vignette_color; - _frame_color = copy._frame_color; -} - //////////////////////////////////////////////////////////////////// // Function: ProjectionScreen::make_copy -// Access: Public, Virtual +// Access: Protected, Virtual // Description: Returns a newly-allocated Node that is a shallow copy // of this one. It will be a different Node pointer, // but its internal data may or may not be shared with // that of the original Node. //////////////////////////////////////////////////////////////////// -Node *ProjectionScreen:: +PandaNode *ProjectionScreen:: make_copy() const { return new ProjectionScreen(*this); } +/* //////////////////////////////////////////////////////////////////// // Function: ProjectionScreen::app_traverse // Access: Public, Virtual @@ -104,6 +89,7 @@ void ProjectionScreen:: app_traverse(const ArcChain &) { recompute_if_stale(); } +*/ //////////////////////////////////////////////////////////////////// // Function: ProjectionScreen::generate_screen @@ -125,15 +111,17 @@ app_traverse(const ArcChain &) { // respectively; distance represents the approximate // distance of the screen from the lens center. //////////////////////////////////////////////////////////////////// -PT(GeomNode) ProjectionScreen:: -generate_screen(LensNode *projector, const string &screen_name, +PT(qpGeomNode) ProjectionScreen:: +generate_screen(qpLensNode *projector, const string &screen_name, int num_x_verts, int num_y_verts, float distance) { - nassertr(projector != (LensNode *)NULL, NULL); + nassertr(projector != (qpLensNode *)NULL, NULL); nassertr(projector->get_lens() != NULL, NULL); // First, get the relative coordinate space of the projector. LMatrix4f rel_mat; - get_rel_mat(projector, this, rel_mat); + qpNodePath projector_np(projector); + qpNodePath this_np(this); + rel_mat = projector_np.get_mat(this_np); // Now compute all the vertices for the screen. These are arranged // in order from left to right and bottom to top. @@ -204,7 +192,7 @@ generate_screen(LensNode *projector, const string &screen_name, geom->set_colors(colors, G_OVERALL); // Now create a GeomNode to hold this mesh. - PT(GeomNode) geom_node = new GeomNode(screen_name); + PT(qpGeomNode) geom_node = new qpGeomNode(screen_name); geom_node->add_geom(geom); _stale = true; @@ -220,18 +208,16 @@ generate_screen(LensNode *projector, const string &screen_name, // generate_screen(). //////////////////////////////////////////////////////////////////// void ProjectionScreen:: -regenerate_screen(LensNode *projector, const string &screen_name, +regenerate_screen(qpLensNode *projector, const string &screen_name, int num_x_verts, int num_y_verts, float distance) { // First, remove all existing children. - while (get_num_children(RenderRelation::get_class_type()) > 0) { - remove_arc(get_child(RenderRelation::get_class_type(), 0)); - } + remove_all_children(); // And attach a new child. - PT(GeomNode) geom_node = + PT(qpGeomNode) geom_node = generate_screen(projector, screen_name, num_x_verts, num_y_verts, distance); - new RenderRelation(this, geom_node); + add_child(geom_node); } //////////////////////////////////////////////////////////////////// @@ -253,15 +239,15 @@ regenerate_screen(LensNode *projector, const string &screen_name, // to caller to parent it somewhere or store it so that // it does not get dereferenced and deleted. //////////////////////////////////////////////////////////////////// -PT_Node ProjectionScreen:: -make_flat_mesh(LensNode *camera) { - nassertr(camera != (LensNode *)NULL, NULL); +PT(PandaNode) ProjectionScreen:: +make_flat_mesh(qpLensNode *camera) { + nassertr(camera != (qpLensNode *)NULL, NULL); nassertr(camera->get_lens() != (Lens *)NULL, NULL); // First, ensure the UV's are up-to-date. recompute_if_stale(); - PT_Node top = new NamedNode(get_name()); + PT(PandaNode) top = new PandaNode(get_name()); LMatrix4f rel_mat; bool computed_rel_mat = false; @@ -285,7 +271,7 @@ make_flat_mesh(LensNode *camera) { //////////////////////////////////////////////////////////////////// void ProjectionScreen:: recompute() { - if (_projector != (LensNode *)NULL && + if (_projector != (qpLensNode *)NULL && _projector->get_lens() != (Lens *)NULL) { _colors.clear(); _colors.push_back(_vignette_color); @@ -310,7 +296,7 @@ recompute() { //////////////////////////////////////////////////////////////////// void ProjectionScreen:: recompute_if_stale() { - if (_projector != (LensNode *)NULL && + if (_projector != (qpLensNode *)NULL && _projector->get_lens() != (Lens *)NULL) { UpdateSeq lens_change = _projector->get_lens()->get_last_change(); if (_stale || lens_change != _projector_lens_change) { @@ -318,8 +304,9 @@ recompute_if_stale() { } else { // Get the relative transform to ensure it hasn't changed. - LMatrix4f top_mat; - get_rel_mat(this, _projector, top_mat); + qpNodePath this_np(this); + qpNodePath projector_np(_projector); + const LMatrix4f &top_mat = this_np.get_mat(projector_np); if (!_rel_top_mat.almost_equal(top_mat)) { _rel_top_mat = top_mat; _computed_rel_top_mat = true; @@ -338,27 +325,30 @@ recompute_if_stale() { // encountered, a new relative matrix is computed. //////////////////////////////////////////////////////////////////// void ProjectionScreen:: -recompute_node(Node *node, LMatrix4f &rel_mat, bool &computed_rel_mat) { - if (node->is_of_type(GeomNode::get_class_type())) { - recompute_geom_node(DCAST(GeomNode, node), rel_mat, computed_rel_mat); +recompute_node(PandaNode *node, LMatrix4f &rel_mat, bool &computed_rel_mat) { + if (node->is_geom_node()) { + recompute_geom_node(DCAST(qpGeomNode, node), rel_mat, computed_rel_mat); } // Now recurse on children. - int num_children = node->get_num_children(RenderRelation::get_class_type()); + int num_children = node->get_num_children(); for (int i = 0; i < num_children; i++) { - NodeRelation *arc = node->get_child(RenderRelation::get_class_type(), i); + PandaNode *child = node->get_child(i); + /* + This needs to be ported to new scene graph. if (arc->has_transition(TransformTransition::get_class_type())) { // This arc has a transform; therefore, we must recompute the // relative matrix from this point. LMatrix4f new_rel_mat; bool computed_new_rel_mat = false; recompute_node(arc->get_child(), new_rel_mat, computed_new_rel_mat); - } else { - // This arc has no transform, so we can use the same transform - // space from before. - recompute_node(arc->get_child(), rel_mat, computed_rel_mat); - } + } else + */ + + // This arc has no transform, so we can use the same transform + // space from before. + recompute_node(child, rel_mat, computed_rel_mat); } } @@ -368,19 +358,20 @@ recompute_node(Node *node, LMatrix4f &rel_mat, bool &computed_rel_mat) { // Description: Recomputes the UV's just for the indicated GeomNode. //////////////////////////////////////////////////////////////////// void ProjectionScreen:: -recompute_geom_node(GeomNode *node, LMatrix4f &rel_mat, bool &computed_rel_mat) { +recompute_geom_node(qpGeomNode *node, LMatrix4f &rel_mat, + bool &computed_rel_mat) { if (!computed_rel_mat) { // All right, time to compute the matrix. - get_rel_mat(node, _projector, rel_mat); + qpNodePath node_np(node); + qpNodePath projector_np(_projector); + rel_mat = node_np.get_mat(projector_np); computed_rel_mat = true; } int num_geoms = node->get_num_geoms(); for (int i = 0; i < num_geoms; i++) { - dDrawable *drawable = node->get_geom(i); - if (drawable->is_of_type(Geom::get_class_type())) { - recompute_geom(DCAST(Geom, drawable), rel_mat); - } + Geom *geom = node->get_geom(i); + recompute_geom(geom, rel_mat); } } @@ -440,8 +431,8 @@ recompute_geom(Geom *geom, const LMatrix4f &rel_mat) { // as seen from the indicated camera. Returns the newly // created, arc, or NULL if no arc was created. //////////////////////////////////////////////////////////////////// -NodeRelation *ProjectionScreen:: -make_mesh_node(Node *result_parent, Node *node, LensNode *camera, +PandaNode *ProjectionScreen:: +make_mesh_node(PandaNode *result_parent, PandaNode *node, qpLensNode *camera, LMatrix4f &rel_mat, bool &computed_rel_mat) { if (!node->safe_to_flatten()) { // If we can't safely flatten this node, ignore it (and all of its @@ -449,19 +440,19 @@ make_mesh_node(Node *result_parent, Node *node, LensNode *camera, return NULL; } - PT(Node) new_node; - if (node->is_of_type(GeomNode::get_class_type())) { + PT(PandaNode) new_node; + if (node->is_geom_node()) { new_node = - make_mesh_geom_node(DCAST(GeomNode, node), camera, + make_mesh_geom_node(DCAST(qpGeomNode, node), camera, rel_mat, computed_rel_mat); } else { new_node = node->make_copy(); } // Now attach the new node to the result. - RenderRelation *arc = new RenderRelation(result_parent, new_node); + result_parent->add_child(new_node); make_mesh_children(new_node, node, camera, rel_mat, computed_rel_mat); - return arc; + return new_node; } //////////////////////////////////////////////////////////////////// @@ -471,13 +462,14 @@ make_mesh_node(Node *result_parent, Node *node, LensNode *camera, // node, calling make_mesh_node() on each one. //////////////////////////////////////////////////////////////////// void ProjectionScreen:: -make_mesh_children(Node *new_node, Node *node, LensNode *camera, +make_mesh_children(PandaNode *new_node, PandaNode *node, qpLensNode *camera, LMatrix4f &rel_mat, bool &computed_rel_mat) { - int num_children = node->get_num_children(RenderRelation::get_class_type()); + int num_children = node->get_num_children(); for (int i = 0; i < num_children; i++) { - NodeRelation *arc = node->get_child(RenderRelation::get_class_type(), i); - NodeRelation *new_arc; + PandaNode *child = node->get_child(i); + PandaNode *new_child; + /* if (arc->has_transition(TransformTransition::get_class_type())) { // This arc has a transform; therefore, we must recompute the // relative matrix from this point. @@ -485,17 +477,17 @@ make_mesh_children(Node *new_node, Node *node, LensNode *camera, bool computed_new_rel_mat = false; new_arc = make_mesh_node(new_node, arc->get_child(), camera, new_rel_mat, computed_new_rel_mat); - } else { - // This arc has no transform, so we can use the same transform - // space from before. - new_arc = make_mesh_node(new_node, arc->get_child(), camera, - rel_mat, computed_rel_mat); - } + } else + */ - // Copy all of the attributes (except TransformTransition) to the + // This arc has no transform, so we can use the same transform + // space from before. + new_child = make_mesh_node(new_node, child, camera, + rel_mat, computed_rel_mat); + + // Copy all of the render state (except TransformState) to the // new arc. - new_arc->copy_transitions_from(arc); - new_arc->clear_transition(TransformTransition::get_class_type()); + new_child->set_state(child->get_state()); } } @@ -506,27 +498,26 @@ make_mesh_children(Node *new_node, Node *node, LensNode *camera, // flattened into two dimensions as seen by the // indicated camera. //////////////////////////////////////////////////////////////////// -PT(GeomNode) ProjectionScreen:: -make_mesh_geom_node(GeomNode *node, LensNode *camera, +PT(qpGeomNode) ProjectionScreen:: +make_mesh_geom_node(qpGeomNode *node, qpLensNode *camera, LMatrix4f &rel_mat, bool &computed_rel_mat) { - PT(GeomNode) new_node = new GeomNode; - new_node->set_name(node->get_name()); + PT(qpGeomNode) new_node = new qpGeomNode(node->get_name()); if (!computed_rel_mat) { // All right, time to compute the matrix. - get_rel_mat(node, camera, rel_mat); + qpNodePath node_np(node); + qpNodePath camera_np(camera); + rel_mat = node_np.get_mat(camera_np); computed_rel_mat = true; } int num_geoms = node->get_num_geoms(); for (int i = 0; i < num_geoms; i++) { - dDrawable *drawable = node->get_geom(i); - if (drawable->is_of_type(Geom::get_class_type())) { - PT(dDrawable) new_drawable = - make_mesh_geom(DCAST(Geom, drawable), camera->get_lens(), rel_mat); - if (new_drawable != (dDrawable *)NULL) { - new_node->add_geom(new_drawable); - } + Geom *geom = node->get_geom(i); + PT(Geom) new_geom = + make_mesh_geom(geom, camera->get_lens(), rel_mat); + if (new_geom != (Geom *)NULL) { + new_node->add_geom(new_geom, node->get_geom_state(i)); } } @@ -541,10 +532,10 @@ make_mesh_geom_node(GeomNode *node, LensNode *camera, // indicated lens. Any triangle in the original mesh // that involves an unprojectable vertex is eliminated. //////////////////////////////////////////////////////////////////// -PT(dDrawable) ProjectionScreen:: +PT(Geom) ProjectionScreen:: make_mesh_geom(Geom *geom, Lens *lens, LMatrix4f &rel_mat) { Geom *new_geom = geom->make_copy(); - PT(dDrawable) result = new_geom; + PT(Geom) result = new_geom; PTA_Vertexf coords; GeomBindType bind; diff --git a/panda/src/distort/projectionScreen.h b/panda/src/distort/projectionScreen.h index b69b749398..7c2cd0445c 100644 --- a/panda/src/distort/projectionScreen.h +++ b/panda/src/distort/projectionScreen.h @@ -21,9 +21,9 @@ #include "pandabase.h" -#include "namedNode.h" -#include "lensNode.h" -#include "geomNode.h" +#include "pandaNode.h" +#include "qplensNode.h" +#include "qpgeomNode.h" class Geom; @@ -45,27 +45,26 @@ class Geom; // using the Lens interface, including fisheye and // cylindrical lenses. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDAFX ProjectionScreen : public NamedNode { +class EXPCL_PANDAFX ProjectionScreen : public PandaNode { PUBLISHED: ProjectionScreen(const string &name = ""); virtual ~ProjectionScreen(); -public: +protected: ProjectionScreen(const ProjectionScreen ©); - void operator = (const ProjectionScreen ©); - - virtual Node *make_copy() const; - virtual void app_traverse(const ArcChain &chain); + virtual PandaNode *make_copy() const; PUBLISHED: - INLINE void set_projector(LensNode *projector); - INLINE LensNode *get_projector() const; + INLINE void set_projector(qpLensNode *projector); + INLINE qpLensNode *get_projector() const; - PT(GeomNode) generate_screen(LensNode *projector, const string &screen_name, - int num_x_verts, int num_y_verts, float distance); - void regenerate_screen(LensNode *projector, const string &screen_name, + PT(qpGeomNode) generate_screen(qpLensNode *projector, + const string &screen_name, + int num_x_verts, int num_y_verts, + float distance); + void regenerate_screen(qpLensNode *projector, const string &screen_name, int num_x_verts, int num_y_verts, float distance); - PT_Node make_flat_mesh(LensNode *camera); + PT(PandaNode) make_flat_mesh(qpLensNode *camera); INLINE void set_vignette_on(bool vignette_on); INLINE bool get_vignette_on() const; @@ -82,21 +81,22 @@ public: private: void recompute_if_stale(); - void recompute_node(Node *node, LMatrix4f &rel_mat, bool &computed_rel_mat); - void recompute_geom_node(GeomNode *node, LMatrix4f &rel_mat, bool &computed_rel_mat); + void recompute_node(PandaNode *node, LMatrix4f &rel_mat, bool &computed_rel_mat); + void recompute_geom_node(qpGeomNode *node, LMatrix4f &rel_mat, bool &computed_rel_mat); void recompute_geom(Geom *geom, const LMatrix4f &rel_mat); - NodeRelation * - make_mesh_node(Node *result_parent, Node *node, LensNode *camera, + PandaNode * + make_mesh_node(PandaNode *result_parent, PandaNode *node, qpLensNode *camera, LMatrix4f &rel_mat, bool &computed_rel_mat); - void make_mesh_children(Node *new_node, Node *node, LensNode *camera, + void make_mesh_children(PandaNode *new_node, PandaNode *node, + qpLensNode *camera, LMatrix4f &rel_mat, bool &computed_rel_mat); - PT(GeomNode) make_mesh_geom_node(GeomNode *node, LensNode *camera, - LMatrix4f &rel_mat, bool &computed_rel_mat); - PT(dDrawable) make_mesh_geom(Geom *geom, Lens *lens, LMatrix4f &rel_mat); + PT(qpGeomNode) make_mesh_geom_node(qpGeomNode *node, qpLensNode *camera, + LMatrix4f &rel_mat, bool &computed_rel_mat); + PT(Geom) make_mesh_geom(Geom *geom, Lens *lens, LMatrix4f &rel_mat); - PT(LensNode) _projector; + PT(qpLensNode) _projector; bool _vignette_on; Colorf _vignette_color; Colorf _frame_color; @@ -113,9 +113,9 @@ public: return _type_handle; } static void init_type() { - NamedNode::init_type(); + PandaNode::init_type(); register_type(_type_handle, "ProjectionScreen", - NamedNode::get_class_type()); + PandaNode::get_class_type()); } virtual TypeHandle get_type() const { return get_class_type(); diff --git a/panda/src/dxgsg/Sources.pp b/panda/src/dxgsg/Sources.pp index 621a68cd64..433a38283c 100644 --- a/panda/src/dxgsg/Sources.pp +++ b/panda/src/dxgsg/Sources.pp @@ -8,8 +8,8 @@ #define TARGET dxgsg #define LOCAL_LIBS \ - cull gsgmisc gsgbase gobj sgattrib sgraphutil graph display \ - putil linmath sgraph mathutil pnmimage event + gsgmisc gsgbase gobj display \ + putil linmath mathutil pnmimage event #define COMBINED_SOURCES $[TARGET]_composite1.cxx diff --git a/panda/src/dxgsg/dxGeomNodeContext.I b/panda/src/dxgsg/dxGeomNodeContext.I index 8d30be3c3b..dc8f11889f 100644 --- a/panda/src/dxgsg/dxGeomNodeContext.I +++ b/panda/src/dxgsg/dxGeomNodeContext.I @@ -23,7 +23,7 @@ // Description: //////////////////////////////////////////////////////////////////// INLINE DXGeomNodeContext:: -DXGeomNodeContext(GeomNode *node) : GeomNodeContext(node) +DXGeomNodeContext(qpGeomNode *node) : GeomNodeContext(node) { _num_verts = 0; _pVB = NULL; diff --git a/panda/src/dxgsg/dxGeomNodeContext.h b/panda/src/dxgsg/dxGeomNodeContext.h index 93e2295b3b..0550a31b4e 100644 --- a/panda/src/dxgsg/dxGeomNodeContext.h +++ b/panda/src/dxgsg/dxGeomNodeContext.h @@ -21,12 +21,10 @@ #include "dxgsgbase.h" -#include -#include +#include "geomNodeContext.h" +#include "qpgeomNode.h" #include "pvector.h" - - typedef struct { DWORD nVerts; D3DPRIMITIVETYPE primtype; @@ -38,12 +36,12 @@ typedef struct { //////////////////////////////////////////////////////////////////// class EXPCL_PANDADX DXGeomNodeContext : public GeomNodeContext { public: - INLINE DXGeomNodeContext(GeomNode *node); + INLINE DXGeomNodeContext(qpGeomNode *node); ~DXGeomNodeContext(); // A list of the dynamic Geoms within the GeomNode; these aren't // part of the above display list and must be drawn separately - typedef pvector Geoms; + typedef pvector< PT(Geom) > Geoms; Geoms _cached_geoms,_other_geoms; // VB's are already reference-counted by D3D, no need to make separate panda object to do that diff --git a/panda/src/dxgsg/dxGraphicsStateGuardian.cxx b/panda/src/dxgsg/dxGraphicsStateGuardian.cxx index 508562ff4f..5df948097e 100644 --- a/panda/src/dxgsg/dxGraphicsStateGuardian.cxx +++ b/panda/src/dxgsg/dxGraphicsStateGuardian.cxx @@ -19,11 +19,7 @@ #include "dxGraphicsStateGuardian.h" #include "config_dxgsg.h" -#include "directRenderTraverser.h" -#include "cullTraverser.h" #include "displayRegion.h" -#include "lensNode.h" -#include "camera.h" #include "renderBuffer.h" #include "geom.h" #include "geomSphere.h" @@ -31,30 +27,11 @@ #include "graphicsWindow.h" #include "graphicsChannel.h" #include "lens.h" -#include "get_rel_pos.h" #include "perspectiveLens.h" #include "ambientLight.h" #include "directionalLight.h" #include "pointLight.h" #include "spotlight.h" -#include "transformTransition.h" -#include "colorTransition.h" -#include "textureTransition.h" -#include "renderModeTransition.h" -#include "materialTransition.h" -#include "colorBlendTransition.h" -#include "colorMaskTransition.h" -#include "texMatrixTransition.h" -#include "texGenTransition.h" -#include "textureApplyTransition.h" -#include "clipPlaneTransition.h" -#include "transparencyTransition.h" -#include "fogTransition.h" -#include "linesmoothTransition.h" -#include "depthTestTransition.h" -#include "depthWriteTransition.h" -#include "cullFaceTransition.h" -#include "stencilTransition.h" #include "textureAttrib.h" #include "lightAttrib.h" #include "cullFaceAttrib.h" @@ -394,13 +371,6 @@ DXGraphicsStateGuardian(GraphicsWindow *win) : GraphicsStateGuardian(win) { ZeroMemory(&matIdentity,sizeof(D3DMATRIX)); matIdentity._11 = matIdentity._22 = matIdentity._33 = matIdentity._44 = 1.0f; - // Create a default RenderTraverser. - if (dx_cull_traversal) { - _render_traverser = new CullTraverser(this, RenderRelation::get_class_type()); - } else { - _render_traverser = new DirectRenderTraverser(this, RenderRelation::get_class_type()); - } - // All implementations have the following buffers. _buffer_mask = (RenderBuffer::T_color | RenderBuffer::T_depth | @@ -456,7 +426,8 @@ free_dxgsg_objects(void) { free_pointers(); // dont want a full reset of gsg, just a state clear - GraphicsStateGuardian::clear_cached_state(); // want gsg to pass all state settings through + set_state(RenderState::make_empty()); + // want gsg to pass all state settings through // we need to reset our internal state guards right here because dx_init() should be called after this, // which resets all of them to our defaults, and syncs them with the D3DRENDERSTATE @@ -525,9 +496,6 @@ dx_init( void) { ZeroMemory(&_lmodel_ambient,sizeof(Colorf)); scrn.pD3DDevice->SetRenderState( D3DRENDERSTATE_AMBIENT, 0x0); - - _clip_plane_enabled = (bool *)NULL; - _cur_clip_plane_enabled = (bool *)NULL; scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPLANEENABLE , 0x0); scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CLIPPING, true); @@ -757,7 +725,7 @@ dx_init( void) { enable_line_smooth(false); // enable_multisample(true); - _current_fill_mode = RenderModeProperty::M_filled; + _current_fill_mode = RenderModeAttrib::M_filled; scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID); scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1); @@ -773,24 +741,13 @@ dx_init( void) { if(dx_auto_normalize_lighting) scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_NORMALIZENORMALS, true); - // Set up the clip plane id map - _max_clip_planes = D3DMAXUSERCLIPPLANES; - _available_clip_plane_ids = PTA(PlaneNode*)::empty_array(_max_clip_planes); - _clip_plane_enabled = new bool[_max_clip_planes]; - _cur_clip_plane_enabled = new bool[_max_clip_planes]; - int i; - for (i = 0; i < _max_clip_planes; i++) { - _available_clip_plane_ids[i] = NULL; - _clip_plane_enabled[i] = false; - } - // initial clip rect SetRect(&scrn.clip_rect, 0,0,0,0); // no clip rect set // must do SetTSS here because redundant states are filtered out by our code based on current values above, so // initial conditions must be correct - _CurTexBlendMode = TextureApplyProperty::M_modulate; + _CurTexBlendMode = TextureApplyAttrib::M_modulate; SetTextureBlendMode(_CurTexBlendMode,FALSE); _texturing_enabled = false; scrn.pD3DDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_DISABLE); // disables texturing @@ -877,11 +834,13 @@ dx_init( void) { DDPIXELFORMAT *pCurPixFmt; + int i; #ifdef USE_TEXFMTVEC - for(i=0,pCurPixFmt=&scrn.TexPixFmts[scrn.TexPixFmts.size()-1];idwRGBBitCount==16) && #ifdef MAKE_FPSMETER_TRANSPARENT (pCurPixFmt->dwFlags & DDPF_ALPHAPIXELS) && @@ -892,18 +851,19 @@ dx_init( void) { #endif ) // emacs gets confused if we don't match parens accurately. break; - } + } #ifdef USE_TEXFMTVEC - if(i>=scrn.TexPixFmts.size()) { + if(i>=scrn.TexPixFmts.size()) #else - if(i>=_cNumTexPixFmts) { + if(i>=_cNumTexPixFmts) #endif + { // if this fails, no 4-4-4-4 fmt, need code to use 5-5-5-1 dxgsg_cat.error() << "couldnt find 4-4-4-4 tex fmt for fpsmeter font!\n"; _bShowFPSMeter = false; return; - } + } memcpy(&ddsd.ddpfPixelFormat,pCurPixFmt,sizeof(DDPIXELFORMAT)); @@ -972,15 +932,13 @@ dx_init( void) { } // Make sure the DX state matches all of our initial attribute states. - PT(DepthTestTransition) dta = new DepthTestTransition; - PT(DepthWriteTransition) dwa = new DepthWriteTransition; - PT(CullFaceTransition) cfa = new CullFaceTransition; - PT(TextureTransition) ta = new TextureTransition; - + CPT(RenderAttrib) dta = DepthTestAttrib::make(DepthTestAttrib::M_less); + CPT(RenderAttrib) dwa = DepthWriteAttrib::make(DepthWriteAttrib::M_on); + CPT(RenderAttrib) cfa = CullFaceAttrib::make(CullFaceAttrib::M_cull_clockwise); + dta->issue(this); dwa->issue(this); cfa->issue(this); - ta->issue(this); // no curtextcontext, this does nothing. dx should already be properly inited above anyway } //////////////////////////////////////////////////////////////////// @@ -1177,83 +1135,6 @@ void INLINE TestDrawPrimFailure(DP_Type dptype,HRESULT hr,LPDIRECTDRAW7 pDD,DWOR #define TestDrawPrimFailure(a,b,c,nVerts,nTris) CountDPs(nVerts,nTris); #endif -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::render_frame -// Access: Public, Virtual -// Description: Renders an entire frame, including all display -// regions within the frame, and includes any necessary -// pre- and post-processing like swapping buffers. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -render_frame() { - if (!_dx_ready) - return; - - _win->begin_frame(); - -#ifdef GSG_VERBOSE - dxgsg_cat.debug() - << "begin frame --------------------------------------------" << endl; -#endif - - _decal_level = 0; - - if (_clear_buffer_type != 0) { - // First, clear the entire window. - #ifndef NO_MULTIPLE_DISPLAY_REGIONS - PT(DisplayRegion) win_dr = _win->make_scratch_display_region(_win->get_width(), _win->get_height()); - clear(get_render_buffer(_clear_buffer_type), win_dr); - #else - clear(get_render_buffer(_clear_buffer_type)); - #endif - } - -#if 0 - int max_channel_index = _win->get_max_channel_index(); - for (int c = 0; c < max_channel_index; c++) { - if (_win->is_channel_defined(c)) { -#endif - - // only 1 channel on dx currently - assert(_win->get_max_channel_index()==1); - assert(_win->is_channel_defined(0)); - - if(_panda_gfx_channel->is_active()) { - // Now render each of our layers in order. - - int num_layers = _panda_gfx_channel->get_num_layers(); - for (int l = 0; l < num_layers; l++) { - GraphicsLayer *layer = _panda_gfx_channel->get_layer(l); - if (layer->is_active()) { - int num_drs = layer->get_num_drs(); - for (int d = 0; d < num_drs; d++) { - DisplayRegion *dr = layer->get_dr(d); - Camera *cam = dr->get_camera(); - - // For each display region, render from the camera's view. - if (dr->is_active() && cam != (Camera *)NULL && - cam->is_active() && cam->get_scene() != (Node *)NULL) { - DisplayRegionStack old_dr = push_display_region(dr); - prepare_display_region(); - render_scene(cam->get_scene(), cam); - pop_display_region(old_dr); - } - } - } // if (layer->is_active()) - } - } // if (chan->is_active()) -#if 0 - } - } // for (int c = 0; c < max_channel_index; c++) -#endif - -#ifdef GSG_VERBOSE - dxgsg_cat.debug() << "end frame ----------------------------------------------" << endl; -#endif - - _win->end_frame(); -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::report_texmgr_stats // Access: Protected @@ -1371,147 +1252,6 @@ report_texmgr_stats() { #endif } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::render_scene -// Access: Public, Virtual -// Description: Renders an entire scene, from the root node of the -// scene graph, as seen from a particular LensNode -// and with a given initial state. This initial state -// may be modified during rendering. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -render_scene(Node *root, LensNode *projnode) { -#ifdef GSG_VERBOSE - _pass_number = 0; - dxgsg_cat.debug() - << "begin scene - - - - - - - - - - - - - - - - - - - - - - - - -" - << endl; -#endif - _current_root_node = root; - - render_subgraph(_render_traverser, root, projnode, - AllTransitionsWrapper()); - -#ifdef GSG_VERBOSE - dxgsg_cat.debug() - << "done scene - - - - - - - - - - - - - - - - - - - - - - - - -" - << endl; -#endif -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::render_subgraph -// Access: Public, Virtual -// Description: Renders a subgraph of the scene graph as seen from a -// given lens node, and with a particular initial -// state. This state may be modified by the render -// process. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -render_subgraph(RenderTraverser *traverser, - Node *subgraph, LensNode *projnode, - const AllTransitionsWrapper &net_trans) { - LensNode *old_camera = _current_camera; - _current_camera = projnode; - LMatrix4f old_projection_mat = _current_projection_mat; - - Lens *lens = projnode->get_lens(); - const LMatrix4f &projection_mat = lens->get_projection_mat(); - - // d3d is left-handed coord system - _current_projection_mat = - LMatrix4f::convert_mat(CS_yup_left, lens->get_coordinate_system()) * - projection_mat; - _projection_mat_stack_count++; - -#if 0 - dxgsg_cat.spam() << "cur projection matrix: " << _current_projection_mat <<"\n"; -#endif - -#ifdef _DEBUG - { - static bool bPrintedMsg=false; - - if((!bPrintedMsg) && !IS_NEARLY_EQUAL(projection_mat(2,3),1.0f)) { - bPrintedMsg=true; - dxgsg_cat.debug() << "non w-compliant render_subgraph projection matrix [2][3] should be 1.0, instead is: " << projection_mat(2,3) << endl; - dxgsg_cat.debug() << "cur projection matrix: " << projection_mat << endl; - } - - // note: a projection matrix that does not have a [3][4] value of 1.0f is - // not w-compliant and could cause problems with fog - - } -#endif - - HRESULT hr; - - // BUGBUG: could we avoid doing this every frame if projmat doesnt change? - // We load the projection matrix directly. - hr = scrn.pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, - (LPD3DMATRIX) _current_projection_mat.get_data()); - - // We infer the modelview matrix by doing a wrt on the projection - // node. - LMatrix4f modelview_mat; - get_rel_mat(subgraph, _current_camera, modelview_mat); //needs reversal from glgsg, probably due D3D LH coordsys -// get_rel_mat(_current_camera, subgraph, modelview_mat); - - if (_coordinate_system != CS_yup_left) { - // Now we build the coordinate system conversion into the - // modelview matrix (as described in the paragraph above). - modelview_mat = modelview_mat * - LMatrix4f::convert_mat(_coordinate_system, CS_yup_left); - } - - // The modelview matrix will be loaded as each geometry is - // encountered. So we set the supplied modelview matrix as an - // initial value instead of loading it now. - AllTransitionsWrapper sub_trans = net_trans; - sub_trans.set_transition(new TransformTransition(modelview_mat)); - - render_subgraph(traverser, subgraph, sub_trans); - - _current_camera = old_camera; - _current_projection_mat = old_projection_mat; - _projection_mat_stack_count--; - - - // We must now restore the projection matrix from before. We could - // do a push/pop matrix if we were using D3DX - if (_projection_mat_stack_count > 0) - hr =scrn.pD3DDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, - (LPD3DMATRIX) _current_projection_mat.get_data()); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::render_subgraph -// Access: Public, Virtual -// Description: Renders a subgraph of the scene graph as seen from the -// current lens node, and with a particular -// initial state. This state may be modified during the -// render process. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -render_subgraph(RenderTraverser *traverser, Node *subgraph, - const AllTransitionsWrapper &net_trans) { -#ifdef GSG_VERBOSE - dxgsg_cat.debug() - << "begin subgraph (pass " << ++_pass_number - << ") - - - - - - - - - - - - - - - - - - - - - - - - -" << endl; -#endif - - nassertv(traverser != (RenderTraverser *)NULL); - traverser->traverse(subgraph, net_trans); - -#ifdef GSG_VERBOSE - dxgsg_cat.debug() - << "end subgraph (pass " << _pass_number - << ") - - - - - - - - - - - - - - - - - - - - - - - - -" - << endl; -#endif -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::add_to_FVFBuf // Access: Private @@ -2225,13 +1965,8 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { DO_PSTATS_STUFF(_vertices_other_pcollector.add_level(nprims)); - D3DMATRIX OldD3DWorldMatrix; - scrn.pD3DDevice->GetTransform(D3DTRANSFORMSTATE_WORLD, &OldD3DWorldMatrix); - bool bReEnableDither=false; - scrn.pD3DDevice->GetTransform(D3DTRANSFORMSTATE_WORLD, &OldD3DWorldMatrix); - Geom::VertexIterator vi = geom->make_vertex_iterator(); Geom::ColorIterator ci = geom->make_color_iterator(); @@ -2244,37 +1979,22 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { Texture *tex = geom->get_texture(); if(tex !=NULL) { - - // set up the texture-rendering state - NodeTransitions state; - - // this sets up texturing. Could just set the renderstates directly, but this is a little cleaner - TextureTransition *ta = new TextureTransition(tex); - state.set_transition(ta); - - TextureApplyTransition *taa = new TextureApplyTransition(TextureApplyProperty::M_modulate); - state.set_transition(taa); - - modify_state(state); - - tex_xsize = tex->_pbuffer->get_xsize(); - tex_ysize = tex->_pbuffer->get_ysize(); + // set up the texture-rendering state + modify_state(RenderState::make + (TextureAttrib::make(tex), + TextureApplyAttrib::make(TextureApplyAttrib::M_modulate))); + tex_xsize = tex->_pbuffer->get_xsize(); + tex_ysize = tex->_pbuffer->get_ysize(); } // save the modelview matrix - LMatrix4f modelview_mat; + const LMatrix4f &modelview_mat = _transform->get_mat(); - const TransformTransition *ctatt; - if (!get_attribute_into(ctatt, this)) - modelview_mat = LMatrix4f::ident_mat(); - else - modelview_mat = ctatt->get_matrix(); + // We don't need to mess with the aspect ratio, since we are now + // using the default projection matrix, which has the right aspect + // ratio built in. - // get the camera information - float aspect_ratio = - get_current_camera()->get_lens()->get_aspect_ratio(); - - // null the world xform, so sprites are orthog to scrn (but not necessarily camera pnt unless they lie along z-axis) + // null the world xform, so sprites are orthog to scrn scrn.pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &matIdentity); // only need to change _WORLD xform, _VIEW xform is Identity @@ -2292,10 +2012,11 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { bool alpha = false; if (!geom->get_alpha_disable()) { - // figure out if alpha's enabled (if not, no reason to sort) - const TransparencyTransition *ctratt; - if (get_attribute_into(ctratt, this)) - alpha = (ctratt->get_mode() != TransparencyProperty::M_none); + // figure out if alpha's enabled (if not, no reason to sort) + const TransparencyAttrib *trans = _qpstate->get_transparency(); + if (trans != (const TransparencyAttrib *)NULL) { + alpha = (trans->get_mode() != TransparencyAttrib::M_none); + } } // inner loop vars @@ -2324,7 +2045,7 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { // y direction if (y_overall) - scaled_height = geom->_y_texel_ratio[0] * half_height * aspect_ratio; + scaled_height = geom->_y_texel_ratio[0] * half_height; else { nassertv(((int)geom->_y_texel_ratio.size() >= geom->get_num_prims())); y_walk = &geom->_y_texel_ratio[0]; @@ -2493,7 +2214,7 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { scaled_width = pSpr->_x_ratio * half_width; if (!y_overall) - scaled_height = pSpr->_y_ratio * half_height * aspect_ratio; + scaled_height = pSpr->_y_ratio * half_height; // if not G_OVERALL, do some trig for this z rotate //what is the theta angle?? if (theta_on) { @@ -2580,8 +2301,8 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { delete [] SpriteArray; // restore the matrices - scrn.pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &OldD3DWorldMatrix); - + scrn.pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, + (LPD3DMATRIX)modelview_mat.get_data()); if(bReEnableDither) enable_dither(true); } @@ -2836,17 +2557,13 @@ draw_tri(GeomTri *geom, GeomContext *gc) { } } - ColorTransition *catt=NULL; - bool bDoGlobalSceneGraphColor=FALSE,bDoColor=(ColorBinding != G_OFF); - // We should issue geometry colors only if the scene graph color is off. - if (get_attribute_into(catt, this)) { - if (!catt->is_real()) - bDoColor=FALSE; // this turns off any Geom colors - else { - ColorBinding=G_OVERALL; - bDoGlobalSceneGraphColor=TRUE; - } + bool bDoGlobalSceneGraphColor = FALSE; + bool bDoColor = (_vertex_colors_enabled && ColorBinding != G_OFF); + if (_has_scene_graph_color) { + bDoColor = TRUE; + bDoGlobalSceneGraphColor = TRUE; + ColorBinding = G_OVERALL; } if (bDoColor || bDoGlobalSceneGraphColor) { @@ -2927,14 +2644,14 @@ draw_tri(GeomTri *geom, GeomContext *gc) { if(!_color_transform_required) { if (bDoGlobalSceneGraphColor) { - Colorf colr = catt->get_color(); + Colorf colr = _scene_graph_color; *pConvertedColorArray = Colorf_to_D3DCOLOR(colr); } else { *pConvertedColorArray = Colorf_to_D3DCOLOR(*pInColor); } } else { if (bDoGlobalSceneGraphColor) { - Colorf colr = catt->get_color(); + Colorf colr = _scene_graph_color; transform_color(colr,*pConvertedColorArray); } else { transform_color(*pInColor,*pConvertedColorArray); @@ -3281,17 +2998,13 @@ draw_multitri(Geom *geom, D3DPRIMITIVETYPE trilisttype) { } } - ColorTransition *catt=NULL; - bool bDoGlobalSceneGraphColor=FALSE,bDoColor=(ColorBinding != G_OFF); - // We should issue geometry colors only if the scene graph color is off. - if (get_attribute_into(catt, this)) { - if (!catt->is_real()) - bDoColor=FALSE; // this turns off any Geom colors - else { - ColorBinding=G_OVERALL; - bDoGlobalSceneGraphColor=TRUE; - } + bool bDoGlobalSceneGraphColor = FALSE; + bool bDoColor = (_vertex_colors_enabled && ColorBinding != G_OFF); + if (_has_scene_graph_color) { + bDoColor = TRUE; + bDoGlobalSceneGraphColor = TRUE; + ColorBinding = G_OVERALL; } if (bDoColor || bDoGlobalSceneGraphColor) { @@ -3413,14 +3126,14 @@ draw_multitri(Geom *geom, D3DPRIMITIVETYPE trilisttype) { if(!_color_transform_required) { if (bDoGlobalSceneGraphColor) { - Colorf colr = catt->get_color(); + Colorf colr = _scene_graph_color(); *pConvertedColorArray = Colorf_to_D3DCOLOR(colr); } else { *pConvertedColorArray = Colorf_to_D3DCOLOR(*pInColor); } } else { if (bDoGlobalSceneGraphColor) { - Colorf colr = catt->get_color(); + Colorf colr = _scene_graph_color(); transform_color(colr,*pConvertedColorArray); } else { transform_color(*pInColor,*pConvertedColorArray); @@ -4064,93 +3777,6 @@ copy_texture(TextureContext *tc, const DisplayRegion *dr, const RenderBuffer &rb copy_texture(tc, dr); } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::draw_texture -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -draw_texture(TextureContext *tc, const DisplayRegion *dr) { - - dxgsg_cat.fatal() << "DXGSG draw_texture unimplemented!!!"; - return; - - nassertv(tc != NULL && dr != NULL); - -#ifdef WBD_GL_MODE - Texture *tex = tc->_texture; - - DisplayRegionStack old_dr = push_display_region(dr); - prepare_display_region(); - - NodeTransitions state; - CullFaceTransition *cfa = new CullFaceTransition(CullFaceProperty::M_cull_none); - DepthTestTransition *dta = new DepthTestTransition(DepthTestProperty::M_none); - DepthWriteTransition *dwa = new DepthWriteTransition(DepthWriteTransition::off()); - TextureTransition *ta = new TextureTransition(tex); - TextureApplyTransition *taa = new TextureApplyTransition(TextureApplyProperty::M_decal); - - state.set_transition(new ColorMaskTransition); - state.set_transition(new RenderModeTransition); - state.set_transition(new TexMatrixTransition); - state.set_transition(new TransformTransition); - state.set_transition(new ColorBlendTransition); - state.set_transition(cfa); - state.set_transition(dta); - state.set_transition(dwa); - state.set_transition(ta); - state.set_transition(taa); - modify_state(state); - - // We set up an orthographic projection that defines our entire - // viewport to the range [0..1] in both dimensions. Then, when we - // create a unit square polygon below, it will exactly fill the - // viewport (and thus exactly fill the display region). - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - gluOrtho2D(0, 1, 0, 1); - - float txl, txr, tyt, tyb; - txl = tyb = 0.; - if (tex->_has_requested_size) { - txr = ((float)(tex->_requested_w)) / ((float)(tex->_pbuffer->get_xsize())); - tyt = ((float)(tex->_requested_h)) / ((float)(tex->_pbuffer->get_ysize())); - } else { - txr = tyt = 1.; - } - - // This two-triangle strip is actually a quad. But it's usually - // better to render quads as tristrips anyway. - glBegin(GL_TRIANGLE_STRIP); - glTexCoord2f(txl, tyb); glVertex2i(0, 0); - glTexCoord2f(txr, tyb); glVertex2i(1, 0); - glTexCoord2f(txl, tyt); glVertex2i(0, 1); - glTexCoord2f(txr, tyt); glVertex2i(1, 1); - glEnd(); - - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - - pop_display_region(old_dr); -#endif // WBD_GL_MODE - -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::draw_texture -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -draw_texture(TextureContext *tc, const DisplayRegion *dr, const RenderBuffer &rb) { - dxgsg_cat.fatal() << "DXGSG draw_texture unimplemented!!!"; - return; - - set_draw_buffer(rb); - draw_texture(tc, dr); -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::texture_to_pixel_buffer // Access: Public, Virtual @@ -4184,22 +3810,8 @@ texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb) { void DXGraphicsStateGuardian:: texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb, const DisplayRegion *dr) { - nassertv(tc != NULL && pb != NULL && dr != NULL); - - Texture *tex = tc->_texture; - - // Do a deep copy to initialize the pixel buffer - pb->copy(tex->_pbuffer); - - // If the image was empty, we need to render the texture into the frame - // buffer and then copy the results into the pixel buffer's image - if (pb->_image.empty()) { - int w = pb->get_xsize(); - int h = pb->get_ysize(); - draw_texture(tc, dr); - pb->_image = PTA_uchar::empty_array(w * h * pb->get_num_components()); - copy_pixel_buffer(pb, dr); - } + dxgsg_cat.error() + << "texture_to_pixel_buffer unimplemented!\n"; } //////////////////////////////////////////////////////////////////// @@ -4250,136 +3862,6 @@ copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, copy_pixel_buffer(pb, dr); } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::draw_pixel_buffer -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, - const NodeTransitions& na) { - - dxgsg_cat.fatal() << "DXGSG draw_pixel_buffer unimplemented!!!"; - return; - -#ifdef WBD_GL_MODE - nassertv(pb != NULL && dr != NULL); - nassertv(!pb->_image.empty()); - - DisplayRegionStack old_dr = push_display_region(dr); - prepare_display_region(); - - NodeTransitions state(na); - state.set_transition(new TextureTransition); - state.set_transition(new TransformTransition); - state.set_transition(new ColorBlendTransition); - state.set_transition(new StencilTransition); - - - switch (pb->get_format()) { - case PixelBuffer::F_depth_component: - { - ColorMaskTransition *cma = new ColorMaskTransition(0); - DepthTestTransition *dta = new DepthTestTransition(DepthTestProperty::M_always); - DepthWriteTransition *dwa = new DepthWriteTransition(DepthWriteTransition::off()); - state.set_transition(cma); - state.set_transition(dta); - state.set_transition(dwa); - } - break; - - case PixelBuffer::F_rgb: - case PixelBuffer::F_rgb5: - case PixelBuffer::F_rgb8: - case PixelBuffer::F_rgb12: - case PixelBuffer::F_rgba: - case PixelBuffer::F_rgba4: - case PixelBuffer::F_rgba8: - case PixelBuffer::F_rgba12: - { - ColorMaskTransition *cma = new ColorMaskTransition; - DepthTestTransition *dta = new DepthTestTransition(DepthTestProperty::M_none); - DepthWriteTransition *dwa = new DepthWriteTransition(DepthWriteTransition::off()); - state.set_transition(cma); - state.set_transition(dta); - state.set_transition(dwa); - } - break; - default: - dxgsg_cat.error() - << "draw_pixel_buffer(): unknown buffer format" << endl; - break; - } - - modify_state(state); - - enable_color_material(false); - set_unpack_alignment(1); - - glMatrixMode( GL_PROJECTION ); - glPushMatrix(); - glLoadIdentity(); - gluOrtho2D(0, _win->get_width(), - 0, _win->get_height()); - -#ifdef GSG_VERBOSE - dxgsg_cat.debug() - << "glDrawPixels(" << pb->get_xsize() << ", " << pb->get_ysize() - << ", "; - switch (get_external_image_format(pb->get_format())) { - case GL_DEPTH_COMPONENT: - dxgsg_cat.debug(false) << "GL_DEPTH_COMPONENT, "; - break; - case GL_RGB: - dxgsg_cat.debug(false) << "GL_RGB, "; - break; - case GL_RGBA: - dxgsg_cat.debug(false) << "GL_RGBA, "; - break; - default: - dxgsg_cat.debug(false) << "unknown, "; - break; - } - switch (get_image_type(pb->get_image_type())) { - case GL_UNSIGNED_BYTE: - dxgsg_cat.debug(false) << "GL_UNSIGNED_BYTE, "; - break; - case GL_float: - dxgsg_cat.debug(false) << "GL_float, "; - break; - default: - dxgsg_cat.debug(false) << "unknown, "; - break; - } - dxgsg_cat.debug(false) - << (void *)pb->_image.p() << ")" << endl; -#endif - - glRasterPos2i( pb->get_xorg(), pb->get_yorg() ); - glDrawPixels( pb->get_xsize(), pb->get_ysize(), - get_external_image_format(pb->get_format()), - get_image_type(pb->get_image_type()), - pb->_image.p() ); - - glMatrixMode( GL_PROJECTION ); - glPopMatrix(); - - pop_display_region(old_dr); -#endif // WBD_GL_MODE -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::draw_pixel_buffer -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, - const RenderBuffer &rb, const NodeTransitions& na) { - set_read_buffer(rb); - draw_pixel_buffer(pb, dr, na); -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::apply_material // Access: Public, Virtual @@ -4395,61 +3877,6 @@ void DXGraphicsStateGuardian::apply_material( const Material* material ) { scrn.pD3DDevice->SetMaterial(&cur_material); } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::apply_fog -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -apply_fog(Fog *fog) { - - if(_doFogType==None) - return; - - Fog::Mode panda_fogmode = fog->get_mode(); - D3DFOGMODE d3dfogmode = get_fog_mode_type(panda_fogmode); - - - // should probably avoid doing redundant SetRenderStates, but whatever - scrn.pD3DDevice->SetRenderState((D3DRENDERSTATETYPE)_doFogType, d3dfogmode); - - const Colorf &fog_colr = fog->get_color(); - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, - MY_D3DRGBA(fog_colr[0], fog_colr[1], fog_colr[2], 0.0f)); // Alpha bits are not used - - // do we need to adjust fog start/end values based on D3DPRASTERCAPS_WFOG/D3DPRASTERCAPS_ZFOG ? - // if not WFOG, then docs say we need to adjust values to range [0,1] - - switch (panda_fogmode) { - case Fog::M_linear: - { - // Linear fog may be world-relative or - // camera-relative. The fog object knows how to - // decode its parameters into camera-relative - // properties. - float fog_start, fog_end; - fog->compute_linear_range(fog_start, fog_end, - _current_camera, - _coordinate_system); - - scrn.pD3DDevice->SetRenderState( D3DRENDERSTATE_FOGSTART, - *((LPDWORD) (&fog_start)) ); - scrn.pD3DDevice->SetRenderState( D3DRENDERSTATE_FOGEND, - *((LPDWORD) (&fog_end)) ); - } - break; - case Fog::M_exponential: - case Fog::M_exponential_squared: - { - // Exponential fog is always camera-relative. - float fog_density = fog->get_exp_density(); - scrn.pD3DDevice->SetRenderState( D3DRENDERSTATE_FOGDENSITY, - *((LPDWORD) (&fog_density)) ); - } - break; - } -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::apply_fog // Access: Public, Virtual @@ -4498,289 +3925,13 @@ apply_fog(qpFog *fog) { } } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_transform -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_transform(const TransformTransition *attrib) { - scrn.pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD/*VIEW*/, - (LPD3DMATRIX) attrib->get_matrix().get_data()); - _bTransformIssued = true; -} +void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyAttrib::Mode TexBlendMode,bool bCanJustEnable) { -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_matrix -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_tex_matrix(const TexMatrixTransition *attrib) { - dxgsg_cat.fatal() << "DXGSG issue_tex_matrix unimplemented!!!"; - return; - -#ifdef WBD_GL_MODE -#ifdef GSG_VERBOSE - dxgsg_cat.debug() - << "glLoadMatrix(GL_TEXTURE): " << attrib->get_matrix() << endl; -#endif - glMatrixMode(GL_TEXTURE); - glLoadMatrixf(attrib->get_matrix().get_data()); -#else - scrn.pD3DDevice->SetTransform( D3DTRANSFORMSTATE_TEXTURE0, - (LPD3DMATRIX)attrib->get_matrix().get_data()); -#endif // WBD_GL_MODE -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_color -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_color(const ColorTransition *attrib) { - - bool bAttribOn=attrib->is_on(); - bool bIsReal = (bAttribOn ? attrib->is_real() : false); - - _has_scene_graph_color = bAttribOn; - - if(bAttribOn && bIsReal) { - _scene_graph_color = attrib->get_color(); - _scene_graph_color_stale = true; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_color_transform -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_color_transform(const ColorMatrixTransition *attrib) { - _current_color_mat = attrib->get_matrix(); - - // couldnt we compare a single ptr instead of doing full comparison? - // bugbug: the ColorMatrixTransition needs to be an On/Off transition - // so we dont have to do this comparison - if (_current_color_mat == LMatrix4f::ident_mat()) { - _color_transform_enabled = false; - - } else { - _color_transform_enabled = true; - } - _scene_graph_color_stale = _has_scene_graph_color; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_alpha_transform -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_alpha_transform(const AlphaTransformTransition *attrib) { - _current_alpha_offset = attrib->get_offset(); - _current_alpha_scale = attrib->get_scale(); - - if ((_current_alpha_offset == 0.0f) && (_current_alpha_scale == 1.0f)) { - _alpha_transform_enabled = false; - } else { - _alpha_transform_enabled = true; - } - _scene_graph_color_stale = _has_scene_graph_color; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_texture -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_texture(const TextureTransition *attrib) { - if (attrib->is_on()) { - enable_texturing(true); - Texture *tex = attrib->get_texture(); - nassertv(tex != (Texture *)NULL); - tex->apply(this); - } else { - enable_texturing(false); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_tex_gen -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_tex_gen(const TexGenTransition *attrib) { - dxgsg_cat.fatal() << "DXGSG issue_tex_gen unimplemented!!!"; - return; -#ifdef WBD_GL_MODE - TexGenProperty::Mode mode = attrib->get_mode(); - - switch (mode) { - case TexGenProperty::M_none: - glDisable(GL_TEXTURE_GEN_S); - glDisable(GL_TEXTURE_GEN_T); - glDisable(GL_TEXTURE_GEN_Q); - glDisable(GL_TEXTURE_GEN_R); - break; - - case TexGenProperty::M_texture_projector: - { - glEnable(GL_TEXTURE_GEN_S); - glEnable(GL_TEXTURE_GEN_T); - glEnable(GL_TEXTURE_GEN_Q); - glEnable(GL_TEXTURE_GEN_R); - const LMatrix4f &plane = attrib->get_plane(); - glTexGenfv(GL_S, GL_OBJECT_PLANE, plane.get_row(0).get_data()); - glTexGenfv(GL_T, GL_OBJECT_PLANE, plane.get_row(1).get_data()); - glTexGenfv(GL_R, GL_OBJECT_PLANE, plane.get_row(2).get_data()); - glTexGenfv(GL_Q, GL_OBJECT_PLANE, plane.get_row(3).get_data()); - glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - } - break; - - case TexGenProperty::M_sphere_map: - glEnable(GL_TEXTURE_GEN_S); - glEnable(GL_TEXTURE_GEN_T); - glDisable(GL_TEXTURE_GEN_Q); - glDisable(GL_TEXTURE_GEN_R); - glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); - glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); - break; - - default: - dxgsg_cat.error() - << "Unknown texgen mode " << (int)mode << endl; - break; - } -#endif // WBD_GL_MODE -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_material -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_material(const MaterialTransition *attrib) { - if (attrib->is_on()) { - const Material *material = attrib->get_material(); - nassertv(material != (const Material *)NULL); - apply_material(material); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_fog -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_fog(const FogTransition *attrib) { - - if (attrib->is_on()) { - enable_fog(true); - Fog *fog = attrib->get_fog(); - nassertv(fog != (Fog *)NULL); - fog->apply(this); - } else { - enable_fog(false); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_render_mode -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_render_mode(const RenderModeTransition *attrib) { - - RenderModeProperty::Mode mode = attrib->get_mode(); - - if(mode==_current_fill_mode) - return; - - switch (mode) { - case RenderModeProperty::M_filled: - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID); - break; - - case RenderModeProperty::M_wireframe: - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_WIREFRAME); - break; - - default: - dxgsg_cat.error() - << "Unknown render mode " << (int)mode << endl; - } - - _current_fill_mode = mode; -} - -/* -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::reset_ambient -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -reset_ambient() { - _lmodel_ambient += 2.0f; -} -*/ - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_color_blend // -// Access: Public, Virtual // -// Description: // -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_color_blend(const ColorBlendTransition *attrib) { - - ColorBlendProperty::Mode mode = attrib->get_mode(); - - switch (mode) { - case ColorBlendProperty::M_none: - enable_blend(false); - break; - case ColorBlendProperty::M_multiply: - enable_blend(true); - call_dxBlendFunc(D3DBLEND_DESTCOLOR, D3DBLEND_ZERO); - break; - case ColorBlendProperty::M_add: - enable_blend(true); - call_dxBlendFunc(D3DBLEND_ONE, D3DBLEND_ONE); - break; - case ColorBlendProperty::M_multiply_add: - enable_blend(true); - call_dxBlendFunc(D3DBLEND_DESTCOLOR, D3DBLEND_ONE); - break; - case ColorBlendProperty::M_alpha: - enable_blend(true); - call_dxBlendFunc(D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA); - break; - default: - dxgsg_cat.error() - << "Unknown color blend mode " << (int)mode << endl; - break; - } -} - -void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyProperty::Mode TexBlendMode,bool bCanJustEnable) { - -/*class TextureApplyProperty { +/*class TextureApplyAttrib { enum Mode { M_modulate,M_decal,M_blend,M_replace,M_add}; */ - static D3DTEXTUREOP TexBlendColorOp1[/* TextureApplyProperty::Mode maxval*/ 10] = + static D3DTEXTUREOP TexBlendColorOp1[/* TextureApplyAttrib::Mode maxval*/ 10] = {D3DTOP_MODULATE,D3DTOP_BLENDTEXTUREALPHA,D3DTOP_MODULATE,D3DTOP_SELECTARG1,D3DTOP_ADD}; //if bCanJustEnable, then we only need to make sure ColorOp is turned on and set properly @@ -4794,7 +3945,7 @@ void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyProperty::Mode Tex switch (TexBlendMode) { - case TextureApplyProperty::M_modulate: + case TextureApplyAttrib::M_modulate: // emulates GL_MODULATE glTexEnv mode // want to multiply tex-color*pixel color to emulate GL modulate blend (see glTexEnv) scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); @@ -4804,7 +3955,7 @@ void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyProperty::Mode Tex scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); break; - case TextureApplyProperty::M_decal: + case TextureApplyAttrib::M_decal: // emulates GL_DECAL glTexEnv mode scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); @@ -4813,13 +3964,13 @@ void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyProperty::Mode Tex scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE ); break; - case TextureApplyProperty::M_replace: + case TextureApplyAttrib::M_replace: scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); break; - case TextureApplyProperty::M_add: + case TextureApplyAttrib::M_add: scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); @@ -4829,7 +3980,7 @@ void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyProperty::Mode Tex scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); break; - case TextureApplyProperty::M_blend: + case TextureApplyAttrib::M_blend: dxgsg_cat.error() << "Impossible to emulate GL_BLEND in DX exactly " << (int) TexBlendMode << endl; /* @@ -4887,289 +4038,6 @@ enable_texturing(bool val) { } } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_texture_apply -// Access: Public, Virtual -// Description: handles texture transition (i.e. filter modes, etc) changes -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_texture_apply(const TextureApplyTransition *attrib) { - - _CurTexBlendMode = attrib->get_mode(); - - if (!_texturing_enabled) { - return; - } - - SetTextureBlendMode(_CurTexBlendMode,FALSE); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_color_mask -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_color_mask(const ColorMaskTransition *attrib) { - dxgsg_cat.fatal() << "DXGSG issue_color_mask unimplemented (not implementable on DX7, need DX8)!!!"; - // because PLANEMASK renderstate has inconsistent to poor driver support on dx6 and before, and is - // explicitly disabled on dx7 - return; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_depth_test -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_depth_test(const DepthTestTransition *attrib) { - DepthTestProperty::Mode mode = attrib->get_mode(); - - // no cache check since we dont store ZFUNC along w/bool val - - if (mode == DepthTestProperty::M_none) { - _depth_test_enabled = false; - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_FALSE); - } else { - _depth_test_enabled = true; - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_TRUE); - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, get_depth_func_type(mode)); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_stencil -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_stencil(const StencilTransition *attrib) { - - StencilProperty::Mode mode = attrib->get_mode(); - - if (mode == StencilProperty::M_none) { - enable_stencil_test(false); - } else { - enable_stencil_test(true); - D3DSTENCILOP pass_op = get_stencil_action_type(attrib->get_pass_action()); - D3DSTENCILOP fail_op = get_stencil_action_type(attrib->get_fail_action()); - D3DSTENCILOP zfail_op = get_stencil_action_type(attrib->get_zfail_action()); - - #ifdef _DEBUG - if(!(scrn.D3DDevDesc.dwStencilCaps & (1<<(pass_op-1)))) { - dxgsg_cat.warning() << "driver doesnt support pass stencil operation: " << pass_op << endl; - } - if(!(scrn.D3DDevDesc.dwStencilCaps & (1<<(fail_op-1)))) { - dxgsg_cat.warning() << "driver doesnt support fail stencil operation: " << fail_op << endl; - } - if(!(scrn.D3DDevDesc.dwStencilCaps & (1<<(zfail_op-1)))) { - dxgsg_cat.warning() << "driver doesnt support zfail stencil operation: " << zfail_op << endl; - } - #endif - // TODO: need to cache all these - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_STENCILFUNC, get_stencil_func_type(mode)); - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_STENCILPASS, pass_op); - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_STENCILFAIL, fail_op); - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_STENCILZFAIL, zfail_op); - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_STENCILREF, attrib->get_reference_value()); - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_STENCILMASK, attrib->get_func_mask()); - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_STENCILWRITEMASK, attrib->get_write_mask()); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_cull_transition -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_cull_face(const CullFaceTransition *attrib) { - -#ifndef NDEBUG - if(dx_force_backface_culling!=0) { - return; // leave as initially set - } -#endif - - CullFaceProperty::Mode mode = attrib->get_mode(); - - switch (mode) { - case CullFaceProperty::M_cull_none: - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE); - break; - case CullFaceProperty::M_cull_clockwise: - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW); - break; - case CullFaceProperty::M_cull_counter_clockwise: - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CCW); - break; - case CullFaceProperty::M_cull_all: - dxgsg_cat.warning() << "M_cull_all is invalid for DX GSG renderer, using CULL_CCW \n"; - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CCW); - break; - default: - dxgsg_cat.error() - << "invalid cull face mode " << (int)mode << endl; - break; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_clip_plane -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_clip_plane(const ClipPlaneTransition *attrib) { - nassertv(attrib->get_default_dir() != TD_on); - - // Initialize the currently enabled clip plane list - int i; - for (i = 0; i < _max_clip_planes; i++) - _cur_clip_plane_enabled[i] = false; - - int num_enabled = 0; - ClipPlaneTransition::const_iterator pi; - for (pi = attrib->begin(); pi != attrib->end(); ++pi) { - PlaneNode *plane_node; - DCAST_INTO_V(plane_node, (*pi).first); - nassertv(plane_node != (PlaneNode *)NULL); - TransitionDirection dir = (*pi).second; - - if (dir == TD_on) { - _cur_clip_plane_id = -1; - num_enabled++; - - // Check to see if this clip plane has already been bound to an id - for (i = 0; i < _max_clip_planes; i++) { - if (_available_clip_plane_ids[i] == plane_node) { - // Clip plane has already been bound to an id, we only need - // to enable the clip plane, not apply it - _cur_clip_plane_id = -2; - enable_clip_plane(i, true); - _cur_clip_plane_enabled[i] = true; - break; - } - } - - // See if there are any unbound clip plane ids - if (_cur_clip_plane_id == -1) { - for (i = 0; i < _max_clip_planes; i++) { - if (_available_clip_plane_ids[i] == NULL) { - _available_clip_plane_ids[i] = plane_node; - _cur_clip_plane_id = i; - break; - } - } - } - - // If there were no unbound clip plane ids, see if we can replace - // a currently unused but previously bound id - if (_cur_clip_plane_id == -1) { - for (i = 0; i < _max_clip_planes; i++) { - if (attrib->is_off(_available_clip_plane_ids[i])) { - _available_clip_plane_ids[i] = plane_node; - _cur_clip_plane_id = i; - break; - } - } - } - - if (_cur_clip_plane_id >= 0) { - enable_clip_plane(_cur_clip_plane_id, true); - _cur_clip_plane_enabled[_cur_clip_plane_id] = true; - const Planef clip_plane = plane_node->get_plane(); - - D3DVALUE equation[4]; - equation[0] = clip_plane._a; - equation[1] = clip_plane._b; - equation[2] = clip_plane._c; - equation[3] = clip_plane._d; - scrn.pD3DDevice->SetClipPlane(_cur_clip_plane_id, equation); - - } else if (_cur_clip_plane_id == -1) { - dxgsg_cat.error() - << "issue_clip_plane() - failed to bind clip plane to id" << endl; - } - } - } - - // Disable all unused clip planes - for (i = 0; i < _max_clip_planes; i++) { - if (!_cur_clip_plane_enabled[i]) - enable_clip_plane(i, false); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_transparency -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_transparency(const TransparencyTransition *attrib ) { - - TransparencyProperty::Mode mode = attrib->get_mode(); - - switch (mode) { - case TransparencyProperty::M_none: -// enable_multisample_alpha_one(false); -// enable_multisample_alpha_mask(false); - enable_blend(false); - enable_alpha_test(false); - break; - case TransparencyProperty::M_alpha: - case TransparencyProperty::M_alpha_sorted: - // Should we really have an "alpha" and an "alpha_sorted" mode, - // like Performer does? (The difference is that "alpha" is with - // the write to the depth buffer disabled.) Or should we just use - // the separate depth write transition to control this? Doing it - // implicitly requires a bit more logic here and in the state - // management; for now we require the user to explicitly turn off - // the depth write. -// enable_multisample_alpha_one(false); -// enable_multisample_alpha_mask(false); - enable_blend(true); - enable_alpha_test(false); - call_dxBlendFunc(D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA); - break; - case TransparencyProperty::M_multisample: -// enable_multisample_alpha_one(true); -// enable_multisample_alpha_mask(true); - enable_blend(false); - enable_alpha_test(false); - break; - case TransparencyProperty::M_multisample_mask: -// enable_multisample_alpha_one(false); -// enable_multisample_alpha_mask(true); - enable_blend(false); - enable_alpha_test(false); - break; - case TransparencyProperty::M_binary: -// enable_multisample_alpha_one(false); -// enable_multisample_alpha_mask(false); - enable_blend(false); - enable_alpha_test(true); - call_dxAlphaFunc(D3DCMP_EQUAL, 1); - break; - default: - dxgsg_cat.error() - << "invalid transparency mode " << (int)mode << endl; - break; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_linesmooth -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_linesmooth(const LinesmoothTransition *attrib) { - enable_line_smooth(attrib->is_on()); -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::issue_transform // Access: Public, Virtual @@ -5249,7 +4117,7 @@ issue_render_mode(const RenderModeAttrib *attrib) { << "Unknown render mode " << (int)mode << endl; } - _current_fill_mode = (RenderModeProperty::Mode)mode; + _current_fill_mode = mode; } //////////////////////////////////////////////////////////////////// @@ -5576,7 +4444,7 @@ end_frame() { scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ZFUNC,D3DCMP_ALWAYS); DWORD saved_fill_state; - if(_current_fill_mode != RenderModeProperty::M_filled) { + if(_current_fill_mode != RenderModeAttrib::M_filled) { scrn.pD3DDevice->GetRenderState(D3DRENDERSTATE_FILLMODE, &saved_fill_state); scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID); } @@ -5657,7 +4525,7 @@ end_frame() { scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_SHADEMODE, _CurShadeMode); } - if(_current_fill_mode != RenderModeProperty::M_filled) { + if(_current_fill_mode != RenderModeAttrib::M_filled) { scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, saved_fill_state); } @@ -5784,175 +4652,6 @@ wants_texcoords() const { } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_depth_write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_depth_write(const DepthWriteTransition *attrib) { - enable_zwritemask(attrib->is_on()); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::begin_decal -// Access: Public, Virtual -// Description: This will be called to initiate decaling mode. It is -// passed the pointer to the GeomNode that will be the -// destination of the decals, which it is expected that -// the GSG will render normally; subsequent geometry -// rendered up until the next call of end_decal() should -// be rendered as decals of the base_geom. -// -// The transitions wrapper is the current state as of the -// base geometry node. It may or may not be modified by -// the GSG to reflect whatever rendering state is -// necessary to render the decals properly. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -begin_decal(GeomNode *base_geom, AllTransitionsWrapper &attrib) { - nassertv(base_geom != (GeomNode *)NULL); - - assert(_decal_level>=0); - - _decal_level++; - -#ifndef DISABLE_DECALING - - #ifndef DISABLE_POLYGON_OFFSET_DECALING - if (dx_decal_type == GDT_offset) { - #define POLYGON_OFFSET_MULTIPLIER 2 - - // note: zbias seems inconsitently supported. may be possible to fake it by - // adding (delta * element[4,3]) to element [3,3] of a regular matrix - // need to test this and see if to offers perf improvement over blend-based decaling - - nassertv(POLYGON_OFFSET_MULTIPLIER*_decal_level < 16); // 16 is the max allowed zbias - - // Just draw the base geometry normally. - base_geom->draw(this); - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ZBIAS, POLYGON_OFFSET_MULTIPLIER * _decal_level); // _decal_level better not be higher than 8! - } else - #endif - - { - if (_decal_level > 1) { - base_geom->draw(this); // If we're already decaling, just draw the geometry. - } else { - // need to save current xform matrix in case it is changed during subrendering, so subsequent decal draws use same xform - _bTransformIssued = false; - scrn.pD3DDevice->GetTransform( D3DTRANSFORMSTATE_WORLD, &_SavedTransform); - - // First turn off writing the depth buffer to render the base geometry. - enable_zwritemask(false); - - // It is also important to update the current state to - // indicate the depth buffer write is off, so that future - // geometry will render correctly. - DepthWriteTransition *dwa = new DepthWriteTransition(DepthWriteTransition::off()); - attrib.set_transition(dwa); - - // Now render the base geometry. - base_geom->draw(this); - - // Render all of the decal geometry, too. We'll keep the depth - // buffer write off during this. - } - } -#else - base_geom->draw(this); -#endif -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::end_decal -// Access: Public, Virtual -// Description: This will be called to terminate decaling mode. It -// is passed the same base_geom that was passed to -// begin_decal(). -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -end_decal(GeomNode *base_geom) { - _decal_level--; - - assert(_decal_level>=0); - -#ifdef DISABLE_DECALING - return; -#endif - - nassertv(base_geom != (GeomNode *)NULL); -// nassertv(_decal_level >= 1); - -#ifndef DISABLE_POLYGON_OFFSET_DECALING - if (dx_decal_type == GDT_offset) { - // Restore the Zbias offset. - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_ZBIAS, POLYGON_OFFSET_MULTIPLIER * _decal_level); // _decal_level better not be higher than 8! - } else -#endif - { // for GDT_mask - if (_decal_level == 0) { - // Now we need to re-render the base geometry with the depth write - // on and the color mask off, so we update the depth buffer - // properly. - bool was_textured = _texturing_enabled; - bool was_blend = _blend_enabled; - D3DBLEND old_blend_source_func = _blend_source_func; - D3DBLEND old_blend_dest_func = _blend_dest_func; - - // Enable the writing to the depth buffer. - enable_zwritemask(true); - - // Disable the writing to the color buffer, however we have to - // do this. (I don't think this is possible in DX without blending.) - if (dx_decal_type == GDT_blend) { - // Expensive. - enable_blend(true); - call_dxBlendFunc(D3DBLEND_ZERO, D3DBLEND_ONE); - } - -#if(DIRECT3D_VERSION < 0x700) - else { // dx7 doesn't support planemask rstate - // note: not saving current planemask val, assumes this is always all 1's. should be ok - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_PLANEMASK,0x0); // note PLANEMASK is supposedly obsolete for DX7 - } -#endif - // No need to have texturing on for this. - enable_texturing(false); - - // if current xform has changed, reset to saved xform - if(_bTransformIssued) - scrn.pD3DDevice->SetTransform( D3DTRANSFORMSTATE_WORLD, &_SavedTransform); - - base_geom->draw(this); - - // Finally, restore the depth write and color mask states to the - // way they're supposed to be. - - if (dx_decal_type == GDT_blend) { - enable_blend(was_blend); - if (was_blend) - call_dxBlendFunc(old_blend_source_func, old_blend_dest_func); - } -#if(DIRECT3D_VERSION < 0x700) - else { - scrn.pD3DDevice->SetRenderState(D3DRENDERSTATE_PLANEMASK,0xFFFFFFFF); // this is unlikely to work due to poor driver support - } -#endif - enable_texturing(was_textured); - - // Finally, restore the depth write state to the - // way they're supposed to be. - - // could we do this faster by saving last issued depth writemask? - DepthWriteTransition *depth_write; - if (get_attribute_into(depth_write, this)) { - issue_depth_write(depth_write); - } - } - } -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::depth_offset_decals // Access: Public, Virtual @@ -6094,28 +4793,6 @@ get_texture_wrap_mode(Texture::WrapMode wm) const { return D3DTADDRESS_WRAP; } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::get_depth_func_type -// Access: Protected -// Description: Maps from the depth func modes to gl version -//////////////////////////////////////////////////////////////////// -INLINE D3DCMPFUNC DXGraphicsStateGuardian:: -get_depth_func_type(DepthTestProperty::Mode m) const { - switch (m) { - case DepthTestProperty::M_never: return D3DCMP_NEVER; - case DepthTestProperty::M_less: return D3DCMP_LESS; - case DepthTestProperty::M_equal: return D3DCMP_EQUAL; - case DepthTestProperty::M_less_equal: return D3DCMP_LESSEQUAL; - case DepthTestProperty::M_greater: return D3DCMP_GREATER; - case DepthTestProperty::M_not_equal: return D3DCMP_NOTEQUAL; - case DepthTestProperty::M_greater_equal: return D3DCMP_GREATEREQUAL; - case DepthTestProperty::M_always: return D3DCMP_ALWAYS; - } - dxgsg_cat.error() - << "Invalid DepthTestProperty::Mode value" << endl; - return D3DCMP_LESS; -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::get_depth_func_type // Access: Protected @@ -6138,63 +4815,6 @@ get_depth_func_type(DepthTestAttrib::Mode m) const { return D3DCMP_LESS; } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::get_stencil_func_type -// Access: Protected -// Description: Maps from the stencil func modes to dx version -//////////////////////////////////////////////////////////////////// -INLINE D3DCMPFUNC DXGraphicsStateGuardian:: -get_stencil_func_type(StencilProperty::Mode m) const { - switch (m) { - case StencilProperty::M_never: return D3DCMP_NEVER; - case StencilProperty::M_less: return D3DCMP_LESS; - case StencilProperty::M_equal: return D3DCMP_EQUAL; - case StencilProperty::M_less_equal: return D3DCMP_LESSEQUAL; - case StencilProperty::M_greater: return D3DCMP_GREATER; - case StencilProperty::M_not_equal: return D3DCMP_NOTEQUAL; - case StencilProperty::M_greater_equal: return D3DCMP_GREATEREQUAL; - case StencilProperty::M_always: return D3DCMP_ALWAYS; - } - dxgsg_cat.error() << "Invalid StencilProperty::Mode value" << endl; - return D3DCMP_LESS; -} - - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::get_stencil_action_type -// Access: Protected -// Description: Maps from the stencil action modes to dx version -//////////////////////////////////////////////////////////////////// -INLINE D3DSTENCILOP DXGraphicsStateGuardian:: -get_stencil_action_type(StencilProperty::Action a) const { - switch (a) { - case StencilProperty::A_keep: return D3DSTENCILOP_KEEP; - case StencilProperty::A_zero: return D3DSTENCILOP_ZERO; - case StencilProperty::A_replace: return D3DSTENCILOP_REPLACE; - case StencilProperty::A_increment: return D3DSTENCILOP_INCR; - case StencilProperty::A_decrement: return D3DSTENCILOP_DECR; - case StencilProperty::A_invert: return D3DSTENCILOP_INVERT; - } - dxgsg_cat.error() << "Invalid StencilProperty::Action value" << endl; - return D3DSTENCILOP_KEEP; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::get_fog_mode_type -// Access: Protected -// Description: Maps from the fog types to gl version -//////////////////////////////////////////////////////////////////// -INLINE D3DFOGMODE DXGraphicsStateGuardian:: -get_fog_mode_type(Fog::Mode m) const { - switch (m) { - case Fog::M_linear: return D3DFOG_LINEAR; - case Fog::M_exponential: return D3DFOG_EXP; - case Fog::M_exponential_squared: return D3DFOG_EXP2; - } - dxgsg_cat.error() << "Invalid Fog::Mode value" << endl; - return D3DFOG_EXP; -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::get_fog_mode_type // Access: Protected @@ -6285,19 +4905,19 @@ set_blend_mode(ColorWriteAttrib::Mode color_write_mode, case ColorBlendAttrib::M_none: break; - case ColorBlendProperty::M_multiply: + case ColorBlendAttrib::M_multiply: enable_blend(true); enable_alpha_test(false); call_dxBlendFunc(D3DBLEND_DESTCOLOR, D3DBLEND_ZERO); return; - case ColorBlendProperty::M_add: + case ColorBlendAttrib::M_add: enable_blend(true); enable_alpha_test(false); call_dxBlendFunc(D3DBLEND_ONE, D3DBLEND_ONE); return; - case ColorBlendProperty::M_multiply_add: + case ColorBlendAttrib::M_multiply_add: enable_blend(true); enable_alpha_test(false); call_dxBlendFunc(D3DBLEND_DESTCOLOR, D3DBLEND_ONE); @@ -6348,14 +4968,6 @@ set_blend_mode(ColorWriteAttrib::Mode color_write_mode, //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian:: free_pointers() { - if (_clip_plane_enabled != (bool *)NULL) { - delete[] _clip_plane_enabled; - _clip_plane_enabled = (bool *)NULL; - } - if (_cur_clip_plane_enabled != (bool *)NULL) { - delete[] _cur_clip_plane_enabled; - _cur_clip_plane_enabled = (bool *)NULL; - } #ifdef USE_TEXFMTVEC scrn.TexPixFmts.clear(); #else @@ -6416,26 +5028,8 @@ save_frame_buffer(const RenderBuffer &buffer, //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian:: restore_frame_buffer(SavedFrameBuffer *frame_buffer) { - dxgsg_cat.error() << "restore_frame_buffer unimplemented!!\n"; return; - -#if 0 - DXSavedFrameBuffer *sfb = DCAST(DXSavedFrameBuffer, frame_buffer); - - if (sfb->_back_rgba != (Texture *)NULL && - (sfb->_buffer._buffer_type & RenderBuffer::T_back) != 0) { - // Restore the color buffer. - draw_texture(sfb->_back_rgba->prepare(this), - sfb->_display_region, sfb->_buffer); - } - - if (sfb->_depth != (PixelBuffer *)NULL && - (sfb->_buffer._buffer_type & RenderBuffer::T_depth) != 0) { - // Restore the depth buffer. - draw_pixel_buffer(sfb->_depth, sfb->_display_region, sfb->_buffer); - } -#endif } // factory and type stuff @@ -7146,9 +5740,8 @@ HRESULT SetViewMatrix( D3DMATRIX& mat, D3DVECTOR& vFrom, D3DVECTOR& vAt, // contents of the node. //////////////////////////////////////////////////////////////////// GeomNodeContext *DXGraphicsStateGuardian:: -prepare_geom_node(GeomNode *node) { - - +prepare_geom_node(qpGeomNode *node) { +#if 0 // temporarily disabled until ported to new scene graph if(link_tristrips) { for(int iGeom=0;iGeomget_num_geoms();iGeom++) { dDrawable *drawable1 = node->get_geom(iGeom); @@ -7601,6 +6194,8 @@ prepare_geom_node(GeomNode *node) { nassertr(inserted, NULL); return dx_gnc; +#endif // temporarily disabled until ported to new scene graph + return NULL; } //////////////////////////////////////////////////////////////////// @@ -7610,7 +6205,8 @@ prepare_geom_node(GeomNode *node) { // prepare_geom_node(). //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian:: -draw_geom_node(GeomNode *node, GeomNodeContext *gnc) { +draw_geom_node(qpGeomNode *node, const RenderState *state, GeomNodeContext *gnc) { +#if 0 // temporarily disabled until ported to new scene graph uint i,num_geoms = node->get_num_geoms(); @@ -7697,6 +6293,7 @@ draw_geom_node(GeomNode *node, GeomNodeContext *gnc) { DO_PSTATS_STUFF(PStatTimer timer(_draw_primitive_pcollector)); _vertices_display_list_pcollector.add_level(dx_gnc->_num_verts); #endif +#endif // temporarily disabled until ported to new scene graph } //////////////////////////////////////////////////////////////////// @@ -7708,6 +6305,7 @@ draw_geom_node(GeomNode *node, GeomNodeContext *gnc) { //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian:: release_geom_node(GeomNodeContext *gnc) { +#if 0 // temporarily disabled until ported to new scene graph if (gnc != (GeomNodeContext *)NULL) { DXGeomNodeContext *dx_gnc = DCAST(DXGeomNodeContext, gnc); @@ -7720,4 +6318,5 @@ release_geom_node(GeomNodeContext *gnc) { dx_gnc->_node->clear_gsg(this); delete dx_gnc; // should release vertex buffer } +#endif // temporarily disabled until ported to new scene graph } diff --git a/panda/src/dxgsg/dxGraphicsStateGuardian.h b/panda/src/dxgsg/dxGraphicsStateGuardian.h index a6c248fa43..561d172e2f 100644 --- a/panda/src/dxgsg/dxGraphicsStateGuardian.h +++ b/panda/src/dxgsg/dxGraphicsStateGuardian.h @@ -20,29 +20,21 @@ #define DXGRAPHICSSTATEGUARDIAN_H #include "dxgsgbase.h" +#include "dxGeomNodeContext.h" +#include "dxTextureContext.h" + #include "graphicsStateGuardian.h" #include "geomprimitives.h" #include "texture.h" #include "pixelBuffer.h" #include "displayRegion.h" #include "material.h" -#include "textureApplyProperty.h" -#include "depthTestProperty.h" #include "depthTestAttrib.h" -#include "stencilProperty.h" -#include "fog.h" +#include "renderModeAttrib.h" +#include "textureApplyAttrib.h" #include "qpfog.h" -#include "renderModeProperty.h" -#include "colorMatrixTransition.h" -#include "alphaTransformTransition.h" #include "pointerToArray.h" -#include "planeNode.h" -#include "dxGeomNodeContext.h" -#include "dxTextureContext.h" -#include - -class PlaneNode; class Light; //#if defined(NOTIFY_DEBUG) || defined(DO_PSTATS) @@ -82,15 +74,6 @@ public: virtual void prepare_display_region(); virtual bool prepare_lens(); - virtual void render_frame(); - virtual void render_scene(Node *root, LensNode *projnode); - virtual void render_subgraph(RenderTraverser *traverser, - Node *subgraph, LensNode *projnode, - const AllTransitionsWrapper &net_trans); - virtual void render_subgraph(RenderTraverser *traverser, - Node *subgraph, - const AllTransitionsWrapper &net_trans); - virtual void draw_point(GeomPoint *geom, GeomContext *gc); virtual void draw_line(GeomLine *geom, GeomContext *gc); virtual void draw_linestrip(GeomLinestrip *geom, GeomContext *gc); @@ -103,8 +86,9 @@ public: virtual void draw_trifan(GeomTrifan *geom, GeomContext *gc); virtual void draw_sphere(GeomSphere *geom, GeomContext *gc); - virtual GeomNodeContext *prepare_geom_node(GeomNode *node); - virtual void draw_geom_node(GeomNode *node, GeomNodeContext *gnc); + virtual GeomNodeContext *prepare_geom_node(qpGeomNode *node); + virtual void draw_geom_node(qpGeomNode *node, const RenderState *state, + GeomNodeContext *gnc); virtual void release_geom_node(GeomNodeContext *gnc); virtual TextureContext *prepare_texture(Texture *tex); @@ -114,9 +98,6 @@ public: virtual void copy_texture(TextureContext *tc, const DisplayRegion *dr); virtual void copy_texture(TextureContext *tc, const DisplayRegion *dr, const RenderBuffer &rb); - virtual void draw_texture(TextureContext *tc, const DisplayRegion *dr); - virtual void draw_texture(TextureContext *tc, const DisplayRegion *dr, - const RenderBuffer &rb); virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb); virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb, @@ -125,37 +106,10 @@ public: virtual void copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr); virtual void copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, const RenderBuffer &rb); - virtual void draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, - const NodeTransitions& na=NodeTransitions()); - virtual void draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, - const RenderBuffer &rb, - const NodeTransitions& na=NodeTransitions()); virtual void apply_material(const Material *material); - virtual void apply_fog(Fog *fog); virtual void apply_fog(qpFog *fog); - virtual void issue_transform(const TransformTransition *attrib); - virtual void issue_tex_matrix(const TexMatrixTransition *attrib); - virtual void issue_color(const ColorTransition *attrib); - virtual void issue_color_transform(const ColorMatrixTransition *); - virtual void issue_alpha_transform(const AlphaTransformTransition *); - virtual void issue_texture(const TextureTransition *attrib); - virtual void issue_material(const MaterialTransition *attrib); - virtual void issue_render_mode(const RenderModeTransition *attrib); - virtual void issue_color_blend(const ColorBlendTransition *attrib); - virtual void issue_texture_apply(const TextureApplyTransition *attrib); - virtual void issue_color_mask(const ColorMaskTransition *attrib); - virtual void issue_depth_test(const DepthTestTransition *attrib); - virtual void issue_depth_write(const DepthWriteTransition *attrib); - virtual void issue_tex_gen(const TexGenTransition *attrib); - virtual void issue_cull_face(const CullFaceTransition *attrib); - virtual void issue_stencil(const StencilTransition *attrib); - virtual void issue_clip_plane(const ClipPlaneTransition *attrib); - virtual void issue_transparency(const TransparencyTransition *attrib); - virtual void issue_fog(const FogTransition *attrib); - virtual void issue_linesmooth(const LinesmoothTransition *attrib); - virtual void issue_transform(const TransformState *transform); virtual void issue_tex_matrix(const TexMatrixAttrib *attrib); virtual void issue_texture(const TextureAttrib *attrib); @@ -178,9 +132,6 @@ public: virtual bool wants_normals(void) const; virtual bool wants_texcoords(void) const; - virtual void begin_decal(GeomNode *base_geom, AllTransitionsWrapper &attrib); - virtual void end_decal(GeomNode *base_geom); - virtual bool depth_offset_decals(); virtual CoordinateSystem get_internal_coordinate_system() const; @@ -254,14 +205,9 @@ protected: INLINE void set_shademode(D3DSHADEMODE val); INLINE D3DTEXTUREADDRESS get_texture_wrap_mode(Texture::WrapMode wm) const; - INLINE D3DCMPFUNC get_depth_func_type(DepthTestProperty::Mode m) const; INLINE D3DCMPFUNC get_depth_func_type(DepthTestAttrib::Mode m) const; - INLINE D3DFOGMODE get_fog_mode_type(Fog::Mode m) const; INLINE D3DFOGMODE get_fog_mode_type(qpFog::Mode m) const; - INLINE D3DCMPFUNC get_stencil_func_type(StencilProperty::Mode m) const; - INLINE D3DSTENCILOP get_stencil_action_type(StencilProperty::Action a) const; - INLINE void enable_primitive_clipping(bool val); INLINE void enable_alpha_test(bool val); INLINE void enable_line_smooth(bool val); @@ -351,11 +297,11 @@ protected: bool _alpha_test_enabled; int _decal_level; - RenderModeProperty::Mode _current_fill_mode; //poinr/wireframe/solid + RenderModeAttrib::Mode _current_fill_mode; //poinr/wireframe/solid GraphicsChannel *_panda_gfx_channel; // cache the 1 channel dx supports // Cur Texture State - TextureApplyProperty::Mode _CurTexBlendMode; + TextureApplyAttrib::Mode _CurTexBlendMode; Texture::FilterType _CurTexMagFilter,_CurTexMinFilter; DWORD _CurTexAnisoDegree; Texture::WrapMode _CurTexWrapModeU,_CurTexWrapModeV; @@ -363,11 +309,6 @@ protected: LMatrix4f _current_projection_mat; int _projection_mat_stack_count; - PTA(PlaneNode*) _available_clip_plane_ids; - int _max_clip_planes; - bool* _cur_clip_plane_enabled; - int _cur_clip_plane_id; - CPT(DisplayRegion) _actual_display_region; // Color/Alpha Matrix Transition stuff @@ -406,7 +347,7 @@ public: void adjust_view_rect(int x, int y); INLINE void SetDXReady(bool stat) { _dx_ready = stat; } INLINE bool GetDXReady(void) { return _dx_ready;} - void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyProperty::Mode TexBlendMode,bool bJustEnable); + void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyAttrib::Mode TexBlendMode,bool bJustEnable); void dx_cleanup(bool bRestoreDisplayMode,bool bAtExitFnCalled); diff --git a/panda/src/dxgsg8/Sources.pp b/panda/src/dxgsg8/Sources.pp index e700a355b7..7221356812 100644 --- a/panda/src/dxgsg8/Sources.pp +++ b/panda/src/dxgsg8/Sources.pp @@ -7,8 +7,8 @@ #begin lib_target #define TARGET dxgsg8 #define LOCAL_LIBS \ - cull gsgmisc gsgbase gobj sgattrib sgraphutil graph display \ - putil linmath sgraph mathutil pnmimage event + gsgmisc gsgbase gobj display \ + putil linmath mathutil pnmimage event #define COMBINED_SOURCES $[TARGET]_composite1.cxx diff --git a/panda/src/dxgsg8/dxGeomNodeContext8.I b/panda/src/dxgsg8/dxGeomNodeContext8.I index 739d1d127a..ab092a9755 100644 --- a/panda/src/dxgsg8/dxGeomNodeContext8.I +++ b/panda/src/dxgsg8/dxGeomNodeContext8.I @@ -23,7 +23,7 @@ // Description: //////////////////////////////////////////////////////////////////// INLINE DXGeomNodeContext:: -DXGeomNodeContext(GeomNode *node) : GeomNodeContext(node) +DXGeomNodeContext(qpGeomNode *node) : GeomNodeContext(node) { _num_verts = 0; /* diff --git a/panda/src/dxgsg8/dxGeomNodeContext8.h b/panda/src/dxgsg8/dxGeomNodeContext8.h index 8d7a797bb9..9a8ad16564 100644 --- a/panda/src/dxgsg8/dxGeomNodeContext8.h +++ b/panda/src/dxgsg8/dxGeomNodeContext8.h @@ -20,8 +20,9 @@ #define DXGEOMNODECONTEXT_H #include "dxgsg8base.h" -#include -#include + +#include "geomNodeContext.h" +#include "qpgeomNode.h" #include "pvector.h" typedef struct { @@ -37,12 +38,12 @@ typedef struct { //////////////////////////////////////////////////////////////////// class EXPCL_PANDADX DXGeomNodeContext : public GeomNodeContext { public: - INLINE DXGeomNodeContext(GeomNode *node); + INLINE DXGeomNodeContext(qpGeomNode *node); ~DXGeomNodeContext(); // A list of the dynamic Geoms within the GeomNode; these aren't // part of the above display list and must be drawn separately - typedef pvector Geoms; + typedef pvector< PT(Geom) > Geoms; Geoms _cached_geoms,_other_geoms; // VB's are already reference-counted by D3D, no need to make separate panda object to do that diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx index 0d1d9b1aaf..9488dbf0bd 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx @@ -16,12 +16,11 @@ // //////////////////////////////////////////////////////////////////// -#include "pandabase.h" -#include "directRenderTraverser.h" -#include "cullTraverser.h" +#include "dxGraphicsStateGuardian8.h" +#include "config_dxgsg8.h" +#include "d3dx8.h" + #include "displayRegion.h" -#include "lensNode.h" -#include "camera.h" #include "renderBuffer.h" #include "geom.h" #include "geomSphere.h" @@ -29,30 +28,11 @@ #include "graphicsWindow.h" #include "graphicsChannel.h" #include "lens.h" -#include "get_rel_pos.h" #include "perspectiveLens.h" #include "ambientLight.h" #include "directionalLight.h" #include "pointLight.h" #include "spotlight.h" -#include "transformTransition.h" -#include "colorTransition.h" -#include "textureTransition.h" -#include "renderModeTransition.h" -#include "materialTransition.h" -#include "colorBlendTransition.h" -#include "colorMaskTransition.h" -#include "texMatrixTransition.h" -#include "texGenTransition.h" -#include "textureApplyTransition.h" -#include "clipPlaneTransition.h" -#include "transparencyTransition.h" -#include "fogTransition.h" -#include "linesmoothTransition.h" -#include "depthTestTransition.h" -#include "depthWriteTransition.h" -#include "cullFaceTransition.h" -#include "stencilTransition.h" #include "textureAttrib.h" #include "lightAttrib.h" #include "cullFaceAttrib.h" @@ -72,10 +52,6 @@ #include "pStatCollector.h" #endif -#include "config_dxgsg8.h" -#include "dxGraphicsStateGuardian8.h" -#include "d3dx8.h" - // This is a temporary hack. The whole color_transform and // alpha_transform system will soon be replaced with something a // little smaller. Until then, we'll just define this macro to @@ -306,15 +282,6 @@ reset_panda_gsg(void) { // stmt below is incorrect for general mono displays, need both right and left flags set. // stereo not supported in dx8 // _buffer_mask &= ~RenderBuffer::T_right; - - if(_render_traverser.is_null()) { - // Create a default RenderTraverser. - if (dx_cull_traversal) { - _render_traverser = new CullTraverser(this, RenderRelation::get_class_type()); - } else { - _render_traverser = new DirectRenderTraverser(this, RenderRelation::get_class_type()); - } - } } //////////////////////////////////////////////////////////////////// @@ -333,8 +300,6 @@ DXGraphicsStateGuardian(GraphicsWindow *win) : GraphicsStateGuardian(win) { _pFvfBufBasePtr = NULL; _index_buf=NULL; - _clip_plane_enabled = (bool *)NULL; - _cur_clip_plane_enabled = (bool *)NULL; _pStatMeterFont=NULL; _bShowFPSMeter = false; @@ -388,7 +353,8 @@ reset(void) { void DXGraphicsStateGuardian:: free_dxgsg_objects(void) { // dont want a full reset of gsg, just a state clear - GraphicsStateGuardian::clear_cached_state(); // want gsg to pass all state settings through + set_state(RenderState::make_empty()); + // want gsg to pass all state settings through _bDXisReady = false; @@ -414,7 +380,7 @@ dx_init(HCURSOR hMouseCursor) { HRESULT hr; // make sure gsg passes all current state down to us - GraphicsStateGuardian::clear_cached_state(); + set_state(RenderState::make_empty()); // want gsg to pass all state settings down so any non-matching defaults we set here get overwritten assert(scrn.pD3D8!=NULL); @@ -631,7 +597,7 @@ dx_init(HCURSOR hMouseCursor) { enable_line_smooth(false); // enable_multisample(true); - _current_fill_mode = RenderModeProperty::M_filled; + _current_fill_mode = RenderModeAttrib::M_filled; scrn.pD3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); scrn.pD3DDevice->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1); // Use the diffuse vertex color. @@ -646,29 +612,10 @@ dx_init(HCURSOR hMouseCursor) { if(dx_auto_normalize_lighting) scrn.pD3DDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true); - // Set up the clip plane id map (need to rewrite this) - if(scrn.d3dcaps.MaxUserClipPlanes==0) - _max_clip_planes = D3DMAXUSERCLIPPLANES; - else _max_clip_planes = scrn.d3dcaps.MaxUserClipPlanes; - - if(_available_clip_plane_ids.is_null()) - _available_clip_plane_ids = PTA(PlaneNode*)::empty_array(_max_clip_planes); - - if(_clip_plane_enabled == NULL) - _clip_plane_enabled = new bool[_max_clip_planes]; - - if(_cur_clip_plane_enabled == NULL) - _cur_clip_plane_enabled = new bool[_max_clip_planes]; - - for (int i = 0; i < _max_clip_planes; i++) { - _available_clip_plane_ids[i] = NULL; - _clip_plane_enabled[i] = false; - } - // must do SetTSS here because redundant states are filtered out by our code based on current values above, so // initial conditions must be correct - _CurTexBlendMode = TextureApplyProperty::M_modulate; + _CurTexBlendMode = TextureApplyAttrib::M_modulate; SetTextureBlendMode(_CurTexBlendMode,false); _texturing_enabled = false; scrn.pD3DDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_DISABLE); // disables texturing @@ -785,15 +732,13 @@ dx_init(HCURSOR hMouseCursor) { PRINT_REFCNT(dxgsg,scrn.pD3DDevice); // Make sure the DX state matches all of our initial attribute states. - PT(DepthTestTransition) dta = new DepthTestTransition; - PT(DepthWriteTransition) dwa = new DepthWriteTransition; - PT(CullFaceTransition) cfa = new CullFaceTransition; - PT(TextureTransition) ta = new TextureTransition; - + CPT(RenderAttrib) dta = DepthTestAttrib::make(DepthTestAttrib::M_less); + CPT(RenderAttrib) dwa = DepthWriteAttrib::make(DepthWriteAttrib::M_on); + CPT(RenderAttrib) cfa = CullFaceAttrib::make(CullFaceAttrib::M_cull_clockwise); + dta->issue(this); dwa->issue(this); cfa->issue(this); - ta->issue(this); // no curtextcontext, this does nothing. dx should already be properly inited above anyway PRINT_REFCNT(dxgsg,scrn.pD3DDevice); } @@ -996,86 +941,6 @@ void INLINE TestDrawPrimFailure(DP_Type dptype,HRESULT hr,IDirect3DDevice8 *pD3D #define TestDrawPrimFailure(a,b,c,nVerts,nTris) CountDPs(nVerts,nTris); #endif -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::render_frame -// Access: Public, Virtual -// Description: Renders an entire frame, including all display -// regions within the frame, and includes any necessary -// pre- and post-processing like swapping buffers. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -render_frame() { - if (!_bDXisReady) { - //if(dxgsg_cat.is_spam()) - // dxgsg_cat.spam() << "dx is not ready, skipping render_frame()\n"; - return; - } - - _win->begin_frame(); - -#ifdef GSG_VERBOSE - dxgsg_cat.debug() - << "begin frame --------------------------------------------" << endl; -#endif - - _decal_level = 0; - - if (_clear_buffer_type != 0) { - // First, clear the entire window. - #ifndef NO_MULTIPLE_DISPLAY_REGIONS - PT(DisplayRegion) win_dr = _win->make_scratch_display_region(_win->get_width(), _win->get_height()); - clear(get_render_buffer(_clear_buffer_type), win_dr); - #else - clear(get_render_buffer(_clear_buffer_type)); - #endif - } - -#if 0 - int max_channel_index = _win->get_max_channel_index(); - for (int c = 0; c < max_channel_index; c++) { - if (_win->is_channel_defined(c)) { -#endif - - // only 1 channel on dx currently - assert(_win->get_max_channel_index()==1); - assert(_win->is_channel_defined(0)); - - if(_panda_gfx_channel->is_active()) { - // Now render each of our layers in order. - - int num_layers = _panda_gfx_channel->get_num_layers(); - for (int l = 0; l < num_layers; l++) { - GraphicsLayer *layer = _panda_gfx_channel->get_layer(l); - if (layer->is_active()) { - int num_drs = layer->get_num_drs(); - for (int d = 0; d < num_drs; d++) { - DisplayRegion *dr = layer->get_dr(d); - Camera *cam = dr->get_camera(); - - // For each display region, render from the camera's view. - if (dr->is_active() && cam != (Camera *)NULL && - cam->is_active() && cam->get_scene() != (Node *)NULL) { - DisplayRegionStack old_dr = push_display_region(dr); - prepare_display_region(); - render_scene(cam->get_scene(), cam); - pop_display_region(old_dr); - } - } - } // if (layer->is_active()) - } - } // if (chan->is_active()) -#if 0 - } - } // for (int c = 0; c < max_channel_index; c++) -#endif - -#ifdef GSG_VERBOSE - dxgsg_cat.debug() << "end frame ----------------------------------------------" << endl; -#endif - - _win->end_frame(); -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::report_texmgr_stats // Access: Protected @@ -1197,147 +1062,6 @@ report_texmgr_stats() { #endif } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::render_scene -// Access: Public, Virtual -// Description: Renders an entire scene, from the root node of the -// scene graph, as seen from a particular LensNode -// and with a given initial state. This initial state -// may be modified during rendering. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -render_scene(Node *root, LensNode *projnode) { -#ifdef GSG_VERBOSE - _pass_number = 0; - dxgsg_cat.debug() - << "begin scene - - - - - - - - - - - - - - - - - - - - - - - - -" - << endl; -#endif - _current_root_node = root; - - render_subgraph(_render_traverser, root, projnode, - AllTransitionsWrapper()); - -#ifdef GSG_VERBOSE - dxgsg_cat.debug() - << "done scene - - - - - - - - - - - - - - - - - - - - - - - - -" - << endl; -#endif -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::render_subgraph -// Access: Public, Virtual -// Description: Renders a subgraph of the scene graph as seen from a -// given lens node, and with a particular initial -// state. This state may be modified by the render -// process. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -render_subgraph(RenderTraverser *traverser, - Node *subgraph, LensNode *projnode, - const AllTransitionsWrapper &net_trans) { - LensNode *old_camera = _current_camera; - _current_camera = projnode; - LMatrix4f old_projection_mat = _current_projection_mat; - - Lens *lens = projnode->get_lens(); - const LMatrix4f &projection_mat = lens->get_projection_mat(); - - // d3d is left-handed coord system - _current_projection_mat = - LMatrix4f::convert_mat(CS_yup_left, lens->get_coordinate_system()) * - projection_mat; - _projection_mat_stack_count++; - -#if 0 - dxgsg_cat.spam() << "cur projection matrix: " << _current_projection_mat <<"\n"; -#endif - -#ifdef _DEBUG - { - static bool bPrintedMsg=false; - - if((!bPrintedMsg) && !IS_NEARLY_EQUAL(projection_mat(2,3),1.0f)) { - bPrintedMsg=true; - dxgsg_cat.debug() << "non w-compliant render_subgraph projection matrix [2][3] should be 1.0, instead is: " << projection_mat(2,3) << endl; - dxgsg_cat.debug() << "cur projection matrix: " << projection_mat << endl; - } - - // note: a projection matrix that does not have a [3][4] value of 1.0f is - // not w-compliant and could cause problems with fog - - } -#endif - - HRESULT hr; - - // BUGBUG: could we avoid doing this every frame if projmat doesnt change? - // We load the projection matrix directly. - hr = scrn.pD3DDevice->SetTransform(D3DTS_PROJECTION, - (D3DMATRIX*) _current_projection_mat.get_data()); - - // We infer the modelview matrix by doing a wrt on the projection - // node. - LMatrix4f modelview_mat; - get_rel_mat(subgraph, _current_camera, modelview_mat); //needs reversal from glgsg, probably due D3D LH coordsys -// get_rel_mat(_current_camera, subgraph, modelview_mat); - - if (_coordinate_system != CS_yup_left) { - // Now we build the coordinate system conversion into the - // modelview matrix (as described in the paragraph above). - modelview_mat = modelview_mat * - LMatrix4f::convert_mat(_coordinate_system, CS_yup_left); - } - - // The modelview matrix will be loaded as each geometry is - // encountered. So we set the supplied modelview matrix as an - // initial value instead of loading it now. - AllTransitionsWrapper sub_trans = net_trans; - sub_trans.set_transition(new TransformTransition(modelview_mat)); - - render_subgraph(traverser, subgraph, sub_trans); - - _current_camera = old_camera; - _current_projection_mat = old_projection_mat; - _projection_mat_stack_count--; - - - // We must now restore the projection matrix from before. We could - // do a push/pop matrix if we were using D3DX - if (_projection_mat_stack_count > 0) - hr =scrn.pD3DDevice->SetTransform(D3DTS_PROJECTION, - (D3DMATRIX*) _current_projection_mat.get_data()); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::render_subgraph -// Access: Public, Virtual -// Description: Renders a subgraph of the scene graph as seen from the -// current lens node, and with a particular -// initial state. This state may be modified during the -// render process. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -render_subgraph(RenderTraverser *traverser, Node *subgraph, - const AllTransitionsWrapper &net_trans) { -#ifdef GSG_VERBOSE - dxgsg_cat.debug() - << "begin subgraph (pass " << ++_pass_number - << ") - - - - - - - - - - - - - - - - - - - - - - - - -" << endl; -#endif - - nassertv(traverser != (RenderTraverser *)NULL); - traverser->traverse(subgraph, net_trans); - -#ifdef GSG_VERBOSE - dxgsg_cat.debug() - << "end subgraph (pass " << _pass_number - << ") - - - - - - - - - - - - - - - - - - - - - - - - -" - << endl; -#endif -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::add_to_FVFBuf // Access: Private @@ -2001,37 +1725,22 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { Texture *tex = geom->get_texture(); if(tex !=NULL) { - - // set up the texture-rendering state - NodeTransitions state; - - // this sets up texturing. Could just set the renderstates directly, but this is a little cleaner - TextureTransition *ta = new TextureTransition(tex); - state.set_transition(ta); - - TextureApplyTransition *taa = new TextureApplyTransition(TextureApplyProperty::M_modulate); - state.set_transition(taa); - - modify_state(state); - - tex_xsize = tex->_pbuffer->get_xsize(); - tex_ysize = tex->_pbuffer->get_ysize(); + // set up the texture-rendering state + modify_state(RenderState::make + (TextureAttrib::make(tex), + TextureApplyAttrib::make(TextureApplyAttrib::M_modulate))); + tex_xsize = tex->_pbuffer->get_xsize(); + tex_ysize = tex->_pbuffer->get_ysize(); } // save the modelview matrix - LMatrix4f modelview_mat; + const LMatrix4f &modelview_mat = _transform->get_mat(); - const TransformTransition *ctatt; - if (!get_attribute_into(ctatt, this)) - modelview_mat = LMatrix4f::ident_mat(); - else - modelview_mat = ctatt->get_matrix(); + // We don't need to mess with the aspect ratio, since we are now + // using the default projection matrix, which has the right aspect + // ratio built in. - // get the camera information - float aspect_ratio = - get_current_camera()->get_lens()->get_aspect_ratio(); - - // null the world xform, so sprites are orthog to scrn (but not necessarily camera pnt unless they lie along z-axis) + // null the world xform, so sprites are orthog to scrn scrn.pD3DDevice->SetTransform(D3DTS_WORLD, &matIdentity); // only need to change _WORLD xform, _VIEW xform is Identity @@ -2049,10 +1758,11 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { bool alpha = false; if (!geom->get_alpha_disable()) { - // figure out if alpha's enabled (if not, no reason to sort) - const TransparencyTransition *ctratt; - if (get_attribute_into(ctratt, this)) - alpha = (ctratt->get_mode() != TransparencyProperty::M_none); + // figure out if alpha's enabled (if not, no reason to sort) + const TransparencyAttrib *trans = _qpstate->get_transparency(); + if (trans != (const TransparencyAttrib *)NULL) { + alpha = (trans->get_mode() != TransparencyAttrib::M_none); + } } // inner loop vars @@ -2081,7 +1791,7 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { // y direction if (y_overall) - scaled_height = geom->_y_texel_ratio[0] * half_height * aspect_ratio; + scaled_height = geom->_y_texel_ratio[0] * half_height; else { nassertv(((int)geom->_y_texel_ratio.size() >= geom->get_num_prims())); y_walk = &geom->_y_texel_ratio[0]; @@ -2228,7 +1938,7 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { scaled_width = pSpr->_x_ratio * half_width; if (!y_overall) - scaled_height = pSpr->_y_ratio * half_height * aspect_ratio; + scaled_height = pSpr->_y_ratio * half_height; // if not G_OVERALL, do some trig for this z rotate //what is the theta angle?? if (theta_on) { @@ -2319,7 +2029,8 @@ draw_sprite(GeomSprite *geom, GeomContext *gc) { delete [] SpriteArray; // restore the matrices - scrn.pD3DDevice->SetTransform(D3DTS_WORLD, &OldD3DWorldMatrix); + scrn.pD3DDevice->SetTransform(D3DTS_WORLD, + (D3DMATRIX*)modelview_mat.get_data()); if(bReEnableDither) enable_dither(true); @@ -3299,93 +3010,6 @@ copy_texture(TextureContext *tc, const DisplayRegion *dr, const RenderBuffer &rb copy_texture(tc, dr); } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::draw_texture -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -draw_texture(TextureContext *tc, const DisplayRegion *dr) { - - dxgsg_cat.fatal() << "DXGSG draw_texture unimplemented!!!"; - return; - - nassertv(tc != NULL && dr != NULL); - -#ifdef WBD_GL_MODE - Texture *tex = tc->_texture; - - DisplayRegionStack old_dr = push_display_region(dr); - prepare_display_region(); - - NodeTransitions state; - CullFaceTransition *cfa = new CullFaceTransition(CullFaceProperty::M_cull_none); - DepthTestTransition *dta = new DepthTestTransition(DepthTestProperty::M_none); - DepthWriteTransition *dwa = new DepthWriteTransition(DepthWriteTransition::off()); - TextureTransition *ta = new TextureTransition(tex); - TextureApplyTransition *taa = new TextureApplyTransition(TextureApplyProperty::M_decal); - - state.set_transition(new ColorMaskTransition); - state.set_transition(new RenderModeTransition); - state.set_transition(new TexMatrixTransition); - state.set_transition(new TransformTransition); - state.set_transition(new ColorBlendTransition); - state.set_transition(cfa); - state.set_transition(dta); - state.set_transition(dwa); - state.set_transition(ta); - state.set_transition(taa); - modify_state(state); - - // We set up an orthographic projection that defines our entire - // viewport to the range [0..1] in both dimensions. Then, when we - // create a unit square polygon below, it will exactly fill the - // viewport (and thus exactly fill the display region). - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - gluOrtho2D(0, 1, 0, 1); - - float txl, txr, tyt, tyb; - txl = tyb = 0.; - if (tex->_has_requested_size) { - txr = ((float)(tex->_requested_w)) / ((float)(tex->_pbuffer->get_xsize())); - tyt = ((float)(tex->_requested_h)) / ((float)(tex->_pbuffer->get_ysize())); - } else { - txr = tyt = 1.; - } - - // This two-triangle strip is actually a quad. But it's usually - // better to render quads as tristrips anyway. - glBegin(GL_TRIANGLE_STRIP); - glTexCoord2f(txl, tyb); glVertex2i(0, 0); - glTexCoord2f(txr, tyb); glVertex2i(1, 0); - glTexCoord2f(txl, tyt); glVertex2i(0, 1); - glTexCoord2f(txr, tyt); glVertex2i(1, 1); - glEnd(); - - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - - pop_display_region(old_dr); -#endif // WBD_GL_MODE - -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::draw_texture -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -draw_texture(TextureContext *tc, const DisplayRegion *dr, const RenderBuffer &rb) { - dxgsg_cat.fatal() << "DXGSG draw_texture unimplemented!!!"; - return; - - set_draw_buffer(rb); - draw_texture(tc, dr); -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::texture_to_pixel_buffer // Access: Public, Virtual @@ -3419,22 +3043,8 @@ texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb) { void DXGraphicsStateGuardian:: texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb, const DisplayRegion *dr) { - nassertv(tc != NULL && pb != NULL && dr != NULL); - - Texture *tex = tc->_texture; - - // Do a deep copy to initialize the pixel buffer - pb->copy(tex->_pbuffer); - - // If the image was empty, we need to render the texture into the frame - // buffer and then copy the results into the pixel buffer's image - if (pb->_image.empty()) { - int w = pb->get_xsize(); - int h = pb->get_ysize(); - draw_texture(tc, dr); - pb->_image = PTA_uchar::empty_array(w * h * pb->get_num_components()); - copy_pixel_buffer(pb, dr); - } + dxgsg_cat.error() + << "texture_to_pixel_buffer unimplemented!\n"; } //////////////////////////////////////////////////////////////////// @@ -3552,135 +3162,6 @@ copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, copy_pixel_buffer(pb, dr); } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::draw_pixel_buffer -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, - const NodeTransitions& na) { - - dxgsg_cat.fatal() << "DXGSG draw_pixel_buffer unimplemented!!!"; - return; - -#ifdef WBD_GL_MODE - nassertv(pb != NULL && dr != NULL); - nassertv(!pb->_image.empty()); - - DisplayRegionStack old_dr = push_display_region(dr); - prepare_display_region(); - - NodeTransitions state(na); - state.set_transition(new TextureTransition); - state.set_transition(new TransformTransition); - state.set_transition(new ColorBlendTransition); - state.set_transition(new StencilTransition); - - switch (pb->get_format()) { - case PixelBuffer::F_depth_component: - { - ColorMaskTransition *cma = new ColorMaskTransition(0); - DepthTestTransition *dta = new DepthTestTransition(DepthTestProperty::M_always); - DepthWriteTransition *dwa = new DepthWriteTransition(DepthWriteTransition::off()); - state.set_transition(cma); - state.set_transition(dta); - state.set_transition(dwa); - } - break; - - case PixelBuffer::F_rgb: - case PixelBuffer::F_rgb5: - case PixelBuffer::F_rgb8: - case PixelBuffer::F_rgb12: - case PixelBuffer::F_rgba: - case PixelBuffer::F_rgba4: - case PixelBuffer::F_rgba8: - case PixelBuffer::F_rgba12: - { - ColorMaskTransition *cma = new ColorMaskTransition; - DepthTestTransition *dta = new DepthTestTransition(DepthTestProperty::M_none); - DepthWriteTransition *dwa = new DepthWriteTransition(DepthWriteTransition::off()); - state.set_transition(cma); - state.set_transition(dta); - state.set_transition(dwa); - } - break; - default: - dxgsg_cat.error() - << "draw_pixel_buffer(): unknown buffer format" << endl; - break; - } - - modify_state(state); - - enable_color_material(false); - set_unpack_alignment(1); - - glMatrixMode( GL_PROJECTION ); - glPushMatrix(); - glLoadIdentity(); - gluOrtho2D(0, _win->get_width(), - 0, _win->get_height()); - -#ifdef GSG_VERBOSE - dxgsg_cat.debug() - << "glDrawPixels(" << pb->get_xsize() << ", " << pb->get_ysize() - << ", "; - switch (get_external_image_format(pb->get_format())) { - case GL_DEPTH_COMPONENT: - dxgsg_cat.debug(false) << "GL_DEPTH_COMPONENT, "; - break; - case GL_RGB: - dxgsg_cat.debug(false) << "GL_RGB, "; - break; - case GL_RGBA: - dxgsg_cat.debug(false) << "GL_RGBA, "; - break; - default: - dxgsg_cat.debug(false) << "unknown, "; - break; - } - switch (get_image_type(pb->get_image_type())) { - case GL_UNSIGNED_BYTE: - dxgsg_cat.debug(false) << "GL_UNSIGNED_BYTE, "; - break; - case GL_float: - dxgsg_cat.debug(false) << "GL_float, "; - break; - default: - dxgsg_cat.debug(false) << "unknown, "; - break; - } - dxgsg_cat.debug(false) - << (void *)pb->_image.p() << ")" << endl; -#endif - - glRasterPos2i( pb->get_xorg(), pb->get_yorg() ); - glDrawPixels( pb->get_xsize(), pb->get_ysize(), - get_external_image_format(pb->get_format()), - get_image_type(pb->get_image_type()), - pb->_image.p() ); - - glMatrixMode( GL_PROJECTION ); - glPopMatrix(); - - pop_display_region(old_dr); -#endif // WBD_GL_MODE -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::draw_pixel_buffer -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, - const RenderBuffer &rb, const NodeTransitions& na) { - set_read_buffer(rb); - draw_pixel_buffer(pb, dr, na); -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::apply_material // Access: Public, Virtual @@ -3696,61 +3177,6 @@ void DXGraphicsStateGuardian::apply_material( const Material* material ) { scrn.pD3DDevice->SetMaterial(&cur_material); } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::apply_fog -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -apply_fog(Fog *fog) { - - if(_doFogType==None) - return; - - Fog::Mode panda_fogmode = fog->get_mode(); - D3DFOGMODE d3dfogmode = get_fog_mode_type(panda_fogmode); - - - // should probably avoid doing redundant SetRenderStates, but whatever - scrn.pD3DDevice->SetRenderState((D3DRENDERSTATETYPE)_doFogType, d3dfogmode); - - const Colorf &fog_colr = fog->get_color(); - scrn.pD3DDevice->SetRenderState(D3DRS_FOGCOLOR, - MY_D3DRGBA(fog_colr[0], fog_colr[1], fog_colr[2], 0.0f)); // Alpha bits are not used - - // do we need to adjust fog start/end values based on D3DPRASTERCAPS_WFOG/D3DPRASTERCAPS_ZFOG ? - // if not WFOG, then docs say we need to adjust values to range [0,1] - - switch (panda_fogmode) { - case Fog::M_linear: - { - // Linear fog may be world-relative or - // camera-relative. The fog object knows how to - // decode its parameters into camera-relative - // properties. - float fog_start, fog_end; - fog->compute_linear_range(fog_start, fog_end, - _current_camera, - _coordinate_system); - - scrn.pD3DDevice->SetRenderState( D3DRS_FOGSTART, - *((LPDWORD) (&fog_start)) ); - scrn.pD3DDevice->SetRenderState( D3DRS_FOGEND, - *((LPDWORD) (&fog_end)) ); - } - break; - case Fog::M_exponential: - case Fog::M_exponential_squared: - { - // Exponential fog is always camera-relative. - float fog_density = fog->get_exp_density(); - scrn.pD3DDevice->SetRenderState( D3DRS_FOGDENSITY, - *((LPDWORD) (&fog_density)) ); - } - break; - } -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::apply_fog // Access: Public, Virtual @@ -3800,289 +3226,13 @@ apply_fog(qpFog *fog) { } } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_transform -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_transform(const TransformTransition *attrib) { - scrn.pD3DDevice->SetTransform(D3DTS_WORLD/*VIEW*/, - (D3DMATRIX*) attrib->get_matrix().get_data()); - _bTransformIssued = true; -} +void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyAttrib::Mode TexBlendMode,bool bCanJustEnable) { -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_matrix -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_tex_matrix(const TexMatrixTransition *attrib) { - dxgsg_cat.fatal() << "DXGSG issue_tex_matrix unimplemented!!!"; - return; - -#ifdef WBD_GL_MODE -#ifdef GSG_VERBOSE - dxgsg_cat.debug() - << "glLoadMatrix(GL_TEXTURE): " << attrib->get_matrix() << endl; -#endif - glMatrixMode(GL_TEXTURE); - glLoadMatrixf(attrib->get_matrix().get_data()); -#else - scrn.pD3DDevice->SetTransform( D3DTS_TEXTURE0, - (D3DMATRIX *)attrib->get_matrix().get_data()); -#endif // WBD_GL_MODE -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_color -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_color(const ColorTransition *attrib) { - - bool bAttribOn=attrib->is_on(); - bool bIsReal = (bAttribOn ? attrib->is_real() : false); - - _has_scene_graph_color = bAttribOn; - - if(bAttribOn && bIsReal) { - _scene_graph_color = attrib->get_color(); - _scene_graph_color_stale = true; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_color_transform -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_color_transform(const ColorMatrixTransition *attrib) { - _current_color_mat = attrib->get_matrix(); - - // couldnt we compare a single ptr instead of doing full comparison? - // bugbug: the ColorMatrixTransition needs to be an On/Off transition - // so we dont have to do this comparison - if (_current_color_mat == LMatrix4f::ident_mat()) { - _color_transform_enabled = false; - - } else { - _color_transform_enabled = true; - } - _scene_graph_color_stale = _has_scene_graph_color; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_alpha_transform -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_alpha_transform(const AlphaTransformTransition *attrib) { - _current_alpha_offset = attrib->get_offset(); - _current_alpha_scale = attrib->get_scale(); - - if ((_current_alpha_offset == 0.0f) && (_current_alpha_scale == 1.0f)) { - _alpha_transform_enabled = false; - } else { - _alpha_transform_enabled = true; - } - _scene_graph_color_stale = _has_scene_graph_color; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_texture -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_texture(const TextureTransition *attrib) { - if (attrib->is_on()) { - enable_texturing(true); - Texture *tex = attrib->get_texture(); - nassertv(tex != (Texture *)NULL); - tex->apply(this); - } else { - enable_texturing(false); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_tex_gen -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_tex_gen(const TexGenTransition *attrib) { - dxgsg_cat.fatal() << "DXGSG issue_tex_gen unimplemented!!!"; - return; -#ifdef WBD_GL_MODE - TexGenProperty::Mode mode = attrib->get_mode(); - - switch (mode) { - case TexGenProperty::M_none: - glDisable(GL_TEXTURE_GEN_S); - glDisable(GL_TEXTURE_GEN_T); - glDisable(GL_TEXTURE_GEN_Q); - glDisable(GL_TEXTURE_GEN_R); - break; - - case TexGenProperty::M_texture_projector: - { - glEnable(GL_TEXTURE_GEN_S); - glEnable(GL_TEXTURE_GEN_T); - glEnable(GL_TEXTURE_GEN_Q); - glEnable(GL_TEXTURE_GEN_R); - const LMatrix4f &plane = attrib->get_plane(); - glTexGenfv(GL_S, GL_OBJECT_PLANE, plane.get_row(0).get_data()); - glTexGenfv(GL_T, GL_OBJECT_PLANE, plane.get_row(1).get_data()); - glTexGenfv(GL_R, GL_OBJECT_PLANE, plane.get_row(2).get_data()); - glTexGenfv(GL_Q, GL_OBJECT_PLANE, plane.get_row(3).get_data()); - glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - } - break; - - case TexGenProperty::M_sphere_map: - glEnable(GL_TEXTURE_GEN_S); - glEnable(GL_TEXTURE_GEN_T); - glDisable(GL_TEXTURE_GEN_Q); - glDisable(GL_TEXTURE_GEN_R); - glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); - glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); - break; - - default: - dxgsg_cat.error() - << "Unknown texgen mode " << (int)mode << endl; - break; - } -#endif // WBD_GL_MODE -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_material -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_material(const MaterialTransition *attrib) { - if (attrib->is_on()) { - const Material *material = attrib->get_material(); - nassertv(material != (const Material *)NULL); - apply_material(material); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_fog -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_fog(const FogTransition *attrib) { - - if (attrib->is_on()) { - enable_fog(true); - Fog *fog = attrib->get_fog(); - nassertv(fog != (Fog *)NULL); - fog->apply(this); - } else { - enable_fog(false); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_render_mode -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_render_mode(const RenderModeTransition *attrib) { - - RenderModeProperty::Mode mode = attrib->get_mode(); - - if(mode==_current_fill_mode) - return; - - switch (mode) { - case RenderModeProperty::M_filled: - scrn.pD3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); - break; - - case RenderModeProperty::M_wireframe: - scrn.pD3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); - break; - - default: - dxgsg_cat.error() - << "Unknown render mode " << (int)mode << endl; - } - - _current_fill_mode = mode; -} - -/* -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::reset_ambient -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -reset_ambient() { - _lmodel_ambient += 2.0f; -} -*/ - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_color_blend // -// Access: Public, Virtual // -// Description: // -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_color_blend(const ColorBlendTransition *attrib) { - - ColorBlendProperty::Mode mode = attrib->get_mode(); - - switch (mode) { - case ColorBlendProperty::M_none: - enable_blend(false); - break; - case ColorBlendProperty::M_multiply: - enable_blend(true); - call_dxBlendFunc(D3DBLEND_DESTCOLOR, D3DBLEND_ZERO); - break; - case ColorBlendProperty::M_add: - enable_blend(true); - call_dxBlendFunc(D3DBLEND_ONE, D3DBLEND_ONE); - break; - case ColorBlendProperty::M_multiply_add: - enable_blend(true); - call_dxBlendFunc(D3DBLEND_DESTCOLOR, D3DBLEND_ONE); - break; - case ColorBlendProperty::M_alpha: - enable_blend(true); - call_dxBlendFunc(D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA); - break; - default: - dxgsg_cat.error() - << "Unknown color blend mode " << (int)mode << endl; - break; - } -} - -void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyProperty::Mode TexBlendMode,bool bCanJustEnable) { - -/*class TextureApplyProperty { +/*class TextureApplyAttrib { enum Mode { M_modulate,M_decal,M_blend,M_replace,M_add}; */ - static D3DTEXTUREOP TexBlendColorOp1[/* TextureApplyProperty::Mode maxval*/ 10] = + static D3DTEXTUREOP TexBlendColorOp1[/* TextureApplyAttrib::Mode maxval*/ 10] = {D3DTOP_MODULATE,D3DTOP_BLENDTEXTUREALPHA,D3DTOP_MODULATE,D3DTOP_SELECTARG1,D3DTOP_ADD}; //if bCanJustEnable, then we only need to make sure ColorOp is turned on and set properly @@ -4096,7 +3246,7 @@ void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyProperty::Mode Tex switch (TexBlendMode) { - case TextureApplyProperty::M_modulate: + case TextureApplyAttrib::M_modulate: // emulates GL_MODULATE glTexEnv mode // want to multiply tex-color*pixel color to emulate GL modulate blend (see glTexEnv) scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); @@ -4106,7 +3256,7 @@ void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyProperty::Mode Tex scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); break; - case TextureApplyProperty::M_decal: + case TextureApplyAttrib::M_decal: // emulates GL_DECAL glTexEnv mode scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); @@ -4115,13 +3265,13 @@ void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyProperty::Mode Tex scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE ); break; - case TextureApplyProperty::M_replace: + case TextureApplyAttrib::M_replace: scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); break; - case TextureApplyProperty::M_add: + case TextureApplyAttrib::M_add: scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); @@ -4131,7 +3281,7 @@ void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyProperty::Mode Tex scrn.pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); break; - case TextureApplyProperty::M_blend: + case TextureApplyAttrib::M_blend: dxgsg_cat.error() << "Impossible to emulate GL_BLEND in DX exactly " << (int) TexBlendMode << endl; /* @@ -4189,300 +3339,6 @@ enable_texturing(bool val) { } } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_texture_apply -// Access: Public, Virtual -// Description: handles texture transition (i.e. filter modes, etc) changes -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_texture_apply(const TextureApplyTransition *attrib) { - - _CurTexBlendMode = attrib->get_mode(); - - if (!_texturing_enabled) { - return; - } - - SetTextureBlendMode(_CurTexBlendMode,FALSE); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_color_mask -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_color_mask(const ColorMaskTransition *attrib) { - if(dxgsg_cat.is_debug() && ((scrn.d3dcaps.PrimitiveMiscCaps & D3DPMISCCAPS_COLORWRITEENABLE)==0)) { - dxgsg_cat.debug() << "DXGSG issue_color_mask unsupported by device #" << scrn.CardIDNum << endl; - return; - } - - UINT maskVal=0x0; - if(attrib->is_write_r()) - maskVal|=D3DCOLORWRITEENABLE_RED; - if(attrib->is_write_g()) - maskVal|=D3DCOLORWRITEENABLE_GREEN; - if(attrib->is_write_b()) - maskVal|=D3DCOLORWRITEENABLE_BLUE; - if(attrib->is_write_a()) - maskVal|=D3DCOLORWRITEENABLE_ALPHA; - - scrn.pD3DDevice->SetRenderState(D3DRS_COLORWRITEENABLE, maskVal); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_depth_test -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_depth_test(const DepthTestTransition *attrib) { - - - DepthTestProperty::Mode mode = attrib->get_mode(); - - if (mode == DepthTestProperty::M_none) { - _depth_test_enabled = false; - scrn.pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); - } else { - _depth_test_enabled = true; - scrn.pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); - scrn.pD3DDevice->SetRenderState(D3DRS_ZFUNC, get_depth_func_type(mode)); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_stencil -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_stencil(const StencilTransition *attrib) { - StencilProperty::Mode mode = attrib->get_mode(); - - if (mode == StencilProperty::M_none) { - enable_stencil_test(false); - } else { - enable_stencil_test(true); - D3DSTENCILOP pass_op = get_stencil_action_type(attrib->get_pass_action()); - D3DSTENCILOP fail_op = get_stencil_action_type(attrib->get_fail_action()); - D3DSTENCILOP zfail_op = get_stencil_action_type(attrib->get_zfail_action()); - - #ifdef _DEBUG - if(!(scrn.d3dcaps.StencilCaps & (1<<(pass_op-1)))) { - dxgsg_cat.warning() << "driver doesnt support pass stencil operation: " << pass_op << endl; - } - if(!(scrn.d3dcaps.StencilCaps & (1<<(fail_op-1)))) { - dxgsg_cat.warning() << "driver doesnt support fail stencil operation: " << fail_op << endl; - } - if(!(scrn.d3dcaps.StencilCaps & (1<<(zfail_op-1)))) { - dxgsg_cat.warning() << "driver doesnt support zfail stencil operation: " << zfail_op << endl; - } - #endif - // TODO: need to cache all these - scrn.pD3DDevice->SetRenderState(D3DRS_STENCILFUNC, get_stencil_func_type(mode)); - scrn.pD3DDevice->SetRenderState(D3DRS_STENCILPASS, pass_op); - scrn.pD3DDevice->SetRenderState(D3DRS_STENCILFAIL, fail_op); - scrn.pD3DDevice->SetRenderState(D3DRS_STENCILZFAIL, zfail_op); - scrn.pD3DDevice->SetRenderState(D3DRS_STENCILREF, attrib->get_reference_value()); - scrn.pD3DDevice->SetRenderState(D3DRS_STENCILMASK, attrib->get_func_mask()); - scrn.pD3DDevice->SetRenderState(D3DRS_STENCILWRITEMASK, attrib->get_write_mask()); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_cull_transition -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_cull_face(const CullFaceTransition *attrib) { - -#ifndef NDEBUG - if(dx_force_backface_culling!=0) { - return; // leave as initially set - } -#endif - - CullFaceProperty::Mode mode = attrib->get_mode(); - - switch (mode) { - case CullFaceProperty::M_cull_none: - scrn.pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); - break; - case CullFaceProperty::M_cull_clockwise: - scrn.pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); - break; - case CullFaceProperty::M_cull_counter_clockwise: - scrn.pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); - break; - case CullFaceProperty::M_cull_all: - dxgsg_cat.warning() << "M_cull_all is invalid for DX GSG renderer, using CULL_CCW \n"; - scrn.pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); - break; - default: - dxgsg_cat.error() - << "invalid cull face mode " << (int)mode << endl; - break; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_clip_plane -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_clip_plane(const ClipPlaneTransition *attrib) { - nassertv(attrib->get_default_dir() != TD_on); - - // Initialize the currently enabled clip plane list - int i; - for (i = 0; i < _max_clip_planes; i++) - _cur_clip_plane_enabled[i] = false; - - int num_enabled = 0; - ClipPlaneTransition::const_iterator pi; - for (pi = attrib->begin(); pi != attrib->end(); ++pi) { - PlaneNode *plane_node; - DCAST_INTO_V(plane_node, (*pi).first); - nassertv(plane_node != (PlaneNode *)NULL); - TransitionDirection dir = (*pi).second; - - if (dir == TD_on) { - _cur_clip_plane_id = -1; - num_enabled++; - - // Check to see if this clip plane has already been bound to an id - for (i = 0; i < _max_clip_planes; i++) { - if (_available_clip_plane_ids[i] == plane_node) { - // Clip plane has already been bound to an id, we only need - // to enable the clip plane, not apply it - _cur_clip_plane_id = -2; - enable_clip_plane(i, true); - _cur_clip_plane_enabled[i] = true; - break; - } - } - - // See if there are any unbound clip plane ids - if (_cur_clip_plane_id == -1) { - for (i = 0; i < _max_clip_planes; i++) { - if (_available_clip_plane_ids[i] == NULL) { - _available_clip_plane_ids[i] = plane_node; - _cur_clip_plane_id = i; - break; - } - } - } - - // If there were no unbound clip plane ids, see if we can replace - // a currently unused but previously bound id - if (_cur_clip_plane_id == -1) { - for (i = 0; i < _max_clip_planes; i++) { - if (attrib->is_off(_available_clip_plane_ids[i])) { - _available_clip_plane_ids[i] = plane_node; - _cur_clip_plane_id = i; - break; - } - } - } - - if (_cur_clip_plane_id >= 0) { - enable_clip_plane(_cur_clip_plane_id, true); - _cur_clip_plane_enabled[_cur_clip_plane_id] = true; - const Planef clip_plane = plane_node->get_plane(); - - float equation[4]; - equation[0] = clip_plane._a; - equation[1] = clip_plane._b; - equation[2] = clip_plane._c; - equation[3] = clip_plane._d; - scrn.pD3DDevice->SetClipPlane(_cur_clip_plane_id, equation); - - } else if (_cur_clip_plane_id == -1) { - dxgsg_cat.error() - << "issue_clip_plane() - failed to bind clip plane to id" << endl; - } - } - } - - // Disable all unused clip planes - for (i = 0; i < _max_clip_planes; i++) { - if (!_cur_clip_plane_enabled[i]) - enable_clip_plane(i, false); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_transparency -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_transparency(const TransparencyTransition *attrib ) { - - TransparencyProperty::Mode mode = attrib->get_mode(); - - switch (mode) { - case TransparencyProperty::M_none: -// enable_multisample_alpha_one(false); -// enable_multisample_alpha_mask(false); - enable_blend(false); - enable_alpha_test(false); - break; - case TransparencyProperty::M_alpha: - case TransparencyProperty::M_alpha_sorted: - // Should we really have an "alpha" and an "alpha_sorted" mode, - // like Performer does? (The difference is that "alpha" is with - // the write to the depth buffer disabled.) Or should we just use - // the separate depth write transition to control this? Doing it - // implicitly requires a bit more logic here and in the state - // management; for now we require the user to explicitly turn off - // the depth write. -// enable_multisample_alpha_one(false); -// enable_multisample_alpha_mask(false); - enable_blend(true); - enable_alpha_test(false); - call_dxBlendFunc(D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA); - break; - case TransparencyProperty::M_multisample: -// enable_multisample_alpha_one(true); -// enable_multisample_alpha_mask(true); - enable_blend(false); - enable_alpha_test(false); - break; - case TransparencyProperty::M_multisample_mask: -// enable_multisample_alpha_one(false); -// enable_multisample_alpha_mask(true); - enable_blend(false); - enable_alpha_test(false); - break; - case TransparencyProperty::M_binary: -// enable_multisample_alpha_one(false); -// enable_multisample_alpha_mask(false); - enable_blend(false); - enable_alpha_test(true); - call_dxAlphaFunc(D3DCMP_EQUAL, 1); - break; - default: - dxgsg_cat.error() - << "invalid transparency mode " << (int)mode << endl; - break; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_linesmooth -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_linesmooth(const LinesmoothTransition *attrib) { - enable_line_smooth(attrib->is_on()); -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::issue_transform // Access: Public, Virtual @@ -4562,7 +3418,7 @@ issue_render_mode(const RenderModeAttrib *attrib) { << "Unknown render mode " << (int)mode << endl; } - _current_fill_mode = (RenderModeProperty::Mode)mode; + _current_fill_mode = mode; } //////////////////////////////////////////////////////////////////// @@ -4970,174 +3826,6 @@ wants_texcoords() const { } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::issue_depth_write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -issue_depth_write(const DepthWriteTransition *attrib) { - enable_zwritemask(attrib->is_on()); -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::begin_decal -// Access: Public, Virtual -// Description: This will be called to initiate decaling mode. It is -// passed the pointer to the GeomNode that will be the -// destination of the decals, which it is expected that -// the GSG will render normally; subsequent geometry -// rendered up until the next call of end_decal() should -// be rendered as decals of the base_geom. -// -// The transitions wrapper is the current state as of the -// base geometry node. It may or may not be modified by -// the GSG to reflect whatever rendering state is -// necessary to render the decals properly. -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -begin_decal(GeomNode *base_geom, AllTransitionsWrapper &attrib) { - nassertv(base_geom != (GeomNode *)NULL); - - assert(_decal_level>=0); - - _decal_level++; - -#ifndef DISABLE_DECALING - - #ifndef DISABLE_POLYGON_OFFSET_DECALING - if (dx_decal_type == GDT_offset) { - #define POLYGON_OFFSET_MULTIPLIER 2 - - // note: zbias seems inconsitently supported. may be possible to fake it by - // adding (delta * element[4,3]) to element [3,3] of a regular matrix - // need to test this and see if to offers perf improvement over blend-based decaling - - nassertv(POLYGON_OFFSET_MULTIPLIER*_decal_level < 16); // 16 is the max allowed zbias - - // Just draw the base geometry normally. - base_geom->draw(this); - scrn.pD3DDevice->SetRenderState(D3DRS_ZBIAS, POLYGON_OFFSET_MULTIPLIER * _decal_level); // _decal_level better not be higher than 8! - } else - #endif - - { - if (_decal_level > 1) { - base_geom->draw(this); // If we're already decaling, just draw the geometry. - } else { - // need to save current xform matrix in case it is changed during subrendering, so subsequent decal draws use same xform - _bTransformIssued = false; - scrn.pD3DDevice->GetTransform( D3DTS_WORLD, &_SavedTransform); - - // First turn off writing the depth buffer to render the base geometry. - enable_zwritemask(false); - - // It is also important to update the current state to - // indicate the depth buffer write is off, so that future - // geometry will render correctly. - DepthWriteTransition *dwa = new DepthWriteTransition(DepthWriteTransition::off()); - attrib.set_transition(dwa); - - // Now render the base geometry. - base_geom->draw(this); - - // Render all of the decal geometry, too. We'll keep the depth - // buffer write off during this. - } - } -#else - base_geom->draw(this); -#endif -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::end_decal -// Access: Public, Virtual -// Description: This will be called to terminate decaling mode. It -// is passed the same base_geom that was passed to -// begin_decal(). -//////////////////////////////////////////////////////////////////// -void DXGraphicsStateGuardian:: -end_decal(GeomNode *base_geom) { - _decal_level--; - - assert(_decal_level>=0); - -#ifdef DISABLE_DECALING - return; -#endif - - nassertv(base_geom != (GeomNode *)NULL); -// nassertv(_decal_level >= 1); - -#ifndef DISABLE_POLYGON_OFFSET_DECALING - if (dx_decal_type == GDT_offset) { - // Restore the Zbias offset. - scrn.pD3DDevice->SetRenderState(D3DRS_ZBIAS, POLYGON_OFFSET_MULTIPLIER * _decal_level); // _decal_level better not be higher than 8! - } else -#endif - { // for GDT_mask - if (_decal_level == 0) { - // Now we need to re-render the base geometry with the depth write - // on and the color mask off, so we update the depth buffer - // properly. - - // need to save the state we change on the stack, since we could get called - // recursively by the draw() method, and the draw method could change any of - // the state below - D3DBLEND saved_blend_source_func = _blend_source_func; - D3DBLEND saved_blend_dest_func = _blend_dest_func; - UINT saved_colorwritemask = _color_writemask; - bool saved_texture_enabled = _texturing_enabled; - bool saved_blend_enabled = _blend_enabled; - - // Enable the writing to the depth buffer. - enable_zwritemask(true); - - // Disable the writing to the color buffer, however we have to - // do this. (I don't think this is possible in DX without blending.) - if (dx_decal_type == GDT_blend) { - // Expensive. - enable_blend(true); - call_dxBlendFunc(D3DBLEND_ZERO, D3DBLEND_ONE); - } else { - set_color_writemask(0x0); - } - - // No need to have texturing on for this. - enable_texturing(false); - - // if current xform has changed, reset to saved xform - if(_bTransformIssued) - scrn.pD3DDevice->SetTransform( D3DTS_WORLD, &_SavedTransform); - - base_geom->draw(this); - - // Finally, restore the depth write and color mask states to the - // way they're supposed to be. - - if (dx_decal_type == GDT_blend) { - enable_blend(saved_blend_enabled); - if (saved_blend_enabled) - call_dxBlendFunc(saved_blend_source_func, saved_blend_dest_func); - } else { - set_color_writemask(saved_colorwritemask); - } - enable_texturing(saved_texture_enabled); - - // Finally, restore the depth write state to the - // way they're supposed to be. - - // needs to match value specified at begin_decal() start, so cant just - // save value across this end_decal() call like the other rstates - DepthWriteTransition *depth_write; - if (get_attribute_into(depth_write, this)) { - issue_depth_write(depth_write); - } - } - } -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::depth_offset_decals // Access: Public, Virtual @@ -5274,28 +3962,6 @@ get_texture_wrap_mode(Texture::WrapMode wm) const { return PandaTexWrapMode_to_D3DTexWrapMode[wm]; } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::get_depth_func_type -// Access: Protected -// Description: Maps from the depth func modes to gl version -//////////////////////////////////////////////////////////////////// -INLINE D3DCMPFUNC DXGraphicsStateGuardian:: -get_depth_func_type(DepthTestProperty::Mode m) const { - switch (m) { - case DepthTestProperty::M_never: return D3DCMP_NEVER; - case DepthTestProperty::M_less: return D3DCMP_LESS; - case DepthTestProperty::M_equal: return D3DCMP_EQUAL; - case DepthTestProperty::M_less_equal: return D3DCMP_LESSEQUAL; - case DepthTestProperty::M_greater: return D3DCMP_GREATER; - case DepthTestProperty::M_not_equal: return D3DCMP_NOTEQUAL; - case DepthTestProperty::M_greater_equal: return D3DCMP_GREATEREQUAL; - case DepthTestProperty::M_always: return D3DCMP_ALWAYS; - } - dxgsg_cat.error() - << "Invalid DepthTestProperty::Mode value" << endl; - return D3DCMP_LESS; -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::get_depth_func_type // Access: Protected @@ -5318,63 +3984,6 @@ get_depth_func_type(DepthTestAttrib::Mode m) const { return D3DCMP_LESS; } -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::get_stencil_func_type -// Access: Protected -// Description: Maps from the stencil func modes to dx version -//////////////////////////////////////////////////////////////////// -INLINE D3DCMPFUNC DXGraphicsStateGuardian:: -get_stencil_func_type(StencilProperty::Mode m) const { - switch (m) { - case StencilProperty::M_never: return D3DCMP_NEVER; - case StencilProperty::M_less: return D3DCMP_LESS; - case StencilProperty::M_equal: return D3DCMP_EQUAL; - case StencilProperty::M_less_equal: return D3DCMP_LESSEQUAL; - case StencilProperty::M_greater: return D3DCMP_GREATER; - case StencilProperty::M_not_equal: return D3DCMP_NOTEQUAL; - case StencilProperty::M_greater_equal: return D3DCMP_GREATEREQUAL; - case StencilProperty::M_always: return D3DCMP_ALWAYS; - } - dxgsg_cat.error() << "Invalid StencilProperty::Mode value" << endl; - return D3DCMP_LESS; -} - - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::get_stencil_action_type -// Access: Protected -// Description: Maps from the stencil action modes to dx version -//////////////////////////////////////////////////////////////////// -INLINE D3DSTENCILOP DXGraphicsStateGuardian:: -get_stencil_action_type(StencilProperty::Action a) const { - switch (a) { - case StencilProperty::A_keep: return D3DSTENCILOP_KEEP; - case StencilProperty::A_zero: return D3DSTENCILOP_ZERO; - case StencilProperty::A_replace: return D3DSTENCILOP_REPLACE; - case StencilProperty::A_increment: return D3DSTENCILOP_INCR; - case StencilProperty::A_decrement: return D3DSTENCILOP_DECR; - case StencilProperty::A_invert: return D3DSTENCILOP_INVERT; - } - dxgsg_cat.error() << "Invalid StencilProperty::Action value" << endl; - return D3DSTENCILOP_KEEP; -} - -//////////////////////////////////////////////////////////////////// -// Function: DXGraphicsStateGuardian::get_fog_mode_type -// Access: Protected -// Description: Maps from the fog types to gl version -//////////////////////////////////////////////////////////////////// -INLINE D3DFOGMODE DXGraphicsStateGuardian:: -get_fog_mode_type(Fog::Mode m) const { - switch (m) { - case Fog::M_linear: return D3DFOG_LINEAR; - case Fog::M_exponential: return D3DFOG_EXP; - case Fog::M_exponential_squared: return D3DFOG_EXP2; - } - dxgsg_cat.error() << "Invalid Fog::Mode value" << endl; - return D3DFOG_EXP; -} - //////////////////////////////////////////////////////////////////// // Function: DXGraphicsStateGuardian::get_fog_mode_type // Access: Protected @@ -5465,19 +4074,19 @@ set_blend_mode(ColorWriteAttrib::Mode color_write_mode, case ColorBlendAttrib::M_none: break; - case ColorBlendProperty::M_multiply: + case ColorBlendAttrib::M_multiply: enable_blend(true); enable_alpha_test(false); call_dxBlendFunc(D3DBLEND_DESTCOLOR, D3DBLEND_ZERO); return; - case ColorBlendProperty::M_add: + case ColorBlendAttrib::M_add: enable_blend(true); enable_alpha_test(false); call_dxBlendFunc(D3DBLEND_ONE, D3DBLEND_ONE); return; - case ColorBlendProperty::M_multiply_add: + case ColorBlendAttrib::M_multiply_add: enable_blend(true); enable_alpha_test(false); call_dxBlendFunc(D3DBLEND_DESTCOLOR, D3DBLEND_ONE); @@ -5532,8 +4141,6 @@ free_local_resources() { // those should be released in free_dxgsg_objects instead SAFE_DELETE_ARRAY(_index_buf); SAFE_DELETE_ARRAY(_pFvfBufBasePtr); - SAFE_DELETE_ARRAY(_cur_clip_plane_enabled); - SAFE_DELETE_ARRAY(_clip_plane_enabled); } //////////////////////////////////////////////////////////////////// @@ -5581,26 +4188,8 @@ save_frame_buffer(const RenderBuffer &buffer, //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian:: restore_frame_buffer(SavedFrameBuffer *frame_buffer) { - dxgsg_cat.error() << "restore_frame_buffer unimplemented!!\n"; return; - -#if 0 - DXSavedFrameBuffer *sfb = DCAST(DXSavedFrameBuffer, frame_buffer); - - if (sfb->_back_rgba != (Texture *)NULL && - (sfb->_buffer._buffer_type & RenderBuffer::T_back) != 0) { - // Restore the color buffer. - draw_texture(sfb->_back_rgba->prepare(this), - sfb->_display_region, sfb->_buffer); - } - - if (sfb->_depth != (PixelBuffer *)NULL && - (sfb->_buffer._buffer_type & RenderBuffer::T_depth) != 0) { - // Restore the depth buffer. - draw_pixel_buffer(sfb->_depth, sfb->_display_region, sfb->_buffer); - } -#endif } // factory and type stuff @@ -6169,466 +4758,9 @@ HRESULT SetViewMatrix( D3DMATRIX& mat, D3DXVECTOR3& vFrom, D3DXVECTOR3& vAt, // contents of the node. //////////////////////////////////////////////////////////////////// GeomNodeContext *DXGraphicsStateGuardian:: -prepare_geom_node(GeomNode *node) { - - dxgsg_cat.error() << "prepare_geom_node unimplemented for DX8!\n"; - return NULL; - -#if 0 - if(link_tristrips) { - for(int iGeom=0;iGeomget_num_geoms();iGeom++) { - dDrawable *drawable1 = node->get_geom(iGeom); - - if(!drawable1->is_of_type(Geom::get_class_type())) - continue; - - Geom *geomptr=DCAST(Geom, drawable1); - assert(geomptr!=NULL); - - if(!geomptr->is_of_type(GeomTristrip::get_class_type())) - continue; - - GeomTristrip *me = DCAST(GeomTristrip, geomptr); - assert(me!=NULL); - - int nPrims=me->get_num_prims(); - if(nPrims==1) - continue; - - if(dxgsg_cat.is_debug()) { - static bool bPrintedMsg=false; - if(!bPrintedMsg) { - dxgsg_cat.debug() << "linking tristrips together with degenerate tris\n"; - bPrintedMsg=true; - } - } - - bool bStripReversalNeeded; - unsigned int nOrigTotalVerts=0; - PTA_int new_lengths; - int p; - - // sum things up so can reserve space for new vecs - for(p=0;pget_length(p); - } - - // could compute it exactly if I wanted to reproduce all the cTotalVertsOutputSoFar logic in the loop below - // might save on memory reallocations. try to overestimate using *3. - int cEstimatedTotalVerts=nOrigTotalVerts+nPrims*3-2; - - #define INIT_ATTRVARS(ATTRNAME,PTA_TYPENAME) \ - PTA_##PTA_TYPENAME old_##ATTRNAME##s,new_##ATTRNAME##s; \ - PTA_ushort old_##ATTRNAME##_indices,new_##ATTRNAME##_indices; \ - GeomBindType ATTRNAME##binding; \ - me->get_##ATTRNAME##s(old_##ATTRNAME##s, ATTRNAME##binding, old_##ATTRNAME##_indices); \ - \ - PTA_##PTA_TYPENAME::iterator old_##ATTRNAME##_iter=old_##ATTRNAME##s.begin(); \ - PTA_ushort::iterator old_##ATTRNAME##index_iter; \ - \ - if((ATTRNAME##binding!=G_OFF)&&(ATTRNAME##binding!=G_OVERALL)) { \ - if(old_##ATTRNAME##_indices!=NULL) { \ - old_##ATTRNAME##index_iter=old_##ATTRNAME##_indices.begin(); \ - new_##ATTRNAME##_indices.reserve(cEstimatedTotalVerts); \ - } else { \ - new_##ATTRNAME##s.reserve(cEstimatedTotalVerts); \ - } \ - } - - INIT_ATTRVARS(coord,Vertexf); - INIT_ATTRVARS(color,Colorf); - INIT_ATTRVARS(normal,Normalf); - INIT_ATTRVARS(texcoord,TexCoordf); - -#define IsOdd(X) (((X) & 0x1)!=0) - - uint cTotalVertsOutputSoFar=0; - int nVerts; - bool bAddExtraStartVert; - - for(p=0;pget_length(p); - - // if bStripStateStartsBackfacing, then if the current strip - // ends frontfacing, we can fix the problem by just reversing - // the current strip order. But if the current strip ends - // backfacing, this will not work, since last tri is encoded for backfacing slot - // so it will be incorrectly backfacing when you put it in a backfacing - // slot AND reverse the vtx order. - - // insert an extra pad vertex at the beginning to force the - // strip backface-state parity to change (more expensive, since - // we make 1 more degen tri). We always want the first tri - // to start in a front-facing slot (unless it's a reversed end - - bStripReversalNeeded = false; - bAddExtraStartVert=false; - - if(p==0) { - cTotalVertsOutputSoFar+=nVerts+1; - } else { - if(!IsOdd(cTotalVertsOutputSoFar)) { - // we're starting on a backfacing slot - if(IsOdd(nVerts)) { - bStripReversalNeeded = true; - } else { - bAddExtraStartVert=true; - cTotalVertsOutputSoFar++; - } - } - - cTotalVertsOutputSoFar+=nVerts+2; - if(p==nPrims-1) - cTotalVertsOutputSoFar--; - } - -#define PERVERTEX_ATTRLOOP(OLDVERT_ITERATOR,NEWVERT_VECTOR,VECLENGTH,NUMSTARTPADDINGATTRS,NUMENDPADDINGATTRS) \ - if(bStripReversalNeeded) { \ - /* to preserve normal-direction property for backface-cull purposes, */ \ - /* vtx order must be reversed*/ \ - \ - OLDVERT_ITERATOR+=((VECLENGTH)-1); /* start at last vert, and go back*/ \ - /*dxgsg_cat.debug() << "doing reversal on strip " << p << " of length " << nVerts << endl;*/ \ - \ - if(p!=0) { \ - /* copy first vert twice to link with last strip*/ \ - for(int i=0;iset_coords(old_coords, new_coord_indices); - new_lengths.push_back(new_coord_indices.size()); - } else { - me->set_coords(new_coords); - new_lengths.push_back(new_coords.size()); - } - - me->set_lengths(new_lengths); - me->set_num_prims(1); - - #define SET_NEW_ATTRIBS(ATTRNAME) \ - if((ATTRNAME##binding!=G_OFF) && (ATTRNAME##binding!=G_OVERALL)) { \ - if(ATTRNAME##binding==G_PER_PRIM) \ - ATTRNAME##binding=G_PER_COMPONENT; \ - if(old_##ATTRNAME##_indices==NULL) { \ - me->set_##ATTRNAME##s(new_##ATTRNAME##s, ATTRNAME##binding); \ - } else { \ - me->set_##ATTRNAME##s(old_##ATTRNAME##s, ATTRNAME##binding, new_##ATTRNAME##_indices); \ - } \ - } - /* - int ii; - for( ii=0;iimake_dirty(); - } - } // if(link_tristrips) - - // for now, only using vertexbufs for static Geom, so - // Make sure we have at least some static Geoms in the GeomNode; - int cNumVerts=0,i,num_geoms = node->get_num_geoms(); - - // need to always put in space for color because we might have some scene-graph color we need to add? - // will that even work? I think we'd have to overwrite all the VB colors dynamically, and then restore - // them from somewhere if the global color goes away - - DWORD fvfFlags=D3DFVF_XYZ;// | D3DFVF_DIFFUSE; - - for (i = 0; (i < num_geoms); i++) { - dDrawable *drawable1 = node->get_geom(i); - if(!drawable1->is_of_type(Geom::get_class_type())) - continue; - - Geom *geom=DCAST(Geom, drawable1); - assert(geom!=NULL); - - DWORD new_fvfFlags=D3DFVF_XYZ; - - if(!geom->is_dynamic()) { - cNumVerts+=geom->get_num_vertices(); - if(geom->get_binding(G_COLOR) != G_OFF) - new_fvfFlags |= D3DFVF_DIFFUSE; - if(geom->get_binding(G_NORMAL) != G_OFF) - new_fvfFlags |= D3DFVF_NORMAL; - if(geom->get_binding(G_TEXCOORD) != G_OFF) - new_fvfFlags |= (D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0)); - } - if(i!=0) { - if(fvfFlags!=new_fvfFlags) { - // all primitives within a geom must use the same FVF type for the DrawPrim api - dxgsg_cat.error() << "error creating vertex buffer, geoms within geomnode require differing vertex data types!!\n"; - exit(1); - } - } else fvfFlags=new_fvfFlags; - } - - if(cNumVerts==0) { - // Never mind. - return (GeomNodeContext *)NULL; - } - - if(cNumVerts>PANDA_MAXNUMVERTS) { - dxgsg_cat.error() << "geom node contains more than " << PANDA_MAXNUMVERTS << " vertices, cant create 1 vertex buffer\n"; - exit(1); - } - - // Ok, we've got something; use it. - DXGeomNodeContext *dx_gnc = new DXGeomNodeContext(node); - - assert(dx_gnc!=NULL); - - // right now there is a 1-1 correspondence b/w vertbufs and geomnodecontexts. - // later multiple geomnodecontexts will use the same vertbuf - - HRESULT hr; - LPDIRECT3D7 pD3D; - - assert(scrn.pD3DDevice!=NULL); - hr=scrn.pD3DDevice->GetDirect3D(&pD3D); - assert(!FAILED(hr)); - LPDIRECT3DVERTEXBUFFER7 pD3DVertexBuffer; - DX_DECLARE_CLEAN(D3DVERTEXBUFFERDESC, VBdesc); - - VBdesc.dwCaps = D3DVBCAPS_WRITEONLY; - VBdesc.dwCaps |= scrn.bIsTNLDevice ? 0x0 : D3DVBCAPS_SYSTEMMEMORY; - VBdesc.dwFVF=fvfFlags; - VBdesc.dwNumVertices=cNumVerts; - - hr=pD3D->CreateVertexBuffer(&VBdesc,&pD3DVertexBuffer,0x0); - if(FAILED(hr)) { - dxgsg_cat.error() << "error creating vertex buffer: " << D3DERRORSTRING(hr); - delete dx_gnc; - exit(1); - } - - dx_gnc->_pVB = pD3DVertexBuffer; - - if(!scrn.bIsTNLDevice) { - // create VB for ProcessVerts to xform to - - fvfFlags&=~D3DFVF_XYZ; // switch to xformed vert type - fvfFlags&=~D3DFVF_NORMAL; // xformed verts are also lighted, so no normals allowed - fvfFlags|=D3DFVF_XYZRHW; - VBdesc.dwFVF=fvfFlags; - - hr=pD3D->CreateVertexBuffer(&VBdesc,&pD3DVertexBuffer,0x0); - if(FAILED(hr)) { - dxgsg_cat.error() << "error creating xformed vertex buffer: " << D3DERRORSTRING(hr); - delete dx_gnc; - exit(1); - } - - dx_gnc->_pXformed_VB = pD3DVertexBuffer; - } - - pD3D->Release(); - - dx_gnc->_num_verts=0; - dx_gnc->_start_index=0; - - LPVOID pVertData=NULL; - DWORD dwVBFlags = DDLOCK_NOOVERWRITE | DDLOCK_NOSYSLOCK | DDLOCK_SURFACEMEMORYPTR | - DDLOCK_WAIT | DDLOCK_DISCARDCONTENTS; - - hr=dx_gnc->_pVB->Lock(dwVBFlags,&pVertData,NULL); - if(FAILED(hr)) { - dxgsg_cat.error() << "error locking vertex buffer: " << D3DERRORSTRING(hr); - delete dx_gnc; - exit(1); - } - - assert(pVertData!=NULL); - _pCurrentGeomContext = dx_gnc; - _pCurrentGeomContext->_pEndofVertData=(BYTE*)pVertData; - _bDrawPrimDoSetupVertexBuffer = true; - - - for (i = 0; (i < num_geoms); i++) { - dDrawable *drawable1 = node->get_geom(i); - if(!drawable1->is_of_type(Geom::get_class_type())) - continue; - - Geom *geom=DCAST(Geom, drawable1); - assert(geom!=NULL); - - if(geom->is_dynamic()) { - dx_gnc->_other_geoms.push_back(geom); - } else { - dx_gnc->_cached_geoms.push_back(geom); - node->get_geom(i)->draw(this); - } - } - - _bDrawPrimDoSetupVertexBuffer = false; - _pCurrentGeomContext->_pEndofVertData=NULL; - _pCurrentGeomContext = NULL; - - hr=dx_gnc->_pVB->Unlock(); - if(FAILED(hr)) { - dxgsg_cat.error() << "error unlocking vertex buffer: " << D3DERRORSTRING(hr); - delete dx_gnc; - exit(1); - } - - assert(cNumVerts==dx_gnc->_num_verts); - - hr=dx_gnc->_pVB->Optimize(scrn.pD3DDevice,0x0); - if(FAILED(hr)) { - dxgsg_cat.error() << "error optimizing vertex buffer: " << D3DERRORSTRING(hr); - delete dx_gnc; - exit(1); - } - - if(dxgsg_cat.is_spam()) - dxgsg_cat.spam() << "creating vertex buffer of size: " << cNumVerts << endl; - -#if 0 //DO_PSTATS - float num_verts_after = - _vertices_tristrip_pcollector.get_level() + - _vertices_trifan_pcollector.get_level() + - _vertices_tri_pcollector.get_level() + - _vertices_other_pcollector.get_level(); - float num_verts = num_verts_after - num_verts_before; - ggnc->_num_verts = (int)(num_verts + 0.5); -#endif - - bool inserted = mark_prepared_geom_node(dx_gnc); - - // If this assertion fails, the same GeomNode was prepared twice, - // which shouldn't be possible, since the GeomNode itself should - // detect this. - nassertr(inserted, NULL); - - return dx_gnc; -#endif - +prepare_geom_node(qpGeomNode *node) { + dxgsg_cat.error() << "prepare_geom_node unimplemented for DX8!\n"; + return NULL; } //////////////////////////////////////////////////////////////////// @@ -6638,97 +4770,9 @@ prepare_geom_node(GeomNode *node) { // prepare_geom_node(). //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian:: -draw_geom_node(GeomNode *node, GeomNodeContext *gnc) { +draw_geom_node(qpGeomNode *node, const RenderState *state, + GeomNodeContext *gnc) { return; // unimplemented - -#if 0 - uint i,num_geoms = node->get_num_geoms(); - - if (gnc == (GeomNodeContext *)NULL) { - - // We don't have a saved context; just draw the GeomNode in - // immediate mode. - for (i = 0; i < num_geoms; i++) { - node->get_geom(i)->draw(this); - } - return; - } - - // We do have a saved context; use it. - add_to_geom_node_record(gnc); - DXGeomNodeContext *dx_gnc = DCAST(DXGeomNodeContext, gnc); - - #ifdef _DEBUG - assert(dx_gnc->_pVB!=NULL); - assert((!scrn.bIsTNLDevice)==(dx_gnc->_pXformed_VB!=NULL)); - #endif - - if(!scrn.bIsTNLDevice) { - HRESULT hr; - - DWORD PVOp=D3DVOP_CLIP | D3DVOP_TRANSFORM | D3DVOP_EXTENTS; - - D3DVERTEXBUFFERDESC VBdesc; - VBdesc.dwSize=sizeof(VBdesc); - hr=dx_gnc->_pVB->GetVertexBufferDesc(&VBdesc); // would be useful to keep fvf in vertbuf struct to avoid having to do this - if(FAILED(hr)) { - dxgsg_cat.error() << "error in getvbdesc: " << D3DERRORSTRING(hr); - exit(1); - } - - if(_lighting_enabled && (VBdesc.dwFVF & D3DFVF_NORMAL)) { - PVOp|=D3DVOP_LIGHT; - } - - hr=dx_gnc->_pXformed_VB->ProcessVertices(PVOp,0,dx_gnc->_num_verts,dx_gnc->_pVB,0,scrn.pD3DDevice,0x0); - if(FAILED(hr)) { - dxgsg_cat.error() << "error in ProcessVertices: " << D3DERRORSTRING(hr); - exit(1); - } - - // disable clipping, since VB is already xformed and clipped - if(_clipping_enabled) - scrn.pD3DDevice->SetRenderState(D3DRS_CLIPPING, false); - } - - // assume we need gouraud for now. we can make this more complex to select flat conditionally later - enable_gouraud_shading(true); - int cur_startvert=dx_gnc->_start_index; - - for (i = 0; i < dx_gnc->_cached_geoms.size(); i++) { - // I think we can just draw them directly? since cant account for issued stuff (since - // its already encoded in the VB), and we can set the renderstates here (e.g. gouraud mode) - // dx_gnc->_cached_geoms[i]->draw(this); - - DPInfo *dpi=&dx_gnc->_PrimInfo[i]; - - LPDIRECT3DVERTEXBUFFER7 pVB; - if(scrn.bIsTNLDevice) { - pVB=dx_gnc->_pVB; - } else { - pVB=dx_gnc->_pXformed_VB; - } - - HRESULT hr = scrn.pD3DDevice->DrawPrimitiveVB(dpi->primtype,pVB,cur_startvert,dpi->nVerts,0x0); - TestDrawPrimFailure(DrawPrim,hr,scrn.pD3DDevice,dpi->nVerts,0); - - cur_startvert+=dpi->nVerts; - } - - if((!scrn.bIsTNLDevice) && _clipping_enabled) - scrn.pD3DDevice->SetRenderState(D3DRS_CLIPPING, true); - - // Also draw all the dynamic Geoms. - for (i = 0; i < dx_gnc->_other_geoms.size(); i++) { - dx_gnc->_other_geoms[i]->draw(this); - } - -#if 0 //def DO_PSTATS - DO_PSTATS_STUFF(PStatTimer timer(_draw_primitive_pcollector)); - _vertices_display_list_pcollector.add_level(dx_gnc->_num_verts); -#endif - -#endif } //////////////////////////////////////////////////////////////////// @@ -6740,20 +4784,6 @@ draw_geom_node(GeomNode *node, GeomNodeContext *gnc) { //////////////////////////////////////////////////////////////////// void DXGraphicsStateGuardian:: release_geom_node(GeomNodeContext *gnc) { -#if 0 - if (gnc != (GeomNodeContext *)NULL) { - DXGeomNodeContext *dx_gnc = DCAST(DXGeomNodeContext, gnc); - - bool erased = unmark_prepared_geom_node(dx_gnc); - - // If this assertion fails, a GeomNode was released that hadn't - // been prepared (or a GeomNode was released twice). - nassertv(erased); - - dx_gnc->_node->clear_gsg(this); - delete dx_gnc; // should release vertex buffer - } -#endif } HRESULT CreateDX8Cursor(LPDIRECT3DDEVICE8 pd3dDevice, HCURSOR hCursor,BOOL bAddWatermark) { diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h index 67016f16a9..aef54077fd 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.h +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.h @@ -21,33 +21,23 @@ //#define GSG_VERBOSE -#include "pandabase.h" +#include "dxgsg8base.h" +#include "dxGeomNodeContext8.h" +#include "dxTextureContext8.h" +#include "d3dfont8.h" + #include "graphicsStateGuardian.h" #include "geomprimitives.h" #include "texture.h" #include "pixelBuffer.h" #include "displayRegion.h" #include "material.h" -#include "textureApplyProperty.h" -#include "depthTestProperty.h" #include "depthTestAttrib.h" -#include "stencilProperty.h" -#include "fog.h" +#include "renderModeAttrib.h" +#include "textureApplyAttrib.h" #include "qpfog.h" -#include "renderModeProperty.h" -#include "colorMatrixTransition.h" -#include "alphaTransformTransition.h" #include "pointerToArray.h" -#include "planeNode.h" -#include "dxgsg8base.h" -#include "dxGeomNodeContext8.h" -#include "dxTextureContext8.h" -#include "d3dfont8.h" - -#include - -class PlaneNode; class Light; //#if defined(NOTIFY_DEBUG) || defined(DO_PSTATS) @@ -89,15 +79,6 @@ public: virtual void prepare_display_region(); virtual bool prepare_lens(); - virtual void render_frame(); - virtual void render_scene(Node *root, LensNode *projnode); - virtual void render_subgraph(RenderTraverser *traverser, - Node *subgraph, LensNode *projnode, - const AllTransitionsWrapper &net_trans); - virtual void render_subgraph(RenderTraverser *traverser, - Node *subgraph, - const AllTransitionsWrapper &net_trans); - virtual void draw_point(GeomPoint *geom, GeomContext *gc); virtual void draw_line(GeomLine *geom, GeomContext *gc); virtual void draw_linestrip(GeomLinestrip *geom, GeomContext *gc); @@ -110,8 +91,9 @@ public: virtual void draw_trifan(GeomTrifan *geom, GeomContext *gc); virtual void draw_sphere(GeomSphere *geom, GeomContext *gc); - virtual GeomNodeContext *prepare_geom_node(GeomNode *node); - virtual void draw_geom_node(GeomNode *node, GeomNodeContext *gnc); + virtual GeomNodeContext *prepare_geom_node(qpGeomNode *node); + virtual void draw_geom_node(qpGeomNode *node, const RenderState *state, + GeomNodeContext *gnc); virtual void release_geom_node(GeomNodeContext *gnc); virtual TextureContext *prepare_texture(Texture *tex); @@ -121,9 +103,6 @@ public: virtual void copy_texture(TextureContext *tc, const DisplayRegion *dr); virtual void copy_texture(TextureContext *tc, const DisplayRegion *dr, const RenderBuffer &rb); - virtual void draw_texture(TextureContext *tc, const DisplayRegion *dr); - virtual void draw_texture(TextureContext *tc, const DisplayRegion *dr, - const RenderBuffer &rb); virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb); virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb, @@ -132,37 +111,10 @@ public: virtual void copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr); virtual void copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, const RenderBuffer &rb); - virtual void draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, - const NodeTransitions& na=NodeTransitions()); - virtual void draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, - const RenderBuffer &rb, - const NodeTransitions& na=NodeTransitions()); virtual void apply_material(const Material *material); - virtual void apply_fog(Fog *fog); virtual void apply_fog(qpFog *fog); - virtual void issue_transform(const TransformTransition *attrib); - virtual void issue_tex_matrix(const TexMatrixTransition *attrib); - virtual void issue_color(const ColorTransition *attrib); - virtual void issue_color_transform(const ColorMatrixTransition *); - virtual void issue_alpha_transform(const AlphaTransformTransition *); - virtual void issue_texture(const TextureTransition *attrib); - virtual void issue_material(const MaterialTransition *attrib); - virtual void issue_render_mode(const RenderModeTransition *attrib); - virtual void issue_color_blend(const ColorBlendTransition *attrib); - virtual void issue_texture_apply(const TextureApplyTransition *attrib); - virtual void issue_color_mask(const ColorMaskTransition *attrib); - virtual void issue_depth_test(const DepthTestTransition *attrib); - virtual void issue_depth_write(const DepthWriteTransition *attrib); - virtual void issue_tex_gen(const TexGenTransition *attrib); - virtual void issue_cull_face(const CullFaceTransition *attrib); - virtual void issue_stencil(const StencilTransition *attrib); - virtual void issue_clip_plane(const ClipPlaneTransition *attrib); - virtual void issue_transparency(const TransparencyTransition *attrib); - virtual void issue_fog(const FogTransition *attrib); - virtual void issue_linesmooth(const LinesmoothTransition *attrib); - virtual void issue_transform(const TransformState *transform); virtual void issue_tex_matrix(const TexMatrixAttrib *attrib); virtual void issue_texture(const TextureAttrib *attrib); @@ -185,9 +137,6 @@ public: virtual bool wants_normals(void) const; virtual bool wants_texcoords(void) const; - virtual void begin_decal(GeomNode *base_geom, AllTransitionsWrapper &attrib); - virtual void end_decal(GeomNode *base_geom); - virtual bool depth_offset_decals(); virtual CoordinateSystem get_internal_coordinate_system() const; @@ -252,14 +201,9 @@ protected: INLINE void set_vertex_format(DWORD NewFvfType); INLINE D3DTEXTUREADDRESS get_texture_wrap_mode(Texture::WrapMode wm) const; - INLINE D3DCMPFUNC get_depth_func_type(DepthTestProperty::Mode m) const; INLINE D3DCMPFUNC get_depth_func_type(DepthTestAttrib::Mode m) const; - INLINE D3DFOGMODE get_fog_mode_type(Fog::Mode m) const; INLINE D3DFOGMODE get_fog_mode_type(qpFog::Mode m) const; - INLINE D3DCMPFUNC get_stencil_func_type(StencilProperty::Mode m) const; - INLINE D3DSTENCILOP get_stencil_action_type(StencilProperty::Action a) const; - INLINE void enable_primitive_clipping(bool val); INLINE void enable_alpha_test(bool val); INLINE void enable_line_smooth(bool val); @@ -352,11 +296,11 @@ protected: bool _alpha_test_enabled; int _decal_level; - RenderModeProperty::Mode _current_fill_mode; //poinr/wireframe/solid + RenderModeAttrib::Mode _current_fill_mode; //poinr/wireframe/solid GraphicsChannel *_panda_gfx_channel; // cache the 1 channel dx supports // Cur Texture State - TextureApplyProperty::Mode _CurTexBlendMode; + TextureApplyAttrib::Mode _CurTexBlendMode; Texture::FilterType _CurTexMagFilter,_CurTexMinFilter; DWORD _CurTexAnisoDegree; Texture::WrapMode _CurTexWrapModeU,_CurTexWrapModeV; @@ -364,11 +308,6 @@ protected: LMatrix4f _current_projection_mat; int _projection_mat_stack_count; - PTA(PlaneNode*) _available_clip_plane_ids; - int _max_clip_planes; - bool* _cur_clip_plane_enabled; - int _cur_clip_plane_id; - CPT(DisplayRegion) _actual_display_region; // Color/Alpha Matrix Transition stuff @@ -391,7 +330,7 @@ public: virtual TypeHandle force_init_type() {init_type(); return get_class_type();} INLINE void SetDXReady(bool status) { _bDXisReady = status; } INLINE bool GetDXReady(void) { return _bDXisReady;} - void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyProperty::Mode TexBlendMode,bool bJustEnable); + void DXGraphicsStateGuardian::SetTextureBlendMode(TextureApplyAttrib::Mode TexBlendMode,bool bJustEnable); void dx_cleanup(bool bRestoreDisplayMode,bool bAtExitFnCalled); void reset_panda_gsg(void); diff --git a/panda/src/effects/Sources.pp b/panda/src/effects/Sources.pp index 17a732fec4..859439a93e 100644 --- a/panda/src/effects/Sources.pp +++ b/panda/src/effects/Sources.pp @@ -5,8 +5,8 @@ #define TARGET effects #define LOCAL_LIBS \ - display sgraph graph sgraphutil sgattrib gobj putil gsgbase linmath \ - mathutil switchnode + display gobj putil gsgbase linmath \ + mathutil #define COMBINED_SOURCES $[TARGET]_composite1.cxx diff --git a/panda/src/effects/config_effects.cxx b/panda/src/effects/config_effects.cxx index a3ff7159a2..b6dd1dc5c9 100644 --- a/panda/src/effects/config_effects.cxx +++ b/panda/src/effects/config_effects.cxx @@ -38,9 +38,8 @@ ConfigureFn(config_effects) { //////////////////////////////////////////////////////////////////// void init_libeffects() { +#if 0 // temporarily disabled until we can port to new scene graph. LensFlareNode::init_type(); - - //Registration of writeable object's creation - //functions with BamReader's factory LensFlareNode::register_with_read_factory(); +#endif // temporarily disabled until we can port to new scene graph. } diff --git a/panda/src/effects/lensFlareNode.cxx b/panda/src/effects/lensFlareNode.cxx index abf3fb824c..02a18ce3c1 100644 --- a/panda/src/effects/lensFlareNode.cxx +++ b/panda/src/effects/lensFlareNode.cxx @@ -16,6 +16,8 @@ // //////////////////////////////////////////////////////////////////// +#if 0 // temporarily disabled until we can port to new scene graph. + #include "lensFlareNode.h" #include "config_effects.h" @@ -732,3 +734,5 @@ prepare_sparkles(vector_relation &arcs, const vector_texture &sparkles, } ****************/ + +#endif // temporarily disabled until we can port to new scene graph. diff --git a/panda/src/effects/lensFlareNode.h b/panda/src/effects/lensFlareNode.h index a17f2da8cf..96a813e045 100644 --- a/panda/src/effects/lensFlareNode.h +++ b/panda/src/effects/lensFlareNode.h @@ -16,8 +16,10 @@ // //////////////////////////////////////////////////////////////////// -#ifndef LENS_FLARE_NODE -#define LENS_FLARE_NODE +#if 0 // temporarily disabled until we can port to new scene graph. + +#ifndef LENSFLARENODE_H +#define LENSFLARENODE_H #include @@ -176,3 +178,5 @@ private: int compute_current(int ¤t_sparkle, vector_texture sparkles); ******************/ + +#endif // temporarily disabled until we can port to new scene graph. diff --git a/panda/src/egg2pg/Sources.pp b/panda/src/egg2pg/Sources.pp index 4eaa415f3f..d7c389c7fd 100644 --- a/panda/src/egg2pg/Sources.pp +++ b/panda/src/egg2pg/Sources.pp @@ -6,13 +6,12 @@ #begin lib_target #define TARGET egg2pg #define LOCAL_LIBS \ - parametrics cull collide egg builder loader chan char switchnode + parametrics collide egg builder loader chan char #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx #define SOURCES \ animBundleMaker.h \ - characterMaker.h \ qpcharacterMaker.h \ computedVerticesMaker.I computedVerticesMaker.h \ computedVerticesMakerEntity.I computedVerticesMakerEntity.h \ @@ -21,18 +20,19 @@ eggBinner.h \ eggLoaderBase.h \ qpeggLoader.h \ - qpload_egg_file.h + qpload_egg_file.h \ + loaderFileTypeEgg.h #define INCLUDED_SOURCES \ animBundleMaker.cxx \ - characterMaker.cxx \ qpcharacterMaker.cxx \ computedVerticesMaker.cxx \ config_egg2pg.cxx \ deferredNodeProperty.cxx \ eggBinner.cxx \ qpeggLoader.cxx \ - qpload_egg_file.cxx + qpload_egg_file.cxx \ + loaderFileTypeEgg.cxx #if $[DONT_COMBINE_PGRAPH] #define SOURCES $[SOURCES] $[INCLUDED_SOURCES] diff --git a/panda/src/egg2pg/animBundleMaker.cxx b/panda/src/egg2pg/animBundleMaker.cxx index f095e90623..15d159c26e 100644 --- a/panda/src/egg2pg/animBundleMaker.cxx +++ b/panda/src/egg2pg/animBundleMaker.cxx @@ -26,7 +26,6 @@ #include "eggXfmSAnim.h" #include "eggGroupNode.h" #include "animBundle.h" -#include "animBundleNode.h" #include "qpanimBundleNode.h" #include "animChannelMatrixXfmTable.h" #include "animChannelScalarTable.h" @@ -65,16 +64,6 @@ AnimBundleMaker(EggTable *root) : _root(root) { } -//////////////////////////////////////////////////////////////////// -// Function: AnimBundleMaker::make_node -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -AnimBundleNode *AnimBundleMaker:: -make_node() { - return new AnimBundleNode(make_bundle()); -} - //////////////////////////////////////////////////////////////////// // Function: AnimBundleMaker::make_qpnode // Access: Public diff --git a/panda/src/egg2pg/animBundleMaker.h b/panda/src/egg2pg/animBundleMaker.h index a1e9c855be..b224c59bdf 100644 --- a/panda/src/egg2pg/animBundleMaker.h +++ b/panda/src/egg2pg/animBundleMaker.h @@ -29,7 +29,6 @@ class EggXfmSAnim; class EggSAnimData; class AnimGroup; class AnimBundle; -class AnimBundleNode; class qpAnimBundleNode; class AnimChannelScalarTable; class AnimChannelMatrixXfmTable; @@ -43,7 +42,6 @@ class EXPCL_PANDAEGG AnimBundleMaker { public: AnimBundleMaker(EggTable *root); - AnimBundleNode *make_node(); qpAnimBundleNode *make_qpnode(); private: diff --git a/panda/src/egg2pg/characterMaker.cxx b/panda/src/egg2pg/characterMaker.cxx deleted file mode 100644 index 214beb1059..0000000000 --- a/panda/src/egg2pg/characterMaker.cxx +++ /dev/null @@ -1,391 +0,0 @@ -// Filename: characterMaker.cxx -// Created by: drose (23Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "characterMaker.h" -#include "qpeggLoader.h" -#include "config_egg2pg.h" - -#include "computedVertices.h" -#include "eggGroup.h" -#include "eggPrimitive.h" -#include "partGroup.h" -#include "characterJoint.h" -#include "characterJointBundle.h" -#include "characterSlider.h" -#include "character.h" -#include "renderRelation.h" -#include "transformTransition.h" - -//////////////////////////////////////////////////////////////////// -// Function: CharacterMaker::Construtor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -CharacterMaker:: -CharacterMaker(EggGroup *root, EggLoaderBase &loader) - : _loader(loader), _egg_root(root) { - - _character_node = new Character(_egg_root->get_name()); - _bundle = _character_node->get_bundle(); - - _morph_root = (PartGroup *)NULL; - _skeleton_root = new PartGroup(_bundle, ""); -} - -//////////////////////////////////////////////////////////////////// -// Function: CharacterMaker::make_node -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -Character *CharacterMaker:: -make_node() { - make_bundle(); - _character_node->_parts = _parts; - return _character_node; -} - - -//////////////////////////////////////////////////////////////////// -// Function: CharacterMaker::egg_to_part -// Access: Public -// Description: Returns the PartGroup node associated with the given -// egg node. If the egg node is not a node in the -// character's hierarchy, returns the top of the -// character's hierarchy. -//////////////////////////////////////////////////////////////////// -PartGroup *CharacterMaker:: -egg_to_part(EggNode *egg_node) const { - int index = egg_to_index(egg_node); - if (index < 0) { - // If there's a reference to the geometry outside of the - // character, just return the root of the character. - return _bundle; - } - nassertr(index < (int)_parts.size(), NULL); - return _parts[index]; -} - -//////////////////////////////////////////////////////////////////// -// Function: CharacterMaker::egg_to_index -// Access: Public -// Description: Returns the index number associated with the -// PartGroup node for the given egg node, or -1. -//////////////////////////////////////////////////////////////////// -int CharacterMaker:: -egg_to_index(EggNode *egg_node) const { - NodeMap::const_iterator nmi = _node_map.find(egg_node); - if (nmi == _node_map.end()) { - return -1; - } - return (*nmi).second; -} - -//////////////////////////////////////////////////////////////////// -// Function: CharacterMaker::part_to_node -// Access: Public -// Description: Returns the scene graph node associated with the -// given PartGroup node, if there is one. If the -// PartGroup does not have an associated node, returns -// the character's top node. -//////////////////////////////////////////////////////////////////// -NamedNode *CharacterMaker:: -part_to_node(PartGroup *part) const { - if (part->is_of_type(CharacterJoint::get_class_type())) { - CharacterJoint *joint = DCAST(CharacterJoint, part); - if (joint->_geom_node != (NamedNode *)NULL) { - return joint->_geom_node; - } - } - - return _character_node; -} - - -//////////////////////////////////////////////////////////////////// -// Function: CharacterMaker::create_slider -// Access: Public -// Description: Creates a new morph slider of the given name, and -// returns its index. This is actually called by -// ComputedVerticesMaker, which is responsible for -// identifying all the unique morph target names. -//////////////////////////////////////////////////////////////////// -int CharacterMaker:: -create_slider(const string &name) { - if (_morph_root == (PartGroup *)NULL) { - _morph_root = new PartGroup(_bundle, "morph"); - } - CharacterSlider *slider = new CharacterSlider(_morph_root, name); - int index = _parts.size(); - _parts.push_back(slider); - return index; -} - - -//////////////////////////////////////////////////////////////////// -// Function: CharacterMaker::make_bundle -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -CharacterJointBundle *CharacterMaker:: -make_bundle() { - build_joint_hierarchy(_egg_root, _skeleton_root); - _bundle->sort_descendants(); - - parent_joint_nodes(_skeleton_root); - make_geometry(_egg_root); - - _character_node->_computed_vertices = - _comp_verts_maker.make_computed_vertices(_character_node, *this); - - return _bundle; -} - -//////////////////////////////////////////////////////////////////// -// Function: CharacterMaker::build_hierarchy -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -void CharacterMaker:: -build_joint_hierarchy(EggNode *egg_node, PartGroup *part) { - int index = -1; - - if (egg_node->is_of_type(EggGroup::get_class_type())) { - EggGroup *egg_group = DCAST(EggGroup, egg_node); - - // Each joint we come across is significant, and gets added to the - // hierarchy. Non-joints we encounter are ignored. - if (egg_group->get_group_type() == EggGroup::GT_joint) { - // We need to get the transform of the joint, and then convert - // it to single-precision. - LMatrix4d matd; - if (egg_group->has_transform()) { - matd = egg_group->get_transform(); - } else { - matd = LMatrix4d::ident_mat(); - } - - LMatrix4f matf = LCAST(float, matd); - - CharacterJoint *joint = - new CharacterJoint(part, egg_group->get_name(), matf); - index = _parts.size(); - _parts.push_back(joint); - - if (egg_group->get_dcs_flag()) { - // If the joint requested an explicit DCS, create a node for - // it. - joint->_geom_node = new NamedNode(egg_group->get_name()); - } - - part = joint; - } - - EggGroup::const_iterator ci; - for (ci = egg_group->begin(); ci != egg_group->end(); ++ci) { - build_joint_hierarchy((*ci), part); - } - } - - _node_map[egg_node] = index; -} - -//////////////////////////////////////////////////////////////////// -// Function: CharacterMaker::parent_joint_nodes -// Access: Private -// Description: Walks the joint hierarchy, and parents any explicit -// nodes created for the joints under the character -// node. -//////////////////////////////////////////////////////////////////// -void CharacterMaker:: -parent_joint_nodes(PartGroup *part) { - if (part->is_of_type(CharacterJoint::get_class_type())) { - CharacterJoint *joint = DCAST(CharacterJoint, part); - NamedNode *joint_node = joint->_geom_node; - if (joint_node != NULL) { - RenderRelation *arc = new RenderRelation(_character_node, joint_node); - joint->add_net_transform(arc); - arc->set_transition(new TransformTransition(joint->_net_transform)); - } - } - - for (int i = 0; i < part->get_num_children(); i++) { - parent_joint_nodes(part->get_child(i)); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CharacterMaker::make_geometry -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -void CharacterMaker:: -make_geometry(EggNode *egg_node) { - if (egg_node->is_of_type(EggPrimitive::get_class_type())) { - EggPrimitive *egg_primitive = DCAST(EggPrimitive, egg_node); - if (!egg_primitive->empty()) { - EggGroupNode *prim_home = determine_primitive_home(egg_primitive); - - if (prim_home == NULL) { - // This is a totally dynamic primitive that lives under the - // character's node. - make_dynamic_primitive(egg_primitive, _egg_root); - - } else { - // This is a static primitive that lives under a particular - // node. - make_static_primitive(egg_primitive, prim_home); - } - } - } - - if (egg_node->is_of_type(EggGroupNode::get_class_type())) { - EggGroupNode *egg_group = DCAST(EggGroupNode, egg_node); - - EggGroupNode::const_iterator ci; - for (ci = egg_group->begin(); ci != egg_group->end(); ++ci) { - make_geometry(*ci); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: CharacterMaker::make_static_primitive -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -void CharacterMaker:: -make_static_primitive(EggPrimitive *egg_primitive, EggGroupNode *prim_home) { - NamedNode *node = part_to_node(egg_to_part(prim_home)); - - // We need this funny transform to convert from the coordinate - // space of the original vertices to that of the new joint node. - LMatrix4d transform = - egg_primitive->get_vertex_frame() * - prim_home->get_node_frame_inv(); - - _loader.make_nonindexed_primitive(egg_primitive, node, &transform); -} - -//////////////////////////////////////////////////////////////////// -// Function: CharacterMaker::make_dynamic_primitive -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -void CharacterMaker:: -make_dynamic_primitive(EggPrimitive *egg_primitive, EggGroupNode *prim_home) { - NamedNode *node = part_to_node(egg_to_part(prim_home)); - - LMatrix4d transform = - egg_primitive->get_vertex_frame() * - prim_home->get_node_frame_inv(); - - _loader.make_indexed_primitive(egg_primitive, node, &transform, - _comp_verts_maker); -} - -//////////////////////////////////////////////////////////////////// -// Function: CharacterMaker::determine_primitive_home -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -EggGroupNode *CharacterMaker:: -determine_primitive_home(EggPrimitive *egg_primitive) { - // A primitive's vertices may be referenced by any joint in the - // character. Or, the primitive itself may be explicitly placed - // under a joint. - - // If any of the vertices are referenced by multiple joints, or if - // any two vertices are referenced by different joints, then the - // entire primitive must be considered dynamic. (We'll indicate a - // dynamic primitive by returning NULL.) - - // We need to keep track of the one joint we've encountered so far, - // to see if all the vertices are referenced by the same joint. - EggGroupNode *home = NULL; - - EggPrimitive::const_iterator vi; - for (vi = egg_primitive->begin(); - vi != egg_primitive->end(); - ++vi) { - EggVertex *vertex = (*vi); - if (vertex->gref_size() > 1) { - // This vertex is referenced by multiple joints; the primitive - // is dynamic. - return NULL; - } - - EggGroupNode *vertex_home; - - if (vertex->gref_size() == 0) { - // This vertex is not referenced at all, which means it belongs - // right where it is. - vertex_home = egg_primitive->get_parent(); - } else { - nassertr(vertex->gref_size() == 1, NULL); - // This vertex is referenced exactly once. - vertex_home = *vertex->gref_begin(); - } - - if (home != NULL && home != vertex_home) { - // Oops, two vertices are referenced by different joints! The - // primitive is dynamic. - return NULL; - } - - home = vertex_home; - } - - // This shouldn't be possible, unless there are no vertices--but we - // check for that before calling this function. - nassertr(home != NULL, NULL); - - // So, all the vertices are assigned to the same group. This means - // the polygon belongs entirely to one joint. - - // If the group is not, in fact, a joint then we return the first - // joint above the group. - EggGroup *egg_group = (EggGroup *)NULL; - if (home->is_of_type(EggGroup::get_class_type())) { - egg_group = DCAST(EggGroup, home); - } - while (egg_group != (EggGroup *)NULL && - egg_group->get_group_type() != EggGroup::GT_joint && - egg_group->get_dart_type() == EggGroup::DT_none) { - nassertr(egg_group->get_parent() != (EggGroupNode *)NULL, NULL); - home = egg_group->get_parent(); - egg_group = (EggGroup *)NULL; - if (home->is_of_type(EggGroup::get_class_type())) { - egg_group = DCAST(EggGroup, home); - } - } - - if (egg_group != (EggGroup *)NULL && - egg_group->get_group_type() == EggGroup::GT_joint && - !egg_group->get_dcs_flag()) { - // If the home is a joint without a flag--this is the normal - // case--we'll move the polygon under the character node and - // animate it from there explicitly. - return NULL; - } - - // Otherwise, if the joint *does* have a flag, we'll create - // static geometry that we parent directly to the joint node. - // We'll also create static geometry for polygons that have no - // explicit joint assignment. - return home; -} diff --git a/panda/src/egg2pg/characterMaker.h b/panda/src/egg2pg/characterMaker.h deleted file mode 100644 index cf53d50dca..0000000000 --- a/panda/src/egg2pg/characterMaker.h +++ /dev/null @@ -1,88 +0,0 @@ -// Filename: characterMaker.h -// Created by: drose (23Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CHARACTERMAKER_H -#define CHARACTERMAKER_H - -#include "pandabase.h" - -#include "computedVerticesMaker.h" - -#include "vector_PartGroupStar.h" -#include "typedef.h" -#include "pmap.h" - -class EggNode; -class EggGroup; -class EggGroupNode; -class EggPrimitive; -class PartGroup; -class CharacterJointBundle; -class Character; -class CharacterSlider; -class MovingPartBase; -class NamedNode; -class EggLoaderBase; - -/////////////////////////////////////////////////////////////////// -// Class : CharacterMaker -// Description : Converts an EggGroup hierarchy, beginning with a -// group with set, to a character node with -// joints. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDAEGG CharacterMaker { -public: - CharacterMaker(EggGroup *root, EggLoaderBase &loader); - - Character *make_node(); - - PartGroup *egg_to_part(EggNode *egg_node) const; - int egg_to_index(EggNode *egg_node) const; - NamedNode *part_to_node(PartGroup *part) const; - - int create_slider(const string &name); - -private: - CharacterJointBundle *make_bundle(); - void build_joint_hierarchy(EggNode *egg_node, PartGroup *part); - void parent_joint_nodes(PartGroup *part); - - void make_geometry(EggNode *egg_node); - - void make_static_primitive(EggPrimitive *egg_primitive, - EggGroupNode *prim_home); - void make_dynamic_primitive(EggPrimitive *egg_primitive, - EggGroupNode *prim_home); - EggGroupNode *determine_primitive_home(EggPrimitive *egg_primitive); - - typedef pmap NodeMap; - NodeMap _node_map; - - typedef vector_PartGroupStar Parts; - Parts _parts; - - EggLoaderBase &_loader; - EggGroup *_egg_root; - Character *_character_node; - CharacterJointBundle *_bundle; - ComputedVerticesMaker _comp_verts_maker; - PartGroup *_morph_root; - PartGroup *_skeleton_root; -}; - -#endif diff --git a/panda/src/egg2pg/computedVerticesMaker.cxx b/panda/src/egg2pg/computedVerticesMaker.cxx index e011091368..e1c87af512 100644 --- a/panda/src/egg2pg/computedVerticesMaker.cxx +++ b/panda/src/egg2pg/computedVerticesMaker.cxx @@ -17,10 +17,10 @@ //////////////////////////////////////////////////////////////////// #include "computedVerticesMaker.h" -#include "characterMaker.h" +#include "qpcharacterMaker.h" #include "characterJoint.h" -#include "character.h" +#include "qpcharacter.h" #include "computedVertices.h" #include "eggNode.h" #include "eggGroup.h" @@ -34,13 +34,12 @@ // Description: //////////////////////////////////////////////////////////////////// ComputedVerticesMaker:: -ComputedVerticesMaker() -{ - _coords= PTA_Vertexf::empty_array(0); - _norms= PTA_Normalf::empty_array(0); - _colors= PTA_Colorf::empty_array(0); - _texcoords= PTA_TexCoordf::empty_array(0); - _current_vc = NULL; +ComputedVerticesMaker() { + _coords= PTA_Vertexf::empty_array(0); + _norms= PTA_Normalf::empty_array(0); + _colors= PTA_Colorf::empty_array(0); + _texcoords= PTA_TexCoordf::empty_array(0); + _current_vc = NULL; } //////////////////////////////////////////////////////////////////// @@ -312,141 +311,6 @@ add_color(const Colorf &color, const EggMorphColorList &morphs) { return index; } -//////////////////////////////////////////////////////////////////// -// Function: ComputedVerticesMaker::make_computed_vertices -// Access: Public -// Description: After all spaces have been defined and all vertices -// added, creates a new ComputedVertices object and -// returns it. -//////////////////////////////////////////////////////////////////// -ComputedVertices *ComputedVerticesMaker:: -make_computed_vertices(Character *character, CharacterMaker &char_maker) { - // We must first build up a set of all the unique kinds of vertex - // transforms. - typedef pset VertexTransforms; - VertexTransforms transforms; - - TransformSpaces::const_iterator tsi; - for (tsi = _transforms.begin(); - tsi != _transforms.end(); - ++tsi) { - const JointWeights &jw = (*tsi).first; - const VertexCollection &vc = (*tsi).second; - - JointWeights::const_iterator jwi; - for (jwi = jw.begin(); jwi != jw.end(); ++jwi) { - double weight = (*jwi).second; - EggNode *egg_joint = (*jwi).first; - int joint_index = char_maker.egg_to_index(egg_joint); - - // Look for a VertexTransform that matches this template. - ComputedVertices::VertexTransform new_vt; - new_vt._joint_index = joint_index; - new_vt._effect = (float)weight; - - // This will either insert the VertexTransform into the set and - // return its newly-created iterator, or it will return the - // iterator referring to the previously-inserted VertexTransform - // like this. - VertexTransforms::iterator vti = transforms.insert(new_vt).first; - - // We can discard the const-ness of the set's iterator, because - // we will only be changing a part of the VertexTransform that - // doesn't affect its sort order within the set. - ComputedVertices::VertexTransform &insert_vt = - (ComputedVertices::VertexTransform &)*vti; - - // Now add in all the vertices and normals. - copy(vc._vindex.begin(), vc._vindex.end(), - back_inserter(insert_vt._vindex)); - copy(vc._nindex.begin(), vc._nindex.end(), - back_inserter(insert_vt._nindex)); - } - } - - // Ok, now we have the set of all VertexTransforms. Create a - // ComputedVertices object that reflects this. - ComputedVertices *comp_verts = new ComputedVertices; - copy(transforms.begin(), transforms.end(), - back_inserter(comp_verts->_transforms)); - - character->_cv._coords = _coords; - character->_cv._norms = _norms; - character->_cv._colors = _colors; - character->_cv._texcoords = _texcoords; - - // Finally, add in all the morph definitions. - Morphs::const_iterator mi; - for (mi = _morphs.begin(); mi != _morphs.end(); ++mi) { - const string &name = (*mi).first; - const MorphList &mlist = (*mi).second; - - int slider_index = char_maker.create_slider(name); - - if (!mlist._vmorphs.empty()) { - // We push an empty MorphVertex object and then modify it, - // rather than filling it first and then pushing it, just to - // avoid unnecessary copying of data. - comp_verts->_vertex_morphs.push_back(ComputedVerticesMorphVertex()); - ComputedVerticesMorphVertex &mv = comp_verts->_vertex_morphs.back(); - mv._slider_index = slider_index; - - VertexMorphList::const_iterator vmi; - for (vmi = mlist._vmorphs.begin(); - vmi != mlist._vmorphs.end(); - ++vmi) { - mv._morphs.push_back(ComputedVerticesMorphValue3((*vmi).first, - (*vmi).second)); - } - } - - if (!mlist._nmorphs.empty()) { - comp_verts->_normal_morphs.push_back(ComputedVerticesMorphNormal()); - ComputedVerticesMorphNormal &mv = comp_verts->_normal_morphs.back(); - mv._slider_index = slider_index; - - NormalMorphList::const_iterator vmi; - for (vmi = mlist._nmorphs.begin(); - vmi != mlist._nmorphs.end(); - ++vmi) { - mv._morphs.push_back(ComputedVerticesMorphValue3((*vmi).first, - (*vmi).second)); - } - } - - if (!mlist._tmorphs.empty()) { - comp_verts->_texcoord_morphs.push_back(ComputedVerticesMorphTexCoord()); - ComputedVerticesMorphTexCoord &mv = comp_verts->_texcoord_morphs.back(); - mv._slider_index = slider_index; - - TexCoordMorphList::const_iterator vmi; - for (vmi = mlist._tmorphs.begin(); - vmi != mlist._tmorphs.end(); - ++vmi) { - mv._morphs.push_back(ComputedVerticesMorphValue2((*vmi).first, - (*vmi).second)); - } - } - - if (!mlist._cmorphs.empty()) { - comp_verts->_color_morphs.push_back(ComputedVerticesMorphColor()); - ComputedVerticesMorphColor &mv = comp_verts->_color_morphs.back(); - mv._slider_index = slider_index; - - ColorMorphList::const_iterator vmi; - for (vmi = mlist._cmorphs.begin(); - vmi != mlist._cmorphs.end(); - ++vmi) { - mv._morphs.push_back(ComputedVerticesMorphValue4((*vmi).first, - (*vmi).second)); - } - } - } - - comp_verts->make_orig(character); - return comp_verts; -} - //////////////////////////////////////////////////////////////////// // Function: ComputedVerticesMaker::make_computed_vertices // Access: Public diff --git a/panda/src/egg2pg/computedVerticesMaker.h b/panda/src/egg2pg/computedVerticesMaker.h index 82ba3aeed0..5ba17bf649 100644 --- a/panda/src/egg2pg/computedVerticesMaker.h +++ b/panda/src/egg2pg/computedVerticesMaker.h @@ -37,7 +37,6 @@ #include "pmap.h" class ComputedVertices; -class CharacterMaker; class qpCharacterMaker; class EggNode; class EggVertex; @@ -79,9 +78,6 @@ public: const LMatrix3d &transform); int add_color(const Colorf &color, const EggMorphColorList &morphs); - ComputedVertices *make_computed_vertices(Character *character, - CharacterMaker &char_maker); - ComputedVertices *make_computed_vertices(qpCharacter *character, qpCharacterMaker &char_maker); diff --git a/panda/src/egg2pg/config_egg2pg.cxx b/panda/src/egg2pg/config_egg2pg.cxx index 89913ef005..f49f2fa17c 100644 --- a/panda/src/egg2pg/config_egg2pg.cxx +++ b/panda/src/egg2pg/config_egg2pg.cxx @@ -20,6 +20,8 @@ #include "dconfig.h" #include "get_config_path.h" +#include "loaderFileTypeEgg.h" +#include "loaderFileTypeRegistry.h" ConfigureDef(config_egg2pg); NotifyCategoryDef(egg2pg, ""); @@ -104,4 +106,10 @@ init_libegg2pg() { } egg_coordinate_system = (cs == CS_default) ? default_coordinate_system : cs; + + LoaderFileTypeEgg::init_type(); + + LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_ptr(); + + reg->register_type(new LoaderFileTypeEgg); } diff --git a/panda/src/egg2pg/deferredNodeProperty.cxx b/panda/src/egg2pg/deferredNodeProperty.cxx index 26101aa1ec..29ddaf77cd 100644 --- a/panda/src/egg2pg/deferredNodeProperty.cxx +++ b/panda/src/egg2pg/deferredNodeProperty.cxx @@ -20,6 +20,7 @@ #include "qpcollisionNode.h" #include "pandaNode.h" +#include "dcast.h" //////////////////////////////////////////////////////////////////// // Function: DeferredNodeProperty::Constructor diff --git a/panda/src/egg2pg/egg2pg_composite1.cxx b/panda/src/egg2pg/egg2pg_composite1.cxx index 6cd3b0d95c..a8d6ef5060 100644 --- a/panda/src/egg2pg/egg2pg_composite1.cxx +++ b/panda/src/egg2pg/egg2pg_composite1.cxx @@ -1,5 +1,4 @@ #include "animBundleMaker.cxx" -#include "characterMaker.cxx" #include "qpcharacterMaker.cxx" #include "computedVerticesMaker.cxx" #include "config_egg2pg.cxx" diff --git a/panda/src/egg2pg/egg2pg_composite2.cxx b/panda/src/egg2pg/egg2pg_composite2.cxx index 304b7d3294..43a13e6bd7 100644 --- a/panda/src/egg2pg/egg2pg_composite2.cxx +++ b/panda/src/egg2pg/egg2pg_composite2.cxx @@ -2,4 +2,5 @@ #include "eggBinner.cxx" #include "qpeggLoader.cxx" #include "qpload_egg_file.cxx" +#include "loaderFileTypeEgg.cxx" diff --git a/panda/src/egg2sg/loaderFileTypeEgg.cxx b/panda/src/egg2pg/loaderFileTypeEgg.cxx similarity index 86% rename from panda/src/egg2sg/loaderFileTypeEgg.cxx rename to panda/src/egg2pg/loaderFileTypeEgg.cxx index 3d2dbe67f7..c907f33dcb 100644 --- a/panda/src/egg2sg/loaderFileTypeEgg.cxx +++ b/panda/src/egg2pg/loaderFileTypeEgg.cxx @@ -17,7 +17,6 @@ //////////////////////////////////////////////////////////////////// #include "loaderFileTypeEgg.h" -#include "load_egg_file.h" #include "qpload_egg_file.h" #include "eggData.h" @@ -65,17 +64,6 @@ resolve_filename(Filename &path) const { EggData::resolve_egg_filename(path); } -//////////////////////////////////////////////////////////////////// -// Function: LoaderFileTypeEgg::load_file -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -PT_Node LoaderFileTypeEgg:: -load_file(const Filename &path, bool) const { - PT_NamedNode result = load_egg_file(path); - return result.p(); -} - //////////////////////////////////////////////////////////////////// // Function: LoaderFileTypeEgg::load_file // Access: Public, Virtual diff --git a/panda/src/egg2sg/loaderFileTypeEgg.h b/panda/src/egg2pg/loaderFileTypeEgg.h similarity index 95% rename from panda/src/egg2sg/loaderFileTypeEgg.h rename to panda/src/egg2pg/loaderFileTypeEgg.h index 19296545b7..a6a0d3fb23 100644 --- a/panda/src/egg2sg/loaderFileTypeEgg.h +++ b/panda/src/egg2pg/loaderFileTypeEgg.h @@ -35,7 +35,6 @@ public: virtual string get_extension() const; virtual void resolve_filename(Filename &path) const; - virtual PT_Node load_file(const Filename &path, bool report_errors) const; virtual PT(PandaNode) qpload_file(const Filename &path, bool report_errors) const; public: diff --git a/panda/src/egg2pg/qpload_egg_file.cxx b/panda/src/egg2pg/qpload_egg_file.cxx index 5d8a013c9a..b6fb58b9f7 100644 --- a/panda/src/egg2pg/qpload_egg_file.cxx +++ b/panda/src/egg2pg/qpload_egg_file.cxx @@ -20,7 +20,6 @@ #include "qpeggLoader.h" #include "config_egg2pg.h" #include "qpsceneGraphReducer.h" -#include "renderRelation.h" static PT(PandaNode) load_from_loader(qpEggLoader &loader) { diff --git a/panda/src/egg2sg/Sources.pp b/panda/src/egg2sg/Sources.pp deleted file mode 100644 index ee67767ef7..0000000000 --- a/panda/src/egg2sg/Sources.pp +++ /dev/null @@ -1,37 +0,0 @@ -#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \ - dtoolutil:c dtoolbase:c dtool:m - -#define USE_NURBSPP yes - -#begin lib_target - #define TARGET egg2sg - #define LOCAL_LIBS \ - parametrics cull collide egg2pg egg builder loader chan char switchnode - - #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx - - #define SOURCES \ - config_egg2sg.h \ - deferredArcProperty.h deferredArcTraverser.h \ - eggLoader.h load_egg_file.h loaderFileTypeEgg.h - - #define INCLUDED_SOURCES \ - config_egg2sg.cxx deferredArcProperty.cxx \ - deferredArcTraverser.cxx eggLoader.cxx \ - load_egg_file.cxx loaderFileTypeEgg.cxx - - #define INSTALL_HEADERS \ - load_egg_file.h config_egg2sg.h - -#end lib_target - -#begin test_bin_target - #define TARGET test_loader - #define LOCAL_LIBS \ - egg2sg - - #define SOURCES \ - test_loader.cxx - -#end test_bin_target - diff --git a/panda/src/egg2sg/config_egg2sg.cxx b/panda/src/egg2sg/config_egg2sg.cxx deleted file mode 100644 index 232415890f..0000000000 --- a/panda/src/egg2sg/config_egg2sg.cxx +++ /dev/null @@ -1,54 +0,0 @@ -// Filename: config_egg2sg.cxx -// Created by: drose (01Oct99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "config_egg2sg.h" -#include "loaderFileTypeEgg.h" - -#include -#include -#include - -ConfigureDef(config_egg2sg); -NotifyCategoryDef(egg2sg, ""); - -ConfigureFn(config_egg2sg) { - init_libegg2sg(); -} - -//////////////////////////////////////////////////////////////////// -// Function: init_libegg2sg -// Description: Initializes the library. This must be called at -// least once before any of the functions or classes in -// this library can be used. Normally it will be -// called by the static initializers and need not be -// called explicitly, but special cases exist. -//////////////////////////////////////////////////////////////////// -void -init_libegg2sg() { - static bool initialized = false; - if (initialized) { - return; - } - initialized = true; - - LoaderFileTypeEgg::init_type(); - - LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_ptr(); - - reg->register_type(new LoaderFileTypeEgg); -} diff --git a/panda/src/egg2sg/config_egg2sg.h b/panda/src/egg2sg/config_egg2sg.h deleted file mode 100644 index 35b41e3a6f..0000000000 --- a/panda/src/egg2sg/config_egg2sg.h +++ /dev/null @@ -1,36 +0,0 @@ -// Filename: config_egg2sg.h -// Created by: drose (01Oct99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CONFIG_EGG2SG_H -#define CONFIG_EGG2SG_H - -#include - -#include -#include -#include -#include - -#include "config_egg2pg.h" // temp to declare the global consts - -ConfigureDecl(config_egg2sg, EXPCL_PANDAEGG, EXPTP_PANDAEGG); -NotifyCategoryDecl(egg2sg, EXPCL_PANDAEGG, EXPTP_PANDAEGG); - -extern EXPCL_PANDAEGG void init_libegg2sg(); - -#endif diff --git a/panda/src/egg2sg/deferredArcProperty.cxx b/panda/src/egg2sg/deferredArcProperty.cxx deleted file mode 100644 index 55770f6dcf..0000000000 --- a/panda/src/egg2sg/deferredArcProperty.cxx +++ /dev/null @@ -1,103 +0,0 @@ -// Filename: deferredArcProperty.cxx -// Created by: drose (04Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "deferredArcProperty.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Function: DeferredArcProperty::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -DeferredArcProperty:: -DeferredArcProperty() { - _flags = 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: DeferredArcProperty::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -DeferredArcProperty:: -DeferredArcProperty(const DeferredArcProperty ©) : - _flags(copy._flags), - _from_collide_mask(copy._from_collide_mask), - _into_collide_mask(copy._into_collide_mask) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: DeferredArcProperty::Copy Assignment -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void DeferredArcProperty:: -operator = (const DeferredArcProperty ©) { - _flags = copy._flags; - _from_collide_mask = copy._from_collide_mask; - _into_collide_mask = copy._into_collide_mask; -} - -//////////////////////////////////////////////////////////////////// -// Function: DeferredArcProperty::compose -// Access: Public -// Description: Composes this state with the next one encountered on -// a lower arc during the apply traversal. -//////////////////////////////////////////////////////////////////// -void DeferredArcProperty:: -compose(const DeferredArcProperty &other) { - _flags |= other._flags; - - if ((other._flags & F_has_from_collide_mask) != 0) { - _from_collide_mask = other._from_collide_mask; - } - - if ((other._flags & F_has_into_collide_mask) != 0) { - _into_collide_mask = other._into_collide_mask; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DeferredArcProperty::apply_to_arc -// Access: Public -// Description: Applies whatever state is appropriate to the arc. -//////////////////////////////////////////////////////////////////// -void DeferredArcProperty:: -apply_to_arc(NodeRelation *) { -} - -//////////////////////////////////////////////////////////////////// -// Function: DeferredArcProperty::apply_to_node -// Access: Public -// Description: Applies whatever state is appropriate to the node. -//////////////////////////////////////////////////////////////////// -void DeferredArcProperty:: -apply_to_node(Node *node) { - if (node->is_of_type(CollisionNode::get_class_type())) { - CollisionNode *cnode = DCAST(CollisionNode, node); - if ((_flags & F_has_from_collide_mask) != 0) { - cnode->set_from_collide_mask(_from_collide_mask); - } - if ((_flags & F_has_into_collide_mask) != 0) { - cnode->set_into_collide_mask(_into_collide_mask); - } - } -} - diff --git a/panda/src/egg2sg/deferredArcProperty.h b/panda/src/egg2sg/deferredArcProperty.h deleted file mode 100644 index e22971b318..0000000000 --- a/panda/src/egg2sg/deferredArcProperty.h +++ /dev/null @@ -1,67 +0,0 @@ -// Filename: deferredArcProperty.h -// Created by: drose (04Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DEFERREDARCPROPERTY_H -#define DEFERREDARCPROPERTY_H - -#include - -#include - -#include "nodeRelation.h" -class Node; - -/////////////////////////////////////////////////////////////////// -// Class : DeferredArcProperty -// Description : This class keeps track of all the state we must make -// note of during the graph traversal, but cannot apply -// immediately. An instance of this class may be -// assigned to arcs as they are created, and then later, -// after the geometry has been created, the graph will -// be traversed again and the state will be applied. -// -// This class is only local to this package; it is not -// exported. -//////////////////////////////////////////////////////////////////// -class DeferredArcProperty { -public: - DeferredArcProperty(); - DeferredArcProperty(const DeferredArcProperty ©); - void operator = (const DeferredArcProperty ©); - - void compose(const DeferredArcProperty &other); - - void apply_to_arc(NodeRelation *arc); - void apply_to_node(Node *node); - - -public: - enum Flags { - F_has_from_collide_mask = 0x0001, - F_has_into_collide_mask = 0x0002, - }; - - int _flags; - CollideMask _from_collide_mask; - CollideMask _into_collide_mask; -}; - -typedef pmap DeferredArcs; - - -#endif diff --git a/panda/src/egg2sg/deferredArcTraverser.cxx b/panda/src/egg2sg/deferredArcTraverser.cxx deleted file mode 100644 index 7d2ebc173e..0000000000 --- a/panda/src/egg2sg/deferredArcTraverser.cxx +++ /dev/null @@ -1,56 +0,0 @@ -// Filename: deferredArcTraverser.cxx -// Created by: drose (04Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "deferredArcTraverser.h" - -//////////////////////////////////////////////////////////////////// -// Function: DeferredArcTraverser::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -DeferredArcTraverser:: -DeferredArcTraverser(const DeferredArcs &deferred_arcs) : - _deferred_arcs(deferred_arcs) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: DeferredArcTraverser::forward_arc -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -bool DeferredArcTraverser:: -forward_arc(NodeRelation *arc, NullTransitionWrapper &, - NullTransitionWrapper &, NullTransitionWrapper &, - DeferredArcProperty &level_state) { - - // Do we have a DeferredArcProperty associated with this arc? - DeferredArcs::const_iterator dai; - dai = _deferred_arcs.find(arc); - - if (dai != _deferred_arcs.end()) { - const DeferredArcProperty &def = (*dai).second; - level_state.compose(def); - } - - // Now apply the accumulated state to both the arc and its node. - level_state.apply_to_arc(arc); - level_state.apply_to_node(arc->get_child()); - - return true; -} diff --git a/panda/src/egg2sg/deferredArcTraverser.h b/panda/src/egg2sg/deferredArcTraverser.h deleted file mode 100644 index f47b02ad14..0000000000 --- a/panda/src/egg2sg/deferredArcTraverser.h +++ /dev/null @@ -1,56 +0,0 @@ -// Filename: deferredArcTraverser.h -// Created by: drose (04Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DEFERREDARCTRAVERSER_H -#define DEFERREDARCTRAVERSER_H - -#include - -#include "deferredArcProperty.h" - -#include -#include - -#include "pmap.h" - -class NodeRelation; - -/////////////////////////////////////////////////////////////////// -// Class : DeferredArcTraverser -// Description : This class is used after all of the nodes have been -// built to go back and apply down all of the -// DeferredArcProperties that might have been built of -// for each arc. It's a standard Panda -// TraverserVisitor. -// -// This class is only local to this package; it is not -// exported. -//////////////////////////////////////////////////////////////////// -class DeferredArcTraverser : public TraverserVisitor { -public: - DeferredArcTraverser(const DeferredArcs &deferred_arcs); - - bool forward_arc(NodeRelation *arc, NullTransitionWrapper &, - NullTransitionWrapper &, NullTransitionWrapper &, - DeferredArcProperty &level_state); - - const DeferredArcs &_deferred_arcs; -}; - - -#endif diff --git a/panda/src/egg2sg/egg2sg_composite1.cxx b/panda/src/egg2sg/egg2sg_composite1.cxx deleted file mode 100644 index 75e05341b9..0000000000 --- a/panda/src/egg2sg/egg2sg_composite1.cxx +++ /dev/null @@ -1,3 +0,0 @@ - -#include "deferredArcProperty.cxx" -#include "deferredArcTraverser.cxx" diff --git a/panda/src/egg2sg/egg2sg_composite2.cxx b/panda/src/egg2sg/egg2sg_composite2.cxx deleted file mode 100644 index ed6b09b916..0000000000 --- a/panda/src/egg2sg/egg2sg_composite2.cxx +++ /dev/null @@ -1,5 +0,0 @@ - -#include "config_egg2sg.cxx" -#include "eggLoader.cxx" -#include "load_egg_file.cxx" -#include "loaderFileTypeEgg.cxx" diff --git a/panda/src/egg2sg/eggLoader.cxx b/panda/src/egg2sg/eggLoader.cxx deleted file mode 100644 index 246b67a39a..0000000000 --- a/panda/src/egg2sg/eggLoader.cxx +++ /dev/null @@ -1,1994 +0,0 @@ -// Filename: eggLoader.cxx -// Created by: drose (21Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include - -#include "eggLoader.h" -#include "animBundleMaker.h" -#include "characterMaker.h" -#include "computedVerticesMaker.h" -#include "eggBinner.h" -#include "config_egg2sg.h" -#include "deferredArcProperty.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -// This class is used in make_node(EggBin *) to sort LOD instances in -// order by switching distance. -class LODInstance { -public: - LODInstance(EggNode *egg_node, RenderRelation *arc); - bool operator < (const LODInstance &other) const { - return _d->_switch_in < other._d->_switch_in; - } - - RenderRelation *_arc; - const EggSwitchConditionDistance *_d; -}; - -LODInstance:: -LODInstance(EggNode *egg_node, RenderRelation *arc) { - assert(arc != NULL); - _arc = arc; - - // We expect this egg node to be an EggGroup with an LOD - // specification. That's what the EggBinner collected together, - // after all. - EggGroup *egg_group = DCAST(EggGroup, egg_node); - assert(egg_group->has_lod()); - const EggSwitchCondition &sw = egg_group->get_lod(); - - // For now, this is the only kind of switch condition there is. - _d = DCAST(EggSwitchConditionDistance, &sw); -} - - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -EggLoader:: -EggLoader() { - // We need to enforce whatever coordinate system the user asked for. - _data.set_coordinate_system(egg_coordinate_system); - _error = false; -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -EggLoader:: -EggLoader(const EggData &data) : - _data(data) -{ - _error = false; -} - - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::build_graph -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void EggLoader:: -build_graph() { - _deferred_arcs.clear(); - - // First, bin up the LOD nodes. - EggBinner binner; - binner.make_bins(&_data); - - // Then load up all of the textures. - load_textures(); - - // Now build up the scene graph. - _root = new ModelRoot; - _root->set_name(_data.get_egg_filename().get_basename()); - make_node(&_data, _root); - _builder.build(); - - reset_directs(); - reparent_decals(); - - apply_deferred_arcs(_root); -} - - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::reparent_decals -// Access: Public -// Description: For each node representing a decal base geometry -// (i.e. a node corresponding to an EggGroup with the -// decal flag set), move all of its nested geometry -// directly below the GeomNode representing the group. -//////////////////////////////////////////////////////////////////// -void EggLoader:: -reparent_decals() { - Decals::const_iterator di; - for (di = _decals.begin(); di != _decals.end(); ++di) { - RenderRelation *arc = (*di); - nassertv(arc != (RenderRelation *)NULL); - NamedNode *node = DCAST(NamedNode, arc->get_child()); - nassertv(node != (NamedNode *)NULL); - - // First, search for the GeomNode. - GeomNode *geom = NULL; - int num_children = - node->get_num_children(RenderRelation::get_class_type()); - for (int i = 0; i < num_children; i++) { - NodeRelation *child_arc = - node->get_child(RenderRelation::get_class_type(), i); - nassertv(child_arc != (NodeRelation *)NULL); - Node *child = child_arc->get_child(); - nassertv(child != (Node *)NULL); - - if (child->is_of_type(GeomNode::get_class_type())) { - if (geom != (GeomNode *)NULL) { - // Oops, too many GeomNodes. - egg2sg_cat.error() - << "Decal onto " << node->get_name() - << " uses base geometry with multiple states.\n"; - _error = true; - } - DCAST_INTO_V(geom, child); - } - } - - if (geom == (GeomNode *)NULL) { - // No children were GeomNodes. - egg2sg_cat.error() - << "Ignoring decal onto " << node->get_name() - << "; no geometry within group.\n"; - _error = true; - } else { - // Now reparent all of the non-GeomNodes to this node. We have - // to be careful so we don't get lost as we self-modify this - // list. - int i = 0; - while (i < num_children) { - NodeRelation *child_arc = - node->get_child(RenderRelation::get_class_type(), i); - nassertv(child_arc != (NodeRelation *)NULL); - Node *child = child_arc->get_child(); - nassertv(child != (Node *)NULL); - - if (child->is_of_type(GeomNode::get_class_type())) { - i++; - } else { - child_arc->change_parent(geom); - num_children--; - } - } - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::reset_directs -// Access: Public -// Description: This applies to all of the nodes marked with the -// "render" flag, i.e. direct rendering of a subgraph, -// in depth-first order, as opposed to state-sorting -// within the subgraph. For each such node, it moves -// all the transitions from the first GeomNode under -// that node up to the node itself, just so we'll be -// able to state-sort at least the tops of the -// subgraphs. -//////////////////////////////////////////////////////////////////// -void EggLoader:: -reset_directs() { - Directs::const_iterator di; - for (di = _directs.begin(); di != _directs.end(); ++di) { - RenderRelation *arc = (*di); - nassertv(arc != (RenderRelation *)NULL); - NamedNode *node = DCAST(NamedNode, arc->get_child()); - nassertv(node != (NamedNode *)NULL); - - // First, search for the first GeomNode. - GeomNode *geom = NULL; - NodeRelation *child_arc = NULL; - - int num_children = - node->get_num_children(RenderRelation::get_class_type()); - for (int i = 0; i < num_children && geom == (GeomNode *)NULL; i++) { - child_arc = node->get_child(RenderRelation::get_class_type(), i); - nassertv(child_arc != (NodeRelation *)NULL); - Node *child = child_arc->get_child(); - nassertv(child != (Node *)NULL); - - if (child->is_of_type(GeomNode::get_class_type())) { - DCAST_INTO_V(geom, child); - } - } - - if (geom != (GeomNode *)NULL) { - // Now copy all of the GeomNode's transitions up to its parent. - nassertv(child_arc != (NodeRelation *)NULL); - arc->copy_transitions_from(child_arc); - } - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::make_nonindexed_primitive -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void EggLoader:: -make_nonindexed_primitive(EggPrimitive *egg_prim, NamedNode *parent, - const LMatrix4d *transform) { - BuilderBucket bucket; - setup_bucket(bucket, parent, egg_prim); - - LMatrix4d mat; - - if (transform != NULL) { - mat = (*transform); - } else { - mat = egg_prim->get_vertex_to_node(); - } - - BuilderPrim bprim; - bprim.set_type(BPT_poly); - if (egg_prim->is_of_type(EggPoint::get_class_type())) { - bprim.set_type(BPT_point); - } - - if (egg_prim->has_normal()) { - Normald norm = egg_prim->get_normal() * mat; - norm.normalize(); - bprim.set_normal(LCAST(float, norm)); - } - if (egg_prim->has_color() && !egg_false_color) { - bprim.set_color(egg_prim->get_color()); - } - - bool has_vert_color = true; - EggPrimitive::const_iterator vi; - for (vi = egg_prim->begin(); vi != egg_prim->end(); ++vi) { - EggVertex *egg_vert = *vi; - BuilderVertex bvert(LCAST(float, egg_vert->get_pos3() * mat)); - - if (egg_vert->has_normal()) { - Normald norm = egg_vert->get_normal() * mat; - norm.normalize(); - bvert.set_normal(LCAST(float, norm)); - } - if (egg_vert->has_color() && !egg_false_color) { - bvert.set_color(egg_vert->get_color()); - } else { - // If any vertex doesn't have a color, we can't use any of the - // vertex colors. - has_vert_color = false; - } - if (egg_vert->has_uv()) { - TexCoordd uv = egg_vert->get_uv(); - if (egg_prim->has_texture() && - egg_prim->get_texture()->has_transform()) { - // If we have a texture matrix, apply it. - uv = uv * egg_prim->get_texture()->get_transform(); - } - bvert.set_texcoord(LCAST(float, uv)); - } - - bprim.add_vertex(bvert); - } - - // Finally, if the primitive didn't have a color, and it didn't have - // vertex color, make it white. - if (!egg_prim->has_color() && !has_vert_color && !egg_false_color) { - bprim.set_color(Colorf(1.0, 1.0, 1.0, 1.0)); - } - - _builder.add_prim(bucket, bprim); -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::make_indexed_primitive -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void EggLoader:: -make_indexed_primitive(EggPrimitive *egg_prim, NamedNode *parent, - const LMatrix4d *transform, - ComputedVerticesMaker &_comp_verts_maker) { - BuilderBucket bucket; - setup_bucket(bucket, parent, egg_prim); - - bucket.set_coords(_comp_verts_maker._coords); - bucket.set_normals(_comp_verts_maker._norms); - bucket.set_texcoords(_comp_verts_maker._texcoords); - bucket.set_colors(_comp_verts_maker._colors); - - LMatrix4d mat; - - if (transform != NULL) { - mat = (*transform); - } else { - mat = egg_prim->get_vertex_to_node(); - } - - BuilderPrimI bprim; - bprim.set_type(BPT_poly); - if (egg_prim->is_of_type(EggPoint::get_class_type())) { - bprim.set_type(BPT_point); - } - - if (egg_prim->has_normal()) { - // Define the transform space of the polygon normal. This will be - // the average of all the vertex transform spaces. - _comp_verts_maker.begin_new_space(); - EggPrimitive::const_iterator vi; - for (vi = egg_prim->begin(); vi != egg_prim->end(); ++vi) { - EggVertex *egg_vert = *vi; - _comp_verts_maker.add_vertex_joints(egg_vert, egg_prim); - } - _comp_verts_maker.mark_space(); - - int nindex = - _comp_verts_maker.add_normal(egg_prim->get_normal(), - egg_prim->_dnormals, mat); - - bprim.set_normal(nindex); - } - - if (egg_prim->has_color() && !egg_false_color) { - int cindex = - _comp_verts_maker.add_color(egg_prim->get_color(), - egg_prim->_drgbas); - bprim.set_color(cindex); - } - - bool has_vert_color = true; - EggPrimitive::const_iterator vi; - for (vi = egg_prim->begin(); vi != egg_prim->end(); ++vi) { - EggVertex *egg_vert = *vi; - - // Set up the ComputedVerticesMaker for the coordinate space of - // the vertex. - _comp_verts_maker.begin_new_space(); - _comp_verts_maker.add_vertex_joints(egg_vert, egg_prim); - _comp_verts_maker.mark_space(); - - int vindex = - _comp_verts_maker.add_vertex(egg_vert->get_pos3(), - egg_vert->_dxyzs, mat); - BuilderVertexI bvert(vindex); - - if (egg_vert->has_normal()) { - int nindex = - _comp_verts_maker.add_normal(egg_vert->get_normal(), - egg_vert->_dnormals, - mat); - bvert.set_normal(nindex); - } - - if (egg_vert->has_color() && !egg_false_color) { - int cindex = - _comp_verts_maker.add_color(egg_vert->get_color(), - egg_vert->_drgbas); - bvert.set_color(cindex); - } else { - // If any vertex doesn't have a color, we can't use any of the - // vertex colors. - has_vert_color = false; - } - - if (egg_vert->has_uv()) { - TexCoordd uv = egg_vert->get_uv(); - LMatrix3d mat; - - if (egg_prim->has_texture() && - egg_prim->get_texture()->has_transform()) { - // If we have a texture matrix, apply it. - mat = egg_prim->get_texture()->get_transform(); - } else { - mat = LMatrix3d::ident_mat(); - } - - int tindex = - _comp_verts_maker.add_texcoord(uv, egg_vert->_duvs, mat); - bvert.set_texcoord(tindex); - } - - bprim.add_vertex(bvert); - } - - // Finally, if the primitive didn't have a color, and it didn't have - // vertex color, make it white. - if (!egg_prim->has_color() && !has_vert_color && !egg_false_color) { - int cindex = - _comp_verts_maker.add_color(Colorf(1.0, 1.0, 1.0, 1.0), - EggMorphColorList()); - bprim.set_color(cindex); - } - - _builder.add_prim(bucket, bprim); -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::load_textures -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -void EggLoader:: -load_textures() { - // First, collect all the textures that are referenced. - EggTextureCollection tc; - tc.find_used_textures(&_data); - - // Collapse the textures down by filename only. Should we also - // differentiate by attributes? Maybe. - EggTextureCollection::TextureReplacement replace; - tc.collapse_equivalent_textures(EggTexture::E_complete_filename, - replace); - - EggTextureCollection::iterator ti; - for (ti = tc.begin(); ti != tc.end(); ++ti) { - PT(EggTexture) egg_tex = (*ti); - - TextureDef def; - if (load_texture(def, egg_tex)) { - // Now associate the pointers, so we'll be able to look up the - // Texture pointer given an EggTexture pointer, later. - _textures[egg_tex] = def; - } - } - - // Finally, associate all of the removed texture references back to - // the same pointers as the others. - EggTextureCollection::TextureReplacement::const_iterator ri; - for (ri = replace.begin(); ri != replace.end(); ++ri) { - PT(EggTexture) orig = (*ri).first; - PT(EggTexture) repl = (*ri).second; - - _textures[orig] = _textures[repl]; - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::load_texture -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -bool EggLoader:: -load_texture(TextureDef &def, const EggTexture *egg_tex) { - Texture *tex; - if (egg_tex->has_alpha_file()) { - tex = TexturePool::load_texture(egg_tex->get_filename(), - egg_tex->get_alpha_file()); - } else { - tex = TexturePool::load_texture(egg_tex->get_filename()); - } - if (tex == (Texture *)NULL) { - return false; - } - - if (egg_keep_texture_pathnames) { - tex->set_filename(egg_tex->get_filename()); - if (egg_tex->has_alpha_file()) { - tex->set_alpha_filename(egg_tex->get_alpha_file()); - } else { - tex->clear_alpha_filename(); - } - } - - PT(TextureApplyTransition) apply = - new TextureApplyTransition(TextureApplyProperty::M_modulate); - - apply_texture_attributes(tex, egg_tex); - apply_texture_apply_attributes(apply, egg_tex); - - def._texture = new TextureTransition(tex); - def._apply = *(_texture_applies.insert(apply).first); - - return true; -} - - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::apply_texture_attributes -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -void EggLoader:: -apply_texture_attributes(Texture *tex, const EggTexture *egg_tex) { - tex->set_name(egg_tex->get_filename().get_fullpath()); - - switch (egg_tex->determine_wrap_u()) { - case EggTexture::WM_repeat: - tex->set_wrapu(Texture::WM_repeat); - break; - - case EggTexture::WM_clamp: - if (egg_ignore_clamp) { - egg2sg_cat.warning() - << "Ignoring clamp request\n"; - tex->set_wrapu(Texture::WM_repeat); - } else { - tex->set_wrapu(Texture::WM_clamp); - } - break; - - case EggTexture::WM_unspecified: - break; - - default: - egg2sg_cat.warning() - << "Unexpected texture wrap flag: " - << (int)egg_tex->determine_wrap_u() << "\n"; - } - - switch (egg_tex->determine_wrap_v()) { - case EggTexture::WM_repeat: - tex->set_wrapv(Texture::WM_repeat); - break; - - case EggTexture::WM_clamp: - if (egg_ignore_clamp) { - egg2sg_cat.warning() - << "Ignoring clamp request\n"; - tex->set_wrapv(Texture::WM_repeat); - } else { - tex->set_wrapv(Texture::WM_clamp); - } - break; - - case EggTexture::WM_unspecified: - break; - - default: - egg2sg_cat.warning() - << "Unexpected texture wrap flag: " - << (int)egg_tex->determine_wrap_v() << "\n"; - } - - switch (egg_tex->get_minfilter()) { - case EggTexture::FT_nearest: - tex->set_minfilter(Texture::FT_nearest); - break; - - case EggTexture::FT_linear: - if (egg_ignore_filters) { - egg2sg_cat.warning() - << "Ignoring minfilter request\n"; - tex->set_minfilter(Texture::FT_nearest); - } else { - tex->set_minfilter(Texture::FT_linear); - } - break; - - case EggTexture::FT_nearest_mipmap_nearest: - if (egg_ignore_filters) { - egg2sg_cat.warning() - << "Ignoring minfilter request\n"; - tex->set_minfilter(Texture::FT_nearest); - } else if (egg_ignore_mipmaps) { - egg2sg_cat.warning() - << "Ignoring mipmap request\n"; - tex->set_minfilter(Texture::FT_nearest); - } else { - tex->set_minfilter(Texture::FT_nearest_mipmap_nearest); - } - break; - - case EggTexture::FT_linear_mipmap_nearest: - if (egg_ignore_filters) { - egg2sg_cat.warning() - << "Ignoring minfilter request\n"; - tex->set_minfilter(Texture::FT_nearest); - } else if (egg_ignore_mipmaps) { - egg2sg_cat.warning() - << "Ignoring mipmap request\n"; - tex->set_minfilter(Texture::FT_linear); - } else { - tex->set_minfilter(Texture::FT_linear_mipmap_nearest); - } - break; - - case EggTexture::FT_nearest_mipmap_linear: - if (egg_ignore_filters) { - egg2sg_cat.warning() - << "Ignoring minfilter request\n"; - tex->set_minfilter(Texture::FT_nearest); - } else if (egg_ignore_mipmaps) { - egg2sg_cat.warning() - << "Ignoring mipmap request\n"; - tex->set_minfilter(Texture::FT_nearest); - } else { - tex->set_minfilter(Texture::FT_nearest_mipmap_linear); - } - break; - - case EggTexture::FT_linear_mipmap_linear: - if (egg_ignore_filters) { - egg2sg_cat.warning() - << "Ignoring minfilter request\n"; - tex->set_minfilter(Texture::FT_nearest); - } else if (egg_ignore_mipmaps) { - egg2sg_cat.warning() - << "Ignoring mipmap request\n"; - tex->set_minfilter(Texture::FT_linear); - } else { - tex->set_minfilter(Texture::FT_linear_mipmap_linear); - } - break; - - case EggTexture::FT_unspecified: - // Default is bilinear, unless egg_ignore_filters is specified. - if (egg_ignore_filters) { - tex->set_minfilter(Texture::FT_nearest); - } else { - tex->set_minfilter(Texture::FT_linear); - } - } - - switch (egg_tex->get_magfilter()) { - case EggTexture::FT_nearest: - case EggTexture::FT_nearest_mipmap_nearest: - case EggTexture::FT_nearest_mipmap_linear: - tex->set_magfilter(Texture::FT_nearest); - break; - - case EggTexture::FT_linear: - case EggTexture::FT_linear_mipmap_nearest: - case EggTexture::FT_linear_mipmap_linear: - if (egg_ignore_filters) { - egg2sg_cat.warning() - << "Ignoring magfilter request\n"; - tex->set_magfilter(Texture::FT_nearest); - } else { - tex->set_magfilter(Texture::FT_linear); - } - break; - - case EggTexture::FT_unspecified: - // Default is bilinear, unless egg_ignore_filters is specified. - if (egg_ignore_filters) { - tex->set_magfilter(Texture::FT_nearest); - } else { - tex->set_magfilter(Texture::FT_linear); - } - } - - if (egg_tex->has_anisotropic_degree()) { - tex->set_anisotropic_degree(egg_tex->get_anisotropic_degree()); - } - - if (tex->_pbuffer->get_num_components() == 1) { - switch (egg_tex->get_format()) { - case EggTexture::F_red: - tex->_pbuffer->set_format(PixelBuffer::F_red); - break; - case EggTexture::F_green: - tex->_pbuffer->set_format(PixelBuffer::F_green); - break; - case EggTexture::F_blue: - tex->_pbuffer->set_format(PixelBuffer::F_blue); - break; - case EggTexture::F_alpha: - tex->_pbuffer->set_format(PixelBuffer::F_alpha); - break; - case EggTexture::F_luminance: - tex->_pbuffer->set_format(PixelBuffer::F_luminance); - break; - - case EggTexture::F_unspecified: - break; - - default: - egg2sg_cat.warning() - << "Ignoring inappropriate format " << egg_tex->get_format() - << " for 1-component texture " << egg_tex->get_name() << "\n"; - } - - } else if (tex->_pbuffer->get_num_components() == 2) { - switch (egg_tex->get_format()) { - case EggTexture::F_luminance_alpha: - tex->_pbuffer->set_format(PixelBuffer::F_luminance_alpha); - break; - - case EggTexture::F_luminance_alphamask: - tex->_pbuffer->set_format(PixelBuffer::F_luminance_alphamask); - break; - - case EggTexture::F_unspecified: - break; - - default: - egg2sg_cat.warning() - << "Ignoring inappropriate format " << egg_tex->get_format() - << " for 2-component texture " << egg_tex->get_name() << "\n"; - } - - } else if (tex->_pbuffer->get_num_components() == 3) { - switch (egg_tex->get_format()) { - case EggTexture::F_rgb: - tex->_pbuffer->set_format(PixelBuffer::F_rgb); - break; - case EggTexture::F_rgb12: - if (tex->_pbuffer->get_component_width() >= 2) { - // Only do this if the component width supports it. - tex->_pbuffer->set_format(PixelBuffer::F_rgb12); - } else { - egg2sg_cat.warning() - << "Ignoring inappropriate format " << egg_tex->get_format() - << " for 8-bit texture " << egg_tex->get_name() << "\n"; - } - break; - case EggTexture::F_rgb8: - case EggTexture::F_rgba8: - // We'll quietly accept RGBA8 for a 3-component texture, since - // flt2egg generates these for 3-component as well as for - // 4-component textures. - tex->_pbuffer->set_format(PixelBuffer::F_rgb8); - break; - case EggTexture::F_rgb5: - tex->_pbuffer->set_format(PixelBuffer::F_rgb5); - break; - case EggTexture::F_rgb332: - tex->_pbuffer->set_format(PixelBuffer::F_rgb332); - break; - - case EggTexture::F_unspecified: - break; - - default: - egg2sg_cat.warning() - << "Ignoring inappropriate format " << egg_tex->get_format() - << " for 3-component texture " << egg_tex->get_name() << "\n"; - } - - } else if (tex->_pbuffer->get_num_components() == 4) { - switch (egg_tex->get_format()) { - case EggTexture::F_rgba: - tex->_pbuffer->set_format(PixelBuffer::F_rgba); - break; - case EggTexture::F_rgbm: - tex->_pbuffer->set_format(PixelBuffer::F_rgbm); - break; - case EggTexture::F_rgba12: - if (tex->_pbuffer->get_component_width() >= 2) { - // Only do this if the component width supports it. - tex->_pbuffer->set_format(PixelBuffer::F_rgba12); - } else { - egg2sg_cat.warning() - << "Ignoring inappropriate format " << egg_tex->get_format() - << " for 8-bit texture " << egg_tex->get_name() << "\n"; - } - break; - case EggTexture::F_rgba8: - tex->_pbuffer->set_format(PixelBuffer::F_rgba8); - break; - case EggTexture::F_rgba4: - tex->_pbuffer->set_format(PixelBuffer::F_rgba4); - break; - case EggTexture::F_rgba5: - tex->_pbuffer->set_format(PixelBuffer::F_rgba5); - break; - - case EggTexture::F_unspecified: - break; - - default: - egg2sg_cat.warning() - << "Ignoring inappropriate format " << egg_tex->get_format() - << " for 4-component texture " << egg_tex->get_name() << "\n"; - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::apply_texture_apply_attributes -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -void EggLoader:: -apply_texture_apply_attributes(TextureApplyTransition *apply, - const EggTexture *egg_tex) { - if (egg_always_decal_textures) { - apply->set_mode(TextureApplyProperty::M_decal); - - } else { - switch (egg_tex->get_env_type()) { - case EggTexture::ET_modulate: - apply->set_mode(TextureApplyProperty::M_modulate); - break; - - case EggTexture::ET_decal: - apply->set_mode(TextureApplyProperty::M_decal); - break; - - case EggTexture::ET_unspecified: - break; - - default: - egg2sg_cat.warning() - << "Invalid texture environment " - << (int)egg_tex->get_env_type() << "\n"; - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::get_material_transition -// Access: Private -// Description: Returns a transition suitable for enabling the -// material indicated by the given EggMaterial, and with -// the indicated backface flag. -//////////////////////////////////////////////////////////////////// -MaterialTransition *EggLoader:: -get_material_transition(const EggMaterial *egg_mat, bool bface) { - Materials &materials = bface ? _materials_bface : _materials; - - // First, check whether we've seen this material before. - Materials::const_iterator mi; - mi = materials.find(egg_mat); - if (mi != materials.end()) { - return (*mi).second; - } - - // Ok, this is the first time we've seen this particular - // EggMaterial. Create a new Material that matches it. - PT(Material) mat = new Material; - if (egg_mat->has_diff()) { - mat->set_diffuse(egg_mat->get_diff()); - // By default, ambient is the same as diffuse, if diffuse is - // specified but ambient is not. - mat->set_ambient(egg_mat->get_diff()); - } - if (egg_mat->has_amb()) { - mat->set_ambient(egg_mat->get_amb()); - } - if (egg_mat->has_emit()) { - mat->set_emission(egg_mat->get_emit()); - } - if (egg_mat->has_spec()) { - mat->set_specular(egg_mat->get_spec()); - } - if (egg_mat->has_shininess()) { - mat->set_shininess(egg_mat->get_shininess()); - } - if (egg_mat->has_local()) { - mat->set_local(egg_mat->get_local()); - } - - mat->set_twoside(bface); - - // Now get a global Material pointer, shared with other models. - const Material *shared_mat = MaterialPool::get_material(mat); - - // And create a MaterialTransition for this Material. - PT(MaterialTransition) mt = new MaterialTransition(shared_mat); - materials.insert(Materials::value_type(egg_mat, mt)); - - return mt; -} - - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::setup_bucket -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -void EggLoader:: -setup_bucket(BuilderBucket &bucket, NamedNode *parent, - EggPrimitive *egg_prim) { - bucket._node = parent; - bucket._mesh = egg_mesh; - bucket._retesselate_coplanar = egg_retesselate_coplanar; - bucket._unroll_fans = egg_unroll_fans; - bucket._show_tstrips = egg_show_tstrips; - bucket._show_qsheets = egg_show_qsheets; - bucket._show_quads = egg_show_quads; - bucket._show_normals = egg_show_normals; - bucket._normal_scale = egg_normal_scale; - bucket._subdivide_polys = egg_subdivide_polys; - bucket._consider_fans = egg_consider_fans; - bucket._max_tfan_angle = egg_max_tfan_angle; - bucket._min_tfan_tris = egg_min_tfan_tris; - bucket._coplanar_threshold = egg_coplanar_threshold; - - // If a primitive has a name that does not begin with a digit, it - // should be used to group primitives together--i.e. each primitive - // with the same name gets placed into the same GeomNode. However, - // if a prim's name begins with a digit, just ignore it. - if (egg_prim->has_name() && !isdigit(egg_prim->get_name()[0])) { - bucket.set_name(egg_prim->get_name()); - } - - // Assign the appropriate properties to the bucket. - - // The various EggRenderMode properties can be defined directly at - // the primitive, at a group above the primitive, or an a texture - // applied to the primitive. The EggNode::determine_*() functions - // can find the right pointer to the level at which this is actually - // defined for a given primitive. - EggRenderMode::AlphaMode am = EggRenderMode::AM_unspecified; - EggRenderMode::DepthWriteMode dwm = EggRenderMode::DWM_unspecified; - EggRenderMode::DepthTestMode dtm = EggRenderMode::DTM_unspecified; - bool implicit_alpha = false; - bool has_draw_order = false; - int draw_order = 0; - bool has_bin = false; - string bin; - - EggRenderMode *render_mode; - render_mode = egg_prim->determine_alpha_mode(); - if (render_mode != (EggRenderMode *)NULL) { - am = render_mode->get_alpha_mode(); - } - render_mode = egg_prim->determine_depth_write_mode(); - if (render_mode != (EggRenderMode *)NULL) { - dwm = render_mode->get_depth_write_mode(); - } - render_mode = egg_prim->determine_depth_test_mode(); - if (render_mode != (EggRenderMode *)NULL) { - dtm = render_mode->get_depth_test_mode(); - } - render_mode = egg_prim->determine_draw_order(); - if (render_mode != (EggRenderMode *)NULL) { - has_draw_order = true; - draw_order = render_mode->get_draw_order(); - } - render_mode = egg_prim->determine_bin(); - if (render_mode != (EggRenderMode *)NULL) { - has_bin = true; - bin = render_mode->get_bin(); - } - - bucket._trans.set_transition(new TextureTransition(TextureTransition::off())); - if (egg_prim->has_texture()) { - PT(EggTexture) egg_tex = egg_prim->get_texture(); - - const TextureDef &def = _textures[egg_tex]; - if (def._texture != (TextureTransition *)NULL) { - bucket._trans.set_transition(def._texture); - bucket._trans.set_transition(def._apply); - - // If neither the primitive nor the texture specified an alpha - // mode, assume it should be alpha'ed if the texture has an - // alpha channel. - if (am == EggRenderMode::AM_unspecified) { - Texture *tex = def._texture->get_texture(); - nassertv(tex != (Texture *)NULL); - int num_components = tex->_pbuffer->get_num_components(); - if (egg_tex->has_alpha_channel(num_components)) { - implicit_alpha = true; - } - } - } - } - - if (egg_prim->has_material()) { - MaterialTransition *mt = get_material_transition(egg_prim->get_material(), - egg_prim->get_bface_flag()); - bucket._trans.set_transition(mt); - } - - - // Also check the color of the primitive to see if we should assume - // alpha based on the alpha values specified in the egg file. - if (am == EggRenderMode::AM_unspecified) { - if (egg_prim->has_color()) { - if (egg_prim->get_color()[3] != 1.0) { - implicit_alpha = true; - } - } - EggPrimitive::const_iterator vi; - for (vi = egg_prim->begin(); - !implicit_alpha && vi != egg_prim->end(); - ++vi) { - if ((*vi)->has_color()) { - if ((*vi)->get_color()[3] != 1.0) { - implicit_alpha = true; - } - } - } - - if (implicit_alpha) { - am = EggRenderMode::AM_on; - } - } - - switch (am) { - case EggRenderMode::AM_on: - case EggRenderMode::AM_blend: - bucket._trans.set_transition(new TransparencyTransition(TransparencyProperty::M_alpha)); - break; - - case EggRenderMode::AM_blend_no_occlude: - bucket._trans.set_transition(new TransparencyTransition(TransparencyProperty::M_alpha)); - bucket._trans.set_transition(new DepthWriteTransition(DepthWriteTransition::off())); - break; - - case EggRenderMode::AM_ms: - bucket._trans.set_transition(new TransparencyTransition(TransparencyProperty::M_multisample)); - break; - - case EggRenderMode::AM_ms_mask: - bucket._trans.set_transition(new TransparencyTransition(TransparencyProperty::M_multisample_mask)); - break; - - default: - // bucket._trans.set_transition(new TransparencyTransition(TransparencyProperty::M_none)); - break; - } - - switch (dwm) { - case EggRenderMode::DWM_on: - bucket._trans.set_transition(new DepthWriteTransition); - break; - - case EggRenderMode::DWM_off: - bucket._trans.set_transition(new DepthWriteTransition(DepthWriteTransition::off())); - break; - - default: - break; - } - - switch (dtm) { - case EggRenderMode::DTM_on: - bucket._trans.set_transition(new DepthTestTransition(DepthTestProperty::M_less)); - break; - - case EggRenderMode::DTM_off: - bucket._trans.set_transition(new DepthTestTransition(DepthTestProperty::M_none)); - break; - - default: - break; - } - - if (has_bin) { - bucket._trans.set_transition(new GeomBinTransition(bin, draw_order)); - - } else if (has_draw_order) { - bucket._trans.set_transition(new GeomBinTransition("fixed", draw_order)); - } - - if (egg_prim->get_bface_flag()) { - // The primitive is marked with backface culling disabled--we want - // to see both sides. - bucket._trans.set_transition(new CullFaceTransition(CullFaceProperty::M_cull_none)); - - /* - Not sure if we need to enforce this between children. - } else { - bucket._trans.set_transition(new CullFaceTransition(CullFaceProperty::M_cull_clockwise)); - */ - } -} - - - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::make_node -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -RenderRelation *EggLoader:: -make_node(EggNode *egg_node, NamedNode *parent) { - if (egg_node->is_of_type(EggNurbsCurve::get_class_type())) { - return make_node(DCAST(EggNurbsCurve, egg_node), parent); - } else if (egg_node->is_of_type(EggPrimitive::get_class_type())) { - return make_node(DCAST(EggPrimitive, egg_node), parent); - } else if (egg_node->is_of_type(EggBin::get_class_type())) { - return make_node(DCAST(EggBin, egg_node), parent); - } else if (egg_node->is_of_type(EggGroup::get_class_type())) { - return make_node(DCAST(EggGroup, egg_node), parent); - } else if (egg_node->is_of_type(EggTable::get_class_type())) { - return make_node(DCAST(EggTable, egg_node), parent); - } else if (egg_node->is_of_type(EggGroupNode::get_class_type())) { - return make_node(DCAST(EggGroupNode, egg_node), parent); - } - - return (RenderRelation *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::make_node (EggNurbsCurve) -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -RenderRelation *EggLoader:: -make_node(EggNurbsCurve *egg_curve, NamedNode *parent) { - return (RenderRelation *)NULL; - /* - assert(parent != NULL); - assert(!parent->is_of_type(GeomNode::get_class_type())); - - PT(ParametricCurve) curve; - - if (egg_load_classic_nurbs_curves) { - curve = new ClassicNurbsCurve; - } else { - curve = new NurbsCurve; - } - - NurbsCurveInterface *nurbs = curve->get_nurbs_interface(); - nassertr(nurbs != (NurbsCurveInterface *)NULL, (RenderRelation *)NULL); - - if (egg_curve->get_order() < 1 || egg_curve->get_order() > 4) { - egg2sg_cat.error() - << "Invalid NURBSCurve order for " << egg_curve->get_name() << ": " - << egg_curve->get_order() << "\n"; - _error = true; - return (RenderRelation *)NULL; - } - - nurbs->set_order(egg_curve->get_order()); - - EggPrimitive::const_iterator pi; - for (pi = egg_curve->begin(); pi != egg_curve->end(); ++pi) { - nurbs->append_cv(LCAST(float, (*pi)->get_pos4())); - } - - int num_knots = egg_curve->get_num_knots(); - if (num_knots != nurbs->get_num_knots()) { - egg2sg_cat.error() - << "Invalid NURBSCurve number of knots for " - << egg_curve->get_name() << ": got " << num_knots - << " knots, expected " << nurbs->get_num_knots() << "\n"; - _error = true; - return (RenderRelation *)NULL; - } - - for (int i = 0; i < num_knots; i++) { - nurbs->set_knot(i, egg_curve->get_knot(i)); - } - - switch (egg_curve->get_curve_type()) { - case EggCurve::CT_xyz: - curve->set_curve_type(PCT_XYZ); - break; - - case EggCurve::CT_hpr: - curve->set_curve_type(PCT_HPR); - break; - - case EggCurve::CT_t: - curve->set_curve_type(PCT_T); - break; - - default: - break; - } - curve->set_name(egg_curve->get_name()); - - if (!curve->recompute()) { - egg2sg_cat.error() - << "Invalid NURBSCurve " << egg_curve->get_name() << "\n"; - _error = true; - return (RenderRelation *)NULL; - } - - return new RenderRelation(parent, curve); - */ -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::make_node (EggPrimitive) -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -RenderRelation *EggLoader:: -make_node(EggPrimitive *egg_prim, NamedNode *parent) { - assert(parent != NULL); - assert(!parent->is_of_type(GeomNode::get_class_type())); - - if (egg_prim->cleanup()) { - if (parent->is_of_type(SwitchNode::get_class_type())) { - // If we're putting a primitive under a SwitchNode of some kind, - // its exact position within the group is relevant, so we need - // to create a placeholder now. - NamedNode *group = new NamedNode(egg_prim->get_name()); - make_nonindexed_primitive(egg_prim, group); - return new RenderRelation(parent, group); - } - - // Otherwise, we don't really care what the position of this - // primitive is within its parent's list of children, and in fact - // we want to allow it to be combined with other polygons added to - // the same parent. - make_nonindexed_primitive(egg_prim, parent); - } - return (RenderRelation *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::make_node (EggBin) -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -RenderRelation *EggLoader:: -make_node(EggBin *egg_bin, NamedNode *parent) { - // Presently, an EggBin can only mean an LOD node (i.e. a parent of - // one or more EggGroups with LOD specifications). Later it might - // mean other things as well. - - assert((EggBinner::BinNumber)egg_bin->get_bin_number() == EggBinner::BN_lod); - LODNode *lod_node = new LODNode; - lod_node->set_name(egg_bin->get_name()); - - pvector instances; - - EggGroup::const_iterator ci; - for (ci = egg_bin->begin(); ci != egg_bin->end(); ++ci) { - RenderRelation *arc = make_node(*ci, lod_node); - assert(arc != (RenderRelation *)NULL); - LODInstance instance(*ci, arc); - instances.push_back(instance); - } - - // Now that we've created all of our children, put them in the - // proper order and tell the LOD node about them. - sort(instances.begin(), instances.end()); - - if (!instances.empty()) { - // Set up the LOD node's center. All of the children should have - // the same center, because that's how we binned them. - lod_node->_lod._center = LCAST(float, instances[0]._d->_center); - } - - for (size_t i = 0; i < instances.size(); i++) { - // Put the children in the proper order within the scene graph. - const LODInstance &instance = instances[i]; - - // All of the children should have the same center, because that's - // how we binned them. - assert(lod_node->_lod._center.almost_equal - (LCAST(float, instance._d->_center), 0.01)); - - instance._arc->set_sort(i); - - // Tell the LOD node about this child's switching distances. - lod_node->add_switch(instance._d->_switch_in, instance._d->_switch_out); - } - - return create_group_arc(egg_bin, parent, lod_node); -} - - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::make_node (EggGroup) -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -RenderRelation *EggLoader:: -make_node(EggGroup *egg_group, NamedNode *parent) { - NamedNode *node = NULL; - - if (egg_group->has_objecttype()) { - // We'll allow recursive expansion of ObjectType strings--but we - // don't want to get caught in a cycle. Keep track of the strings - // we've expanded so far. - pset expanded; - pvector expanded_history; - - while (egg_group->has_objecttype()) { - string objecttype = egg_group->get_objecttype(); - if (!expanded.insert(objecttype).second) { - egg2sg_cat.error() - << "Cycle in ObjectType expansions:\n"; - copy(expanded_history.begin(), expanded_history.end(), - ostream_iterator(egg2sg_cat.error(false), " -> ")); - egg2sg_cat.error(false) << objecttype << "\n"; - _error = true; - break; - } - expanded_history.push_back(objecttype); - - // Now clear the group's ObjectType flag. We'll only loop back - // here again if we end up setting this during the ObjectType - // expansion; e.g. the expansion string itself contains an - // reference. - egg_group->clear_objecttype(); - - // Now try to find the egg syntax that the given objecttype is - // shorthand for. First, look in the config file. - - string egg_syntax = - config_egg2sg.GetString("egg-object-type-" + objecttype, "none"); - - if (egg_syntax == "none") { - // It wasn't defined in a config file. Maybe it's built in? - - if (cmp_nocase_uh(objecttype, "barrier") == 0) { - egg_syntax = " { Polyset descend }"; - - } else if (cmp_nocase_uh(objecttype, "solidpoly") == 0) { - egg_syntax = " { Polyset descend solid }"; - - } else if (cmp_nocase_uh(objecttype, "turnstile") == 0) { - egg_syntax = " { Polyset descend turnstile }"; - - } else if (cmp_nocase_uh(objecttype, "sphere") == 0) { - egg_syntax = " { Sphere descend }"; - - } else if (cmp_nocase_uh(objecttype, "trigger") == 0) { - egg_syntax = " { Polyset descend intangible }"; - - } else if (cmp_nocase_uh(objecttype, "trigger_sphere") == 0) { - egg_syntax = " { Sphere descend intangible }"; - - } else if (cmp_nocase_uh(objecttype, "eye_trigger") == 0) { - egg_syntax = " { Polyset descend intangible center }"; - - } else if (cmp_nocase_uh(objecttype, "bubble") == 0) { - egg_syntax = " { Sphere keep descend }"; - - } else if (cmp_nocase_uh(objecttype, "ghost") == 0) { - egg_syntax = " collide-mask { 0 }"; - - } else if (cmp_nocase_uh(objecttype, "backstage") == 0) { - // Ignore "backstage" geometry. - return NULL; - - } else { - egg2sg_cat.error() - << "Unknown ObjectType " << objecttype << "\n"; - _error = true; - break; - } - } - - if (!egg_syntax.empty()) { - if (!egg_group->parse_egg(egg_syntax)) { - egg2sg_cat.error() - << "Error while parsing definition for ObjectType " - << objecttype << "\n"; - _error = true; - } - } - } - } - - if (egg_group->get_dart_type() != EggGroup::DT_none) { - // A group with the flag set means to create a character. - CharacterMaker char_maker(egg_group, *this); - node = char_maker.make_node(); - - } else if (egg_group->get_cs_type() != EggGroup::CST_none && - egg_group->get_cs_type() != EggGroup::CST_geode) { - // A collision group: create collision geometry. - node = new CollisionNode; - node->set_name(egg_group->get_name()); - - make_collision_solids(egg_group, egg_group, (CollisionNode *)node); - if ((egg_group->get_collide_flags() & EggGroup::CF_keep) != 0) { - // If we also specified to keep the geometry, continue the - // traversal. - EggGroup::const_iterator ci; - for (ci = egg_group->begin(); ci != egg_group->end(); ++ci) { - make_node(*ci, parent); - } - } - - RenderRelation *arc = create_group_arc(egg_group, parent, node); - - if (!egg_show_collision_solids) { - arc->set_transition(new PruneTransition()); - } - return arc; - - } else if (egg_group->get_switch_flag() && - egg_group->get_switch_fps() != 0.0) { - // Create a sequence node. - node = new SequenceNode(1.0 / egg_group->get_switch_fps()); - node->set_name(egg_group->get_name()); - - EggGroup::const_iterator ci; - for (ci = egg_group->begin(); ci != egg_group->end(); ++ci) { - make_node(*ci, node); - } - - } else if (egg_group->get_model_flag() || egg_group->get_dcs_flag()) { - // A model or DCS flag; create a model node. - node = new ModelNode; - node->set_name(egg_group->get_name()); - - DCAST(ModelNode, node)->set_preserve_transform(egg_group->get_dcs_flag()); - - EggGroup::const_iterator ci; - for (ci = egg_group->begin(); ci != egg_group->end(); ++ci) { - make_node(*ci, node); - } - - } else { - // A normal group; just create a normal node, and traverse. - node = new NamedNode; - node->set_name(egg_group->get_name()); - - EggGroup::const_iterator ci; - for (ci = egg_group->begin(); ci != egg_group->end(); ++ci) { - make_node(*ci, node); - } - } - - if (node == (NamedNode *)NULL) { - return NULL; - } - return create_group_arc(egg_group, parent, node); -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::create_group_arc -// Access: Private -// Description: Creates the arc parenting a new group to the scene -// graph, and applies any relevant transitions to the -// arc according to the EggGroup node that inspired the -// group. -//////////////////////////////////////////////////////////////////// -RenderRelation *EggLoader:: -create_group_arc(EggGroup *egg_group, NamedNode *parent, NamedNode *node) { - RenderRelation *arc = new RenderRelation(parent, node); - - // If the group had a transform, apply it to the arc. - if (egg_group->has_transform()) { - LMatrix4f matf = LCAST(float, egg_group->get_transform()); - arc->set_transition(new TransformTransition(matf)); - } - - // If the group has a billboard flag, apply that. - switch (egg_group->get_billboard_type()) { - case EggGroup::BT_point_camera_relative: - arc->set_transition(new BillboardTransition(BillboardTransition::point_eye())); - break; - - case EggGroup::BT_point_world_relative: - arc->set_transition(new BillboardTransition(BillboardTransition::point_world())); - break; - - case EggGroup::BT_axis: - arc->set_transition(new BillboardTransition(BillboardTransition::axis())); - break; - - case EggGroup::BT_none: - break; - } - - if (egg_group->get_decal_flag()) { - if (egg_ignore_decals) { - egg2sg_cat.error() - << "Ignoring decal flag on " << egg_group->get_name() << "\n"; - _error = true; - } - - // If the group has the "decal" flag set, it means that all of the - // descendant groups will be decaled onto the geometry within - // this group. This means we'll need to reparent things a bit - // afterward. - _decals.insert(arc); - - // We'll also set up the DecalTransition now. - arc->set_transition(new DecalTransition); - - } - - if (egg_group->get_direct_flag()) { - // If the group has the "direct" flag set, it means that - // everything at this node and below should be rendered in direct - // mode, i.e. in depth-first tree order, without state-sorting. - - arc->set_transition(new DirectRenderTransition); - - // We'll also want to set up the transitions on this arc to - // reflect the geometry at the top of the tree below this node, so - // we get good state-sorting behavior. We'll have to do this - // later. - _directs.insert(arc); - } - - // If the group specified some property that should propagate down - // to the leaves, we have to remember this arc and apply the - // property later, after we've created the actual geometry. - DeferredArcProperty def; - if (egg_group->has_collide_mask()) { - def._from_collide_mask = egg_group->get_collide_mask(); - def._into_collide_mask = egg_group->get_collide_mask(); - def._flags |= - DeferredArcProperty::F_has_from_collide_mask | - DeferredArcProperty::F_has_into_collide_mask; - } - if (egg_group->has_from_collide_mask()) { - def._from_collide_mask = egg_group->get_from_collide_mask(); - def._flags |= DeferredArcProperty::F_has_from_collide_mask; - } - if (egg_group->has_into_collide_mask()) { - def._into_collide_mask = egg_group->get_into_collide_mask(); - def._flags |= DeferredArcProperty::F_has_into_collide_mask; - } - - if (def._flags != 0) { - _deferred_arcs[arc] = def; - } - - return arc; -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::make_node (EggTable) -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -RenderRelation *EggLoader:: -make_node(EggTable *egg_table, NamedNode *parent) { - if (egg_table->get_table_type() != EggTable::TT_bundle) { - // We only do anything with bundles. Isolated tables are treated - // as ordinary groups. - return make_node(DCAST(EggGroupNode, egg_table), parent); - } - - // It's an actual bundle, so make an AnimBundle from it and its - // descendants. - AnimBundleMaker bundle_maker(egg_table); - AnimBundleNode *node = bundle_maker.make_node(); - return new RenderRelation(parent, node); -} - - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::make_node (EggGroupNode) -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -RenderRelation *EggLoader:: -make_node(EggGroupNode *egg_group, NamedNode *parent) { - NamedNode *node = new NamedNode; - node->set_name(egg_group->get_name()); - - EggGroupNode::const_iterator ci; - for (ci = egg_group->begin(); ci != egg_group->end(); ++ci) { - make_node(*ci, node); - } - - return new RenderRelation(parent, node); -} - - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::make_collision_solids -// Access: Private -// Description: Creates CollisionSolids corresponding to the -// collision geometry indicated at the given node and -// below. -//////////////////////////////////////////////////////////////////// -void EggLoader:: -make_collision_solids(EggGroup *start_group, EggGroup *egg_group, - CollisionNode *cnode) { - if (egg_group->get_cs_type() != EggGroup::CST_none) { - start_group = egg_group; - } - - switch (start_group->get_cs_type()) { - case EggGroup::CST_none: - case EggGroup::CST_geode: - // No collision flags; do nothing. Don't even traverse further. - return; - - case EggGroup::CST_inverse_sphere: - // These aren't presently supported. - egg2sg_cat.error() - << "Not presently supported: { " - << egg_group->get_cs_type() << " }\n"; - _error = true; - break; - - case EggGroup::CST_plane: - make_collision_plane(egg_group, cnode, start_group->get_collide_flags()); - break; - - case EggGroup::CST_polygon: - make_collision_polygon(egg_group, cnode, start_group->get_collide_flags()); - break; - - case EggGroup::CST_polyset: - make_collision_polyset(egg_group, cnode, start_group->get_collide_flags()); - break; - - case EggGroup::CST_sphere: - make_collision_sphere(egg_group, cnode, start_group->get_collide_flags()); - break; - } - - if ((start_group->get_collide_flags() & EggGroup::CF_descend) != 0) { - // Now pick up everything below. - EggGroup::const_iterator ci; - for (ci = egg_group->begin(); ci != egg_group->end(); ++ci) { - if ((*ci)->is_of_type(EggGroup::get_class_type())) { - make_collision_solids(start_group, DCAST(EggGroup, *ci), cnode); - } - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::make_collision_plane -// Access: Private -// Description: Creates a single CollisionPlane corresponding -// to the first polygon associated with this group. -//////////////////////////////////////////////////////////////////// -void EggLoader:: -make_collision_plane(EggGroup *egg_group, CollisionNode *cnode, - EggGroup::CollideFlags flags) { - EggGroup *geom_group = find_collision_geometry(egg_group); - if (geom_group != (EggGroup *)NULL) { - EggGroup::const_iterator ci; - for (ci = geom_group->begin(); ci != geom_group->end(); ++ci) { - if ((*ci)->is_of_type(EggPolygon::get_class_type())) { - CollisionPlane *csplane = - create_collision_plane(DCAST(EggPolygon, *ci), egg_group); - if (csplane != (CollisionPlane *)NULL) { - apply_collision_flags(csplane, flags); - cnode->add_solid(csplane); - return; - } - } - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::make_collision_polygon -// Access: Private -// Description: Creates a single CollisionPolygon corresponding -// to the first polygon associated with this group. -//////////////////////////////////////////////////////////////////// -void EggLoader:: -make_collision_polygon(EggGroup *egg_group, CollisionNode *cnode, - EggGroup::CollideFlags flags) { - - EggGroup *geom_group = find_collision_geometry(egg_group); - if (geom_group != (EggGroup *)NULL) { - EggGroup::const_iterator ci; - for (ci = geom_group->begin(); ci != geom_group->end(); ++ci) { - if ((*ci)->is_of_type(EggPolygon::get_class_type())) { - create_collision_polygons(cnode, DCAST(EggPolygon, *ci), - egg_group, flags); - } - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::make_collision_polyset -// Access: Private -// Description: Creates a series of CollisionPolygons corresponding -// to the polygons associated with this group. -//////////////////////////////////////////////////////////////////// -void EggLoader:: -make_collision_polyset(EggGroup *egg_group, CollisionNode *cnode, - EggGroup::CollideFlags flags) { - EggGroup *geom_group = find_collision_geometry(egg_group); - if (geom_group != (EggGroup *)NULL) { - EggGroup::const_iterator ci; - for (ci = geom_group->begin(); ci != geom_group->end(); ++ci) { - if ((*ci)->is_of_type(EggPolygon::get_class_type())) { - create_collision_polygons(cnode, DCAST(EggPolygon, *ci), - egg_group, flags); - } - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::make_collision_sphere -// Access: Private -// Description: Creates a single CollisionSphere corresponding -// to the polygons associated with this group. -//////////////////////////////////////////////////////////////////// -void EggLoader:: -make_collision_sphere(EggGroup *egg_group, CollisionNode *cnode, - EggGroup::CollideFlags flags) { - EggGroup *geom_group = find_collision_geometry(egg_group); - if (geom_group != (EggGroup *)NULL) { - // Collect all of the vertices. - pset vertices; - - EggGroup::const_iterator ci; - for (ci = geom_group->begin(); ci != geom_group->end(); ++ci) { - if ((*ci)->is_of_type(EggPrimitive::get_class_type())) { - EggPrimitive *prim = DCAST(EggPrimitive, *ci); - EggPrimitive::const_iterator pi; - for (pi = prim->begin(); pi != prim->end(); ++pi) { - vertices.insert(*pi); - } - } - } - - // Now average together all of the vertices to get a center. - int num_vertices = 0; - LPoint3d center(0.0, 0.0, 0.0); - pset::const_iterator vi; - - for (vi = vertices.begin(); vi != vertices.end(); ++vi) { - EggVertex *vtx = (*vi); - if (vtx->get_num_dimensions() == 3) { - center += vtx->get_pos3(); - num_vertices++; - - } else if (vtx->get_num_dimensions() == 4) { - LPoint4d p4 = vtx->get_pos4(); - if (p4[3] != 0.0) { - center += LPoint3d(p4[0], p4[1], p4[2]) / p4[3]; - num_vertices++; - } - } - } - - if (num_vertices > 0) { - center /= (double)num_vertices; - - // And the furthest vertex determines the radius. - double radius2 = 0.0; - for (vi = vertices.begin(); vi != vertices.end(); ++vi) { - EggVertex *vtx = (*vi); - if (vtx->get_num_dimensions() == 3) { - LVector3d v = vtx->get_pos3() - center; - radius2 = max(radius2, v.length_squared()); - - } else if (vtx->get_num_dimensions() == 4) { - LPoint4d p = vtx->get_pos4(); - if (p[3] != 0.0) { - LVector3d v = LPoint3d(p[0], p[1], p[2]) / p[3] - center; - radius2 = max(radius2, v.length_squared()); - } - } - } - - float radius = sqrtf(radius2); - CollisionSphere *cssphere = - new CollisionSphere(LCAST(float, center), radius); - apply_collision_flags(cssphere, flags); - cnode->add_solid(cssphere); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::apply_collision_flags -// Access: Private -// Description: Does funny stuff to the CollisionSolid as -// appropriate, based on the settings of the given -// CollideFlags. -//////////////////////////////////////////////////////////////////// -void EggLoader:: -apply_collision_flags(CollisionSolid *solid, - EggGroup::CollideFlags flags) { - if ((flags & EggGroup::CF_intangible) != 0) { - solid->set_tangible(false); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::find_collision_geometry -// Access: Private -// Description: Looks for the node, at or below the indicated node, -// that contains the associated collision geometry. -//////////////////////////////////////////////////////////////////// -EggGroup *EggLoader:: -find_collision_geometry(EggGroup *egg_group) { - if ((egg_group->get_collide_flags() & EggGroup::CF_descend) != 0) { - // If we have the "descend" instruction, we'll get to it when we - // get to it. Don't worry about it now. - return egg_group; - } - - // Does this group have any polygons? - EggGroup::const_iterator ci; - for (ci = egg_group->begin(); ci != egg_group->end(); ++ci) { - if ((*ci)->is_of_type(EggPolygon::get_class_type())) { - // Yes! Use this group. - return egg_group; - } - } - - // Well, the group had no polygons; look for a child group that has - // the same collision type. - for (ci = egg_group->begin(); ci != egg_group->end(); ++ci) { - if ((*ci)->is_of_type(EggGroup::get_class_type())) { - EggGroup *child_group = DCAST(EggGroup, *ci); - if (child_group->get_cs_type() == egg_group->get_cs_type()) { - return child_group; - } - } - } - - // We got nothing. - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::create_collision_plane -// Access: Private -// Description: Creates a single CollisionPlane from the indicated -// EggPolygon. -//////////////////////////////////////////////////////////////////// -CollisionPlane *EggLoader:: -create_collision_plane(EggPolygon *egg_poly, EggGroup *parent_group) { - if (!egg_poly->cleanup()) { - egg2sg_cat.error() - << "Degenerate collision plane in " << parent_group->get_name() - << "\n"; - _error = true; - return NULL; - } - - pvector vertices; - if (!egg_poly->empty()) { - EggPolygon::const_iterator vi; - vi = egg_poly->begin(); - - Vertexd vert = (*vi)->get_pos3(); - vertices.push_back(LCAST(float, vert)); - - Vertexd last_vert = vert; - ++vi; - while (vi != egg_poly->end()) { - vert = (*vi)->get_pos3(); - if (!vert.almost_equal(last_vert)) { - vertices.push_back(LCAST(float, vert)); - } - - last_vert = vert; - ++vi; - } - } - - if (vertices.size() < 3) { - return NULL; - } - Planef plane(vertices[0], vertices[1], vertices[2]); - return new CollisionPlane(plane); -} - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::create_collision_polygons -// Access: Private -// Description: Creates one or more CollisionPolygons from the -// indicated EggPolygon, and adds them to the indicated -// CollisionNode. -//////////////////////////////////////////////////////////////////// -void EggLoader:: -create_collision_polygons(CollisionNode *cnode, EggPolygon *egg_poly, - EggGroup *parent_group, - EggGroup::CollideFlags flags) { - - PT(EggGroup) group = new EggGroup; - - if (!egg_poly->triangulate_into(group, false)) { - egg2sg_cat.error() - << "Degenerate collision polygon in " << parent_group->get_name() - << "\n"; - _error = true; - return; - } - - if (group->size() != 1) { - egg2sg_cat.error() - << "Concave collision polygon in " << parent_group->get_name() - << "\n"; - _error = true; - } - - EggGroup::iterator ci; - for (ci = group->begin(); ci != group->end(); ++ci) { - EggPolygon *poly = DCAST(EggPolygon, *ci); - - pvector vertices; - if (!poly->empty()) { - EggPolygon::const_iterator vi; - vi = poly->begin(); - - Vertexd vert = (*vi)->get_pos3(); - vertices.push_back(LCAST(float, vert)); - - Vertexd last_vert = vert; - ++vi; - while (vi != poly->end()) { - vert = (*vi)->get_pos3(); - if (!vert.almost_equal(last_vert)) { - vertices.push_back(LCAST(float, vert)); - } - - last_vert = vert; - ++vi; - } - } - - if (vertices.size() >= 3) { - const Vertexf *vertices_begin = &vertices[0]; - const Vertexf *vertices_end = vertices_begin + vertices.size(); - CollisionPolygon *cspoly = - new CollisionPolygon(vertices_begin, vertices_end); - apply_collision_flags(cspoly, flags); - cnode->add_solid(cspoly); - } - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: EggLoader::apply_deferred_arcs -// Access: Private -// Description: Walks back over the tree and applies the -// DeferredArcProperties that were saved up along the -// way. -//////////////////////////////////////////////////////////////////// -void EggLoader:: -apply_deferred_arcs(Node *root) { - DeferredArcTraverser trav(_deferred_arcs); - - df_traverse(root, trav, NullTransitionWrapper(), DeferredArcProperty(), - RenderRelation::get_class_type()); -} diff --git a/panda/src/egg2sg/eggLoader.h b/panda/src/egg2sg/eggLoader.h deleted file mode 100644 index cbe3eab9b6..0000000000 --- a/panda/src/egg2sg/eggLoader.h +++ /dev/null @@ -1,160 +0,0 @@ -// Filename: eggLoader.h -// Created by: drose (21Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef EGGLOADER_H -#define EGGLOADER_H - -#include - -#include "deferredArcTraverser.h" -#include "eggLoaderBase.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class EggNode; -class EggBin; -class EggTable; -class EggNurbsCurve; -class EggPrimitive; -class EggPolygon; -class EggMaterial; -class ComputedVerticesMaker; -class RenderRelation; -class CollisionSolid; -class CollisionNode; -class CollisionPlane; -class CollisionPolygon; - -/////////////////////////////////////////////////////////////////// -// Class : EggLoader -// Description : Converts an egg data structure, possibly read from an -// egg file but not necessarily, into a scene graph -// suitable for rendering. -// -// This class isn't exported from this package. -//////////////////////////////////////////////////////////////////// -class EggLoader : public EggLoaderBase { -public: - EggLoader(); - EggLoader(const EggData &data); - - void build_graph(); - void reparent_decals(); - void reset_directs(); - - void make_nonindexed_primitive(EggPrimitive *egg_prim, NamedNode *parent, - const LMatrix4d *transform = NULL); - - void make_indexed_primitive(EggPrimitive *egg_prim, NamedNode *parent, - const LMatrix4d *transform, - ComputedVerticesMaker &_comp_verts_maker); - -private: - class TextureDef { - public: - PT(TextureTransition) _texture; - PT(TextureApplyTransition) _apply; - }; - - void load_textures(); - bool load_texture(TextureDef &def, const EggTexture *egg_tex); - void apply_texture_attributes(Texture *tex, const EggTexture *egg_tex); - void apply_texture_apply_attributes(TextureApplyTransition *apply, - const EggTexture *egg_tex); - - MaterialTransition *get_material_transition(const EggMaterial *egg_mat, - bool bface); - - void setup_bucket(BuilderBucket &bucket, NamedNode *parent, - EggPrimitive *egg_prim); - - RenderRelation *make_node(EggNode *egg_node, NamedNode *parent); - RenderRelation *make_node(EggNurbsCurve *egg_curve, NamedNode *parent); - RenderRelation *make_node(EggPrimitive *egg_prim, NamedNode *parent); - RenderRelation *make_node(EggBin *egg_bin, NamedNode *parent); - RenderRelation *make_node(EggGroup *egg_group, NamedNode *parent); - RenderRelation *create_group_arc(EggGroup *egg_group, NamedNode *parent, - NamedNode *node); - RenderRelation *make_node(EggTable *egg_table, NamedNode *parent); - RenderRelation *make_node(EggGroupNode *egg_group, NamedNode *parent); - - void make_collision_solids(EggGroup *start_group, EggGroup *egg_group, - CollisionNode *cnode); - void make_collision_plane(EggGroup *egg_group, CollisionNode *cnode, - EggGroup::CollideFlags flags); - void make_collision_polygon(EggGroup *egg_group, CollisionNode *cnode, - EggGroup::CollideFlags flags); - void make_collision_polyset(EggGroup *egg_group, CollisionNode *cnode, - EggGroup::CollideFlags flags); - void make_collision_sphere(EggGroup *egg_group, CollisionNode *cnode, - EggGroup::CollideFlags flags); - void apply_collision_flags(CollisionSolid *solid, - EggGroup::CollideFlags flags); - EggGroup *find_collision_geometry(EggGroup *egg_group); - CollisionPlane *create_collision_plane(EggPolygon *egg_poly, - EggGroup *parent_group); - void create_collision_polygons(CollisionNode *cnode, EggPolygon *egg_poly, - EggGroup *parent_group, - EggGroup::CollideFlags flags); - - void apply_deferred_arcs(Node *root); - - - Builder _builder; - - typedef pset > TextureApplies; - TextureApplies _texture_applies; - - typedef pmap Textures; - Textures _textures; - - typedef pmap Materials; - Materials _materials; - Materials _materials_bface; - - typedef pset Decals; - Decals _decals; - - typedef pset Directs; - Directs _directs; - - DeferredArcs _deferred_arcs; - -public: - PT_NamedNode _root; - EggData _data; - bool _error; -}; - - -#endif diff --git a/panda/src/egg2sg/load_egg_file.cxx b/panda/src/egg2sg/load_egg_file.cxx deleted file mode 100644 index 55c76b636d..0000000000 --- a/panda/src/egg2sg/load_egg_file.cxx +++ /dev/null @@ -1,108 +0,0 @@ -// Filename: load_egg_file.cxx -// Created by: drose (09Feb00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "load_egg_file.h" -#include "eggLoader.h" -#include "config_egg2sg.h" - -#include -#include - -static PT_NamedNode -load_from_loader(EggLoader &loader) { - loader._data.resolve_externals(); - - loader.build_graph(); - - if (loader._error && !egg_accept_errors) { - egg2sg_cat.error() - << "Errors in egg file.\n"; - return NULL; - } - - if (loader._root != (NamedNode *)NULL && egg_flatten) { - SceneGraphReducer gr(RenderRelation::get_class_type()); - int num_reduced = gr.flatten(loader._root, egg_flatten_siblings); - egg2sg_cat.info() << "Flattened " << num_reduced << " arcs.\n"; - } - - return loader._root; -} - -//////////////////////////////////////////////////////////////////// -// Function: load_egg_file -// Description: A convenience function. Loads up the indicated egg -// file, and returns the root of a scene graph. Returns -// NULL if the file cannot be read for some reason. -// Does not search along the egg path for the filename -// first; use EggData::resolve_egg_filename() if this is -// required. -//////////////////////////////////////////////////////////////////// -PT_NamedNode -load_egg_file(const string &filename, CoordinateSystem cs) { - Filename egg_filename = Filename::text_filename(filename); - if (!egg_filename.exists()) { - egg2sg_cat.error() - << "Could not find " << egg_filename << "\n"; - return NULL; - } - - egg2sg_cat.info() - << "Reading " << egg_filename << "\n"; - - ifstream file; - if (!egg_filename.open_read(file)) { - egg2sg_cat.error() - << "Could not open " << egg_filename << " for reading.\n"; - return NULL; - } - - EggLoader loader; - loader._data.set_egg_filename(egg_filename); - if (cs != CS_default) { - loader._data.set_coordinate_system(cs); - } - - if (!loader._data.read(file)) { - egg2sg_cat.error() - << "Error reading " << egg_filename << "\n"; - return NULL; - } - - return load_from_loader(loader); -} - -//////////////////////////////////////////////////////////////////// -// Function: load_egg_data -// Description: Another convenience function; works like -// load_egg_file() but starts from an already-filled -// EggData structure. The structure is destroyed in the -// loading. -//////////////////////////////////////////////////////////////////// -PT_NamedNode -load_egg_data(EggData &data) { - // We temporarily shuttle the children to a holding node so we can - // copy them into the EggLoader's structure without it complaining. - EggGroupNode children_holder; - children_holder.steal_children(data); - - EggLoader loader(data); - loader._data.steal_children(children_holder); - - return load_from_loader(loader); -} diff --git a/panda/src/egg2sg/load_egg_file.h b/panda/src/egg2sg/load_egg_file.h deleted file mode 100644 index 201fb957b8..0000000000 --- a/panda/src/egg2sg/load_egg_file.h +++ /dev/null @@ -1,53 +0,0 @@ -// Filename: load_egg_file.h -// Created by: drose (09Feb00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef LOAD_EGG_FILE_H -#define LOAD_EGG_FILE_H - -#include - -#include -#include -#include - -class EggData; - -//////////////////////////////////////////////////////////////////// -// Function: load_egg_file -// Description: A convenience function; the primary interface to this -// package. Loads up the indicated egg file, and -// returns the root of a scene graph. Returns NULL if -// the file cannot be read for some reason. -// -// Also see the EggLoader class, which can exercise a -// bit more manual control over the loading process. -//////////////////////////////////////////////////////////////////// -EXPCL_PANDAEGG PT_NamedNode -load_egg_file(const string &filename, CoordinateSystem cs = CS_default); - -//////////////////////////////////////////////////////////////////// -// Function: load_egg_data -// Description: Another convenience function; works like -// load_egg_file() but starts from an already-filled -// EggData structure. The structure is destroyed in the -// loading. -//////////////////////////////////////////////////////////////////// -EXPCL_PANDAEGG PT_NamedNode -load_egg_data(EggData &data); - -#endif diff --git a/panda/src/egg2sg/test_loader.cxx b/panda/src/egg2sg/test_loader.cxx deleted file mode 100644 index 20250029f6..0000000000 --- a/panda/src/egg2sg/test_loader.cxx +++ /dev/null @@ -1,112 +0,0 @@ -// Filename: test_loader.cxx -// Created by: drose (21Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "load_egg_file.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -class PrintNodes : - public TraverserVisitor { -public: - PrintNodes() { - _indent_level = 0; - } - bool reached_node(Node *node, AttributeWrapper &state, NullLevelState &) { - if (node->is_of_type(GeomNode::get_class_type())) { - GeomNode *geomNode = (GeomNode *)node; - indent(nout, _indent_level) - << *geomNode << ", " << geomNode->get_num_geoms() - << " geoms:\n"; - int num_geoms = geomNode->get_num_geoms(); - for (int i = 0; i < num_geoms; i++) { - dDrawable *draw = geomNode->get_geom(i); - if (draw->is_of_type(Geom::get_class_type())) { - Geom *geom = DCAST(Geom, draw); - // geom->output_verbose(nout); - indent(nout, _indent_level + 2) << *geom << "\n"; - } else { - indent(nout, _indent_level + 2) << draw->get_type() << "\n"; - } - } - } - return true; - } - bool forward_arc(NodeRelation *arc, TransitionWrapper &trans, - AttributeWrapper &pre, AttributeWrapper &post, - NullLevelState &) { - indent(nout, _indent_level) << *arc << " has:\n"; - trans.write(nout, _indent_level + 4); - _indent_level += 2; - return true; - } - void backward_arc(NodeRelation *arc, TransitionWrapper &trans, - AttributeWrapper &pre, AttributeWrapper &post, - const NullLevelState &) { - _indent_level -= 2; - } - int _indent_level; -}; - -int -main(int argc, char *argv[]) { - if (argc < 2) { - nout << "Specify an egg file to load.\n"; - exit(1); - } - - PT_NamedNode root = new NamedNode("root"); - - for (int i = 1; i < argc; i++) { - const char *egg_filename = argv[i]; - - PT_NamedNode egg_root = load_egg_file(egg_filename); - if (egg_root == NULL) { - nout << "Unable to load " << egg_filename << ".\n"; - exit(1); - } - - new RenderRelation(root, egg_root); - } - - PrintNodes pn; - df_traverse(root, pn, AllAttributesWrapper(), NullLevelState(), - RenderRelation::get_class_type()); - - return(0); -} diff --git a/panda/src/framework/Sources.pp b/panda/src/framework/Sources.pp index 4a4f502c6b..d6bba492f3 100644 --- a/panda/src/framework/Sources.pp +++ b/panda/src/framework/Sources.pp @@ -5,7 +5,7 @@ #define TARGET framework #define BUILDING_DLL BUILDING_FRAMEWORK #define LOCAL_LIBS \ - pgraph putil collide loader sgmanip chan text chancfg cull \ + pgraph putil collide loader chan text chancfg \ pnmimage pnmimagetypes event #define SOURCES \ diff --git a/panda/src/glgsg/Sources.pp b/panda/src/glgsg/Sources.pp index 3f6c14b0e5..c5c133690c 100644 --- a/panda/src/glgsg/Sources.pp +++ b/panda/src/glgsg/Sources.pp @@ -7,8 +7,8 @@ #begin lib_target #define TARGET glgsg #define LOCAL_LIBS \ - cull gsgmisc gsgbase gobj sgattrib sgraphutil graph display \ - putil linmath sgraph mathutil pnmimage + gsgmisc gsgbase gobj display \ + putil linmath mathutil pnmimage #define COMBINED_SOURCES $[TARGET]_composite1.cxx diff --git a/panda/src/glgsg/glGeomNodeContext.I b/panda/src/glgsg/glGeomNodeContext.I index 69d8471892..56d9c5cd34 100644 --- a/panda/src/glgsg/glGeomNodeContext.I +++ b/panda/src/glgsg/glGeomNodeContext.I @@ -23,7 +23,7 @@ // Description: //////////////////////////////////////////////////////////////////// INLINE GLGeomNodeContext:: -GLGeomNodeContext(GeomNode *node) : +GLGeomNodeContext(qpGeomNode *node) : GeomNodeContext(node) { _index = 0; diff --git a/panda/src/glgsg/glGeomNodeContext.h b/panda/src/glgsg/glGeomNodeContext.h index 8bbb63936b..802271c1b2 100644 --- a/panda/src/glgsg/glGeomNodeContext.h +++ b/panda/src/glgsg/glGeomNodeContext.h @@ -19,7 +19,10 @@ #ifndef GLGEOMNODECONTEXT_H #define GLGEOMNODECONTEXT_H -#include +#include "pandabase.h" +#include "geomNodeContext.h" +#include "qpgeomNode.h" +#include "pvector.h" #ifdef WIN32_VC // Must include windows.h before gl.h on NT @@ -29,9 +32,6 @@ #endif #include -#include -#include -#include "pvector.h" //////////////////////////////////////////////////////////////////// // Class : GLGeomNodeContext @@ -39,7 +39,7 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDAGL GLGeomNodeContext : public GeomNodeContext { public: - INLINE GLGeomNodeContext(GeomNode *node); + INLINE GLGeomNodeContext(qpGeomNode *node); // The GL display list index that draws the contents of this // GeomNode. @@ -47,7 +47,7 @@ public: // A list of the dynamic Geoms within the GeomNode; these aren't // part of the above display list. - typedef pvector Geoms; + typedef pvector< PT(Geom) > Geoms; Geoms _dynamic_geoms; // The number of vertices represented by the display list. This is diff --git a/panda/src/glgsg/glGraphicsStateGuardian.cxx b/panda/src/glgsg/glGraphicsStateGuardian.cxx index 78234a1fbd..5da055108d 100644 --- a/panda/src/glgsg/glGraphicsStateGuardian.cxx +++ b/panda/src/glgsg/glGraphicsStateGuardian.cxx @@ -23,46 +23,18 @@ #include "config_glgsg.h" #include "config_util.h" -#include "directRenderTraverser.h" -#include "cullTraverser.h" #include "displayRegion.h" -#include "lensNode.h" -#include "camera.h" #include "renderBuffer.h" #include "geom.h" #include "geomIssuer.h" #include "graphicsWindow.h" #include "graphicsChannel.h" #include "lens.h" -#include "get_rel_pos.h" #include "perspectiveLens.h" #include "directionalLight.h" #include "pointLight.h" #include "spotlight.h" #include "GL/glu.h" -#include "lensNode.h" -#include "transformTransition.h" -#include "colorMatrixTransition.h" -#include "alphaTransformTransition.h" -#include "colorTransition.h" -#include "textureTransition.h" -#include "renderModeTransition.h" -#include "materialTransition.h" -#include "colorBlendTransition.h" -#include "colorMaskTransition.h" -#include "texMatrixTransition.h" -#include "texGenTransition.h" -#include "textureApplyTransition.h" -#include "clipPlaneTransition.h" -#include "transparencyTransition.h" -#include "fogTransition.h" -#include "linesmoothTransition.h" -#include "depthTestTransition.h" -#include "depthWriteTransition.h" -#include "cullFaceTransition.h" -#include "stencilTransition.h" -#include "pointShapeTransition.h" -#include "polygonOffsetTransition.h" #include "textureAttrib.h" #include "lightAttrib.h" #include "cullFaceAttrib.h" @@ -158,15 +130,6 @@ GLGraphicsStateGuardian(GraphicsWindow *win) : GraphicsStateGuardian(win) { _clip_plane_enabled = (bool *)NULL; _cur_clip_plane_enabled = (bool *)NULL; - // Create a default RenderTraverser. - if (gl_cull_traversal) { - _render_traverser = - new CullTraverser(this, RenderRelation::get_class_type()); - } else { - _render_traverser = - new DirectRenderTraverser(this, RenderRelation::get_class_type()); - } - reset(); } @@ -310,10 +273,10 @@ reset() { // Make sure the GL state matches all of our initial attribute // states. - PT(DepthTestTransition) dta = new DepthTestTransition; - PT(DepthWriteTransition) dwa = new DepthWriteTransition; - PT(CullFaceTransition) cfa = new CullFaceTransition; - PT(TextureTransition) ta = new TextureTransition; + CPT(RenderAttrib) dta = DepthTestAttrib::make(DepthTestAttrib::M_less); + CPT(RenderAttrib) dwa = DepthWriteAttrib::make(DepthWriteAttrib::M_on); + CPT(RenderAttrib) cfa = CullFaceAttrib::make(CullFaceAttrib::M_cull_clockwise); + CPT(RenderAttrib) ta = TextureAttrib::make_off(); dta->issue(this); dwa->issue(this); @@ -359,14 +322,14 @@ clear(const RenderBuffer &buffer) { nassertv(buffer._gsg == this); int buffer_type = buffer._buffer_type; GLbitfield mask = 0; - NodeTransitions state; + CPT(RenderState) state = RenderState::make_empty(); if (buffer_type & RenderBuffer::T_color) { call_glClearColor(_color_clear_value[0], _color_clear_value[1], _color_clear_value[2], _color_clear_value[3]); - state.set_transition(new ColorMaskTransition); + state = state->add_attrib(ColorWriteAttrib::make(ColorWriteAttrib::M_on)); mask |= GL_COLOR_BUFFER_BIT; set_draw_buffer(buffer); @@ -379,7 +342,7 @@ clear(const RenderBuffer &buffer) { // In order to clear the depth buffer, the depth mask must enable // writing to the depth buffer. if (!_depth_mask) { - state.set_transition(new DepthWriteTransition); + state = state->add_attrib(DepthWriteAttrib::make(DepthWriteAttrib::M_on)); } } @@ -506,191 +469,6 @@ prepare_lens() { return true; } - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::render_frame -// Access: Public, Virtual -// Description: Renders an entire frame, including all display -// regions within the frame, and includes any necessary -// pre- and post-processing like swapping buffers. -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -render_frame() { -#ifdef GSG_VERBOSE - glgsg_cat.debug() - << "begin frame " << ClockObject::get_global_clock()->get_frame_count() - << " --------------------------------------------" << endl; -#endif - - activate(); - _win->begin_frame(); - report_errors(); - _decal_level = 0; - -#ifdef DO_PSTATS - _vertices_display_list_pcollector.clear_level(); -#endif - - // First, clear the entire window. - clear_framebuffer(); - - // Now render each of our layers in order. - int max_channel_index = _win->get_max_channel_index(); - for (int c = 0; c < max_channel_index; c++) { - if (_win->is_channel_defined(c)) { - GraphicsChannel *chan = _win->get_channel(c); - if (chan->is_active()) { - int num_layers = chan->get_num_layers(); - for (int l = 0; l < num_layers; l++) { - GraphicsLayer *layer = chan->get_layer(l); - if (layer->is_active()) { - int num_drs = layer->get_num_drs(); - for (int d = 0; d < num_drs; d++) { - DisplayRegion *dr = layer->get_dr(d); - nassertv(dr != (DisplayRegion *)NULL); - Camera *cam = dr->get_camera(); - - // For each display region, render from the camera's view. - if (dr->is_active() && cam != (Camera *)NULL && - cam->is_active() && cam->get_scene() != (Node *)NULL) { - DisplayRegionStack old_dr = push_display_region(dr); - prepare_display_region(); - render_scene(cam->get_scene(), cam); - pop_display_region(old_dr); - } - } - } - } - } - } - } - - // Now we're done with the frame processing. Clean up. - -#ifndef NDEBUG - report_errors(); -#endif - - _win->end_frame(); - -#ifdef GSG_VERBOSE - glgsg_cat.debug() - << "end frame ----------------------------------------------" << endl; -#endif -} - - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::render_scene -// Access: Public, Virtual -// Description: Renders an entire scene, from the root node of the -// scene graph, as seen from a particular LensNode -// and with a given initial state. This initial state -// may be modified during rendering. -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -render_scene(Node *root, LensNode *projnode) { -#ifdef GSG_VERBOSE - _pass_number = 0; - glgsg_cat.debug() - << "begin scene - - - - - - - - - - - - - - - - - - - - - - - - -" - << endl; -#endif - _current_root_node = root; - - render_subgraph(_render_traverser, root, projnode, - AllTransitionsWrapper()); - -#ifdef GSG_VERBOSE - glgsg_cat.debug() - << "done scene - - - - - - - - - - - - - - - - - - - - - - - - -" - << endl; -#endif -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::render_subgraph -// Access: Public, Virtual -// Description: Renders a subgraph of the scene graph as seen from a -// given lens node, and with a particular initial -// state. This state may be modified by the render -// process. -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -render_subgraph(RenderTraverser *traverser, - Node *subgraph, LensNode *projnode, - const AllTransitionsWrapper &net_trans) { - // Calling activate() frequently seems to be intolerably expensive - // on some platforms. We'll limit ourselves for now to calling it - // only in render_frame(). - - // activate(); - - Lens *lens = projnode->get_lens(); - LensNode *old_camera = _current_camera; - _current_camera = projnode; - - LensStack lens_stack = push_lens(lens); - if (!prepare_lens()) { - glgsg_cat.error() - << "Cannot render with a nonlinear lens!\n"; - return; - } - - // We infer the modelview matrix by doing a wrt on the lens - // node. - LMatrix4f modelview_mat; - get_rel_mat(subgraph, _current_camera, modelview_mat); - - if (_coordinate_system != CS_yup_right) { - // Now we build the coordinate system conversion into the - // modelview matrix (as described in the paragraph above). - modelview_mat = modelview_mat * - LMatrix4f::convert_mat(_coordinate_system, CS_yup_right); - } - - // The modelview matrix will be loaded as each geometry is - // encountered. So we set the supplied modelview matrix as an - // initial value instead of loading it now. - AllTransitionsWrapper sub_trans = net_trans; - sub_trans.set_transition(new TransformTransition(modelview_mat)); - - render_subgraph(traverser, subgraph, sub_trans); - - _current_camera = old_camera; - - pop_lens(lens_stack); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::render_subgraph -// Access: Public, Virtual -// Description: Renders a subgraph of the scene graph as seen from the -// current lens node, and with a particular -// initial state. This state may be modified during the -// render process. -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -render_subgraph(RenderTraverser *traverser, Node *subgraph, - const AllTransitionsWrapper &net_trans) { -#ifdef GSG_VERBOSE - glgsg_cat.debug() - << "begin subgraph (pass " << ++_pass_number - << ") - - - - - - - - - - - - - - - - - - - - - - - - -" << endl; -#endif - // activate(); - - nassertv(traverser != (RenderTraverser *)NULL); - traverser->traverse(subgraph, net_trans); - -#ifdef GSG_VERBOSE - glgsg_cat.debug() - << "end subgraph (pass " << _pass_number - << ") - - - - - - - - - - - - - - - - - - - - - - - - -" - << endl; -#endif -} - //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::draw_point // Access: Public, Virtual @@ -1804,7 +1582,9 @@ release_texture(TextureContext *tc) { // contents of the node. //////////////////////////////////////////////////////////////////// GeomNodeContext *GLGraphicsStateGuardian:: -prepare_geom_node(GeomNode *node) { +prepare_geom_node(qpGeomNode *node) { +#if 0 // temporarily disabled until we bring to new scene graph + // Make sure we have at least some static Geoms in the GeomNode; // otherwise there's no point in building a display list. int num_geoms = node->get_num_geoms(); @@ -1888,6 +1668,8 @@ prepare_geom_node(GeomNode *node) { nassertr(inserted, NULL); return ggnc; +#endif // temporarily disabled until we bring to new scene graph + return NULL; } //////////////////////////////////////////////////////////////////// @@ -1897,7 +1679,9 @@ prepare_geom_node(GeomNode *node) { // prepare_geom_node(). //////////////////////////////////////////////////////////////////// void GLGraphicsStateGuardian:: -draw_geom_node(GeomNode *node, GeomNodeContext *gnc) { +draw_geom_node(qpGeomNode *node, const RenderState *state, + GeomNodeContext *gnc) { +#if 0 // temporarily disabled until we bring to new scene graph if (gnc == (GeomNodeContext *)NULL) { // We don't have a saved context; just draw the GeomNode in // immediate mode. @@ -1923,6 +1707,7 @@ draw_geom_node(GeomNode *node, GeomNodeContext *gnc) { ggnc->_dynamic_geoms[i]->draw(this); } } +#endif // temporarily disabled until we bring to new scene graph } //////////////////////////////////////////////////////////////////// @@ -1934,6 +1719,7 @@ draw_geom_node(GeomNode *node, GeomNodeContext *gnc) { //////////////////////////////////////////////////////////////////// void GLGraphicsStateGuardian:: release_geom_node(GeomNodeContext *gnc) { +#if 0 // temporarily disabled until we bring to new scene graph if (gnc != (GeomNodeContext *)NULL) { GLGeomNodeContext *ggnc = DCAST(GLGeomNodeContext, gnc); glDeleteLists(ggnc->_index, 1); @@ -1947,6 +1733,7 @@ release_geom_node(GeomNodeContext *gnc) { ggnc->_node->clear_gsg(this); delete ggnc; } +#endif // temporarily disabled until we bring to new scene graph } static int logs[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, @@ -2001,7 +1788,9 @@ copy_texture(TextureContext *tc, const DisplayRegion *dr) { get_internal_image_format(pb->get_format()), pb->get_xorg(), pb->get_yorg(), pb->get_xsize(), pb->get_ysize(), pb->get_border()); - clear_attribute(TextureTransition::get_class_type()); + + // Clear the internal texture state, since we've just monkeyed with it. + modify_state(get_untextured_state()); } //////////////////////////////////////////////////////////////////// @@ -2016,90 +1805,6 @@ copy_texture(TextureContext *tc, const DisplayRegion *dr, const RenderBuffer &rb copy_texture(tc, dr); } -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::draw_texture -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -draw_texture(TextureContext *tc, const DisplayRegion *dr) { - nassertv(tc != NULL && dr != NULL); - // activate(); - - Texture *tex = tc->_texture; - - DisplayRegionStack old_dr = push_display_region(dr); - prepare_display_region(); - - NodeTransitions state; - CullFaceTransition *cfa = new CullFaceTransition; - cfa->set_mode(CullFaceProperty::M_cull_none); - DepthTestTransition *dta = new DepthTestTransition; - dta->set_mode(DepthTestProperty::M_none); - DepthWriteTransition *dwa = new DepthWriteTransition; - dwa->set_off(); - TextureTransition *ta = new TextureTransition; - ta->set_on(tex); - TextureApplyTransition *taa = new TextureApplyTransition; - taa->set_mode(TextureApplyProperty::M_decal); - - state.set_transition(new ColorMaskTransition); - state.set_transition(new RenderModeTransition); - state.set_transition(new TexMatrixTransition); - state.set_transition(new TransformTransition); - state.set_transition(new ColorBlendTransition); - state.set_transition(cfa); - state.set_transition(dta); - state.set_transition(dwa); - state.set_transition(ta); - state.set_transition(taa); - modify_state(state); - - // We set up an orthographic projection that defines our entire - // viewport to the range [0..1] in both dimensions. Then, when we - // create a unit square polygon below, it will exactly fill the - // viewport (and thus exactly fill the display region). - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - gluOrtho2D(0, 1, 0, 1); - - float txl, txr, tyt, tyb; - txl = tyb = 0.; - if (tex->_has_requested_size) { - txr = ((float)(tex->_requested_w)) / ((float)(tex->_pbuffer->get_xsize())); - tyt = ((float)(tex->_requested_h)) / ((float)(tex->_pbuffer->get_ysize())); - } else { - txr = tyt = 1.; - } - - // This two-triangle strip is actually a quad. But it's usually - // better to render quads as tristrips anyway. - glBegin(GL_TRIANGLE_STRIP); - glTexCoord2f(txl, tyb); glVertex2i(0, 0); - glTexCoord2f(txr, tyb); glVertex2i(1, 0); - glTexCoord2f(txl, tyt); glVertex2i(0, 1); - glTexCoord2f(txr, tyt); glVertex2i(1, 1); - glEnd(); - - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - - pop_display_region(old_dr); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::draw_texture -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -draw_texture(TextureContext *tc, const DisplayRegion *dr, const RenderBuffer &rb) { - // activate(); - set_draw_buffer(rb); - draw_texture(tc, dr); -} - //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::texture_to_pixel_buffer // Access: Public, Virtual @@ -2170,7 +1875,7 @@ copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr) { // for glReadPixels() to work // NOTE: reading the depth buffer is *much* slower than reading the // color buffer - clear_attribute(TextureTransition::get_class_type()); + modify_state(get_untextured_state()); int xo, yo, w, h; dr->get_region_pixels(xo, yo, w, h); @@ -2242,141 +1947,6 @@ copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, copy_pixel_buffer(pb, dr); } -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::draw_pixel_buffer -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, - const NodeTransitions& na) { - nassertv(pb != NULL && dr != NULL); - nassertv(!pb->_image.empty()); - // activate(); - - DisplayRegionStack old_dr = push_display_region(dr); - prepare_display_region(); - - NodeTransitions state(na); - state.set_transition(new TextureTransition); - state.set_transition(new TransformTransition); - //state.set_transition(new ColorBlendTransition); - state.set_transition(new StencilTransition); - - switch (pb->get_format()) { - case PixelBuffer::F_depth_component: - { - ColorMaskTransition *cma = new ColorMaskTransition(0); - DepthTestTransition *dta = new DepthTestTransition(DepthTestProperty::M_always); - DepthWriteTransition *dwa = new DepthWriteTransition; - state.set_transition(cma); - state.set_transition(dta); - state.set_transition(dwa); - } - break; - - case PixelBuffer::F_rgb: - case PixelBuffer::F_rgb5: - case PixelBuffer::F_rgb8: - case PixelBuffer::F_rgb12: - case PixelBuffer::F_rgba: - case PixelBuffer::F_rgbm: - case PixelBuffer::F_rgba4: - case PixelBuffer::F_rgba5: - case PixelBuffer::F_rgba8: - case PixelBuffer::F_rgba12: - { - ColorMaskTransition *cma = new ColorMaskTransition; - DepthTestTransition *dta = new DepthTestTransition(DepthTestProperty::M_none); - DepthWriteTransition *dwa = new DepthWriteTransition(DepthWriteTransition::off()); - state.set_transition(cma); - state.set_transition(dta); - state.set_transition(dwa); - } - break; - default: - glgsg_cat.error() - << "draw_pixel_buffer(): unknown buffer format" << endl; - break; - } - - modify_state(state); - - set_unpack_alignment(1); - - glMatrixMode( GL_PROJECTION ); - glPushMatrix(); - glLoadIdentity(); - gluOrtho2D(0, _win->get_width(), - 0, _win->get_height()); - -#ifdef GSG_VERBOSE - glgsg_cat.debug() - << "glDrawPixels(" << pb->get_xsize() << ", " << pb->get_ysize() - << ", "; - switch (get_external_image_format(pb->get_format())) { - case GL_DEPTH_COMPONENT: - glgsg_cat.debug(false) << "GL_DEPTH_COMPONENT, "; - break; - case GL_RGB: - glgsg_cat.debug(false) << "GL_RGB, "; - break; - case GL_RGBA: - glgsg_cat.debug(false) << "GL_RGBA, "; - break; -#ifdef GL_BGR - case GL_BGR: - glgsg_cat.debug(false) << "GL_BGR, "; - break; - case GL_BGRA: - glgsg_cat.debug(false) << "GL_BGRA, "; - break; -#endif // GL_BGR - default: - glgsg_cat.debug(false) << "unknown, "; - break; - } - switch (get_image_type(pb->get_image_type())) { - case GL_UNSIGNED_BYTE: - glgsg_cat.debug(false) << "GL_UNSIGNED_BYTE, "; - break; - case GL_FLOAT: - glgsg_cat.debug(false) << "GL_FLOAT, "; - break; - default: - glgsg_cat.debug(false) << "unknown, "; - break; - } - glgsg_cat.debug(false) - << (void *)pb->_image.p() << ")" << endl; -#endif - - glRasterPos2i( pb->get_xorg(), pb->get_yorg() ); - glDrawPixels( pb->get_xsize(), pb->get_ysize(), - get_external_image_format(pb->get_format()), - get_image_type(pb->get_image_type()), - pb->_image.p() ); - - glMatrixMode( GL_PROJECTION ); - glPopMatrix(); - - pop_display_region(old_dr); - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::draw_pixel_buffer -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, - const RenderBuffer &rb, const NodeTransitions& na) { - // activate(); - set_draw_buffer(rb); - draw_pixel_buffer(pb, dr, na); -} - //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::apply_material // Access: Public, Virtual @@ -2422,35 +1992,6 @@ void GLGraphicsStateGuardian::apply_material(const Material *material) { report_errors(); } -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::apply_fog -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -apply_fog(Fog *fog) { - Fog::Mode fmode = fog->get_mode(); - call_glFogMode(get_fog_mode_type(fmode)); - - if (fmode == Fog::M_linear) { - // Linear fog may be world-relative or camera-relative. The fog - // object knows how to decode its parameters into camera-relative - // properties. - float onset, opaque; - fog->compute_linear_range(onset, opaque, _current_camera, - _coordinate_system); - call_glFogStart(onset); - call_glFogEnd(opaque); - - } else { - // Exponential fog is always camera-relative. - call_glFogDensity(fog->get_exp_density()); - } - - call_glFogColor(fog->get_color()); - report_errors(); -} - //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::apply_fog // Access: Public, Virtual @@ -2459,7 +2000,7 @@ apply_fog(Fog *fog) { void GLGraphicsStateGuardian:: apply_fog(qpFog *fog) { qpFog::Mode fmode = fog->get_mode(); - call_glFogMode(get_fog_mode_type((Fog::Mode)fmode)); + call_glFogMode(get_fog_mode_type(fmode)); if (fmode == qpFog::M_linear) { float onset, opaque; @@ -2476,614 +2017,6 @@ apply_fog(qpFog *fog) { report_errors(); } -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_transform -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_transform(const TransformTransition *attrib) { - // activate(); -#ifdef GSG_VERBOSE - glgsg_cat.debug() - << "glLoadMatrix(GL_MODELVIEW): " << attrib->get_matrix() << endl; -#endif - glMatrixMode(GL_MODELVIEW); - glLoadMatrixf(attrib->get_matrix().get_data()); - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_color_transform -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_color_transform(const ColorMatrixTransition *attrib) { - _current_color_mat = attrib->get_matrix(); - - if (_current_color_mat == LMatrix4f::ident_mat()) { - _color_transform_enabled = false; - } else { - _color_transform_enabled = true; - } - - _scene_graph_color_stale = _has_scene_graph_color; -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_alpha_transform -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_alpha_transform(const AlphaTransformTransition *attrib) { - _current_alpha_offset= attrib->get_offset(); - _current_alpha_scale = attrib->get_scale(); - - if (_current_alpha_offset == 0 && _current_alpha_scale == 1) { - _alpha_transform_enabled = false; - } else { - _alpha_transform_enabled = true; - } - - _scene_graph_color_stale = _has_scene_graph_color; -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_matrix -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_tex_matrix(const TexMatrixTransition *attrib) { - // activate(); -#ifdef GSG_VERBOSE - glgsg_cat.debug() - << "glLoadMatrix(GL_TEXTURE): " << attrib->get_matrix() << endl; -#endif - glMatrixMode(GL_TEXTURE); - glLoadMatrixf(attrib->get_matrix().get_data()); - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_color -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_color(const ColorTransition *attrib) { - if (attrib->is_on()) { - if (attrib->is_real()) { - // The color attribute is "on" and "real": it specifies a scene - // graph color that overrides the vertex color. - _scene_graph_color = attrib->get_color(); - _has_scene_graph_color = true; - _vertex_colors_enabled = false; - _scene_graph_color_stale = true; - - } else { - // The color attribute is "on" but not "real": it specifies that - // no scene graph color is in effect, but vertex color is not - // important either. - _has_scene_graph_color = false; - _scene_graph_color_stale = false; - _vertex_colors_enabled = false; - } - } else { - // The color attribute is "off": it specifies that vertex color - // should be revealed. - _has_scene_graph_color = false; - _scene_graph_color_stale = false; - _vertex_colors_enabled = true; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_texture -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_texture(const TextureTransition *attrib) { - // activate(); - - if (attrib->is_on()) { - enable_texturing(true); - Texture *tex = attrib->get_texture(); - nassertv(tex != (Texture *)NULL); - tex->apply(this); - } else { - enable_texturing(false); - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_tex_gen -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_tex_gen(const TexGenTransition *attrib) { - // activate(); - TexGenProperty::Mode mode = attrib->get_mode(); - - switch (mode) { - case TexGenProperty::M_none: - glDisable(GL_TEXTURE_GEN_S); - glDisable(GL_TEXTURE_GEN_T); - glDisable(GL_TEXTURE_GEN_Q); - glDisable(GL_TEXTURE_GEN_R); - break; - - case TexGenProperty::M_texture_projector: - { - glEnable(GL_TEXTURE_GEN_S); - glEnable(GL_TEXTURE_GEN_T); - glEnable(GL_TEXTURE_GEN_Q); - glEnable(GL_TEXTURE_GEN_R); - const LMatrix4f &plane = attrib->get_plane(); - glTexGenfv(GL_S, GL_OBJECT_PLANE, plane.get_row(0).get_data()); - glTexGenfv(GL_T, GL_OBJECT_PLANE, plane.get_row(1).get_data()); - glTexGenfv(GL_R, GL_OBJECT_PLANE, plane.get_row(2).get_data()); - glTexGenfv(GL_Q, GL_OBJECT_PLANE, plane.get_row(3).get_data()); - glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - } - break; - - case TexGenProperty::M_sphere_map: - glEnable(GL_TEXTURE_GEN_S); - glEnable(GL_TEXTURE_GEN_T); - glDisable(GL_TEXTURE_GEN_Q); - glDisable(GL_TEXTURE_GEN_R); - glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); - glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); - break; - - default: - glgsg_cat.error() - << "Unknown texgen mode " << (int)mode << endl; - break; - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_material -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_material(const MaterialTransition *attrib) { - // activate(); - if (attrib->is_on()) { - const Material *material = attrib->get_material(); - nassertv(material != (const Material *)NULL); - apply_material(material); - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_fog -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_fog(const FogTransition *attrib) { - // activate(); - - if (attrib->is_on()) { - enable_fog(true); - Fog *fog = attrib->get_fog(); - nassertv(fog != (Fog *)NULL); - fog->apply(this); - } else { - enable_fog(false); - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_render_mode -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_render_mode(const RenderModeTransition *attrib) { - // activate(); - - RenderModeProperty::Mode mode = attrib->get_mode(); - - switch (mode) { - case RenderModeProperty::M_filled: - call_glPolygonMode(GL_FILL); - break; - - case RenderModeProperty::M_wireframe: - // Make sure line width is back to default (1 pixel) - call_glLineWidth(attrib->get_line_width()); - call_glPolygonMode(GL_LINE); - break; - - default: - glgsg_cat.error() - << "Unknown render mode " << (int)mode << endl; - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_color_blend -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_color_blend(const ColorBlendTransition *attrib) { - // activate(); - ColorBlendProperty::Mode mode = attrib->get_mode(); - - switch (mode) { - case ColorBlendProperty::M_none: - enable_blend(false); - break; - case ColorBlendProperty::M_multiply: - enable_blend(true); - call_glBlendFunc(GL_DST_COLOR, GL_ZERO); - break; - case ColorBlendProperty::M_add: - enable_blend(true); - call_glBlendFunc(GL_ONE, GL_ONE); - break; - case ColorBlendProperty::M_multiply_add: - enable_blend(true); - call_glBlendFunc(GL_DST_COLOR, GL_ONE); - break; - case ColorBlendProperty::M_alpha: - enable_blend(true); - call_glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - break; - default: - glgsg_cat.error() - << "Unknown color blend mode " << (int)mode << endl; - break; - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_texture_apply -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_texture_apply(const TextureApplyTransition *attrib) { - // activate(); - GLint glmode = get_texture_apply_mode_type(attrib->get_mode()); - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, glmode); - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_color_mask -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_color_mask(const ColorMaskTransition *attrib) { - // activate(); - glColorMask(attrib->is_write_r(), - attrib->is_write_g(), - attrib->is_write_b(), - attrib->is_write_a()); - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_depth_test -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_depth_test(const DepthTestTransition *attrib) { - // activate(); - - DepthTestProperty::Mode mode = attrib->get_mode(); - if (mode == DepthTestProperty::M_none) { - enable_depth_test(false); - } else { - enable_depth_test(true); - glDepthFunc(get_depth_func_type(mode)); - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_depth_write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_depth_write(const DepthWriteTransition *attrib) { - // activate(); - glDepthMask(attrib->is_on()); - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_stencil -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_stencil(const StencilTransition *attrib) { - StencilProperty::Mode mode = attrib->get_mode(); - if (mode == StencilProperty::M_none) { - enable_stencil_test(false); - - } else { - enable_stencil_test(true); - call_glStencilFunc(get_stencil_func_type(mode),attrib->get_reference_value(),attrib->get_func_mask()); - call_glStencilOp(get_stencil_action_type(attrib->get_fail_action()), - get_stencil_action_type(attrib->get_zfail_action()), - get_stencil_action_type(attrib->get_pass_action())); - #ifdef _DEBUG - if (attrib->get_write_mask() != 0xFFFFFFFF) - glgsg_cat.warning() << "OpenGL doesnt support stencil writemasks!\n"; - #endif - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_cull_transition -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_cull_face(const CullFaceTransition *attrib) { - // activate(); - CullFaceProperty::Mode mode = attrib->get_mode(); - - switch (mode) { - case CullFaceProperty::M_cull_none: - glDisable(GL_CULL_FACE); - break; - case CullFaceProperty::M_cull_clockwise: - glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); - break; - case CullFaceProperty::M_cull_counter_clockwise: - glEnable(GL_CULL_FACE); - glCullFace(GL_FRONT); - break; - case CullFaceProperty::M_cull_all: - glEnable(GL_CULL_FACE); - glCullFace(GL_FRONT_AND_BACK); - break; - default: - glgsg_cat.error() - << "invalid cull face mode " << (int)mode << endl; - break; - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_clip_plane -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_clip_plane(const ClipPlaneTransition *attrib) -{ - nassertv(attrib->get_default_dir() != TD_on); - // activate(); - - // Initialize the currently enabled clip plane list - int i; - for (i = 0; i < _max_clip_planes; i++) - _cur_clip_plane_enabled[i] = false; - - int num_enabled = 0; - ClipPlaneTransition::const_iterator pi; - for (pi = attrib->begin(); pi != attrib->end(); ++pi) { - PlaneNode *plane_node; - DCAST_INTO_V(plane_node, (*pi).first); - nassertv(plane_node != (PlaneNode *)NULL); - TransitionDirection dir = (*pi).second; - - if (dir == TD_on) { - _cur_clip_plane_id = -1; - num_enabled++; - - // Check to see if this clip plane has already been bound to an id - for (i = 0; i < _max_clip_planes; i++) { - if (_available_clip_plane_ids[i] == plane_node) { - // Clip plane has already been bound to an id, we only need - // to enable the clip plane, not apply it - _cur_clip_plane_id = -2; - enable_clip_plane(i, true); - _cur_clip_plane_enabled[i] = true; - break; - } - } - - // See if there are any unbound clip plane ids - if (_cur_clip_plane_id == -1) { - for (i = 0; i < _max_clip_planes; i++) { - if (_available_clip_plane_ids[i] == NULL) { - _available_clip_plane_ids[i] = plane_node; - _cur_clip_plane_id = i; - break; - } - } - } - - // If there were no unbound clip plane ids, see if we can replace - // a currently unused but previously bound id - if (_cur_clip_plane_id == -1) { - for (i = 0; i < _max_clip_planes; i++) { - if (attrib->is_off(_available_clip_plane_ids[i])) { - _available_clip_plane_ids[i] = plane_node; - _cur_clip_plane_id = i; - break; - } - } - } - - if (_cur_clip_plane_id >= 0) { - enable_clip_plane(_cur_clip_plane_id, true); - _cur_clip_plane_enabled[_cur_clip_plane_id] = true; - double equation[4]; - const Planef clip_plane = plane_node->get_plane(); - // Move us into the coordinate space of the plane - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadMatrixf(clip_plane.get_reflection_mat().get_data()); - equation[0] = clip_plane._a; - equation[1] = clip_plane._b; - equation[2] = clip_plane._c; - equation[3] = clip_plane._d; - glClipPlane(get_clip_plane_id(_cur_clip_plane_id), equation); - glPopMatrix(); - } else if (_cur_clip_plane_id == -1) { - glgsg_cat.error() - << "issue_clip_plane() - failed to bind clip plane to id" << endl; - } - } - } - - // Disable all unused clip planes - for (i = 0; i < _max_clip_planes; i++) { - if (_cur_clip_plane_enabled[i] == false) - enable_clip_plane(i, false); - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_transparency -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_transparency(const TransparencyTransition *attrib ) -{ - // activate(); - - TransparencyProperty::Mode mode = attrib->get_mode(); - - switch (mode) { - case TransparencyProperty::M_none: - enable_multisample_alpha_one(false); - enable_multisample_alpha_mask(false); - enable_blend(false); - enable_alpha_test(false); - break; - case TransparencyProperty::M_alpha: - case TransparencyProperty::M_alpha_sorted: - // Should we really have an "alpha" and an "alpha_sorted" mode, - // like Performer does? (The difference is that "alpha" is with - // the write to the depth buffer disabled.) Or should we just use - // the separate depth write transition to control this? Doing it - // implicitly requires a bit more logic here and in the state - // management; for now we require the user to explicitly turn off - // the depth write. - enable_multisample_alpha_one(false); - enable_multisample_alpha_mask(false); - enable_blend(true); - enable_alpha_test(false); - call_glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - break; - case TransparencyProperty::M_multisample: - enable_multisample_alpha_one(true); - enable_multisample_alpha_mask(true); - enable_blend(false); - enable_alpha_test(false); - break; - case TransparencyProperty::M_multisample_mask: - enable_multisample_alpha_one(false); - enable_multisample_alpha_mask(true); - enable_blend(false); - enable_alpha_test(false); - break; - case TransparencyProperty::M_binary: - enable_multisample_alpha_one(false); - enable_multisample_alpha_mask(false); - enable_blend(false); - enable_alpha_test(true); - call_glAlphaFunc(GL_EQUAL, 1); - break; - default: - glgsg_cat.error() - << "invalid transparency mode " << (int)mode << endl; - break; - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_linesmooth -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_linesmooth(const LinesmoothTransition *attrib) { - // activate(); - enable_line_smooth(attrib->is_on()); - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_point_shape -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_point_shape(const PointShapeTransition *attrib) { - // activate(); - - if (attrib->get_mode() == PointShapeProperty::M_square) - glDisable(GL_POINT_SMOOTH); - else - glEnable(GL_POINT_SMOOTH); - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::issue_polygon_offset -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -issue_polygon_offset(const PolygonOffsetTransition *attrib) { - // activate(); - //GL really wants to do a enable/disable of PolygonOffset, but it - //seems more intuitive to have a PolygonOffset "on" all the time, - //and have zero mean nothing is being done. So check for a zero - //offset to decide whether to enable or disable PolygonOffset - if(attrib->get_units() != 0 || attrib->get_factor() != 0) - { - // GLfloat newfactor=attrib->get_factor(); - GLfloat newfactor= 1.0f; - - GLfloat newunits=attrib->get_units(); - glPolygonOffset(newfactor,newunits); - enable_polygon_offset(true); - } - else - { - enable_polygon_offset(false); - } - report_errors(); -} - //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::issue_transform // Access: Public, Virtual @@ -3455,151 +2388,6 @@ wants_texcoords() const { return _texturing_enabled; } -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::begin_decal -// Access: Public, Virtual -// Description: This will be called to initiate decaling mode. It is -// passed the pointer to the GeomNode that will be the -// destination of the decals, which it is expected that -// the GSG will render normally; subsequent geometry -// rendered up until the next call of end_decal() should -// be rendered as decals of the base_geom. -// -// The transitions wrapper is the current state as of the -// base geometry node. It may or may not be modified by -// the GSG to reflect whatever rendering state is -// necessary to render the decals properly. -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -begin_decal(GeomNode *base_geom, AllTransitionsWrapper &attrib) { - nassertv(base_geom != (GeomNode *)NULL); - _decal_level++; - -#define POLYGON_OFFSET_MULTIPLIER -2 - - if (gl_decal_type == GDT_offset) { - // GL 1.1-style: use glPolygonOffset to do decals. - - // Just draw the base geometry normally. - base_geom->draw(this); - glPolygonOffset(0.0f,POLYGON_OFFSET_MULTIPLIER * _decal_level); - glEnable(GL_POLYGON_OFFSET_FILL); - - } else { - // GL 1.0f-style: use three-step rendering to do decals. - - if (_decal_level > 1) { - // If we're already decaling, just draw the geometry. - base_geom->draw(this); - - } else { - // Turn off writing the depth buffer to render the base geometry. - glDepthMask(false); - DepthWriteTransition *dwa = new DepthWriteTransition; - dwa->set_off(); - attrib.set_transition(dwa); - - // Now render the base geometry. - base_geom->draw(this); - - // Render all of the decal geometry, too. We'll keep the depth - // buffer write off during this. - - // Save the current transform within the GL state so we can - // restore it when we come back to draw the base geometry again. - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - } - } - report_errors(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::end_decal -// Access: Public, Virtual -// Description: This will be called to terminate decaling mode. It -// is passed the same base_geom that was passed to -// begin_decal(). -//////////////////////////////////////////////////////////////////// -void GLGraphicsStateGuardian:: -end_decal(GeomNode *base_geom) { - nassertv(base_geom != (GeomNode *)NULL); - - _decal_level--; - - if (gl_decal_type == GDT_offset) { - // GL 1.1-style: use glPolygonOffset to do decals. - glPolygonOffset(0.0f,POLYGON_OFFSET_MULTIPLIER * _decal_level); - if (_decal_level == 0) { - glDisable(GL_POLYGON_OFFSET_FILL); - } - - } else { - // GL 1.0f-style: use three-step rendering to do decals. - - if (_decal_level == 0) { - // Now we need to re-render the base geometry with the depth write - // on and the color mask off, so we update the depth buffer - // properly. - bool was_textured = _texturing_enabled; - bool was_blend = _blend_enabled; - GLenum old_blend_source_func = _blend_source_func; - GLenum old_blend_dest_func = _blend_dest_func; - - // First, we'd better restore the transform matrix in case our - // decals screwed it up. - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - - // Enable the writing to the depth buffer. - glDepthMask(true); - - // Disable the writing to the color buffer, however we have to - // do this. - if (gl_decal_type == GDT_blend) { - // For the early nVidia Linux driver, at least, we don't seem - // to have a working glColorMask. So we have to disable the - // color writes through the use of a blend function. - // Expensive. - - enable_blend(true); - call_glBlendFunc(GL_ZERO, GL_ONE); - } else { - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - } - - // No need to have texturing on for this. - enable_texturing(false); - - base_geom->draw(this); - - // Finally, restore the depth write and color mask states to the - // way they're supposed to be. - DepthWriteTransition *depth_write; - if (get_attribute_into(depth_write, this)) { - issue_depth_write(depth_write); - } - - if (gl_decal_type == GDT_blend) { - enable_blend(was_blend); - if (was_blend) { - call_glBlendFunc(old_blend_source_func, old_blend_dest_func); - } - } else { - ColorMaskTransition *color_mask; - if (get_attribute_into(color_mask, this)) { - issue_color_mask(color_mask); - } else { - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - } - } - - enable_texturing(was_textured); - } - } - report_errors(); -} - //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::depth_offset_decals // Access: Public, Virtual @@ -4020,6 +2808,223 @@ apply_texture_immediate(Texture *tex) { return true; } +//////////////////////////////////////////////////////////////////// +// Function: GLGraphicsStateGuardian::draw_texture +// Access: Protected +// Description: Copies the texture image directly onto the frame +// buffer within the indicated display region. +//////////////////////////////////////////////////////////////////// +void GLGraphicsStateGuardian:: +draw_texture(TextureContext *tc, const DisplayRegion *dr) { + nassertv(tc != NULL && dr != NULL); + // activate(); + + Texture *tex = tc->_texture; + + DisplayRegionStack old_dr = push_display_region(dr); + prepare_display_region(); + + static CPT(RenderState) basic_state; + if (basic_state == (RenderState *)NULL) { + // Create a State object for rendering textures in general. Lots + // of things get turned off. + const RenderAttrib *attribs[] = { + CullFaceAttrib::make(CullFaceAttrib::M_cull_none), + DepthTestAttrib::make(DepthTestAttrib::M_none), + DepthWriteAttrib::make(DepthWriteAttrib::M_off), + TextureApplyAttrib::make(TextureApplyAttrib::M_decal), + ColorWriteAttrib::make(ColorWriteAttrib::M_on), + RenderModeAttrib::make(RenderModeAttrib::M_filled), + //TexMatrixAttrib::make(LMatrix4f::ident_mat()), + ColorBlendAttrib::make(ColorBlendAttrib::M_none), + TransparencyAttrib::make(TransparencyAttrib::M_none), + }; + basic_state = + RenderState::make(attribs, sizeof(attribs) / sizeof(void *)); + } + CPT(RenderState) state = basic_state->compose + (RenderState::make(TextureAttrib::make(tex))); + modify_state(state); + set_transform(TransformState::make_identity()); + + // We set up an orthographic projection that defines our entire + // viewport to the range [0..1] in both dimensions. Then, when we + // create a unit square polygon below, it will exactly fill the + // viewport (and thus exactly fill the display region). + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + gluOrtho2D(0, 1, 0, 1); + + float txl, txr, tyt, tyb; + txl = tyb = 0.; + if (tex->_has_requested_size) { + txr = ((float)(tex->_requested_w)) / ((float)(tex->_pbuffer->get_xsize())); + tyt = ((float)(tex->_requested_h)) / ((float)(tex->_pbuffer->get_ysize())); + } else { + txr = tyt = 1.; + } + + // This two-triangle strip is actually a quad. But it's usually + // better to render quads as tristrips anyway. + glBegin(GL_TRIANGLE_STRIP); + glTexCoord2f(txl, tyb); glVertex2i(0, 0); + glTexCoord2f(txr, tyb); glVertex2i(1, 0); + glTexCoord2f(txl, tyt); glVertex2i(0, 1); + glTexCoord2f(txr, tyt); glVertex2i(1, 1); + glEnd(); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + + pop_display_region(old_dr); +} + +//////////////////////////////////////////////////////////////////// +// Function: GLGraphicsStateGuardian::draw_texture +// Access: Protected +// Description: +//////////////////////////////////////////////////////////////////// +void GLGraphicsStateGuardian:: +draw_texture(TextureContext *tc, const DisplayRegion *dr, + const RenderBuffer &rb) { + // activate(); + set_draw_buffer(rb); + draw_texture(tc, dr); +} + +//////////////////////////////////////////////////////////////////// +// Function: GLGraphicsStateGuardian::draw_pixel_buffer +// Access: Protected +// Description: Copies the indicated pixel buffer into the frame +// buffer in the given display region. +//////////////////////////////////////////////////////////////////// +void GLGraphicsStateGuardian:: +draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr) { + nassertv(pb != NULL && dr != NULL); + nassertv(!pb->_image.empty()); + // activate(); + + DisplayRegionStack old_dr = push_display_region(dr); + prepare_display_region(); + + static CPT(RenderState) depth_state; + static CPT(RenderState) color_state; + if (depth_state == (RenderState *)NULL) { + // Create a State object for rendering depth-mask pixel buffers. + depth_state = + RenderState::make(TextureAttrib::make_off(), + ColorWriteAttrib::make(ColorWriteAttrib::M_off), + DepthTestAttrib::make(DepthTestAttrib::M_always), + DepthWriteAttrib::make(DepthWriteAttrib::M_on)); + + // And one for rendering color buffers. + color_state = + RenderState::make(TextureAttrib::make_off(), + ColorWriteAttrib::make(ColorWriteAttrib::M_on), + DepthTestAttrib::make(DepthTestAttrib::M_none), + DepthWriteAttrib::make(DepthWriteAttrib::M_off)); + } + + switch (pb->get_format()) { + case PixelBuffer::F_depth_component: + modify_state(depth_state); + break; + + case PixelBuffer::F_rgb: + case PixelBuffer::F_rgb5: + case PixelBuffer::F_rgb8: + case PixelBuffer::F_rgb12: + case PixelBuffer::F_rgba: + case PixelBuffer::F_rgbm: + case PixelBuffer::F_rgba4: + case PixelBuffer::F_rgba5: + case PixelBuffer::F_rgba8: + case PixelBuffer::F_rgba12: + modify_state(color_state); + break; + + default: + glgsg_cat.error() + << "draw_pixel_buffer(): unknown buffer format" << endl; + } + set_transform(TransformState::make_identity()); + + set_unpack_alignment(1); + + glMatrixMode( GL_PROJECTION ); + glPushMatrix(); + glLoadIdentity(); + gluOrtho2D(0, _win->get_width(), + 0, _win->get_height()); + +#ifdef GSG_VERBOSE + glgsg_cat.debug() + << "glDrawPixels(" << pb->get_xsize() << ", " << pb->get_ysize() + << ", "; + switch (get_external_image_format(pb->get_format())) { + case GL_DEPTH_COMPONENT: + glgsg_cat.debug(false) << "GL_DEPTH_COMPONENT, "; + break; + case GL_RGB: + glgsg_cat.debug(false) << "GL_RGB, "; + break; + case GL_RGBA: + glgsg_cat.debug(false) << "GL_RGBA, "; + break; +#ifdef GL_BGR + case GL_BGR: + glgsg_cat.debug(false) << "GL_BGR, "; + break; + case GL_BGRA: + glgsg_cat.debug(false) << "GL_BGRA, "; + break; +#endif // GL_BGR + default: + glgsg_cat.debug(false) << "unknown, "; + break; + } + switch (get_image_type(pb->get_image_type())) { + case GL_UNSIGNED_BYTE: + glgsg_cat.debug(false) << "GL_UNSIGNED_BYTE, "; + break; + case GL_FLOAT: + glgsg_cat.debug(false) << "GL_FLOAT, "; + break; + default: + glgsg_cat.debug(false) << "unknown, "; + break; + } + glgsg_cat.debug(false) + << (void *)pb->_image.p() << ")" << endl; +#endif + + glRasterPos2i( pb->get_xorg(), pb->get_yorg() ); + glDrawPixels( pb->get_xsize(), pb->get_ysize(), + get_external_image_format(pb->get_format()), + get_image_type(pb->get_image_type()), + pb->_image.p() ); + + glMatrixMode( GL_PROJECTION ); + glPopMatrix(); + + pop_display_region(old_dr); + report_errors(); +} + +//////////////////////////////////////////////////////////////////// +// Function: GLGraphicsStateGuardian::draw_pixel_buffer +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +void GLGraphicsStateGuardian:: +draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, + const RenderBuffer &rb) { + // activate(); + set_draw_buffer(rb); + draw_pixel_buffer(pb, dr); +} + //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::get_texture_wrap_mode // Access: Protected @@ -4224,27 +3229,6 @@ get_internal_image_format(PixelBuffer::Format format) { } } -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::get_texture_apply_mode_type -// Access: Protected -// Description: Maps from the texture environment's mode types -// to the corresponding OpenGL ids -//////////////////////////////////////////////////////////////////// -GLint GLGraphicsStateGuardian:: -get_texture_apply_mode_type( TextureApplyProperty::Mode am ) const -{ - switch( am ) { - case TextureApplyProperty::M_modulate: return GL_MODULATE; - case TextureApplyProperty::M_decal: return GL_DECAL; - case TextureApplyProperty::M_blend: return GL_BLEND; - case TextureApplyProperty::M_replace: return GL_REPLACE; - case TextureApplyProperty::M_add: return GL_ADD; - } - glgsg_cat.error() - << "Invalid TextureApplyProperty::Mode value" << endl; - return GL_MODULATE; -} - //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::get_texture_apply_mode_type // Access: Protected @@ -4265,31 +3249,6 @@ get_texture_apply_mode_type(TextureApplyAttrib::Mode am) const { return GL_MODULATE; } -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::get_depth_func_type -// Access: Protected -// Description: Maps from the depth func modes to gl version -//////////////////////////////////////////////////////////////////// -GLenum GLGraphicsStateGuardian:: -get_depth_func_type(DepthTestProperty::Mode m) const -{ - switch(m) { - case DepthTestProperty::M_never: return GL_NEVER; - case DepthTestProperty::M_less: return GL_LESS; - case DepthTestProperty::M_equal: return GL_EQUAL; - case DepthTestProperty::M_less_equal: return GL_LEQUAL; - case DepthTestProperty::M_greater: return GL_GREATER; - case DepthTestProperty::M_not_equal: return GL_NOTEQUAL; - case DepthTestProperty::M_greater_equal: return GL_GEQUAL; - case DepthTestProperty::M_always: return GL_ALWAYS; - - default: - glgsg_cat.error() - << "Invalid DepthTestProperty::Mode value" << endl; - return GL_LESS; - } -} - //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::get_depth_func_type // Access: Protected @@ -4315,79 +3274,25 @@ get_depth_func_type(DepthTestAttrib::Mode m) const } } -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::get_stencil_func_type -// Access: Protected -// Description: Maps from the stencil func modes to gl version -//////////////////////////////////////////////////////////////////// -GLenum GLGraphicsStateGuardian:: -get_stencil_func_type(StencilProperty::Mode m) const -{ - // TODO: should do this with a table, not a switch - switch(m) { - case StencilProperty::M_never: return GL_NEVER; - case StencilProperty::M_less: return GL_LESS; - case StencilProperty::M_equal: return GL_EQUAL; - case StencilProperty::M_less_equal: return GL_LEQUAL; - case StencilProperty::M_greater: return GL_GREATER; - case StencilProperty::M_not_equal: return GL_NOTEQUAL; - case StencilProperty::M_greater_equal: return GL_GEQUAL; - case StencilProperty::M_always: return GL_ALWAYS; - - default: - glgsg_cat.error() - << "Invalid StencilProperty::Mode value" << endl; - return GL_LESS; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GLGraphicsStateGuardian::get_stencil_action_type -// Access: Protected -// Description: Maps from the stencil action modes to gl version -//////////////////////////////////////////////////////////////////// -GLenum GLGraphicsStateGuardian:: -get_stencil_action_type(StencilProperty::Action a) const -{ - // TODO: should do this with a table, not a switch - switch(a) { - case StencilProperty::A_keep: return GL_KEEP; - case StencilProperty::A_zero: return GL_ZERO; - case StencilProperty::A_replace: return GL_REPLACE; - case StencilProperty::A_increment_clamp: return GL_INCR; - case StencilProperty::A_decrement_clamp: return GL_DECR; - case StencilProperty::A_invert: return GL_INVERT; - - case StencilProperty::A_increment: - case StencilProperty::A_decrement: - glgsg_cat.error() - << "wraparound incr/decr StencilProperty::Action not supported by OpenGL\n"; - return ((a == StencilProperty::A_increment) ? GL_INCR : GL_DECR); - } - glgsg_cat.error() - << "Invalid StencilProperty::Action value" << endl; - return GL_KEEP; -} - //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::get_fog_mode_type // Access: Protected // Description: Maps from the fog types to gl version //////////////////////////////////////////////////////////////////// GLenum GLGraphicsStateGuardian:: -get_fog_mode_type(Fog::Mode m) const { +get_fog_mode_type(qpFog::Mode m) const { switch(m) { - case Fog::M_linear: return GL_LINEAR; - case Fog::M_exponential: return GL_EXP; - case Fog::M_exponential_squared: return GL_EXP2; + case qpFog::M_linear: return GL_LINEAR; + case qpFog::M_exponential: return GL_EXP; + case qpFog::M_exponential_squared: return GL_EXP2; /* #ifdef GL_FOG_FUNC_SGIS - case Fog::M_spline: return GL_FOG_FUNC_SGIS; + case qpFog::M_spline: return GL_FOG_FUNC_SGIS; #endif */ default: - glgsg_cat.error() << "Invalid Fog::Mode value" << endl; + glgsg_cat.error() << "Invalid qpFog::Mode value" << endl; return GL_EXP; } } @@ -4748,6 +3653,21 @@ restore_frame_buffer(SavedFrameBuffer *frame_buffer) { } } +//////////////////////////////////////////////////////////////////// +// Function: GLGraphicsStateGuardian::get_untextured_state +// Access: Protected, Static +// Description: Returns a RenderState object that represents +// texturing off. +//////////////////////////////////////////////////////////////////// +CPT(RenderState) GLGraphicsStateGuardian:: +get_untextured_state() { + static CPT(RenderState) state; + if (state == (RenderState *)NULL) { + state = RenderState::make(TextureAttrib::make_off()); + } + return state; +} + #ifndef NDEBUG //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::build_phony_mipmaps diff --git a/panda/src/glgsg/glGraphicsStateGuardian.h b/panda/src/glgsg/glGraphicsStateGuardian.h index 2fecbb73d6..7161f9aec1 100644 --- a/panda/src/glgsg/glGraphicsStateGuardian.h +++ b/panda/src/glgsg/glGraphicsStateGuardian.h @@ -29,13 +29,10 @@ #include "pixelBuffer.h" #include "displayRegion.h" #include "material.h" -#include "textureApplyProperty.h" -#include "depthTestProperty.h" -#include "stencilProperty.h" -#include "fog.h" #include "depthTestAttrib.h" #include "textureApplyAttrib.h" #include "pointerToArray.h" +#include "qpfog.h" #ifdef WIN32_VC // Must include windows.h before gl.h on NT @@ -77,15 +74,6 @@ public: virtual void prepare_display_region(); virtual bool prepare_lens(); - virtual void render_frame(); - virtual void render_scene(Node *root, LensNode *projnode); - virtual void render_subgraph(RenderTraverser *traverser, - Node *subgraph, LensNode *projnode, - const AllTransitionsWrapper &net_trans); - virtual void render_subgraph(RenderTraverser *traverser, - Node *subgraph, - const AllTransitionsWrapper &net_trans); - virtual void draw_point(GeomPoint *geom, GeomContext *gc); virtual void draw_line(GeomLine *geom, GeomContext *gc); virtual void draw_linestrip(GeomLinestrip *geom, GeomContext *gc); @@ -101,16 +89,14 @@ public: virtual void apply_texture(TextureContext *tc); virtual void release_texture(TextureContext *tc); - virtual GeomNodeContext *prepare_geom_node(GeomNode *node); - virtual void draw_geom_node(GeomNode *node, GeomNodeContext *gnc); + virtual GeomNodeContext *prepare_geom_node(qpGeomNode *node); + virtual void draw_geom_node(qpGeomNode *node, const RenderState *state, + GeomNodeContext *gnc); virtual void release_geom_node(GeomNodeContext *gnc); virtual void copy_texture(TextureContext *tc, const DisplayRegion *dr); virtual void copy_texture(TextureContext *tc, const DisplayRegion *dr, const RenderBuffer &rb); - virtual void draw_texture(TextureContext *tc, const DisplayRegion *dr); - virtual void draw_texture(TextureContext *tc, const DisplayRegion *dr, - const RenderBuffer &rb); virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb); virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb, @@ -119,39 +105,10 @@ public: virtual void copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr); virtual void copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, const RenderBuffer &rb); - virtual void draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, - const NodeTransitions& na=NodeTransitions()); - virtual void draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, - const RenderBuffer &rb, - const NodeTransitions& na=NodeTransitions()); virtual void apply_material(const Material *material); - virtual void apply_fog(Fog *fog); void apply_fog(qpFog *fog); - virtual void issue_transform(const TransformTransition *attrib); - virtual void issue_color_transform(const ColorMatrixTransition *attrib); - virtual void issue_alpha_transform(const AlphaTransformTransition *attrib); - virtual void issue_tex_matrix(const TexMatrixTransition *attrib); - virtual void issue_color(const ColorTransition *attrib); - virtual void issue_texture(const TextureTransition *attrib); - virtual void issue_material(const MaterialTransition *attrib); - virtual void issue_render_mode(const RenderModeTransition *attrib); - virtual void issue_color_blend(const ColorBlendTransition *attrib); - virtual void issue_texture_apply(const TextureApplyTransition *attrib); - virtual void issue_color_mask(const ColorMaskTransition *attrib); - virtual void issue_depth_test(const DepthTestTransition *attrib); - virtual void issue_depth_write(const DepthWriteTransition *attrib); - virtual void issue_tex_gen(const TexGenTransition *attrib); - virtual void issue_cull_face(const CullFaceTransition *attrib); - virtual void issue_stencil(const StencilTransition *attrib); - virtual void issue_clip_plane(const ClipPlaneTransition *attrib); - virtual void issue_transparency(const TransparencyTransition *attrib); - virtual void issue_fog(const FogTransition *attrib); - virtual void issue_linesmooth(const LinesmoothTransition *attrib); - virtual void issue_point_shape(const PointShapeTransition *attrib); - virtual void issue_polygon_offset(const PolygonOffsetTransition *attrib); - virtual void issue_transform(const TransformState *transform); virtual void issue_tex_matrix(const TexMatrixAttrib *attrib); virtual void issue_texture(const TextureAttrib *attrib); @@ -175,9 +132,6 @@ public: virtual bool wants_normals(void) const; virtual bool wants_texcoords(void) const; - virtual void begin_decal(GeomNode *base_geom, AllTransitionsWrapper &attrib); - virtual void end_decal(GeomNode *base_geom); - virtual bool depth_offset_decals(); virtual CoordinateSystem get_internal_coordinate_system() const; @@ -273,18 +227,23 @@ protected: void specify_texture(Texture *tex); bool apply_texture_immediate(Texture *tex); + void draw_texture(TextureContext *tc, const DisplayRegion *dr); + void draw_texture(TextureContext *tc, const DisplayRegion *dr, + const RenderBuffer &rb); + void draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr); + void draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, + const RenderBuffer &rb); + GLenum get_texture_wrap_mode(Texture::WrapMode wm); GLenum get_texture_filter_type(Texture::FilterType ft); GLenum get_image_type(PixelBuffer::Type type); GLenum get_external_image_format(PixelBuffer::Format format); GLenum get_internal_image_format(PixelBuffer::Format format); - GLint get_texture_apply_mode_type( TextureApplyProperty::Mode am ) const; GLint get_texture_apply_mode_type(TextureApplyAttrib::Mode am) const; - GLenum get_depth_func_type(DepthTestProperty::Mode m) const; GLenum get_depth_func_type(DepthTestAttrib::Mode m) const; - GLenum get_stencil_func_type(StencilProperty::Mode m) const; - GLenum get_stencil_action_type(StencilProperty::Action a) const; - GLenum get_fog_mode_type(Fog::Mode m) const; + GLenum get_fog_mode_type(qpFog::Mode m) const; + + static CPT(RenderState) get_untextured_state(); #ifndef NDEBUG void build_phony_mipmaps(Texture *tex); diff --git a/panda/src/glutdisplay/Sources.pp b/panda/src/glutdisplay/Sources.pp index a2af50d23d..03f98fa8cb 100644 --- a/panda/src/glutdisplay/Sources.pp +++ b/panda/src/glutdisplay/Sources.pp @@ -9,7 +9,7 @@ #begin lib_target #define TARGET glutdisplay #define LOCAL_LIBS \ - glgsg display putil gobj gsgbase pnmimage mathutil graph sgraph + glgsg display putil gobj gsgbase pnmimage mathutil #define SOURCES \ config_glutdisplay.cxx config_glutdisplay.h glutGraphicsPipe.cxx \ diff --git a/panda/src/gobj/Sources.pp b/panda/src/gobj/Sources.pp index 28f43b1fec..241323aece 100644 --- a/panda/src/gobj/Sources.pp +++ b/panda/src/gobj/Sources.pp @@ -4,36 +4,42 @@ #begin lib_target #define TARGET gobj #define LOCAL_LIBS \ - event linmath mathutil pnmimage gsgbase graph putil + event linmath mathutil pnmimage gsgbase putil #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx #define SOURCES \ - LOD.I LOD.h config_gobj.h drawable.h geom.I geom.N \ - geom.h geomLine.h geomLinestrip.h geomPoint.h geomPolygon.h \ - geomQuad.h geomSphere.h geomSprite.I geomSprite.h geomTri.h \ - geomTrifan.h geomTristrip.h imageBuffer.I imageBuffer.h \ - material.I material.h materialPool.I materialPool.h \ - matrixLens.I matrixLens.h \ - orthographicLens.I orthographicLens.h perspectiveLens.I \ - perspectiveLens.h pixelBuffer.I pixelBuffer.N \ - pixelBuffer.h lens.h lens.I \ - savedContext.I savedContext.h \ - texture.I texture.N texture.h \ - textureContext.I textureContext.h \ - texturePool.I texturePool.h + LOD.I LOD.h \ + boundedObject.I boundedObject.h \ + config_gobj.h drawable.h geom.I geom.N \ + geom.h geomLine.h geomLinestrip.h geomPoint.h geomPolygon.h \ + geomQuad.h geomSphere.h geomSprite.I geomSprite.h geomTri.h \ + geomTrifan.h geomTristrip.h imageBuffer.I imageBuffer.h \ + material.I material.h materialPool.I materialPool.h \ + matrixLens.I matrixLens.h \ + orthographicLens.I orthographicLens.h perspectiveLens.I \ + perspectiveLens.h pixelBuffer.I pixelBuffer.N \ + pixelBuffer.h lens.h lens.I \ + savedContext.I savedContext.h \ + texture.I texture.N texture.h \ + textureContext.I textureContext.h \ + texturePool.I texturePool.h #define INCLUDED_SOURCES \ - LOD.cxx config_gobj.cxx drawable.cxx geom.cxx \ - geomLine.cxx geomLinestrip.cxx geomPoint.cxx geomPolygon.cxx \ - geomQuad.cxx geomSphere.cxx geomSprite.cxx geomTri.cxx \ - geomTrifan.cxx geomTristrip.cxx imageBuffer.cxx material.cxx \ - materialPool.cxx matrixLens.cxx orthographicLens.cxx \ - perspectiveLens.cxx pixelBuffer.cxx lens.cxx \ - savedContext.cxx texture.cxx textureContext.cxx texturePool.cxx + LOD.cxx \ + boundedObject.cxx \ + config_gobj.cxx drawable.cxx geom.cxx \ + geomLine.cxx geomLinestrip.cxx geomPoint.cxx geomPolygon.cxx \ + geomQuad.cxx geomSphere.cxx geomSprite.cxx geomTri.cxx \ + geomTrifan.cxx geomTristrip.cxx imageBuffer.cxx material.cxx \ + materialPool.cxx matrixLens.cxx orthographicLens.cxx \ + perspectiveLens.cxx pixelBuffer.cxx lens.cxx \ + savedContext.cxx texture.cxx textureContext.cxx texturePool.cxx #define INSTALL_HEADERS \ - LOD.I LOD.h config_gobj.h \ + LOD.I LOD.h \ + boundedObject.I boundedObject.h \ + config_gobj.h \ drawable.h geom.I geom.h geomLine.h \ geomLinestrip.h geomPoint.h geomPolygon.h geomQuad.h geomSphere.h \ geomSprite.I geomSprite.h geomTri.h geomTrifan.h geomTristrip.h \ diff --git a/panda/src/graph/boundedObject.I b/panda/src/gobj/boundedObject.I similarity index 94% rename from panda/src/graph/boundedObject.I rename to panda/src/gobj/boundedObject.I index 14a46584a6..10620da660 100644 --- a/panda/src/graph/boundedObject.I +++ b/panda/src/gobj/boundedObject.I @@ -16,14 +16,13 @@ // //////////////////////////////////////////////////////////////////// -#include //////////////////////////////////////////////////////////////////// // Function: BoundedObject::CData::Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE_GRAPH BoundedObject::CData:: +INLINE BoundedObject::CData:: CData() { _bound_type = BoundedObject::BVT_dynamic_sphere; _flags = F_bound_stale; @@ -34,7 +33,7 @@ CData() { // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE_GRAPH BoundedObject::CData:: +INLINE BoundedObject::CData:: CData(const BoundedObject::CData ©) : _flags(copy._flags), _bound_type(copy._bound_type), @@ -47,7 +46,7 @@ CData(const BoundedObject::CData ©) : // Access: Public // Description: //////////////////////////////////////////////////////////////////// -INLINE_GRAPH void BoundedObject::CData:: +INLINE void BoundedObject::CData:: operator = (const BoundedObject::CData ©) { _flags = copy._flags; _bound_type = copy._bound_type; @@ -60,7 +59,7 @@ operator = (const BoundedObject::CData ©) { // Access: Published // Description: //////////////////////////////////////////////////////////////////// -INLINE_GRAPH BoundedObject:: +INLINE BoundedObject:: BoundedObject() { } @@ -69,7 +68,7 @@ BoundedObject() { // Access: Published // Description: //////////////////////////////////////////////////////////////////// -INLINE_GRAPH BoundedObject:: +INLINE BoundedObject:: BoundedObject(const BoundedObject ©) : _cycler(copy._cycler) { @@ -80,7 +79,7 @@ BoundedObject(const BoundedObject ©) : // Access: Published // Description: //////////////////////////////////////////////////////////////////// -INLINE_GRAPH void BoundedObject:: +INLINE void BoundedObject:: operator = (const BoundedObject ©) { _cycler = copy._cycler; } @@ -92,7 +91,7 @@ operator = (const BoundedObject ©) { // dynamically computed for this particular node. // Presently, this should only be BVT_dynamic_sphere. //////////////////////////////////////////////////////////////////// -INLINE_GRAPH void BoundedObject:: +INLINE void BoundedObject:: set_bound(BoundedObject::BoundingVolumeType type) { nassertv(type != BVT_static); mark_bound_stale(); @@ -107,7 +106,7 @@ set_bound(BoundedObject::BoundingVolumeType type) { // This will be a static bounding volume that will no // longer be recomputed automatically. //////////////////////////////////////////////////////////////////// -INLINE_GRAPH void BoundedObject:: +INLINE void BoundedObject:: set_bound(const BoundingVolume &bound) { mark_bound_stale(); CDWriter cdata(_cycler); @@ -126,7 +125,7 @@ set_bound(const BoundingVolume &bound) { // setting was changed, or false if it was already // marked stale (or if it is a static bounding volume). //////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool BoundedObject:: +INLINE bool BoundedObject:: mark_bound_stale() { if (is_bound_stale()) { return false; @@ -147,7 +146,7 @@ mark_bound_stale() { // effect at least one level, even if it had already // been marked stale. //////////////////////////////////////////////////////////////////// -INLINE_GRAPH void BoundedObject:: +INLINE void BoundedObject:: force_bound_stale() { { CDWriter cdata(_cycler); @@ -167,7 +166,7 @@ force_bound_stale() { // because several of the inline functions below // reference it. //////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool BoundedObject:: +INLINE bool BoundedObject:: is_bound_stale() const { CDReader cdata(_cycler); return (cdata->_flags & F_bound_stale) != 0; @@ -191,7 +190,7 @@ is_bound_stale() const { // special properties, like billboards, that may move // geometry out of its bounding volume otherwise. //////////////////////////////////////////////////////////////////// -INLINE_GRAPH void BoundedObject:: +INLINE void BoundedObject:: set_final(bool flag) { CDWriter cdata(_cycler); if (flag) { @@ -209,7 +208,7 @@ set_final(bool flag) { // changed by an explicit call to set_final(). See // set_final(). //////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool BoundedObject:: +INLINE bool BoundedObject:: is_final() const { CDReader cdata(_cycler); return (cdata->_flags & F_final) != 0; @@ -232,7 +231,7 @@ is_final() const { // pointer, just use the return value from that as a // non-const BoundingVolume pointer. //////////////////////////////////////////////////////////////////// -INLINE_GRAPH const BoundingVolume *BoundedObject:: +INLINE const BoundingVolume *BoundedObject:: get_bound_ptr() const { CDReader cdata(_cycler); return cdata->_bound; @@ -247,7 +246,7 @@ get_bound_ptr() const { // pointer passed in, as a convenience (it will now be // reference counted). //////////////////////////////////////////////////////////////////// -INLINE_GRAPH BoundingVolume *BoundedObject:: +INLINE BoundingVolume *BoundedObject:: set_bound_ptr(BoundingVolume *bound) { CDWriter cdata(_cycler); cdata->_bound = bound; diff --git a/panda/src/graph/boundedObject.cxx b/panda/src/gobj/boundedObject.cxx similarity index 98% rename from panda/src/graph/boundedObject.cxx rename to panda/src/gobj/boundedObject.cxx index b95bf5f0d0..fe949252b8 100644 --- a/panda/src/graph/boundedObject.cxx +++ b/panda/src/gobj/boundedObject.cxx @@ -17,9 +17,9 @@ //////////////////////////////////////////////////////////////////// #include "boundedObject.h" -#include "config_graph.h" +#include "config_gobj.h" -#include +#include "boundingSphere.h" TypeHandle BoundedObject::_type_handle; @@ -113,7 +113,7 @@ recompute_bound() { break; default: - graph_cat.error() + gobj_cat.error() << "Unexpected _bound_type: " << (int)cdata->_bound_type << " in BoundedObject::recompute_bound()\n"; cdata->_bound = new BoundingSphere; diff --git a/panda/src/graph/boundedObject.h b/panda/src/gobj/boundedObject.h similarity index 76% rename from panda/src/graph/boundedObject.h rename to panda/src/gobj/boundedObject.h index 473a92bbb7..0e8a236353 100644 --- a/panda/src/graph/boundedObject.h +++ b/panda/src/gobj/boundedObject.h @@ -39,9 +39,9 @@ //////////////////////////////////////////////////////////////////// class EXPCL_PANDA BoundedObject { public: - INLINE_GRAPH BoundedObject(); - INLINE_GRAPH BoundedObject(const BoundedObject ©); - INLINE_GRAPH void operator = (const BoundedObject ©); + INLINE BoundedObject(); + INLINE BoundedObject(const BoundedObject ©); + INLINE void operator = (const BoundedObject ©); virtual ~BoundedObject(); PUBLISHED: @@ -50,23 +50,23 @@ PUBLISHED: BVT_dynamic_sphere, }; - INLINE_GRAPH void set_bound(BoundingVolumeType type); - INLINE_GRAPH void set_bound(const BoundingVolume &volume); + INLINE void set_bound(BoundingVolumeType type); + INLINE void set_bound(const BoundingVolume &volume); const BoundingVolume &get_bound() const; - INLINE_GRAPH bool mark_bound_stale(); - INLINE_GRAPH void force_bound_stale(); - INLINE_GRAPH bool is_bound_stale() const; + INLINE bool mark_bound_stale(); + INLINE void force_bound_stale(); + INLINE bool is_bound_stale() const; - INLINE_GRAPH void set_final(bool flag); - INLINE_GRAPH bool is_final() const; + INLINE void set_final(bool flag); + INLINE bool is_final() const; protected: virtual void propagate_stale_bound(); virtual BoundingVolume *recompute_bound(); - INLINE_GRAPH const BoundingVolume *get_bound_ptr() const; - INLINE_GRAPH BoundingVolume *set_bound_ptr(BoundingVolume *bound); + INLINE const BoundingVolume *get_bound_ptr() const; + INLINE BoundingVolume *set_bound_ptr(BoundingVolume *bound); private: enum Flags { @@ -77,9 +77,9 @@ private: // This is the data that must be cycled between pipeline stages. class EXPCL_PANDA CData : public CycleData { public: - INLINE_GRAPH CData(); - INLINE_GRAPH CData(const CData ©); - INLINE_GRAPH void operator = (const CData ©); + INLINE CData(); + INLINE CData(const CData ©); + INLINE void operator = (const CData ©); virtual CycleData *make_copy() const; @@ -106,9 +106,7 @@ private: friend class PandaNode; }; -#ifndef DONT_INLINE_GRAPH #include "boundedObject.I" -#endif #endif diff --git a/panda/src/gobj/config_gobj.cxx b/panda/src/gobj/config_gobj.cxx index 6e7d317fc9..4d8ddf8da3 100644 --- a/panda/src/gobj/config_gobj.cxx +++ b/panda/src/gobj/config_gobj.cxx @@ -17,8 +17,9 @@ //////////////////////////////////////////////////////////////////// #include -#include "config_gobj.h" #include "LOD.h" +#include "boundedObject.h" +#include "config_gobj.h" #include "drawable.h" #include "geom.h" #include "geomprimitives.h" @@ -163,6 +164,7 @@ ConfigureFn(config_gobj) { textures_down_square = config_gobj.GetBool("textures-square", false); } + BoundedObject::init_type(); Geom::init_type(); GeomLine::init_type(); GeomLinestrip::init_type(); diff --git a/panda/src/gobj/drawable.h b/panda/src/gobj/drawable.h index 0eec0cc175..e6e419691a 100644 --- a/panda/src/gobj/drawable.h +++ b/panda/src/gobj/drawable.h @@ -15,17 +15,15 @@ // panda3d@yahoogroups.com . // //////////////////////////////////////////////////////////////////// + #ifndef DDRAWABLE_H #define DDRAWABLE_H -// -//////////////////////////////////////////////////////////////////// -// Includes -//////////////////////////////////////////////////////////////////// -#include -#include -#include -#include +#include "pandabase.h" + +#include "boundedObject.h" +#include "writableConfigurable.h" +#include "referenceCount.h" //////////////////////////////////////////////////////////////////// // Defines diff --git a/panda/src/gobj/gobj_composite1.cxx b/panda/src/gobj/gobj_composite1.cxx index 5818a592fb..a6a2c7e2cd 100644 --- a/panda/src/gobj/gobj_composite1.cxx +++ b/panda/src/gobj/gobj_composite1.cxx @@ -1,4 +1,5 @@ +#include "boundedObject.cxx" #include "geom.cxx" #include "geomLine.cxx" #include "geomLinestrip.cxx" diff --git a/panda/src/gobj/imageBuffer.h b/panda/src/gobj/imageBuffer.h index 47cdaecb9e..87686123a9 100644 --- a/panda/src/gobj/imageBuffer.h +++ b/panda/src/gobj/imageBuffer.h @@ -38,9 +38,10 @@ class DisplayRegion; // Class : ImageBuffer // Description : //////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ImageBuffer : public dDrawable, public Namable { +class EXPCL_PANDA ImageBuffer : public ReferenceCount, + public WritableConfigurable, public Namable { PUBLISHED: - ImageBuffer() : dDrawable() { } + ImageBuffer() { } virtual ~ImageBuffer() { } public: @@ -49,10 +50,6 @@ public: virtual void copy(GraphicsStateGuardianBase *, const DisplayRegion *)=0; virtual void copy(GraphicsStateGuardianBase *, const DisplayRegion *, const RenderBuffer &rb)=0; - virtual void draw(GraphicsStateGuardianBase *)=0; - virtual void draw(GraphicsStateGuardianBase *, const DisplayRegion *)=0; - virtual void draw(GraphicsStateGuardianBase *, const DisplayRegion *, - const RenderBuffer &rb)=0; PUBLISHED: INLINE bool has_filename() const; @@ -83,6 +80,9 @@ public: return _type_handle; } static void init_type() { + // This indicates an inheritance from dDrawable, even though we + // don't any more. When we upgrade to Bam version 4.0 we will + // change this. dDrawable::init_type(); Namable::init_type(); register_type(_type_handle, "ImageBuffer", diff --git a/panda/src/gobj/pixelBuffer.cxx b/panda/src/gobj/pixelBuffer.cxx index cb30bc09eb..2d909ff63e 100644 --- a/panda/src/gobj/pixelBuffer.cxx +++ b/panda/src/gobj/pixelBuffer.cxx @@ -403,17 +403,3 @@ void PixelBuffer::copy(GraphicsStateGuardianBase *gsg, const DisplayRegion *dr, gsg->copy_pixel_buffer(this, dr, rb); } -void PixelBuffer::draw(GraphicsStateGuardianBase *) { - gobj_cat.error() - << "DisplayRegion required to draw pixel buffer.\n"; -} - -void PixelBuffer::draw(GraphicsStateGuardianBase *gsg, const DisplayRegion *dr) { - gsg->draw_pixel_buffer(this, dr); -} - -void PixelBuffer::draw(GraphicsStateGuardianBase *gsg, const DisplayRegion *dr, - const RenderBuffer &rb) { - gsg->draw_pixel_buffer(this, dr, rb); -} - diff --git a/panda/src/gobj/pixelBuffer.h b/panda/src/gobj/pixelBuffer.h index e7f2bface6..1ef7fe3d74 100644 --- a/panda/src/gobj/pixelBuffer.h +++ b/panda/src/gobj/pixelBuffer.h @@ -112,10 +112,6 @@ public: virtual void copy(GraphicsStateGuardianBase *gsg, const DisplayRegion *dr); virtual void copy(GraphicsStateGuardianBase *gsg, const DisplayRegion *dr, const RenderBuffer &rb); - virtual void draw(GraphicsStateGuardianBase *gsg); - virtual void draw(GraphicsStateGuardianBase *gsg, const DisplayRegion *dr); - virtual void draw(GraphicsStateGuardianBase *gsg, const DisplayRegion *dr, - const RenderBuffer &rb); INLINE void set_xsize(int size); INLINE void set_ysize(int size); diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index 6a494cd14b..12f7e6c506 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -521,20 +521,6 @@ void Texture::copy(GraphicsStateGuardianBase *gsg, const DisplayRegion *dr, gsg->copy_texture(prepare(gsg), dr, rb); } -void Texture::draw(GraphicsStateGuardianBase *) { - gobj_cat.error() - << "DisplayRegion required to draw texture.\n"; -} - -void Texture::draw(GraphicsStateGuardianBase *gsg, const DisplayRegion *dr) { - gsg->draw_texture(prepare(gsg), dr); -} - -void Texture::draw(GraphicsStateGuardianBase *gsg, const DisplayRegion *dr, - const RenderBuffer &rb) { - gsg->draw_texture(prepare(gsg), dr, rb); -} - //////////////////////////////////////////////////////////////////// // Function: Texture::mark_dirty // Access: Public diff --git a/panda/src/gobj/texture.h b/panda/src/gobj/texture.h index 783a8e66af..09221ae74f 100644 --- a/panda/src/gobj/texture.h +++ b/panda/src/gobj/texture.h @@ -122,10 +122,6 @@ public: virtual void copy(GraphicsStateGuardianBase *gsg, const DisplayRegion *dr); virtual void copy(GraphicsStateGuardianBase *gsg, const DisplayRegion *dr, const RenderBuffer &rb); - virtual void draw(GraphicsStateGuardianBase *gsg); - virtual void draw(GraphicsStateGuardianBase *gsg, const DisplayRegion *dr); - virtual void draw(GraphicsStateGuardianBase *gsg, const DisplayRegion *dr, - const RenderBuffer &rb); // These bits are used as parameters to Texture::mark_dirty() and // also TextureContext::mark_dirty() (and related functions in diff --git a/panda/src/graph/Sources.pp b/panda/src/graph/Sources.pp deleted file mode 100644 index 4a90d4ff6c..0000000000 --- a/panda/src/graph/Sources.pp +++ /dev/null @@ -1,105 +0,0 @@ -#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \ - dtoolutil:c dtoolbase:c dtool:m - -#begin lib_target - #define TARGET graph - #define LOCAL_LIBS \ - pstatclient putil mathutil - - #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx - - #define SOURCES \ - allTransitionsWrapper.I \ - allTransitionsWrapper.T allTransitionsWrapper.h arcChain.I \ - arcChain.h bitMask32Transition.h bitMaskTransition.T \ - bitMaskTransition.h \ - boundedObject.I boundedObject.N boundedObject.h \ - config_graph.h dftraverser.T dftraverser.h \ - graphHashGenerator.h graphReducer.h \ - immediateTransition.I immediateTransition.h \ - lmatrix4fTransition.h \ - matrixTransition.T matrixTransition.h multiNodeTransition.h \ - multiTransition.T multiTransition.h multiTransitionHelpers.I \ - multiTransitionHelpers.h namedNode.I namedNode.h node.I \ - node.h \ - nodeConnection.I \ - nodeConnection.h nodeRelation.I nodeRelation.N \ - nodeRelation.T nodeRelation.h nodeTransition.I \ - nodeTransition.N nodeTransition.h nodeTransitionCache.I \ - nodeTransitionCache.h nodeTransitionCacheEntry.I \ - nodeTransitionCacheEntry.h nodeTransitionWrapper.I \ - nodeTransitionWrapper.T nodeTransitionWrapper.h \ - nodeTransitions.I nodeTransitions.T nodeTransitions.h \ - nullLevelState.h nullTransitionWrapper.I \ - nullTransitionWrapper.h onOffTransition.I onOffTransition.h \ - onTransition.I onTransition.h pointerNameClass.h \ - pt_NamedNode.N pt_NamedNode.h pt_Node.N pt_Node.h \ - pt_NodeRelation.h setTransitionHelpers.T \ - setTransitionHelpers.h transitionDirection.h \ - traverserVisitor.T traverserVisitor.h vector_PT_Node.h \ - vector_PT_NodeRelation.h vector_NodeRelation_star.h wrt.T \ - wrt.h - - #define INCLUDED_SOURCES \ - allTransitionsWrapper.cxx \ - arcChain.cxx bitMask32Transition.cxx \ - boundedObject.cxx config_graph.cxx graphReducer.cxx \ - immediateTransition.cxx \ - lmatrix4fTransition.cxx \ - multiNodeTransition.cxx namedNode.cxx node.cxx \ - nodeConnection.cxx nodeRelation.cxx \ - nodeTransition.cxx nodeTransitionCache.cxx \ - nodeTransitionCacheEntry.cxx nodeTransitionWrapper.cxx \ - nodeTransitions.cxx \ - nullLevelState.cxx \ - nullTransitionWrapper.cxx \ - onOffTransition.cxx onTransition.cxx pt_NamedNode.cxx \ - pt_Node.cxx pt_NodeRelation.cxx vector_PT_Node.cxx \ - vector_PT_NodeRelation.cxx vector_NodeRelation_star.cxx \ - wrt.cxx - - #define INSTALL_HEADERS \ - allTransitionsWrapper.I \ - allTransitionsWrapper.T allTransitionsWrapper.h arcChain.I \ - arcChain.h bitMask32Transition.h \ - bitMaskTransition.T bitMaskTransition.h \ - boundedObject.I boundedObject.h config_graph.h dftraverser.T \ - dftraverser.h graphHashGenerator.h \ - graphReducer.h \ - immediateTransition.I immediateTransition.h lmatrix4fTransition.h \ - matrixTransition.T \ - matrixTransition.h \ - multiNodeTransition.h multiTransition.T \ - multiTransition.h multiTransitionHelpers.I \ - multiTransitionHelpers.h namedNode.I namedNode.h node.I node.h \ - nodeConnection.I \ - nodeConnection.h nodeRelation.I nodeRelation.T nodeRelation.h \ - nodeTransition.I nodeTransition.h nodeTransitionCache.I \ - nodeTransitionCache.h nodeTransitionCacheEntry.I \ - nodeTransitionCacheEntry.h nodeTransitionWrapper.I \ - nodeTransitionWrapper.T nodeTransitionWrapper.h nodeTransitions.I \ - nodeTransitions.T nodeTransitions.h \ - nullLevelState.h nullTransitionWrapper.I \ - nullTransitionWrapper.h onOffTransition.I onOffTransition.h \ - onTransition.I onTransition.h pointerNameClass.h pt_NamedNode.h \ - pt_Node.h pt_NodeRelation.h \ - setTransitionHelpers.T setTransitionHelpers.h \ - transitionDirection.h traverserVisitor.T traverserVisitor.h \ - vector_PT_Node.h vector_PT_NodeRelation.h vector_NodeRelation_star.h \ - wrt.T wrt.h - - #define IGATESCAN all - -#end lib_target - -#begin test_bin_target - #define TARGET test_graph - #define LOCAL_LIBS \ - graph putil - #define OTHER_LIBS $[OTHER_LIBS] pystub - - #define SOURCES \ - test_graph.cxx - -#end test_bin_target - diff --git a/panda/src/graph/allTransitionsWrapper.I b/panda/src/graph/allTransitionsWrapper.I deleted file mode 100644 index b5244b9806..0000000000 --- a/panda/src/graph/allTransitionsWrapper.I +++ /dev/null @@ -1,449 +0,0 @@ -// Filename: allTransitionsWrapper.I -// Created by: drose (21Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "nodeRelation.h" - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH AllTransitionsWrapper:: -AllTransitionsWrapper() { -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH AllTransitionsWrapper:: -AllTransitionsWrapper(const AllTransitionsWrapper ©) : - _cache(copy._cache), - _all_verified(copy._all_verified) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void AllTransitionsWrapper:: -operator = (const AllTransitionsWrapper ©) { - _cache = copy._cache; - _all_verified = copy._all_verified; -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH AllTransitionsWrapper:: -~AllTransitionsWrapper() { -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::init_from -// Access: Public, Static -// Description: This is a named constructor that creates an empty -// AllTransitionsWrapper ready to access the same type -// of NodeTransition as the other. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH AllTransitionsWrapper AllTransitionsWrapper:: -init_from(const AllTransitionsWrapper &) { - return AllTransitionsWrapper(); -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::is_empty -// Access: Public -// Description: Returns true if there are no Transitions stored in -// the wrapper, or false if there are any (even identity) -// Transitions. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool AllTransitionsWrapper:: -is_empty() const { - return - (_cache == (NodeTransitionCache *)NULL) || - _cache->is_empty(); -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::set_transition -// Access: Public -// Description: This flavor of set_transition() accepts a pointer to -// a NodeTransition only. It infers the type of the -// NodeTransition from the pointer. However, it is not -// valid to pass a NULL pointer to this flavor of -// set_transition; if the pointer might be NULL, use the -// above flavor instead (or just call clear_transition). -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH PT(NodeTransition) AllTransitionsWrapper:: -set_transition(NodeTransition *trans) { - nassertr(trans != (NodeTransition *)NULL, NULL); - nassertr(trans->get_handle() != TypeHandle::none(), NULL); - return set_transition(trans->get_handle(), trans); -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::has_transition -// Access: Public -// Description: Returns true if a transition associated with the -// indicated handle has been stored in the wrapper, or -// false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool AllTransitionsWrapper:: -has_transition(TypeHandle handle) const { - if (_cache == (NodeTransitionCache *)NULL) { - return false; - } - return _cache->has_transition(handle); -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::get_transition -// Access: Public -// Description: Returns the transition associated with the indicated -// handle, or NULL if no such transition has been stored -// in the wrapper. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransition *AllTransitionsWrapper:: -get_transition(TypeHandle handle) const { - if (_cache == (NodeTransitionCache *)NULL) { - return NULL; - } - return _cache->get_transition(handle); -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::clear -// Access: Public -// Description: Completely empties the set of Transitions stored in -// the wrapper. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void AllTransitionsWrapper:: -clear() { - _cache = (NodeTransitionCache *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::get_transitions -// Access: Public -// Description: Returns the entire cache of transitions. You -// shouldn't modify this, or probably even store it for -// any length of time. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH const NodeTransitionCache &AllTransitionsWrapper:: -get_transitions() const { - static NodeTransitionCache empty_transitions; - - if (_cache == (NodeTransitionCache *)NULL) { - return empty_transitions; - } - return *_cache; -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::is_identity -// Access: Public -// Description: Returns true if the wrapper represents an identity -// transition. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool AllTransitionsWrapper:: -is_identity() const { - if (_cache == (NodeTransitionCache *)NULL) { - return true; - } - return _cache->is_identity(); -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::compare_to -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH int AllTransitionsWrapper:: -compare_to(const AllTransitionsWrapper &other) const { - if (_cache == other._cache) { - return 0; - } - if (_cache == (NodeTransitionCache *)NULL) { - return other._cache->is_identity() ? 0 : -1; - } - if (other._cache == (NodeTransitionCache *)NULL) { - return _cache->is_identity() ? 0 : 1; - } - - return _cache->compare_to(*other._cache); -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::generate_hash -// Access: Public -// Description: Adds the transitions to the indicated hash generator. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void AllTransitionsWrapper:: -generate_hash(GraphHashGenerator &hashgen) const { - if (_cache != (NodeTransitionCache *)NULL) { - _cache->generate_hash(hashgen); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::make_identity -// Access: Public -// Description: Resets the wrapper to the empty set. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void AllTransitionsWrapper:: -make_identity() { - _cache = (NodeTransitionCache *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::extract_from -// Access: Public -// Description: Sets the wrapper to the set of transitions contained -// on the arc. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void AllTransitionsWrapper:: -extract_from(const NodeRelation *arc) { - nassertv(arc != (NodeRelation *)NULL); - if (arc->_transitions.is_empty()) { - _cache = (NodeTransitionCache *)NULL; - } else { - _cache = new NodeTransitionCache(arc->_transitions); - } - _all_verified.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::store_to -// Access: Public -// Description: Stores all the transitions in the wrapper to the arc. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void AllTransitionsWrapper:: -store_to(NodeRelation *arc) const { - nassertv(arc != (NodeRelation *)NULL); - NodeTransitionCache::store_to(_cache, arc, arc->_transitions); -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::compose_in_place -// Access: Public -// Description: Sets this transition to the composition of this -// transition and the following one. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void AllTransitionsWrapper:: -compose_in_place(const AllTransitionsWrapper &other) { - _cache = NodeTransitionCache::compose(_cache, other._cache); - _all_verified.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::compose_from -// Access: Public -// Description: Sets this transition to the composition of the two -// transitions. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void AllTransitionsWrapper:: -compose_from(const AllTransitionsWrapper &a, const AllTransitionsWrapper &b) { - _cache = NodeTransitionCache::compose(a._cache, b._cache); - _all_verified.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::invert_in_place -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void AllTransitionsWrapper:: -invert_in_place() { - _cache = NodeTransitionCache::invert(_cache); - _all_verified.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::invert_compose_in_place -// Access: Public -// Description: Sets this transition to the composition of this -// transition and the following one. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void AllTransitionsWrapper:: -invert_compose_in_place(const AllTransitionsWrapper &other) { - _cache = NodeTransitionCache::invert_compose(_cache, other._cache); - _all_verified.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::extract_from_cache -// Access: Public -// Description: Sets this wrapper to the set of transitions indicated -// in the cache on the arc. Also returns the arc's -// top_subtree indication. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH Node *AllTransitionsWrapper:: -extract_from_cache(const NodeRelation *arc) { - _cache = arc->_net_transitions; - _all_verified = arc->_all_verified; - if (wrt_cat.is_spam()) { - wrt_cat.spam() - << "AllTransitionsWrapper::extract_from_cache(" << *arc - << "), _all_verified = " << _all_verified << "\n"; - } - return arc->_top_subtree; -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::store_to_cache -// Access: Public -// Description: Completely replaces the cached state on the arc with -// what is represented here. This makes sense if we -// have computed the complete set of net transitions to -// the arc. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void AllTransitionsWrapper:: -store_to_cache(NodeRelation *arc, Node *top_subtree) { - arc->_top_subtree = top_subtree; - arc->_net_transitions = _cache; - arc->_all_verified = _all_verified; - - if (wrt_cat.is_spam()) { - wrt_cat.spam() - << "AllTransitionsWrapper::store_to_cache(" << *arc - << "), _all_verified = " << _all_verified << "\n"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::store_to_cache_partial -// Access: Public -// Description: Updates the cached state on the arc with what is -// represented here, but does not remove transitions on -// the arc's cache that are not mentioned here. This -// makes sense if this cache represents only some of the -// net transitions to the arc, but not necessarily all -// of them. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void AllTransitionsWrapper:: -store_to_cache_partial(NodeRelation *arc, Node *top_subtree) { - arc->_top_subtree = top_subtree; - arc->_net_transitions = - NodeTransitionCache::c_union(arc->_net_transitions, _cache); - - if (wrt_cat.is_spam()) { - wrt_cat.spam() - << "AllTransitionsWrapper::store_to_cache_partial(" << *arc - << "), _all_verified = " << _all_verified << "\n"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::is_cache_verified -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool AllTransitionsWrapper:: -is_cache_verified(UpdateSeq as_of) const { - if (wrt_cat.is_spam()) { - wrt_cat.spam() - << "AllTransitionsWrapper::is_cache_verified(" << as_of - << "), _all_verified = " << _all_verified << ", result = " - << (as_of <= _all_verified) << "\n"; - } - return as_of <= _all_verified; -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::set_computed_verified -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void AllTransitionsWrapper:: -set_computed_verified(UpdateSeq now) { - _cache = NodeTransitionCache::set_computed_verified(_cache, now); - _all_verified = now; - - if (wrt_cat.is_spam()) { - wrt_cat.spam() - << "AllTransitionsWrapper::set_computed_verified(" << now << ")\n"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::cached_compose -// Access: Public -// Description: Computes the composition of this wrapper's value with -// that indicated by value, using the cache as a helper, -// and stores the result in this wrapper. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void AllTransitionsWrapper:: -cached_compose(const AllTransitionsWrapper &cache, - const AllTransitionsWrapper &value, - UpdateSeq now) { - _cache = NodeTransitionCache::cached_compose(_cache, cache._cache, - value._cache, now); - _all_verified = now; -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::size -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH AllTransitionsWrapper::size_type AllTransitionsWrapper:: -size() const { - if (_cache == (NodeTransitionCache *)NULL) { - return 0; - } - return _cache->size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::begin -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH AllTransitionsWrapper::const_iterator AllTransitionsWrapper:: -begin() const { - if (_cache == (NodeTransitionCache *)NULL) { - return _empty_cache.begin(); - } - return _cache->begin(); -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::end -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH AllTransitionsWrapper::const_iterator AllTransitionsWrapper:: -end() const { - if (_cache == (NodeTransitionCache *)NULL) { - // We intentionally return begin() instead of end() here, just in - // case the "empty" cache accidentally gets something added to it. - return _empty_cache.begin(); - } - return _cache->end(); -} - -INLINE_GRAPH ostream &operator << (ostream &out, const AllTransitionsWrapper &ntw) { - ntw.output(out); - return out; -} diff --git a/panda/src/graph/allTransitionsWrapper.T b/panda/src/graph/allTransitionsWrapper.T deleted file mode 100644 index 6fd9a76e26..0000000000 --- a/panda/src/graph/allTransitionsWrapper.T +++ /dev/null @@ -1,49 +0,0 @@ -// Filename: allTransitionsWrapper.T -// Created by: drose (21Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: get_transition_into -// Description: This external template function is handy for -// extracting a transition of a particular type from the -// set. If the transition exists, it is automatically -// downcasted to the correct type and stored in the -// pointer given in the first parameter, and the return -// value is true. If the transition does not exist, the -// pointer is filled with NULL and the return value is -// false. -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH bool -get_transition_into(Transition *&ptr, const AllTransitionsWrapper &trans, - TypeHandle transition_type) { - NodeTransition *nt = trans.get_transition(transition_type); - if (nt == (NodeTransition *)NULL) { - ptr = (Transition *)NULL; - return false; - } - DCAST_INTO_R(ptr, nt, false); - return true; -} - -template -INLINE_GRAPH bool -get_transition_into(Transition *&ptr, const AllTransitionsWrapper &trans) { - return get_transition_into(ptr, trans, Transition::get_class_type()); -} - - diff --git a/panda/src/graph/allTransitionsWrapper.cxx b/panda/src/graph/allTransitionsWrapper.cxx deleted file mode 100644 index eb7c5b3da2..0000000000 --- a/panda/src/graph/allTransitionsWrapper.cxx +++ /dev/null @@ -1,104 +0,0 @@ -// Filename: allTransitionsWrapper.cxx -// Created by: drose (21Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "allTransitionsWrapper.h" -#include "nodeRelation.h" - -#include - -NodeTransitionCache AllTransitionsWrapper::_empty_cache; - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::set_transition -// Access: Public -// Description: This flavor of set_transition() accepts a specific -// TypeHandle, indicating the type of transition that we -// are setting, and a NodeTransition pointer indicating -// the value of the transition. The NodeTransition may -// be NULL indicating that the transition should be -// cleared. If the NodeTransition is not NULL, it must -// match the type indicated by the TypeHandle. -// -// The return value is a pointer to the *previous* -// transition in the set, if any, or NULL if there was -// none. -//////////////////////////////////////////////////////////////////// -PT(NodeTransition) AllTransitionsWrapper:: -set_transition(TypeHandle handle, NodeTransition *trans) { - if (_cache == (NodeTransitionCache *)NULL) { - _cache = new NodeTransitionCache; - - } else if (_cache->get_ref_count() != 1) { - // Copy-on-write. - _cache = new NodeTransitionCache(*_cache); - } - - _all_verified.clear(); - return _cache->set_transition(handle, trans); -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::clear_transition -// Access: Public -// Description: Removes any transition associated with the indicated -// handle from the set. -// -// The return value is a pointer to the previous -// transition in the set, if any, or NULL if there was -// none. -//////////////////////////////////////////////////////////////////// -PT(NodeTransition) AllTransitionsWrapper:: -clear_transition(TypeHandle handle) { - if (_cache == (NodeTransitionCache *)NULL) { - return NULL; - - } else if (_cache->get_ref_count() != 1) { - // Copy-on-write. - _cache = new NodeTransitionCache(*_cache); - } - - _all_verified.clear(); - return _cache->clear_transition(handle); -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void AllTransitionsWrapper:: -output(ostream &out) const { - if (_cache != (NodeTransitionCache *)NULL) { - out << *_cache; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: AllTransitionsWrapper::write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void AllTransitionsWrapper:: -write(ostream &out, int indent_level) const { - if (_cache != (NodeTransitionCache *)NULL) { - indent(out, indent_level) - << "Cache pointer is " << _cache << "\n"; - _cache->write(out, indent_level); - } -} - diff --git a/panda/src/graph/allTransitionsWrapper.h b/panda/src/graph/allTransitionsWrapper.h deleted file mode 100644 index 69c5251c9e..0000000000 --- a/panda/src/graph/allTransitionsWrapper.h +++ /dev/null @@ -1,139 +0,0 @@ -// Filename: allTransitionsWrapper.h -// Created by: drose (21Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef ALLTRANSITIONSWRAPPER_H -#define ALLTRANSITIONSWRAPPER_H - -// -// There are several flavors of TransitionWrappers. These are classes -// that represent one or a number of transitions simultaneously and -// are passed to template functions like df_traverse() and wrt() so -// that the same functions can be used to operate on either one -// transition type or a number of them. -// -// Since these classes are used as template parameters, they do not -// need to use inheritance or virtual functions; but they all must -// have a similar interface. -// - -#include - -#include "nodeTransition.h" -#include "nodeTransitionCache.h" -#include "config_graph.h" -#include "graphHashGenerator.h" - -#include - -class Node; -class NodeRelation; - -//////////////////////////////////////////////////////////////////// -// Class : AllTransitionsWrapper -// Description : This wrapper represents all transitions that might be -// stored on arcs. It is especially useful when -// performing a traversal or computing a wrt() and you -// want to determine the complete state at a given node. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA AllTransitionsWrapper { -public: - typedef AllTransitionsWrapper TransitionWrapper; - typedef GraphHashGenerator HashGenerator; - - INLINE_GRAPH AllTransitionsWrapper(); - INLINE_GRAPH AllTransitionsWrapper(const AllTransitionsWrapper ©); - INLINE_GRAPH void operator = (const AllTransitionsWrapper ©); - INLINE_GRAPH ~AllTransitionsWrapper(); - - INLINE_GRAPH static AllTransitionsWrapper - init_from(const AllTransitionsWrapper &other); - - INLINE_GRAPH bool is_empty() const; - PT(NodeTransition) set_transition(TypeHandle handle, - NodeTransition *trans); - INLINE_GRAPH PT(NodeTransition) set_transition(NodeTransition *trans); - PT(NodeTransition) clear_transition(TypeHandle handle); - INLINE_GRAPH bool has_transition(TypeHandle handle) const; - INLINE_GRAPH NodeTransition *get_transition(TypeHandle handle) const; - - INLINE_GRAPH void clear(); - - INLINE_GRAPH const NodeTransitionCache &get_transitions() const; - - INLINE_GRAPH bool is_identity() const; - INLINE_GRAPH int compare_to(const AllTransitionsWrapper &other) const; - INLINE_GRAPH void generate_hash(GraphHashGenerator &hashgen) const; - - INLINE_GRAPH void make_identity(); - INLINE_GRAPH void extract_from(const NodeRelation *arc); - INLINE_GRAPH void store_to(NodeRelation *arc) const; - - INLINE_GRAPH void compose_in_place(const AllTransitionsWrapper &other); - INLINE_GRAPH void compose_from(const AllTransitionsWrapper &a, - const AllTransitionsWrapper &b); - INLINE_GRAPH void invert_in_place(); - INLINE_GRAPH void invert_compose_in_place(const AllTransitionsWrapper &other); - - INLINE_GRAPH Node *extract_from_cache(const NodeRelation *arc); - INLINE_GRAPH void store_to_cache(NodeRelation *arc, Node *top_subtree); - INLINE_GRAPH void store_to_cache_partial(NodeRelation *arc, Node *top_subtree); - INLINE_GRAPH bool is_cache_verified(UpdateSeq as_of) const; - INLINE_GRAPH void set_computed_verified(UpdateSeq now); - - INLINE_GRAPH void cached_compose(const AllTransitionsWrapper &cache, - const AllTransitionsWrapper &value, - UpdateSeq now); - -public: - // STL-like definitions to allow read-only traversal of the - // individual transitions. Note that each of these is a - // NodeTransitionCacheEntry, not simply a PT(NodeTransition). - // Beware! It is not safe to use this interface outside of - // PANDA.DLL. - typedef NodeTransitionCache::const_iterator iterator; - typedef NodeTransitionCache::const_iterator const_iterator; - typedef NodeTransitionCache::value_type value_type; - typedef NodeTransitionCache::size_type size_type; - - INLINE_GRAPH size_type size() const; - INLINE_GRAPH const_iterator begin() const; - INLINE_GRAPH const_iterator end() const; - -public: - void output(ostream &out) const; - void write(ostream &out, int indent_level = 0) const; - -private: - PT(NodeTransitionCache) _cache; - UpdateSeq _all_verified; - - // This is a special cache object which is always around and always - // empty. It's used just so we can have a sensible return value - // from begin() and end() when our pointer is NULL. - static NodeTransitionCache _empty_cache; -}; - -EXPCL_PANDA INLINE_GRAPH ostream &operator << (ostream &out, const AllTransitionsWrapper &ntw); - -#include "allTransitionsWrapper.T" - -#ifndef DONT_INLINE_GRAPH -#include "allTransitionsWrapper.I" -#endif - -#endif diff --git a/panda/src/graph/arcChain.I b/panda/src/graph/arcChain.I deleted file mode 100644 index 6b1ea7d8ff..0000000000 --- a/panda/src/graph/arcChain.I +++ /dev/null @@ -1,537 +0,0 @@ -// Filename: arcChain.I -// Created by: drose (05Jan01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::ArcComponent::Constructor -// Access: Public -// Description: Constructs an ArcComponent that references a node. -// This kind of ArcComponent may *only* be at the head -// of the chain; i.e. _next must always be NULL. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH ArcChain::ArcComponent:: -ArcComponent(Node *node) : - _next(NULL) -{ -#ifdef DO_MEMORY_USAGE - MemoryUsage::update_type(this, get_class_type()); -#endif - _p._node = node; - nassertv(node != (Node *)NULL); - _p._node->ref(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::ArcComponent::Constructor -// Access: Public -// Description: Constructs an ArcComponent that references an arc. -// This kind of ArcComponent must be in the middle or -// tail of the chain; it may not be at the head of the -// chain; i.e. _next must never be NULL. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH ArcChain::ArcComponent:: -ArcComponent(NodeRelation *arc, ArcComponent *next) : - _next(next) -{ -#ifdef DO_MEMORY_USAGE - MemoryUsage::update_type(this, get_class_type()); -#endif - _p._arc = arc; - nassertv(_next != (ArcComponent *)NULL); - nassertv(arc != (NodeRelation *)NULL); - _p._arc->ref(); - _p._arc->ref_parent(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::ArcComponent::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH ArcChain::ArcComponent:: -ArcComponent(const ArcComponent ©) : - _next(copy._next) -{ -#ifdef DO_MEMORY_USAGE - MemoryUsage::update_type(this, get_class_type()); -#endif - if (has_arc()) { - _p._arc = copy._p._arc; - nassertv(_p._arc != (NodeRelation *)NULL); - _p._arc->ref(); - _p._arc->ref_parent(); - } else { - _p._node = copy._p._node; - nassertv(_p._node != (Node *)NULL); - _p._node->ref(); - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::ArcComponent::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH ArcChain::ArcComponent:: -~ArcComponent() { - if (has_arc()) { - nassertv(_p._arc != (NodeRelation *)NULL); - _p._arc->unref_parent(); - unref_delete(_p._arc); - } else { - nassertv(_p._node != (Node *)NULL); - unref_delete(_p._node); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::ArcComponent::has_arc -// Access: Public -// Description: Returns true if this component stores an arc, false -// if it stores a node. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool ArcChain::ArcComponent:: -has_arc() const { - return (_next != (ArcComponent *)NULL); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::ArcComponent::get_arc -// Access: Public -// Description: Returns the arc referenced by this component. It is -// an error to call this unless has_arc() has already -// returned true. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeRelation *ArcChain::ArcComponent:: -get_arc() const { - nassertr(has_arc(), (NodeRelation *)NULL); - return _p._arc; -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::ArcComponent::get_node -// Access: Public -// Description: Returns the node referenced by this component. If -// this component references a node (i.e. has_arc() is -// false), this will return that node; if the component -// references an arc (has_arc() is true), this will -// return the child node of the arc. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH Node *ArcChain::ArcComponent:: -get_node() const { - if (has_arc()) { - return _p._arc->get_child(); - } else { - return _p._node; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::ArcComponent::is_top_node -// Access: Public -// Description: Returns true if this component represents the top -// node in the chain. This is the one component at the -// top of the chain that represents a node; the rest of -// the chain represents arcs. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool ArcChain::ArcComponent:: -is_top_node() const { - return (_next == (ArcComponent *)NULL); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::ArcComponent::is_top_arc -// Access: Public -// Description: Returns true if this component represents the top arc -// in the chain. This is the component just below the -// top of the chain; the highest component in the chain -// that still represents an arc. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool ArcChain::ArcComponent:: -is_top_arc() const { - return (_next != (ArcComponent *)NULL && _next->is_top_node()); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::ArcComponent::get_next -// Access: Public -// Description: Returns the next component in the chain. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH ArcChain::ArcComponent *ArcChain::ArcComponent:: -get_next() const { - return _next; -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::ArcComponent::set_next -// Access: Public -// Description: Changes the next component in the chain. This breaks -// the chain at this component and relinks it to another -// chain. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void ArcChain::ArcComponent:: -set_next(ArcComponent *next) { - nassertv(next != (ArcComponent *)NULL); - nassertv(_next != (ArcComponent *)NULL); - - _next = next; -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::ForwardIterator::Constructor -// Access: Public -// Description: This is an STL-style iterator that can be used to -// traverse the full list of arcs traversed so far by -// the ArcChain. Its primary purpose is as a -// parameter to wrt() so we can compute a correct -// relative wrt to the particular instance we've reached -// so far. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH ArcChain::ForwardIterator:: -ForwardIterator(ArcChain::ArcComponent *comp) : _comp(comp) { -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::ForwardIterator::Dereference Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeRelation *ArcChain::ForwardIterator:: -operator * () const { - nassertr(_comp != (ArcComponent *)NULL, NULL); - return _comp->get_arc(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::ForwardIterator::Increment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void ArcChain::ForwardIterator:: -operator ++() { - nassertv(_comp != (ArcComponent *)NULL); - if (_comp->is_top_arc()) { - // We only visit arcs, not nodes. When we reach the end of the - // list of arcs (i.e. the "top" arc), we stop. - _comp = (ArcComponent *)NULL; - } else { - _comp = _comp->get_next(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::ForwardIterator::Equality Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool ArcChain::ForwardIterator:: -operator == (const ArcChain::ForwardIterator &other) const { - return _comp == other._comp; -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::ForwardIterator::Inequality Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool ArcChain::ForwardIterator:: -operator != (const ArcChain::ForwardIterator &other) const { - return _comp != other._comp; -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::Default Constructor -// Access: Public -// Description: This constructs an empty ArcChain with no nodes. It -// cannot be extended, since you cannot add arcs without -// first specifying the top node. Use the constructor -// that receives a node if you ever want to do anything -// with this chain. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH ArcChain:: -ArcChain() { -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::Constructor -// Access: Public -// Description: This constructs an empty ArcChain with a single node. -// This chain may now be extended by repeatedly calling -// push_back() with each arc below that node in -// sequence. -// -// If the Node pointer is NULL, this quietly creates an -// empty ArcChain. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH ArcChain:: -ArcChain(Node *top_node) { - if (top_node != (Node *)NULL) { - _head = new ArcComponent(top_node); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH ArcChain:: -ArcChain(const ArcChain ©) : - _head(copy._head) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void ArcChain:: -operator = (const ArcChain ©) { - _head = copy._head; -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::is_empty -// Access: Public -// Description: Returns true if the ArcChain contains no nodes and no -// arcs. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool ArcChain:: -is_empty() const { - return (_head == (ArcComponent *)NULL); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::is_singleton -// Access: Public -// Description: Returns true if the ArcChain contains exactly one -// node, and no arcs. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool ArcChain:: -is_singleton() const { - return (_head != (ArcComponent *)NULL && _head->is_top_node()); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::has_arcs -// Access: Public -// Description: Returns true if the ArcChain contains at least one -// arc, and therefore at least two nodes. This is the -// same thing as asking get_num_arcs() > 0, but is -// easier to compute. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool ArcChain:: -has_arcs() const { - return (_head != (ArcComponent *)NULL && !_head->is_top_node()); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::get_num_arcs -// Access: Public -// Description: Returns the number of arcs in the path. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH int ArcChain:: -get_num_arcs() const { - if (!has_arcs()) { - return 0; - } - return get_num_nodes() - 1; -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::node -// Access: Public -// Description: Returns the bottom node of the path, or NULL if the -// path is empty. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH Node *ArcChain:: -node() const { - if (is_empty()) { - return (Node *)NULL; - } - return _head->get_node(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::arc -// Access: Public -// Description: Returns the bottom arc of the path, or NULL if the -// path is empty or is a singleton. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeRelation *ArcChain:: -arc() const { - if (!has_arcs()) { - // A singleton or empty list. - return (NodeRelation *)NULL; - } - return _head->get_arc(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::begin -// Access: Public -// Description: Returns an iterator that can be used to traverse the -// list of arcs. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH ArcChain::const_iterator ArcChain:: -begin() const { - if (empty()) { - return ForwardIterator(); - } else { - return ForwardIterator(_head); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::end -// Access: Public -// Description: Returns an iterator that can be used to traverse the -// list of arcs. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH ArcChain::const_iterator ArcChain:: -end() const { - return ForwardIterator(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::empty -// Access: Public -// Description: Returns true if the list of arcs returned by begin() -// .. end() is empty (i.e. begin() == end()), false -// otherwise. This is the same as !has_arcs(). -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool ArcChain:: -empty() const { - return (_head == (ArcComponent *)NULL || _head->is_top_node()); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::push_back -// Access: Public -// Description: Appends the indicated arc onto the end of the chain. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void ArcChain:: -push_back(NodeRelation *arc) { - // It is invalid to push an arc onto a chain that does not already - // have at least a top node. - nassertv(_head != (ArcComponent *)NULL); - _head = new ArcComponent(arc, _head); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::pop_back -// Access: Public -// Description: Removes the last arc from the end of the chain. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void ArcChain:: -pop_back() { - nassertv(_head != (ArcComponent *)NULL); - _head = _head->get_next(); - - // It is invalid to pop off the top node of the chain. - nassertv(_head != (ArcComponent *)NULL); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::back -// Access: Public -// Description: Returns the last arc in the chain. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeRelation *ArcChain:: -back() const { - nassertr(_head != (ArcComponent *)NULL, (NodeRelation *)NULL); - return _head->get_arc(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::operator == -// Access: Public -// Description: Returns true if the two chains are equivalent; that -// is, if they contain the same list of arcs in the same -// order. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool ArcChain:: -operator == (const ArcChain &other) const { - return (compare_to(other) == 0); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::operator != -// Access: Public -// Description: Returns true if the two chains are not equivalent. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool ArcChain:: -operator != (const ArcChain &other) const { - return !operator == (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::operator < -// Access: Public -// Description: Returns true if this ArcChain sorts before the other -// one, false otherwise. The sorting order of two -// nonequivalent ArcChains is consistent but undefined, -// and is useful only for storing ArcChains in a sorted -// container like an STL set. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool ArcChain:: -operator < (const ArcChain &other) const { - return (compare_to(other) < 0); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::compare_to -// Access: Public -// Description: Returns a number less than zero if this ArcChain -// sorts before the other one, greater than zero if it -// sorts after, or zero if they are equivalent. -// -// Two ArcChains are considered equivalent if they -// consist of exactly the same list of arcs in the same -// order. Otherwise, they are different; different -// ArcChains will be ranked in a consistent but -// undefined ordering; the ordering is useful only for -// placing the ArcChains in a sorted container like an -// STL set. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH int ArcChain:: -compare_to(const ArcChain &other) const { - return r_compare_to(_head, other._head); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::output -// Access: Public -// Description: Writes a sensible description of the ArcChain to the -// indicated output stream. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void ArcChain:: -output(ostream &out) const { - if (_head == (ArcComponent *)NULL) { - out << "(empty)"; - } else { - r_output(out, _head); - } -} - -INLINE_GRAPH ostream &operator << (ostream &out, const ArcChain &arc_chain) { - arc_chain.output(out); - return out; -} - diff --git a/panda/src/graph/arcChain.cxx b/panda/src/graph/arcChain.cxx deleted file mode 100644 index 965f775519..0000000000 --- a/panda/src/graph/arcChain.cxx +++ /dev/null @@ -1,214 +0,0 @@ -// Filename: arcChain.cxx -// Created by: drose (05Jan01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "arcChain.h" -#include "node.h" -#include "namedNode.h" - -TypeHandle ArcChain::_type_handle; -TypeHandle ArcChain::ArcComponent::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::ArcComponent::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void ArcChain::ArcComponent:: -operator = (const ArcComponent ©) { - // We have to be careful with the reference counts here, - // particularly since we might be changing the pointer type from arc - // pointer to node pointer, or vice-versa, with this assignment. - - // First, ref the new pointer once, so we don't accidentally delete - // in the interim. - if (copy.has_arc()) { - copy._p._arc->ref(); - copy._p._arc->ref_parent(); - } else { - copy._p._node->ref(); - } - - // Now unref the old pointer. - if (has_arc()) { - _p._arc->unref_parent(); - unref_delete(_p._arc); - } else { - unref_delete(_p._node); - } - - // Now reassign the pointers. - _next = copy._next; - if (has_arc()) { - _p._arc = copy._p._arc; - } else { - _p._node = copy._p._node; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::get_num_nodes -// Access: Public -// Description: Returns the number of nodes in the path. This is -// always one more than the number of arcs (except for -// a completely empty path). -//////////////////////////////////////////////////////////////////// -int ArcChain:: -get_num_nodes() const { - int num = 0; - ArcComponent *comp = _head; - while (comp != (ArcComponent *)NULL) { - num++; - comp = comp->get_next(); - } - return num; -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::get_node -// Access: Public -// Description: Returns the nth node of the path, where 0 is the -// bottom node and get_num_nodes() - 1 is the top node. -// This requires iterating through the path. -//////////////////////////////////////////////////////////////////// -Node *ArcChain:: -get_node(int index) const { - nassertr(index >= 0 && index < get_num_nodes(), NULL); - - ArcComponent *comp = _head; - while (index > 0) { - // If this assertion fails, the index was out of range. - nassertr(comp != (ArcComponent *)NULL, NULL); - comp = comp->get_next(); - index--; - } - - // If this assertion fails, the index was out of range. - nassertr(comp != (ArcComponent *)NULL, NULL); - return comp->get_node(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::get_arc -// Access: Public -// Description: Returns the nth arc of the path, where 0 is the arc -// above the bottom node node and get_num_arcs() - 1 is -// the arc below the top node. This requires iterating -// through the path. -//////////////////////////////////////////////////////////////////// -NodeRelation *ArcChain:: -get_arc(int index) const { - nassertr(index >= 0 && index < get_num_arcs(), NULL); - - ArcComponent *comp = _head; - while (index > 0) { - // If this assertion fails, the index was out of range. - nassertr(comp != (ArcComponent *)NULL, NULL); - comp = comp->get_next(); - index--; - } - - // If either assertion fails, the index was out of range. - nassertr(comp != (ArcComponent *)NULL, NULL); - nassertr(comp->has_arc(), NULL); - return comp->get_arc(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::get_top_node -// Access: Public -// Description: Returns the top node of the path, or NULL if the path -// is empty. This requires iterating through the path. -//////////////////////////////////////////////////////////////////// -Node *ArcChain:: -get_top_node() const { - if (is_empty()) { - return (Node *)NULL; - } - - ArcComponent *comp = _head; - while (!comp->is_top_node()) { - comp = comp->get_next(); - nassertr(comp != (ArcComponent *)NULL, NULL); - } - - return comp->get_node(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::r_output -// Access: Private -// Description: The recursive implementation of output(), this writes -// the names of each arc component in order from -// beginning to end, by first walking to the end of the -// linked list and then outputting from there. -//////////////////////////////////////////////////////////////////// -void ArcChain:: -r_output(ostream &out, ArcComponent *comp) const { - ArcComponent *next = comp->get_next(); - if (next != (ArcComponent *)NULL) { - // This is not the head of the list; keep going up. - r_output(out, next); - out << "/"; - } - - // Now output this component. - Node *node = comp->get_node(); - if (node->is_of_type(NamedNode::get_class_type())) { - NamedNode *named_node = DCAST(NamedNode, node); - if (named_node->has_name()) { - out << named_node->get_name(); - } else { - out << node->get_type(); - } - } else { - out << node->get_type(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: ArcChain::r_compare_to -// Access: Private, Static -// Description: The recursive implementation of compare_to(). Returns -// < 0 if a sorts before b, > 0 if b sorts before a, or -// == 0 if they are equivalent. -//////////////////////////////////////////////////////////////////// -int ArcChain:: -r_compare_to(const ArcComponent *a, const ArcComponent *b) { - if (a == b) { - return 0; - - } else if (a == (const ArcComponent *)NULL) { - return -1; - - } else if (b == (const ArcComponent *)NULL) { - return 1; - - } else if (a->has_arc() != b->has_arc()) { - return a->has_arc() - b->has_arc(); - - } else if (a->has_arc() && (a->get_arc() != b->get_arc())) { - return a->get_arc() - b->get_arc(); - - } else if (!a->has_arc() && (a->get_node() != b->get_node())) { - return a->get_node() - b->get_node(); - - } else { - return r_compare_to(a->get_next(), b->get_next()); - } -} - diff --git a/panda/src/graph/arcChain.h b/panda/src/graph/arcChain.h deleted file mode 100644 index a905bfdc5b..0000000000 --- a/panda/src/graph/arcChain.h +++ /dev/null @@ -1,200 +0,0 @@ -// Filename: arcChain.h -// Created by: drose (05Jan01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef ARCCHAIN_H -#define ARCCHAIN_H - -#include - -#include "nodeRelation.h" -#include "node.h" - -#include -#include -#include -#include - -//////////////////////////////////////////////////////////////////// -// Class : ArcChain -// Description : This defines a singly-linked chain of arcs from one -// point (e.g. the root of the scene graph) to another -// point (e.g. a leaf), although no assumption is made -// about the relationship between the arcs. It is -// simply a list of arcs that may only be lengthened or -// shortened, or copied. -// -// This list may be copied by reference using the copy -// constructor; the new copy may be appended to without -// modifying the source (but individual nodes may not be -// modified). -// -// This serves as the fundamental implementation of -// NodePaths, for instance, and also is used during -// render traversals to manage the list of arcs -// traversed so far (and thus compute unambiguous -// wrt's). -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ArcChain { -protected: - // We maintain our own linked list structure here instead of using - // some STL structure, so we can efficiently copy-construct these - // things by sharing the initial part of the list. - - // We have a singly-linked list whose head is the bottom arc of the - // path, and whose tail is the top arc of the path. Thus, we can - // copy the entire path by simply copying the head pointer, and we - // can then append to or shorten our own path without affecting the - // paths we're sharing ArcComponents with. Very LISPy. - - // Normally, an ArcChain represents a list of arcs from the root of - // some graph down to a leaf. This kind of structure works pretty - // well because the ArcChain keeps a reference count to each arc, - // which in turn keeps a reference count to each child node. This - // means each node in the chain is reference counted, *except* the - // top node. - - // To ensure that we also reference count the top node, we allow - // each ArcComponent to store either a pointer to an arc or, if it - // is the last node in the chain (and *only* if it is the last node - // in the chain), a pointer to a node. Thus, the last ArcComponent - // in the chain will store a reference-counting pointer to the - // chain's top node. - - class EXPCL_PANDA ArcComponent : public ReferenceCount { - public: - INLINE_GRAPH ArcComponent(Node *node); - INLINE_GRAPH ArcComponent(NodeRelation *arc, ArcComponent *next); - INLINE_GRAPH ArcComponent(const ArcComponent ©); - void operator = (const ArcComponent ©); - INLINE_GRAPH ~ArcComponent(); - - INLINE_GRAPH bool has_arc() const; - INLINE_GRAPH NodeRelation *get_arc() const; - INLINE_GRAPH Node *get_node() const; - INLINE_GRAPH bool is_top_node() const; - INLINE_GRAPH bool is_top_arc() const; - - INLINE_GRAPH ArcComponent *get_next() const; - INLINE_GRAPH void set_next(ArcComponent *next); - - private: - union { - // These are plain pointers instead of PT's, because they are - // stored in a union. We manage the reference counts by hand in - // the constructors and destructor. - NodeRelation *_arc; - Node *_node; - } _p; - PT(ArcComponent) _next; - - public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - ReferenceCount::init_type(); - register_type(_type_handle, "ArcChain::ArcComponent", - ReferenceCount::get_class_type()); - } - - private: - static TypeHandle _type_handle; - }; - - PT(ArcComponent) _head; - - // This is a supporting class for iterating through all the arcs via - // begin() .. end(). - class EXPCL_PANDA ForwardIterator { - public: - INLINE_GRAPH ForwardIterator(ArcComponent *comp = NULL); - INLINE_GRAPH NodeRelation *operator * () const; - INLINE_GRAPH void operator ++(); - INLINE_GRAPH bool operator == (const ForwardIterator &other) const; - INLINE_GRAPH bool operator != (const ForwardIterator &other) const; - - private: - ArcComponent *_comp; - }; - -public: - typedef ForwardIterator iterator; - typedef ForwardIterator const_iterator; - - INLINE_GRAPH ArcChain(); - INLINE_GRAPH ArcChain(Node *top_node); - INLINE_GRAPH ArcChain(const ArcChain ©); - INLINE_GRAPH void operator = (const ArcChain ©); - - // Methods to query an ArcChain's contents. -PUBLISHED: - INLINE_GRAPH bool is_empty() const; - INLINE_GRAPH bool is_singleton() const; - INLINE_GRAPH bool has_arcs() const; - int get_num_nodes() const; - Node *get_node(int index) const; - - INLINE_GRAPH int get_num_arcs() const; - NodeRelation *get_arc(int index) const; - - Node *get_top_node() const; - INLINE_GRAPH Node *node() const; - INLINE_GRAPH NodeRelation *arc() const; - -public: - // Methods to make an ArcChain behave like an STL container. - - INLINE_GRAPH const_iterator begin() const; - INLINE_GRAPH const_iterator end() const; - INLINE_GRAPH bool empty() const; - - INLINE_GRAPH void push_back(NodeRelation *arc); - INLINE_GRAPH void pop_back(); - INLINE_GRAPH NodeRelation *back() const; - - INLINE_GRAPH bool operator == (const ArcChain &other) const; - INLINE_GRAPH bool operator != (const ArcChain &other) const; - INLINE_GRAPH bool operator < (const ArcChain &other) const; - INLINE_GRAPH int compare_to(const ArcChain &other) const; - - INLINE_GRAPH void output(ostream &out) const; - -private: - void r_output(ostream &out, ArcComponent *comp) const; - static int r_compare_to(const ArcComponent *a, const ArcComponent *v); - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - ArcComponent::init_type(); - register_type(_type_handle, "ArcChain"); - } - -private: - static TypeHandle _type_handle; -}; - -INLINE_GRAPH ostream &operator << (ostream &out, const ArcChain &arc_chain); - -#ifndef DONT_INLINE_GRAPH -#include "arcChain.I" -#endif - -#endif diff --git a/panda/src/graph/bitMask32Transition.cxx b/panda/src/graph/bitMask32Transition.cxx deleted file mode 100644 index fc0cc7c02e..0000000000 --- a/panda/src/graph/bitMask32Transition.cxx +++ /dev/null @@ -1,25 +0,0 @@ -// Filename: bitMask32Transition.cxx -// Created by: drose (08Jun00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "bitMask32Transition.h" - -#ifdef __GNUC__ -#pragma implementation -#endif - - diff --git a/panda/src/graph/bitMask32Transition.h b/panda/src/graph/bitMask32Transition.h deleted file mode 100644 index 07b68bb121..0000000000 --- a/panda/src/graph/bitMask32Transition.h +++ /dev/null @@ -1,45 +0,0 @@ -// Filename: bitMask32Transition.h -// Created by: drose (08Jun00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef BITMASK32TRANSITION_H -#define BITMASK32TRANSITION_H - -#include - -#include "bitMaskTransition.h" - -#include - - -//////////////////////////////////////////////////////////////////// -// Class : BitMask32Transition -// Description : This is just an instantation of BitMaskTransition -// using BitMask32, the most common bitmask type. -//////////////////////////////////////////////////////////////////// - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, BitMaskTransition); - -typedef BitMaskTransition BitMask32Transition; - -#ifdef __GNUC__ -#pragma interface -#endif - -#endif - - diff --git a/panda/src/graph/bitMaskTransition.T b/panda/src/graph/bitMaskTransition.T deleted file mode 100644 index 6e8163a4d5..0000000000 --- a/panda/src/graph/bitMaskTransition.T +++ /dev/null @@ -1,220 +0,0 @@ -// Filename: bitMaskTransition.T -// Created by: drose (08Jun00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -template -TypeHandle BitMaskTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: BitMaskTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH BitMaskTransition:: -BitMaskTransition() { - _and = MaskType::all_on(); - _or = MaskType::all_off(); -} - -//////////////////////////////////////////////////////////////////// -// Function: BitMaskTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH BitMaskTransition:: -BitMaskTransition(const MaskType &and, const MaskType &or) { - _and = and; - _or = or; -} - -//////////////////////////////////////////////////////////////////// -// Function: BitMaskTransition::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH BitMaskTransition:: -BitMaskTransition(const BitMaskTransition ©) : - NodeTransition(copy), - _and(copy._and), - _or(copy._or) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: BitMaskTransition::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH void BitMaskTransition:: -operator = (const BitMaskTransition ©) { - NodeTransition::operator = (copy); - _and = copy._and; - _or = copy._or; -} - -//////////////////////////////////////////////////////////////////// -// Function: BitMaskTransition::set_and -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH void BitMaskTransition:: -set_and(const MaskType &and) { - _and = and; - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: BitMaskTransition::get_and -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH const MaskType &BitMaskTransition:: -get_and() const { - return _and; -} - -//////////////////////////////////////////////////////////////////// -// Function: BitMaskTransition::set_or -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH void BitMaskTransition:: -set_or(const MaskType &or) { - _or = or; - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: BitMaskTransition::get_or -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH const MaskType &BitMaskTransition:: -get_or() const { - return _or; -} - -//////////////////////////////////////////////////////////////////// -// Function: BitMaskTransition::compose -// Access: Public, Virtual -// Description: Returns a new transition that corresponds to the -// composition of this transition with the second -// transition (which must be of an equivalent type). -// This may return the same pointer as either source -// transition. Applying the transition returned from -// this function to an attribute attribute will produce -// the same effect as applying each transition -// separately. -//////////////////////////////////////////////////////////////////// -template -NodeTransition *BitMaskTransition:: -compose(const NodeTransition *other) const { - const BitMaskTransition *ot; - DCAST_INTO_R(ot, other, NULL); - - if (ot->_priority < _priority) { - // The other transition is too low-priority; the result is - // unchanged. - return (BitMaskTransition *)this; - } - - return make_with_masks(ot->_and & _and, ot->_or | _or); -} - -//////////////////////////////////////////////////////////////////// -// Function: BitMaskTransition::invert -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -NodeTransition *BitMaskTransition:: -invert() const { - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: BitMaskTransition::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -void BitMaskTransition:: -output(ostream &out) const { - out << "&"; - _and.output_hex(out); - out << " |"; - _or.output_hex(out); -} - -//////////////////////////////////////////////////////////////////// -// Function: BitMaskTransition::internal_compare_to -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -int BitMaskTransition:: -internal_compare_to(const NodeTransition *other) const { - const BitMaskTransition *ot; - DCAST_INTO_R(ot, other, false); - - int result = _and.compare_to(ot->_and); - if (result == 0) { - result = _or.compare_to(ot->_or); - } - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: BitMaskTransition::internal_generate_hash -// Access: Protected, Virtual -// Description: Should be overridden by particular NodeTransitions to -// generate a hash value uniquifying this particular -// transition. -//////////////////////////////////////////////////////////////////// -template -void BitMaskTransition:: -internal_generate_hash(GraphHashGenerator &hashgen) const { - _and.generate_hash(hashgen); - _or.generate_hash(hashgen); -} - -//////////////////////////////////////////////////////////////////// -// Function: BitMaskTransition::make_with_masks -// Access: Protected, Virtual -// Description: This function creates a new BitMaskTransition of the -// appropriate type, given the indicated and & or masks. -// -// This is a pure virtual function and normally wouldn't -// require a definition, but for some reason VC++ -// objects to instantiating the template if it's missing -// any function definitions--even those for pure-virtual -// functions. -//////////////////////////////////////////////////////////////////// -template -BitMaskTransition *BitMaskTransition:: -make_with_masks(const MaskType &, const MaskType &) const { - return NULL; -} diff --git a/panda/src/graph/bitMaskTransition.h b/panda/src/graph/bitMaskTransition.h deleted file mode 100644 index 2c9ddab25b..0000000000 --- a/panda/src/graph/bitMaskTransition.h +++ /dev/null @@ -1,91 +0,0 @@ -// Filename: bitMaskTransition.h -// Created by: drose (08Jun00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef BITMASKTRANSITION_H -#define BITMASKTRANSITION_H - -#include - -#include "nodeTransition.h" - -class NodeRelation; - -//////////////////////////////////////////////////////////////////// -// Class : BitMaskTransition -// Description : This is an abstract template class that encapsulates -// transitions on a bitmask. Each transition may add -// and/or remove bits from the accumulated bitmask. -// -// It's the base class for a number of scene graph -// transitions like DrawMaskTransition and -// CollideMaskTransition. -//////////////////////////////////////////////////////////////////// -template -class BitMaskTransition : public NodeTransition { -protected: - INLINE_GRAPH BitMaskTransition(); - INLINE_GRAPH BitMaskTransition(const MaskType &and, const MaskType &or); - INLINE_GRAPH BitMaskTransition(const BitMaskTransition ©); - INLINE_GRAPH void operator = (const BitMaskTransition ©); - -public: - INLINE_GRAPH void set_and(const MaskType &and); - INLINE_GRAPH const MaskType &get_and() const; - INLINE_GRAPH void set_or(const MaskType &or); - INLINE_GRAPH const MaskType &get_or() const; - - virtual NodeTransition *compose(const NodeTransition *other) const; - virtual NodeTransition *invert() const; - - virtual void output(ostream &out) const; - -protected: - virtual int internal_compare_to(const NodeTransition *other) const; - virtual void internal_generate_hash(GraphHashGenerator &hashgen) const; - -protected: - virtual BitMaskTransition * - make_with_masks(const MaskType &and, const MaskType &or) const=0; - -private: - MaskType _and, _or; - -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() { - NodeTransition::init_type(); - MaskType::init_type(); - register_type(_type_handle, - string("BitMaskTransition<") + - MaskType::get_class_type().get_name() + ">", - NodeTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "bitMaskTransition.T" - -#endif diff --git a/panda/src/graph/boundedObject.N b/panda/src/graph/boundedObject.N deleted file mode 100644 index 93a0d92259..0000000000 --- a/panda/src/graph/boundedObject.N +++ /dev/null @@ -1 +0,0 @@ -forcetype BoundedObject diff --git a/panda/src/graph/config_graph.cxx b/panda/src/graph/config_graph.cxx deleted file mode 100644 index 716ed894f5..0000000000 --- a/panda/src/graph/config_graph.cxx +++ /dev/null @@ -1,105 +0,0 @@ -// Filename: config_graph.cxx -// Created by: drose (01Oct99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "config_graph.h" -#include "arcChain.h" -#include "namedNode.h" -#include "node.h" -#include "nodeRelation.h" -#include "nodeTransition.h" -#include "nodeTransitionCache.h" -#include "onOffTransition.h" -#include "multiNodeTransition.h" -#include "immediateTransition.h" - -#include - -Configure(config_graph); -NotifyCategoryDef(graph, ""); -NotifyCategoryDef(wrt, graph_cat); - -ConfigureFn(config_graph) { - init_libgraph(); -} - -// Set this true if you want to cache some of the work of computing -// wrt(), so that the second time wrt() is called on a particular -// node-node pair it will be much cheaper than the first time. This -// is the default behavior; you'd only want to turn it off if for some -// reason it was broken. This is true by default and cannot be turned -// off in optimized (NDEBUG) mode. -const bool cache_wrt = config_graph.GetBool("cache-wrt", true); - -// Set this true to force abort() to be called if an ambiguous wrt() -// call is made. This will hopefully allow the programmer to get a -// stack dump and determine who is issuing the ambiguous wrt(). This -// cannot be turned on in optimized (NDEBUG) mode. -const bool ambiguous_wrt_abort = config_graph.GetBool("ambiguous-wrt-abort", false); - -// Set this true to double-check the cached value of wrt(), above, by -// performing an explicit uncached wrt() and comparing the results. -// Obviously very slow. This cannot be turned on in optimized -// (NDEBUG) mode. -const bool paranoid_wrt = config_graph.GetBool("paranoid-wrt", false); - -// This is similar to paranoid-wrt, above. Set it true to -// double-check each parent/unparent operation, to make sure that it -// always places the arc in the correct position in the parent's arc -// list, and that the arc list always remains properly sorted. Again, -// it cannot be turned on in NDEBUG mode. -const bool paranoid_graph = config_graph.GetBool("paranoid-graph", false); - - -//////////////////////////////////////////////////////////////////// -// Function: init_libgraph -// Description: Initializes the library. This must be called at -// least once before any of the functions or classes in -// this library can be used. Normally it will be -// called by the static initializers and need not be -// called explicitly, but special cases exist. -//////////////////////////////////////////////////////////////////// -void -init_libgraph() { - static bool initialized = false; - if (initialized) { - return; - } - initialized = true; - - void init_last_graph_update(); - init_last_graph_update(); - - ArcChain::init_type(); - BoundedObject::init_type(); - NamedNode::init_type(); - Node::init_type(); - NodeRelation::init_type(); - NodeTransition::init_type(); - NodeTransitionCache::init_type(); - OnOffTransition::init_type(); - MultiNodeTransition::init_type(); - ImmediateTransition::init_type(); - - NodeRelation::register_with_factory(); - - //Registration of writeable object's creation - //functions with BamReader's factory - Node::register_with_read_factory(); - NamedNode::register_with_read_factory(); - NodeRelation::register_with_read_factory(); -} diff --git a/panda/src/graph/config_graph.h b/panda/src/graph/config_graph.h deleted file mode 100644 index d3cf1b591f..0000000000 --- a/panda/src/graph/config_graph.h +++ /dev/null @@ -1,36 +0,0 @@ -// Filename: config_graph.h -// Created by: drose (01Oct99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CONFIG_GRAPH_H -#define CONFIG_GRAPH_H - -#include -#include - -NotifyCategoryDecl(graph, EXPCL_PANDA, EXPTP_PANDA); -NotifyCategoryDecl(wrt, EXPCL_PANDA, EXPTP_PANDA); - -// Configure variables for graph package. -extern const bool EXPCL_PANDA cache_wrt; -extern const bool EXPCL_PANDA ambiguous_wrt_abort; -extern const bool EXPCL_PANDA paranoid_wrt; -extern const bool EXPCL_PANDA paranoid_graph; - -extern EXPCL_PANDA void init_libgraph(); - -#endif diff --git a/panda/src/graph/dftraverser.T b/panda/src/graph/dftraverser.T deleted file mode 100644 index 754ca97827..0000000000 --- a/panda/src/graph/dftraverser.T +++ /dev/null @@ -1,130 +0,0 @@ -// Filename: dftraverser.T -// Created by: drose (26Oct98) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: DFTraverser::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH DFTraverser:: -DFTraverser(Visitor &visitor, - const TransitionWrapper &initial_render_state, - TypeHandle graph_type) : - _visitor(visitor), - _initial_render_state(initial_render_state), - _graph_type(graph_type) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: DFTraverser::start -// Access: Public -// Description: Starts the traversal from the indicated arc. -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH void DFTraverser:: -start(NodeRelation *arc, const LevelState &initial_level_state) { - traverse(arc, _initial_render_state, initial_level_state); -} - -//////////////////////////////////////////////////////////////////// -// Function: DFTraverser::start -// Access: Public -// Description: Starts the traversal from the indicated node. -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH void DFTraverser:: -start(Node *root, const LevelState &initial_level_state) { - LevelState level_state(initial_level_state); - traverse(root, _initial_render_state, level_state); -} - -//////////////////////////////////////////////////////////////////// -// Function: DFTraverser::Traverse -// Access: Public -// Description: Walks to the next arc of the graph. -//////////////////////////////////////////////////////////////////// -template -void DFTraverser:: -traverse(NodeRelation *arc, TransitionWrapper state, LevelState level_state) { - nassertv(arc->get_child() != (Node *)NULL); - - // Give the visitor a chance to veto this arc. - TransitionWrapper trans = - TransitionWrapper::init_from(_initial_render_state); - trans.extract_from(arc); - - TransitionWrapper post_state(state); - post_state.compose_in_place(trans); - if (_visitor.forward_arc(arc, trans, state, post_state, level_state)) { - traverse(arc->get_child(), post_state, level_state); - _visitor.backward_arc(arc, trans, state, post_state, level_state); - } -} - - - -//////////////////////////////////////////////////////////////////// -// Function: DFTraverser::Traverse -// Access: Public -// Description: Walks to the next node of the graph. -//////////////////////////////////////////////////////////////////// -template -void DFTraverser:: -traverse(Node *node, TransitionWrapper &state, LevelState &level_state) { - // Tell the visitor we reached the node, and give it a chance to - // veto our further progress. - if (_visitor.reached_node(node, state, level_state)) { - - // Look for further children of the given NodeRelation. - const DownRelationPointers &drp = - node->find_connection(_graph_type).get_down(); - - // Now visit each of the children in turn. - DownRelationPointers::const_iterator drpi; - for (drpi = drp.begin(); drpi != drp.end(); ++drpi) { - traverse(*drpi, state, level_state); - } - } -} - -// Convenience functions. -template -INLINE void -df_traverse(NodeRelation *arc, Visitor &visitor, - const TransitionWrapper &initial_render_state, - const LevelState &initial_level_state, - TypeHandle graph_type) { - DFTraverser - dft(visitor, initial_render_state, graph_type); - dft.start(arc, initial_level_state); -} - -template -INLINE void -df_traverse(Node *root, Visitor &visitor, - const TransitionWrapper &initial_render_state, - const LevelState &initial_level_state, - TypeHandle graph_type) { - DFTraverser - dft(visitor, initial_render_state, graph_type); - dft.start(root, initial_level_state); -} - diff --git a/panda/src/graph/dftraverser.h b/panda/src/graph/dftraverser.h deleted file mode 100644 index 4353f9ddcf..0000000000 --- a/panda/src/graph/dftraverser.h +++ /dev/null @@ -1,65 +0,0 @@ -// Filename: dftraverser.h -// Created by: drose (26Oct98) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DFTRAVERSER_H -#define DFTRAVERSER_H - -#include - -#include "node.h" -#include "nodeRelation.h" - -#include -#include - -/////////////////////////////////////////////////////////////////// -// Class : DFTraverser -// Description : Implements a depth-first traversal of the graph -// beginning at the indicated node or arc. DFTraverser -// will also call visitor.forward_arc() and -// visitor.backward_arc() to allow the visitor to manage -// state. See traverserVisitor.h. -//////////////////////////////////////////////////////////////////// -template -class DFTraverser { -public: - typedef TYPENAME Visitor::TransitionWrapper TransitionWrapper; - - INLINE_GRAPH DFTraverser(Visitor &visitor, - const TransitionWrapper &initial_render_state, - TypeHandle graph_type); - - INLINE_GRAPH void start(NodeRelation *arc, const LevelState &initial_level_state); - INLINE_GRAPH void start(Node *root, const LevelState &initial_level_state); - -protected: - void traverse(NodeRelation *arc, - TransitionWrapper render_state, - LevelState level_state); - void traverse(Node *node, - TransitionWrapper &render_state, - LevelState &level_state); - - Visitor &_visitor; - TransitionWrapper _initial_render_state; - TypeHandle _graph_type; -}; - -#include "dftraverser.T" - -#endif diff --git a/panda/src/graph/graphHashGenerator.h b/panda/src/graph/graphHashGenerator.h deleted file mode 100644 index e5267e9461..0000000000 --- a/panda/src/graph/graphHashGenerator.h +++ /dev/null @@ -1,39 +0,0 @@ -// Filename: graphHashGenerator.h -// Created by: drose (14May01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef GRAPHHASHGENERATOR_H -#define GRAPHHASHGENERATOR_H - -//////////////////////////////////////////////////////////////////// -// -// This file defines the typedef for GraphHashGenerator, which defines -// the kind of HashGenerator used by all the NodeTransitions. By -// changing this typedef we can change the fundamental hash generation -// mechanism for these things, if necessary. -// -// These hash codes are used to uniquify NodeTransitions, particularly -// in the cull traverser, but only if the hashtable based extensions -// to STL are available (e.g. and ). -// -//////////////////////////////////////////////////////////////////// - -#include - -typedef ChecksumHashGenerator GraphHashGenerator; - -#endif diff --git a/panda/src/graph/graphReducer.cxx b/panda/src/graph/graphReducer.cxx deleted file mode 100644 index 726329b706..0000000000 --- a/panda/src/graph/graphReducer.cxx +++ /dev/null @@ -1,516 +0,0 @@ -// Filename: graphReducer.cxx -// Created by: drose (26Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "graphReducer.h" -#include "config_graph.h" -#include "namedNode.h" -#include "pt_Node.h" - -#include "pmap.h" -#include "plist.h" - -//////////////////////////////////////////////////////////////////// -// Function: GraphReducer::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -GraphReducer:: -GraphReducer(TypeHandle graph_type) : - _graph_type(graph_type) -{ - _max_children = 1; -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphReducer::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -GraphReducer:: -~GraphReducer() { -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphReducer::set_max_children -// Access: Public -// Description: Sets the maximum number of children a node is allowed -// to have and still be flattened. Normally, this is 1; -// we don't typically want to flatten a node that has -// multiple children. However, sometimes this may be -// desirable; set this parameter to control the limit. -// If this is set to -1, there is no limit. -// -// If any of a node's arcs cannot be flattened, -// generally none of them will be, although this depends -// on how late the inability to flatten a particular arc -// is discovered. -//////////////////////////////////////////////////////////////////// -void GraphReducer:: -set_max_children(int count) { - _max_children = count; -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphReducer::flatten -// Access: Public -// Description: Simplifies the graph by removing unnecessary nodes -// and arcs. -// -// In general, a node (and its parent arc) is a -// candidate for removal if the node has no siblings and -// the node and arc have no special properties. The -// definition of what, precisely, is a 'special -// property' may be extended by subclassing from this -// type and redefining consider_arc() appropriately. -// -// If combine_siblings is true, sibling nodes may also -// be collapsed into a single node. This will further -// reduce scene graph complexity, sometimes -// substantially, at the cost of reduced spatial -// separation. -// -// Returns the number of arcs removed from the graph. -//////////////////////////////////////////////////////////////////// -int GraphReducer:: -flatten(Node *root, bool combine_siblings) { - int num_total_nodes = 0; - int num_pass_nodes; - - do { - num_pass_nodes = 0; - - const DownRelationPointers &drp = - root->find_connection(_graph_type).get_down(); - - // Get a copy of the children list, so we don't have to worry - // about self-modifications. - DownRelationPointers drp_copy = drp; - - // Now visit each of the children in turn. - DownRelationPointers::const_iterator drpi; - for (drpi = drp_copy.begin(); drpi != drp_copy.end(); ++drpi) { - NodeRelation *arc = (*drpi); - num_pass_nodes += r_flatten(arc->get_child(), combine_siblings); - } - - num_total_nodes += num_pass_nodes; - - // If combine_siblings is true, we should repeat the above until - // we don't get any more benefit from flattening, because each - // pass could convert cousins into siblings, which may get - // flattened next pass. If combine_siblings is not true, the - // first pass will be fully effective, and there's no point in - // trying again. - } while (combine_siblings && num_pass_nodes != 0); - - return num_total_nodes; -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphReducer::r_flatten -// Access: Protected -// Description: The recursive implementation of flatten(). -//////////////////////////////////////////////////////////////////// -int GraphReducer:: -r_flatten(Node *root, bool combine_siblings) { - int num_nodes = 0; - - const DownRelationPointers &drp = - root->find_connection(_graph_type).get_down(); - - // Get a copy of the children list, so we don't have to worry - // about self-modifications. - DownRelationPointers drp_copy = drp; - - // Now visit each of the children in turn. - DownRelationPointers::const_iterator drpi; - for (drpi = drp_copy.begin(); drpi != drp_copy.end(); ++drpi) { - NodeRelation *arc = (*drpi); - num_nodes += r_flatten(arc->get_child(), combine_siblings); - } - - if (combine_siblings && drp.size() >= 2) { - num_nodes += flatten_siblings(root); - } - - if (!drp.empty() && (_max_children < 0 || (int)drp.size() <= _max_children)) { - // If we don't have too many children, consider flattening each of - // our child arcs. - bool all_ok = true; - for (drpi = drp_copy.begin(); drpi != drp_copy.end() && all_ok; ++drpi) { - NodeRelation *arc = (*drpi); - all_ok = consider_arc(arc); - } - - if (all_ok) { - // All our arcs can (potentially) be flattened; do it. - - // Get a new copy of the children list. - drp_copy = drp; - - for (drpi = drp_copy.begin(); drpi != drp_copy.end(); ++drpi) { - NodeRelation *arc = (*drpi); - if (flatten_arc(arc)) { - num_nodes++; - } - } - } - } - - return num_nodes; -} - -class SortByTransitions { -public: - INLINE bool - operator () (const NodeRelation *arc1, const NodeRelation *arc2) const; -}; - -INLINE bool SortByTransitions:: -operator () (const NodeRelation *arc1, const NodeRelation *arc2) const { - return (arc1->compare_transitions_to(arc2) < 0); -} - - -//////////////////////////////////////////////////////////////////// -// Function: GraphReducer::flatten_siblings -// Access: Protected -// Description: Attempts to collapse together any pairs of siblings -// of the indicated node that share the same properties. -//////////////////////////////////////////////////////////////////// -int GraphReducer:: -flatten_siblings(Node *root) { - int num_nodes = 0; - - // First, collect the children into groups of arcs with common - // properties. - typedef pmap, SortByTransitions> Children; - Children children; - - const DownRelationPointers &drp = - root->find_connection(_graph_type).get_down(); - DownRelationPointers::const_iterator drpi; - for (drpi = drp.begin(); drpi != drp.end(); ++drpi) { - NodeRelation *arc = (*drpi); - children[arc].push_back(arc); - } - - // Now visit each of those groups and try to collapse them together. - Children::iterator ci; - for (ci = children.begin(); ci != children.end(); ++ci) { - plist &arcs = (*ci).second; - - plist::iterator ai1; - ai1 = arcs.begin(); - while (ai1 != arcs.end()) { - plist::iterator ai1_hold = ai1; - NodeRelation *arc1 = (*ai1); - ++ai1; - plist::iterator ai2 = ai1; - while (ai2 != arcs.end()) { - plist::iterator ai2_hold = ai2; - NodeRelation *arc2 = (*ai2); - ++ai2; - - if (consider_siblings(root, arc1, arc2)) { - NodeRelation *new_arc = collapse_siblings(root, arc1, arc2); - if (new_arc != (NodeRelation *)NULL) { - // We successfully collapsed an arc. - arcs.erase(ai2_hold); - arcs.erase(ai1_hold); - arcs.push_back(new_arc); - ai1 = arcs.begin(); - ai2 = arcs.end(); - num_nodes++; - } - } - } - } - } - - return num_nodes; -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphReducer::consider_arc -// Access: Protected, Virtual -// Description: Decides whether or not the indicated arc is a -// suitable candidate for removal. Returns true if the -// arc may be removed, false if it should be kept. This -// function may be extended in a user class to protect -// special kinds of arcs from deletion. -//////////////////////////////////////////////////////////////////// -bool GraphReducer:: -consider_arc(NodeRelation *arc) { - // On reflection, there's no reason to forbid the removal of arcs - // with sub_render transitions. It should all work out properly. - /* - if (arc->has_sub_render_trans()) { - if (graph_cat.is_debug()) { - graph_cat.debug() - << "Not removing " << *arc - << " because it contains a sub_render transition.\n"; - } - return false; - } - */ - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphReducer::consider_siblings -// Access: Protected, Virtual -// Description: Decides whether or not the indicated sibling nodes -// (and their associated arcs) should be collapsed into -// a single node or not. Returns true if the arcs may -// be collapsed, false if they should be kept distinct. -//////////////////////////////////////////////////////////////////// -bool GraphReducer:: -consider_siblings(Node *, NodeRelation *arc1, NodeRelation *arc2) { - // Don't attempt to combine any sibling arcs with different - // transitions. - if (arc1->compare_transitions_to(arc2) != 0) { - return false; - } - - // We can't collapse siblings with arcs that contain sub_render - // transitions. That could be bad. - - // On the other hand, maybe we can; why not? The only one that - // could cause grief is the DecalTransition, which we'll - // special-case in SceneGraphReducer. - /* - if (arc1->has_sub_render_trans()) { - if (graph_cat.is_debug()) { - graph_cat.debug() - << "Not combining " << *arc1 << " and " << *arc2 - << " because they contain a sub_render transition.\n"; - } - return false; - } - */ - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphReducer::flatten_arc -// Access: Protected, Virtual -// Description: Removes the indicated arc, collapsing together the -// two nodes and leaving them parented in the same -// place. The return value is true if the arc is -// successfully collapsed, false if we chickened out. -// -// This function may be extended in a user class to -// handle special kinds of nodes. -//////////////////////////////////////////////////////////////////// -bool GraphReducer:: -flatten_arc(NodeRelation *arc) { - PT_Node parent = arc->get_parent(); - PT_Node child = arc->get_child(); - - if (graph_cat.is_debug()) { - graph_cat.debug() - << "Removing " << *arc << "\n"; - } - - PT_Node new_parent = collapse_nodes(parent, child, false); - if (new_parent == (Node *)NULL) { - if (graph_cat.is_debug()) { - graph_cat.debug() - << "Decided not to remove " << *arc << "\n"; - } - return false; - } - - choose_name(new_parent, parent, child); - - move_children(new_parent, parent); - move_children(new_parent, child); - - // Move all of the transitions from the arc to the parent's arcs. - int num_grandparents = parent->get_num_parents(_graph_type); - for (int i = 0; i < num_grandparents; i++) { - NodeRelation *grandparent_arc = parent->get_parent(_graph_type, i); - - grandparent_arc->compose_transitions_from(arc); - if (new_parent != parent) { - // Also switch out the parent node. - grandparent_arc->change_child(new_parent); - } - } - - remove_arc(arc); - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphReducer::collapse_siblings -// Access: Protected, Virtual -// Description: Performs the work of collapsing two sibling arcs -// together into a single arc (and their associated -// nodes into a single node). -// -// Returns a pointer to a NodeRelation the reflects the -// combined arc (which may be either of the source arcs, -// or a new arc altogether) if the siblings are -// successfully collapsed, or NULL if we chickened out. -//////////////////////////////////////////////////////////////////// -NodeRelation *GraphReducer:: -collapse_siblings(Node *parent, NodeRelation *arc1, NodeRelation *arc2) { - PT_Node node1 = arc1->get_child(); - PT_Node node2 = arc2->get_child(); - - if (graph_cat.is_debug()) { - graph_cat.debug() - << "Collapsing " << *node1 << " and " << *node2 << "\n"; - } - - PT_Node new_node = collapse_nodes(node1, node2, true); - if (new_node == (Node *)NULL) { - if (graph_cat.is_debug()) { - graph_cat.debug() - << "Decided not to collapse " << *node1 << " and " << *node2 << "\n"; - } - return NULL; - } - - choose_name(new_node, node1, node2); - - move_children(new_node, node1); - move_children(new_node, node2); - - arc1->change_child(new_node); - remove_arc(arc2); - - return arc1; -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphReducer::collapse_nodes -// Access: Protected, Virtual -// Description: Collapses the two nodes into a single node, if -// possible. The 'siblings' flag is true if the two -// nodes are siblings nodes; otherwise, node1 is a -// parent of node2. The return value is the resulting -// node, which may be either one of the source nodes, or -// a new node altogether, or it may be NULL to indicate -// that the collapse operation could not take place. -// -// This function may be extended in a user class to -// handle combining special kinds of nodes. -//////////////////////////////////////////////////////////////////// -Node *GraphReducer:: -collapse_nodes(Node *node1, Node *node2, bool) { - if (!node1->safe_to_combine() || !node2->safe_to_combine()) { - // One or both nodes cannot be safely combined with another node; - // do nothing. - return NULL; - } - - return node2->combine_with(node1); -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphReducer::choose_name -// Access: Protected, Virtual -// Description: Chooses a suitable name for the collapsed node, based -// on the names of the two sources nodes. -//////////////////////////////////////////////////////////////////// -void GraphReducer:: -choose_name(Node *preserve, Node *source1, Node *source2) { - if (!preserve->is_of_type(NamedNode::get_class_type())) { - // It's not even a namable class, so we can't name it anyway. - // Never mind. - return; - } - - NamedNode *named_preserve; - DCAST_INTO_V(named_preserve, preserve); - - string name; - bool got_name = false; - - if (source1->is_of_type(NamedNode::get_class_type())) { - NamedNode *named_source1; - DCAST_INTO_V(named_source1, source1); - name = named_source1->get_name(); - got_name = !name.empty() || named_source1->preserve_name(); - } - - if (source2->is_of_type(NamedNode::get_class_type())) { - NamedNode *named_source2; - DCAST_INTO_V(named_source2, source2); - if (named_source2->preserve_name() || !got_name) { - name = named_source2->get_name(); - got_name = !name.empty() || named_source2->preserve_name(); - } - } - - if (got_name) { - named_preserve->set_name(name); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphReducer::move_children -// Access: Protected -// Description: Moves all of the children arcs of the 'from' node to -// the 'to' node. -//////////////////////////////////////////////////////////////////// -void GraphReducer:: -move_children(Node *to, Node *from) { - if (to != from) { - /* - if (graph_cat.is_debug()) { - graph_cat.debug() - << "Moving children to " << *to << " from " << *from << "\n"; - } - */ - - int num_children = from->get_num_children(_graph_type); - while (num_children > 0) { - NodeRelation *arc = from->get_child(_graph_type, 0); - arc->change_parent(to); - num_children--; - nassertv(num_children == from->get_num_children(_graph_type)); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GraphReducer::copy_children -// Access: Protected -// Description: Copies all of the children arcs of the 'from' node to -// the 'to' node, without removing the from the 'from' -// node. -//////////////////////////////////////////////////////////////////// -void GraphReducer:: -copy_children(Node *to, Node *from) { - if (to != from) { - int num_children = from->get_num_children(_graph_type); - for (int i = 0; i < num_children; i++) { - NodeRelation *arc = from->get_child(_graph_type, i); - NodeRelation *new_arc = NodeRelation::create_typed_arc - (_graph_type, to, arc->get_child()); - nassertv(new_arc != (NodeRelation *)NULL); - nassertv(new_arc->is_exact_type(_graph_type)); - new_arc->copy_transitions_from(arc); - } - } -} diff --git a/panda/src/graph/graphReducer.h b/panda/src/graph/graphReducer.h deleted file mode 100644 index 78bd8d5466..0000000000 --- a/panda/src/graph/graphReducer.h +++ /dev/null @@ -1,72 +0,0 @@ -// Filename: graphReducer.h -// Created by: drose (26Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef GRAPHREDUCER_H -#define GRAPHREDUCER_H - -#include - -#include "nodeRelation.h" - -#include - -/////////////////////////////////////////////////////////////////// -// Class : GraphReducer -// Description : A generic interface to simplify a graph in various -// ways, generally as a performance optimization. This -// class is designed for generic graphs; also see the -// SceneGraphReducer (which inherits from this class) -// for a specific class to optimize renderable scene -// graphs. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA GraphReducer { -public: - GraphReducer(TypeHandle graph_type); - virtual ~GraphReducer(); - - void set_max_children(int count); - int flatten(Node *root, bool combine_siblings); - -protected: - int r_flatten(Node *root, bool combine_siblings); - int flatten_siblings(Node *root); - - virtual bool consider_arc(NodeRelation *arc); - virtual bool consider_siblings(Node *parent, - NodeRelation *arc1, NodeRelation *arc2); - - virtual bool flatten_arc(NodeRelation *arc); - virtual NodeRelation *collapse_siblings(Node *parent, NodeRelation *arc1, - NodeRelation *arc2); - - virtual Node *collapse_nodes(Node *node1, Node *node2, bool siblings); - virtual void choose_name(Node *preserve, Node *source1, Node *source2); - -protected: - void move_children(Node *to, Node *from); - void copy_children(Node *to, Node *from); - -protected: - int _max_children; - TypeHandle _graph_type; -}; - -#endif - - - diff --git a/panda/src/graph/graph_composite1.cxx b/panda/src/graph/graph_composite1.cxx deleted file mode 100644 index 7ccf588a56..0000000000 --- a/panda/src/graph/graph_composite1.cxx +++ /dev/null @@ -1,20 +0,0 @@ - -#include "allTransitionsWrapper.cxx" -#include "arcChain.cxx" -#include "bitMask32Transition.cxx" -#include "boundedObject.cxx" -#include "config_graph.cxx" -#include "graphReducer.cxx" -#include "immediateTransition.cxx" -#include "lmatrix4fTransition.cxx" -#include "multiNodeTransition.cxx" -#include "onOffTransition.cxx" -#include "onTransition.cxx" -#include "pt_NamedNode.cxx" -#include "pt_Node.cxx" -#include "pt_NodeRelation.cxx" -#include "vector_PT_Node.cxx" -#include "vector_PT_NodeRelation.cxx" -#include "vector_NodeRelation_star.cxx" -#include "wrt.cxx" - diff --git a/panda/src/graph/graph_composite2.cxx b/panda/src/graph/graph_composite2.cxx deleted file mode 100644 index 52faa5c8fc..0000000000 --- a/panda/src/graph/graph_composite2.cxx +++ /dev/null @@ -1,13 +0,0 @@ - -#include "namedNode.cxx" -#include "node.cxx" -#include "nodeConnection.cxx" -#include "nodeRelation.cxx" -#include "nodeTransition.cxx" -#include "nodeTransitionCache.cxx" -#include "nodeTransitionCacheEntry.cxx" -#include "nodeTransitionWrapper.cxx" -#include "nodeTransitions.cxx" -#include "nullLevelState.cxx" -#include "nullTransitionWrapper.cxx" - diff --git a/panda/src/graph/immediateTransition.I b/panda/src/graph/immediateTransition.I deleted file mode 100644 index 1788b2b339..0000000000 --- a/panda/src/graph/immediateTransition.I +++ /dev/null @@ -1,47 +0,0 @@ -// Filename: immediateTransition.I -// Created by: drose (24Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: ImmediateTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH ImmediateTransition:: -ImmediateTransition() { -} - -//////////////////////////////////////////////////////////////////// -// Function: ImmediateTransition::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH ImmediateTransition:: -ImmediateTransition(const ImmediateTransition ©) : - NodeTransition(copy) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: ImmediateTransition::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void ImmediateTransition:: -operator = (const ImmediateTransition ©) { - NodeTransition::operator = (copy); -} diff --git a/panda/src/graph/immediateTransition.cxx b/panda/src/graph/immediateTransition.cxx deleted file mode 100644 index d9d0c5a0a4..0000000000 --- a/panda/src/graph/immediateTransition.cxx +++ /dev/null @@ -1,63 +0,0 @@ -// Filename: immediateTransition.cxx -// Created by: drose (24Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "immediateTransition.h" - -#include - -TypeHandle ImmediateTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: ImmediateTransition::compose -// Access: Public, Virtual -// Description: Returns a new transition that corresponds to the -// composition of this transition with the second -// transition (which must be of an equivalent type). -// This may return the same pointer as either source -// transition. Applying the transition returned from -// this function to an attribute attribute will produce -// the same effect as applying each transition -// separately. -//////////////////////////////////////////////////////////////////// -NodeTransition *ImmediateTransition:: -compose(const NodeTransition *) const { - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: ImmediateTransition::invert -// Access: Public, Virtual -// Description: Returns a new transition that corresponds to the -// inverse of this transition. If the transition was -// identity, this may return the same pointer. Returns -// NULL if the transition cannot be inverted. -//////////////////////////////////////////////////////////////////// -NodeTransition *ImmediateTransition:: -invert() const { - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: ImmediateTransition::internal_compare_to -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int ImmediateTransition:: -internal_compare_to(const NodeTransition *) const { - return 0; -} diff --git a/panda/src/graph/immediateTransition.h b/panda/src/graph/immediateTransition.h deleted file mode 100644 index b8f8bf62e3..0000000000 --- a/panda/src/graph/immediateTransition.h +++ /dev/null @@ -1,87 +0,0 @@ -// Filename: immediateTransition.h -// Created by: drose (24Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef IMMEDIATETRANSITION_H -#define IMMEDIATETRANSITION_H - -#include - -#include "nodeTransition.h" - -class NodeRelation; - -//////////////////////////////////////////////////////////////////// -// Class : ImmediateTransition -// Description : This is a special kind of transition that doesn't -// accumulate state, but instead has some immediate -// effect when it is encountered in the scene graph. -// BillboardTransition and ShaderTransition are examples -// of these; rather than changing the state of geometry -// below them, they cause everything to be rendered -// differently somehow from that point and below. -// -// The compose() etc. methods for an ImmediateTransition -// do nothing. Presumably any transitions that inherit -// from ImmediateTransition will redefine sub_render() -// to do something suitably interesting. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ImmediateTransition : public NodeTransition { -protected: - INLINE_GRAPH ImmediateTransition(); - INLINE_GRAPH ImmediateTransition(const ImmediateTransition ©); - INLINE_GRAPH void operator = (const ImmediateTransition ©); - -public: - virtual NodeTransition *compose(const NodeTransition *other) const; - virtual NodeTransition *invert() const; - -protected: - virtual int internal_compare_to(const NodeTransition *other) const; - - //ImmediateTransition is merely an interface class, so no need to - //define the code necessary for anything relating to reading/writing - -public: - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -PUBLISHED: - static TypeHandle get_class_type() { - return _type_handle; - } - -public: - static void init_type() { - NodeTransition::init_type(); - register_type(_type_handle, "ImmediateTransition", - NodeTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#ifndef DONT_INLINE_GRAPH -#include "immediateTransition.I" -#endif - -#endif - - diff --git a/panda/src/graph/lmatrix4fTransition.cxx b/panda/src/graph/lmatrix4fTransition.cxx deleted file mode 100644 index 5e8786228c..0000000000 --- a/panda/src/graph/lmatrix4fTransition.cxx +++ /dev/null @@ -1,25 +0,0 @@ -// Filename: lmatrix4fTransition.cxx -// Created by: drose (05May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "lmatrix4fTransition.h" - -#ifdef __GNUC__ -#pragma implementation -#endif - - diff --git a/panda/src/graph/lmatrix4fTransition.h b/panda/src/graph/lmatrix4fTransition.h deleted file mode 100644 index 61a887c91c..0000000000 --- a/panda/src/graph/lmatrix4fTransition.h +++ /dev/null @@ -1,45 +0,0 @@ -// Filename: lmatrix4fTransition.h -// Created by: drose (05May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef LMATRIX4FTRANSITION_H -#define LMATRIX4FTRANSITION_H - -#include - -#include "matrixTransition.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : LMatrix4fTransition -// Description : This is just an instantation of MatrixTransition -// using LMatrix4f, the most common transform matrix -// type. -//////////////////////////////////////////////////////////////////// - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, MatrixTransition); - -typedef MatrixTransition LMatrix4fTransition; - -#ifdef __GNUC__ -#pragma interface -#endif - -#endif - - diff --git a/panda/src/graph/matrixTransition.T b/panda/src/graph/matrixTransition.T deleted file mode 100644 index e4afa49141..0000000000 --- a/panda/src/graph/matrixTransition.T +++ /dev/null @@ -1,235 +0,0 @@ -// Filename: matrixTransition.T -// Created by: drose (24Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -template -TypeHandle MatrixTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: MatrixTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH MatrixTransition:: -MatrixTransition() { - _matrix = Matrix::ident_mat(); -} - -//////////////////////////////////////////////////////////////////// -// Function: MatrixTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH MatrixTransition:: -MatrixTransition(const Matrix &matrix) { - _matrix = matrix; -} - -//////////////////////////////////////////////////////////////////// -// Function: MatrixTransition::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH MatrixTransition:: -MatrixTransition(const MatrixTransition ©) : - NodeTransition(copy), - _matrix(copy._matrix) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: MatrixTransition::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH void MatrixTransition:: -operator = (const MatrixTransition ©) { - NodeTransition::operator = (copy); - _matrix = copy._matrix; -} - -//////////////////////////////////////////////////////////////////// -// Function: MatrixTransition::set_matrix -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH void MatrixTransition:: -set_matrix(const Matrix &mat) { - _matrix = mat; - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: MatrixTransition::get_matrix -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH const Matrix &MatrixTransition:: -get_matrix() const { - return _matrix; -} - -//////////////////////////////////////////////////////////////////// -// Function: MatrixTransition::compose -// Access: Public, Virtual -// Description: Returns a new transition that corresponds to the -// composition of this transition with the second -// transition (which must be of an equivalent type). -// This may return the same pointer as either source -// transition. Applying the transition returned from -// this function to an attribute attribute will produce -// the same effect as applying each transition -// separately. -//////////////////////////////////////////////////////////////////// -template -NodeTransition *MatrixTransition:: -compose(const NodeTransition *other) const { - const MatrixTransition *ot; - DCAST_INTO_R(ot, other, NULL); - - return make_with_matrix(ot->_matrix * _matrix); -} - -//////////////////////////////////////////////////////////////////// -// Function: MatrixTransition::invert -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -NodeTransition *MatrixTransition:: -invert() const { - if (_matrix.almost_equal(Matrix::ident_mat())) { - return (MatrixTransition *)this; - } - Matrix inverted; - inverted.invert_from(_matrix); - return make_with_matrix(inverted); -} - -//////////////////////////////////////////////////////////////////// -// Function: MatrixTransition::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -void MatrixTransition:: -output(ostream &out) const { - out << _matrix; -} - -//////////////////////////////////////////////////////////////////// -// Function: MatrixTransition::write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -void MatrixTransition:: -write(ostream &out, int indent_level) const { - _matrix.write(out, indent_level); -} - -//////////////////////////////////////////////////////////////////// -// Function: MatrixTransition::internal_compare_to -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -int MatrixTransition:: -internal_compare_to(const NodeTransition *other) const { - const MatrixTransition *ot; - DCAST_INTO_R(ot, other, false); - - // Should we bother comparing matrices componentwise, or should we - // just assume that any two different Matrix pointers are probably - // different matrices? - - // For now, we compare componentwise. It makes paranoid_wrt more - // sensible, and it doesn't seem to make a big different to - // performance. - return _matrix.compare_to(ot->_matrix, 0.00001f); - - // Uncomment this line instead to compare matrices pointerwise. - // return this - other; -} - -//////////////////////////////////////////////////////////////////// -// Function: MatrixTransition::internal_generate_hash -// Access: Protected, Virtual -// Description: Should be overridden by particular NodeTransitions to -// generate a hash value uniquifying this particular -// transition. -//////////////////////////////////////////////////////////////////// -template -void MatrixTransition:: -internal_generate_hash(GraphHashGenerator &hashgen) const { - _matrix.generate_hash(hashgen, 0.00001f); -} - -//////////////////////////////////////////////////////////////////// -// Function: MatrixTransition::make_with_matrix -// Access: Protected, Virtual -// Description: This function creates a new MatrixTransition of the -// appropriate type, given the indicated matrix. -// -// This is a pure virtual function and normally wouldn't -// require a definition, but for some reason VC++ -// objects to instantiating the template if it's missing -// any function definitions--even those for pure-virtual -// functions. -//////////////////////////////////////////////////////////////////// -template -MatrixTransition *MatrixTransition:: -make_with_matrix(const Matrix &) const { - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: MatrixTransition::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -template -void MatrixTransition:: -write_datagram(BamWriter *manager, Datagram &me) -{ - NodeTransition::write_datagram(manager, me); - _matrix.write_datagram(me); -} - -//////////////////////////////////////////////////////////////////// -// Function: MatrixTransition::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -template -void MatrixTransition:: -fillin(DatagramIterator& scan, BamReader* manager) -{ - NodeTransition::fillin(scan, manager); - _matrix.read_datagram(scan); -} diff --git a/panda/src/graph/matrixTransition.h b/panda/src/graph/matrixTransition.h deleted file mode 100644 index 7cd7e0e16f..0000000000 --- a/panda/src/graph/matrixTransition.h +++ /dev/null @@ -1,101 +0,0 @@ -// Filename: matrixTransition.h -// Created by: drose (24Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef MATRIXTRANSITION_H -#define MATRIXTRANSITION_H - -#include "pandabase.h" - -#include "nodeTransition.h" - -#include "indent.h" - -class NodeRelation; - -//////////////////////////////////////////////////////////////////// -// Class : MatrixTransition -// Description : This is an abstract template class that encapsulates -// all transitions that involve some kind of matrix, -// either a 4x4 or a 3x3, either float or double. It -// templates on the matrix type. -// -// It's the base class for a number of scene graph -// transitions like TransformTransition and -// TexMatrixTransition. -//////////////////////////////////////////////////////////////////// -template -class MatrixTransition : public NodeTransition { -protected: - INLINE_GRAPH MatrixTransition(); - INLINE_GRAPH MatrixTransition(const Matrix &matrix); - INLINE_GRAPH MatrixTransition(const MatrixTransition ©); - INLINE_GRAPH void operator = (const MatrixTransition ©); - -public: - INLINE_GRAPH void set_matrix(const Matrix &mat); - INLINE_GRAPH const Matrix &get_matrix() const; - - virtual NodeTransition *compose(const NodeTransition *other) const; - virtual NodeTransition *invert() const; - - virtual void output(ostream &out) const; - virtual void write(ostream &out, int indent_level = 0) const; - -protected: - virtual int internal_compare_to(const NodeTransition *other) const; - virtual void internal_generate_hash(GraphHashGenerator &hashgen) const; - -protected: - virtual MatrixTransition * - make_with_matrix(const Matrix &matrix) const=0; - -private: - Matrix _matrix; - -public: - virtual void write_datagram(BamWriter* manager, Datagram &me); - - //Matrix has no factory method as it is a virtual template - //class -protected: - virtual 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() { - NodeTransition::init_type(); - Matrix::init_type(); - register_type(_type_handle, - string("MatrixTransition<") + - Matrix::get_class_type().get_name() + ">", - NodeTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "matrixTransition.T" - -#endif diff --git a/panda/src/graph/multiNodeTransition.cxx b/panda/src/graph/multiNodeTransition.cxx deleted file mode 100644 index 700372c754..0000000000 --- a/panda/src/graph/multiNodeTransition.cxx +++ /dev/null @@ -1,21 +0,0 @@ -// Filename: multiNodeTransition.cxx -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "multiNodeTransition.h" - -TypeHandle MultiNodeTransition::_type_handle; diff --git a/panda/src/graph/multiNodeTransition.h b/panda/src/graph/multiNodeTransition.h deleted file mode 100644 index 8b996b6725..0000000000 --- a/panda/src/graph/multiNodeTransition.h +++ /dev/null @@ -1,77 +0,0 @@ -// Filename: multiNodeTransition.h -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef MULTINODETRANSITION_H -#define MULTINODETRANSITION_H - -#include - -#include "multiTransition.h" -#include "pointerNameClass.h" -#include "node.h" -#include "pt_Node.h" - -#include - -class NodeRelation; - -// We need to define this temporary macro so we can pass a parameter -// containing a comma through the macro. -#define MULTITRANSITION_NODE MultiTransition -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, MULTITRANSITION_NODE); - -//////////////////////////////////////////////////////////////////// -// Class : MultiNodeTransition -// Description : This is a particular instantiation of MultiTransition -// on PT_Node. It is its own class in an attempt to -// cut down on code bloat; if a particular transition -// wants to be a MultiTransition on some kind of -// Node, it should inherit from MultiNodeTransition -// (rather than instantiating a whole new kind of -// MultiTransition). -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA MultiNodeTransition : - public MultiTransition { -protected: - INLINE_GRAPH MultiNodeTransition() {}; - INLINE_GRAPH MultiNodeTransition(const MultiNodeTransition ©) : - MultiTransition(copy) {}; - - INLINE_GRAPH void operator = (const MultiNodeTransition ©) - {MultiTransition::operator = (copy);}; - -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() { - MultiTransition::init_type(); - register_type(_type_handle, "MultiNodeTransition", - MultiTransition:: - get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#endif diff --git a/panda/src/graph/multiTransition.T b/panda/src/graph/multiTransition.T deleted file mode 100644 index 89c8f278d4..0000000000 --- a/panda/src/graph/multiTransition.T +++ /dev/null @@ -1,539 +0,0 @@ -// Filename: multiTransition.T -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -template -TypeHandle MultiTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -MultiTransition:: -MultiTransition() { - _default_dir = TD_identity; -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -MultiTransition:: -MultiTransition(const MultiTransition ©) : - NodeTransition(copy), - _properties(copy._properties), - _default_dir(copy._default_dir) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -void MultiTransition:: -operator = (const MultiTransition ©) { - NodeTransition::operator = (copy); - _properties = copy._properties; - _default_dir = copy._default_dir; -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::clear -// Access: Public -// Description: Removes all properties from the set, and resets it to -// its initial state. -//////////////////////////////////////////////////////////////////// -template -void MultiTransition:: -clear() { - _properties.clear(); - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::is_identity -// Access: Public -// Description: Returns true if this transition does not have any -// effect. -//////////////////////////////////////////////////////////////////// -template -bool MultiTransition:: -is_identity() const { - if (_default_dir != TD_identity) { - return false; - } - - Properties::const_iterator pi; - for (pi = _properties.begin(); pi != _properties.end(); ++pi) { - if ((*pi).second != TD_identity) { - return false; - } - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::set_default_dir -// Access: Public -// Description: Sets the default direction on the MultiTransition. -// This controls whether the MultiTransition applies -// itself by completely replacing everything that went -// before, or by adding to whatever has gone before. -// -// When this is set to either TD_on or TD_off, all -// properties which are not explicitly mentioned are -// assumed to be 'on' or 'off' transitions, -// respectively; when it is set to TD_identity, the -// default, all properties which are not explicitly -// mentions are assumed to be identity transitions and -// are left unchanged. -//////////////////////////////////////////////////////////////////// -template -INLINE void MultiTransition:: -set_default_dir(TransitionDirection dir) { - _default_dir = dir; -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::get_default_dir -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE TransitionDirection MultiTransition:: -get_default_dir() const { - return _default_dir; -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::set_identity -// Access: Public -// Description: Changes the indicated property to an identity -// transition: this property will not be changed by the -// application of the MultiTransition. -//////////////////////////////////////////////////////////////////// -template -void MultiTransition:: -set_identity(const Property &property) { - Properties::iterator pi; - for (pi = _properties.begin(); pi != _properties.end(); ++pi) { - if ((*pi).first == property) { - (*pi).second = TD_identity; - state_changed(); - return; - } - } - - // It wasn't already on the list; append it. - _properties.push_back(Element(property, TD_identity)); - - // And now we need to re-sort the list. - sort(_properties.begin(), _properties.end(), SortByFirstOfPair()); - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::set_on -// Access: Public -// Description: Changes the indicated property to an 'on' transition: -// this property will be explicitly turned on by the -// application of the MultiTransition. -//////////////////////////////////////////////////////////////////// -template -void MultiTransition:: -set_on(const Property &property) { - Properties::iterator pi; - for (pi = _properties.begin(); pi != _properties.end(); ++pi) { - if ((*pi).first == property) { - (*pi).second = TD_on; - state_changed(); - return; - } - } - - // It wasn't already on the list; append it. - _properties.push_back(Element(property, TD_on)); - - // And now we need to re-sort the list. - sort(_properties.begin(), _properties.end(), SortByFirstOfPair()); - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::set_off -// Access: Public -// Description: Changes the indicated property to an 'off' transition: -// this property will be explicitly turned off by the -// application of the MultiTransition. -//////////////////////////////////////////////////////////////////// -template -void MultiTransition:: -set_off(const Property &property) { - Properties::iterator pi; - for (pi = _properties.begin(); pi != _properties.end(); ++pi) { - if ((*pi).first == property) { - (*pi).second = TD_off; - state_changed(); - return; - } - } - - // It wasn't already on the list; append it. - _properties.push_back(Element(property, TD_off)); - - // And now we need to re-sort the list. - sort(_properties.begin(), _properties.end(), SortByFirstOfPair()); - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::is_identity -// Access: Public -// Description: Returns true if this property has been indicated as -// an identity transition, false otherwise. -//////////////////////////////////////////////////////////////////// -template -bool MultiTransition:: -is_identity(const Property &property) const { - Properties::const_iterator pi; - for (pi = _properties.begin(); pi != _properties.end(); ++pi) { - if ((*pi).first == property) { - return (*pi).second == TD_identity; - } - } - - // The property is not mentioned. It's implicitly identity only if - // the default_dir flag is identity. - return (_default_dir == TD_identity); -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::is_on -// Access: Public -// Description: Returns true if this property has been indicated as -// an 'on' transition, false otherwise. -//////////////////////////////////////////////////////////////////// -template -bool MultiTransition:: -is_on(const Property &property) const { - Properties::const_iterator pi; - for (pi = _properties.begin(); pi != _properties.end(); ++pi) { - if ((*pi).first == property) { - return (*pi).second == TD_on; - } - } - - // The property is not mentioned. It's implicitly on only if - // the default_dir flag is on. - return (_default_dir == TD_on); -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::is_on -// Access: Public -// Description: Returns true if this property has been indicated as -// an 'off' transition, false otherwise. -//////////////////////////////////////////////////////////////////// -template -bool MultiTransition:: -is_off(const Property &property) const { - Properties::const_iterator pi; - for (pi = _properties.begin(); pi != _properties.end(); ++pi) { - if ((*pi).first == property) { - return (*pi).second == TD_off; - } - } - - // The property is not mentioned. It's implicitly off only if - // the default_dir flag is off. - return (_default_dir == TD_off); -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::make_identity -// Access: Public, Virtual -// Description: This is a pure virtual function and normally would -// not need a body, except that VC++ doesn't seem happy -// about instantiating the template otherwise. -//////////////////////////////////////////////////////////////////// -template -NodeTransition *MultiTransition:: -make_identity() const { - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::compose -// Access: Public, Virtual -// Description: Returns a new transition that corresponds to the -// composition of this transition with the second -// transition (which must be of an equivalent type). -// This may return the same pointer as either source -// transition. Applying the transition returned from -// this function to an attribute attribute will produce -// the same effect as applying each transition -// separately. -//////////////////////////////////////////////////////////////////// -template -NodeTransition *MultiTransition:: -compose(const NodeTransition *other) const { - const MultiTransition *ot; - DCAST_INTO_R(ot, other, NULL); - - if (ot->_priority < _priority) { - // The other transition too low-priority; the result is unchanged. - return (MultiTransition *)this; - - } else if (ot->_priority > _priority) { - // The other priority is higher: the result is the same as the other. - return (MultiTransition *)ot; - - } else if (ot->_default_dir != TD_identity) { - // The other transition is a complete-world transition: the result - // is the same as other. - return (MultiTransition *)ot; - - } else if (is_identity()) { - // We're identity: the result is the same as other. - return (MultiTransition *)ot; - - } else if (ot->is_identity()) { - // The other transition is identity: it has no effect. - return (MultiTransition *)this; - - } else { - // Neither of us is identity. Build and return a new list. - MultiTransition *result; - DCAST_INTO_R(result, make_identity(), NULL); - result->_default_dir = _default_dir; - - dmap_compose(_properties.begin(), _properties.end(), - ot->_properties.begin(), ot->_properties.end(), - back_inserter(result->_properties)); - - return result; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::invert -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -NodeTransition *MultiTransition:: -invert() const { - if (is_identity()) { - return (MultiTransition *)this; - } - - MultiTransition *result; - DCAST_INTO_R(result, make_identity(), NULL); - - result->_default_dir = TD_identity; - - dmap_invert(_properties.begin(), _properties.end(), - back_inserter(result->_properties), - (Element *)NULL); - - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -void MultiTransition:: -output(ostream &out) const { - Properties::const_iterator pi; - - bool any_identity = false; - for (pi = _properties.begin(); pi != _properties.end(); ++pi) { - if ((*pi).second == TD_identity) { - if (!any_identity) { - out << " identity("; - any_identity = true; - } else { - out << ", "; - } - output_property(out, (*pi).first); - } - } - if (any_identity) { - out << ")"; - } - - bool any_on = false; - for (pi = _properties.begin(); pi != _properties.end(); ++pi) { - if ((*pi).second == TD_on) { - if (!any_on) { - out << " on("; - any_on = true; - } else { - out << ", "; - } - output_property(out, (*pi).first); - } - } - if (any_on) { - out << ")"; - } - - bool any_off = false; - for (pi = _properties.begin(); pi != _properties.end(); ++pi) { - if ((*pi).second == TD_off) { - if (!any_off) { - out << " off("; - any_off = true; - } else { - out << ", "; - } - output_property(out, (*pi).first); - } - } - if (any_off) { - out << ")"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -void MultiTransition:: -write(ostream &out, int indent_level) const { - Properties::const_iterator pi; - - bool any_identity = false; - for (pi = _properties.begin(); pi != _properties.end(); ++pi) { - if ((*pi).second == TD_identity) { - if (!any_identity) { - indent(out, indent_level) << "identity:\n"; - any_identity = true; - } - write_property(out, (*pi).first, indent_level + 2); - } - } - - bool any_on = false; - for (pi = _properties.begin(); pi != _properties.end(); ++pi) { - if ((*pi).second == TD_on) { - if (!any_on) { - indent(out, indent_level) << "on:\n"; - any_on = true; - } - write_property(out, (*pi).first, indent_level + 2); - } - } - - bool any_off = false; - for (pi = _properties.begin(); pi != _properties.end(); ++pi) { - if ((*pi).second == TD_off) { - if (!any_off) { - indent(out, indent_level) << "off:\n"; - any_off = true; - } - write_property(out, (*pi).first, indent_level + 2); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::internal_compare_to -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -int MultiTransition:: -internal_compare_to(const NodeTransition *other) const { - const MultiTransition *ot; - DCAST_INTO_R(ot, other, false); - - if (_default_dir != ot->_default_dir) { - return (int)_default_dir - (int)ot->_default_dir; - } - - return dmap_compare(_properties.begin(), _properties.end(), - ot->_properties.begin(), ot->_properties.end()); -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::output_property -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -void MultiTransition:: -output_property(ostream &, const Property &) const { -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::write_property -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -template -void MultiTransition:: -write_property(ostream &, const Property &, int) const { -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::size -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -INLINE MultiTransition::size_type MultiTransition:: -size() const { - return _properties.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::begin -// Access: Public -// Description: Returns an iterator that begins the sequence of -// properties in the transition. -//////////////////////////////////////////////////////////////////// -template -INLINE MultiTransition::const_iterator MultiTransition:: -begin() const { - return _properties.begin(); -} - -//////////////////////////////////////////////////////////////////// -// Function: MultiTransition::end -// Access: Public -// Description: Returns an iterator that marks the end of the -// sequence of properties in the transition. -//////////////////////////////////////////////////////////////////// -template -INLINE MultiTransition::const_iterator MultiTransition:: -end() const { - return _properties.end(); -} - diff --git a/panda/src/graph/multiTransition.h b/panda/src/graph/multiTransition.h deleted file mode 100644 index bb0d76449b..0000000000 --- a/panda/src/graph/multiTransition.h +++ /dev/null @@ -1,154 +0,0 @@ -// Filename: multiTransition.h -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef MULTITRANSITION_H -#define MULTITRANSITION_H - -#include "pandabase.h" - -#include "nodeTransition.h" -#include "transitionDirection.h" -#include "multiTransitionHelpers.h" - -#include "indent.h" -#include "firstOfPairLess.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : MultiTransition -// Description : This is an abstract template class that encapsulates -// states that may have any number of subcomponents, in -// no particular order, any of which may be on or off at -// a given time. The classic example of this is a -// LightTransition, which may represent any arbitrary -// set of lights that are to be considered on at a given -// time. -// -// This is a template class; it templates on the type of -// thing that is to be on or off, as well as a class -// that encodes the name of the thing. This class -// (which might be the same as the Property class) -// should contain a static method called -// "get_class_name()" which returns the string name of -// the Property class. This is necessary to allow the -// MultiTransition it initialize its TypeHandle -// properly. -// -// Also see MultiNodeTransition. -//////////////////////////////////////////////////////////////////// -template -class MultiTransition : public NodeTransition { -private: - typedef pair Element; - - // This has to be a vector and not a map, so we can safely access - // the iterators outside of PANDA.DLL. - typedef pvector Properties; - - // We use this as an STL function object for sorting the vector in - // order by its property. - typedef FirstOfPairLess SortByFirstOfPair; - -protected: - MultiTransition(); - MultiTransition(const MultiTransition ©); - void operator = (const MultiTransition ©); - -PUBLISHED: - void clear(); - bool is_identity() const; - - // Typically a MultiTransition will be in "incomplete" mode; that - // is, it presents an incomplete view of the state that we desire. - // That means that components which are not mentioned in a - // particular transition will not be affected by the transition; if - // they were off, they will remain off; if they were on, they will - // remain on. - - // Sometimes you want a transition to be able to turn off all - // components (for instance, to disable lighting by turning off all - // lights) or to turn on all components. To achieve either effect, - // set the default direction, which indicates whether to implicitly - // turn on or off (or leave alone) any property not explicitly - // mentioned in the transition. - INLINE void set_default_dir(TransitionDirection dir); - INLINE TransitionDirection get_default_dir() const; - - void set_identity(const Property &prop); - void set_on(const Property &prop); - void set_off(const Property &prop); - - bool is_identity(const Property &prop) const; - bool is_on(const Property &prop) const; - bool is_off(const Property &prop) const; - -public: - virtual NodeTransition *make_identity() const=0; - - virtual NodeTransition *compose(const NodeTransition *other) const; - virtual NodeTransition *invert() const; - - virtual void output(ostream &out) const; - virtual void write(ostream &out, int indent_level = 0) const; - -protected: - virtual int internal_compare_to(const NodeTransition *other) const; - - virtual void output_property(ostream &out, const Property &prop) const; - virtual void write_property(ostream &out, const Property &prop, - int indent_level) const; - -public: - // These functions and typedefs allow one to peruse all of the - // Properties in the transition. - typedef Properties::const_iterator iterator; - typedef Properties::const_iterator const_iterator; - typedef Properties::value_type value_type; - typedef Properties::size_type size_type; - - INLINE size_type size() const; - INLINE const_iterator begin() const; - INLINE const_iterator end() const; - -private: - Properties _properties; - TransitionDirection _default_dir; - -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() { - NodeTransition::init_type(); - register_type(_type_handle, - string("MultiTransition<")+NameClass::get_class_name()+">", - NodeTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "multiTransition.T" - -#endif diff --git a/panda/src/graph/multiTransitionHelpers.I b/panda/src/graph/multiTransitionHelpers.I deleted file mode 100644 index f2d032cdd0..0000000000 --- a/panda/src/graph/multiTransitionHelpers.I +++ /dev/null @@ -1,447 +0,0 @@ -// Filename: multiTransitionHelpers.I -// Created by: drose (15Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: dmap_compose -// Description: Accepts two DirectionMaps, and builds a new -// list (another DirectionMap) which represents the -// memberwise composition of the two input maps. -//////////////////////////////////////////////////////////////////// -template -OutputIterator -dmap_compose(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result) { - while (first1 != last1 && first2 != last2) { - if ((*first1).first < (*first2).first) { - *result = *first1; - ++first1; - ++result; - } else if ((*first2).first < (*first1).first) { - *result = *first2; - ++first2; - ++result; - } else { - // If the second Transition is identity, it has no effect. - // Otherwise, it replaces us. - if ((*first2).second != TD_identity) { - *result = *first2; - } else { - *result = *first1; - } - ++first1; - ++first2; - ++result; - } - } - - while (first1 != last1) { - *result = *first1; - ++first1; - ++result; - } - - while (first2 != last2) { - *result = *first2; - ++first2; - ++result; - } - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: dmap_invert_compose -// Description: Accepts two DirectionMaps, and builds a new -// list (another DirectionMap) which represents the -// memberwise result inverting and composing. -//////////////////////////////////////////////////////////////////// -template -OutputIterator -dmap_invert_compose(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result) { - typedef TYPENAME InputIterator1::value_type OutputType; - - while (first1 != last1 && first2 != last2) { - if ((*first1).first < (*first2).first) { - (*result) = OutputType((*first1).first, TD_inverse); - ++first1; - ++result; - } else if ((*first2).first < (*first1).first) { - *result = *first2; - ++first2; - ++result; - } else { - TransitionDirection dir1 = (*first1).second; - TransitionDirection dir2 = (*first2).second; - - if (dir1 == dir2 && - (dir1 != TD_normal || (*first1).first == (*first2).first)) { - // The two transitions are equivalent, so the invert_compose - // will be identity. Don't bother to store it. - - } else { - if ((*first2).second != TD_identity) { - *result = *first2; - } else { - (*result) = OutputType((*first1).first, TD_inverse); - } - ++result; - } - ++first1; - ++first2; - } - } - - while (first1 != last1) { - (*result) = OutputType((*first1).first, TD_inverse); - ++first1; - ++result; - } - - while (first2 != last2) { - *result = *first2; - ++first2; - ++result; - } - return result; -} - - -//////////////////////////////////////////////////////////////////// -// Function: dmap_invert -// Description: Accepts a DirectionMap, and builds a new list -// which represents the memberwise inversion of the -// input. Guarantees that the new list will have -// exactly the same length as the input list. -//////////////////////////////////////////////////////////////////// -template -OutputIterator -dmap_invert(InputIterator first, InputIterator last, - OutputIterator result, ValueType *) { - while (first != last) { - switch ((*first).second) { - case TD_identity: - (*result) = ValueType((*first).first, TD_identity); - ++result; - break; - - case TD_on: - (*result) = ValueType((*first).first, TD_off); - ++result; - break; - - case TD_off: - (*result) = ValueType((*first).first, TD_on); - ++result; - break; - } - ++first; - } - return result; -} - - -//////////////////////////////////////////////////////////////////// -// Function: dmap_equiv -// Description: Accepts a pair of DirectionMaps, and returns -// true if they are equivalent, false otherwise. Two -// DirectionMaps are defined to be equivalent if -// all nonidentity members present in one set are -// present and equivalent in the other set, -//////////////////////////////////////////////////////////////////// -template -bool -dmap_equiv(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2) { - while (first1 != last1 && first2 != last2) { - if ((*first1).first < (*first2).first) { - if ((*first1).second != TD_identity) { - return false; - } - ++first1; - } else if ((*first2).first < (*first1).first) { - if ((*first2).second != TD_identity) { - return false; - } - ++first2; - } else { - TransitionDirection dir1 = (*first1).second; - TransitionDirection dir2 = (*first2).second; - - if (dir1 != dir2) { - return false; - } - ++first1; - ++first2; - } - } - - while (first1 != last1) { - if ((*first1).second != TD_identity) { - return false; - } - ++first1; - } - - while (first2 != last2) { - if ((*first2).second != TD_identity) { - return false; - } - ++first2; - } - return true; -} - - -//////////////////////////////////////////////////////////////////// -// Function: dmap_compare -// Description: Accepts a pair of DirectionMaps, and returns -// < 0 if the first one sorts before the second one, > 0 -// if the first one sorts after, 0 if they are -// equivalent. -//////////////////////////////////////////////////////////////////// -template -int -dmap_compare(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2) { - while (first1 != last1 && first2 != last2) { - if ((*first1).first < (*first2).first) { - if ((*first1).second != TD_identity) { - // list1 has the first value that does not appear in list2. - return 1; - } - ++first1; - } else if ((*first2).first < (*first1).first) { - if ((*first2).second != TD_identity) { - // list2 has the first value that does not appear in list1. - return -1; - } - ++first2; - } else { - TransitionDirection dir1 = (*first1).second; - TransitionDirection dir2 = (*first2).second; - - if (dir1 != dir2) { - if (dir1 == TD_identity) { - // list1 has the first value that does not appear in list2. - return 1; - } else if (dir2 == TD_identity) { - // list2 has the first value that does not appear in list1. - return -1; - } - - // This value appears in both lists, but it is TD_normal in - // one and TD_inverse in the other. - return (dir1 < dir2) ? -1 : 1; - } - - ++first1; - ++first2; - } - } - - while (first1 != last1) { - if ((*first1).second != TD_identity) { - // list1 is longer. - return -1; - } - ++first1; - } - - while (first2 != last2) { - if ((*first2).second != TD_identity) { - // list2 is longer. - return 1; - } - ++first2; - } - - return 0; -} - - -//////////////////////////////////////////////////////////////////// -// Function: dmap_is_identity -// Description: Accepts a DirectionMap, and returns true if all -// elements in the map correspond to the identity -// transition, false otherwise. -//////////////////////////////////////////////////////////////////// -template -bool -dmap_is_identity(InputIterator first, InputIterator last) { - while (first != last) { - if ((*first).second != TD_identity) { - return false; - } - ++first; - } - return true; -} - - - -//////////////////////////////////////////////////////////////////// -// Function: bmap_equiv -// Description: Accepts a pair of BoolMaps, and returns true if they -// are equivalent, false otherwise. Two BoolMaps are -// defined to be equivalent if all 'on' members present -// in one set are present and equivalent in the other -// set, -//////////////////////////////////////////////////////////////////// -template -bool -bmap_equiv(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2) { - while (first1 != last1 && first2 != last2) { - if ((*first1) < (*first2)) { - return false; - } else if ((*first2) < (*first1)) { - return false; - } else { - ++first1; - ++first2; - } - } - - if (first1 != last1 || first2 != last2) { - return false; - } - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: bmap_compare -// Description: Accepts a pair of BoolMaps, and returns < 0 if the -// first one sorts first, > 0 if the second one sorts -// first, 0 if they are equivalent. -//////////////////////////////////////////////////////////////////// -template -int -bmap_compare(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2) { - while (first1 != last1 && first2 != last2) { - if ((*first1) < (*first2)) { - return -1; - } else if ((*first2) < (*first1)) { - return 1; - } else { - ++first1; - ++first2; - } - } - - if (first1 != last1) { - // list 1 is longer. - return -1; - } - if (first2 != last2) { - // list 2 is longer. - return 1; - } - - return 0; -} - - -//////////////////////////////////////////////////////////////////// -// Function: bmap_apply -// Description: Accepts a BoolMap and a DirectionMap, and builds a -// new list (another BoolMap) which represents the -// memberwise application of the two input maps. -//////////////////////////////////////////////////////////////////// -template -OutputIterator -bmap_apply(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - bool complete_transition, TransitionDirection want_dirs, - OutputIterator result) { - while (first1 != last1 && first2 != last2) { - if ((*first1) < (*first2).first) { - // Here's an attribute property that wasn't mentioned by the - // transition. It stays, unless the transition is "complete". - if (!complete_transition) { - *result = *first1; - ++result; - } - ++first1; - - } else if ((*first2).first < (*first1)) { - // The transition mentions this property that wasn't previously - // in the attribute. It becomes a member of the attribute only - // if the transition explicitly turned it on. - - if ((*first2).second == want_dirs) { - *result = (*first2).first; - ++result; - break; - } - - ++first2; - - } else { // ((*first2).first == (*first1)) - - // The transition mentions this property that was already in the - // attribute. Does the transition replace, preserve, or delete - // the attribute? - - if ((*first2).second == TD_identity) { - // Preserve. - *result = *first1; - ++result; - - } else if ((*first2).second == want_dirs) { - // Replace. - *result = (*first2).first; - ++result; - - } else { - // Omit. - } - - ++first1; - ++first2; - } - } - - while (first1 != last1) { - // Here's an attribute property that wasn't mentioned by the - // transition. It stays, unless the transition is "complete". - if (!complete_transition) { - *result = *first1; - ++result; - } - ++first1; - } - - while (first2 != last2) { - // The transition mentions this property that wasn't previously - // in the attribute. It becomes a member of the attribute only - // if the transition explicitly turned it on. - - if ((*first2).second == want_dirs) { - *result = (*first2).first; - ++result; - break; - } - - ++first2; - } - return result; -} diff --git a/panda/src/graph/multiTransitionHelpers.h b/panda/src/graph/multiTransitionHelpers.h deleted file mode 100644 index 9333293ca2..0000000000 --- a/panda/src/graph/multiTransitionHelpers.h +++ /dev/null @@ -1,144 +0,0 @@ -// Filename: multiTransitionHelpers.h -// Created by: drose (15Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef MULTITRANSITIONHELPERS_H -#define MULTITRANSITIONHELPERS_H - -#include - -#include "transitionDirection.h" - -//////////////////////////////////////////////////////////////////// -// Function: dmap_compose -// Description: Accepts two DirectionMaps, and builds a new -// list (another DirectionMap) which represents the -// memberwise composition of the two input maps. -//////////////////////////////////////////////////////////////////// -template -OutputIterator -dmap_compose(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result); - - -//////////////////////////////////////////////////////////////////// -// Function: dmap_invert_compose -// Description: Accepts two DirectionMaps, and builds a new -// list (another DirectionMap) which represents the -// memberwise result inverting and composing. -//////////////////////////////////////////////////////////////////// -template -OutputIterator -dmap_invert_compose(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result); - - -//////////////////////////////////////////////////////////////////// -// Function: dmap_invert -// Description: Accepts a DirectionMap, and builds a new list -// which represents the memberwise inversion of the -// input. Guarantees that the new list will have -// exactly the same length as the input list. -//////////////////////////////////////////////////////////////////// -template -OutputIterator -dmap_invert(InputIterator first, InputIterator last, - OutputIterator result, ValueType *); - - -//////////////////////////////////////////////////////////////////// -// Function: dmap_equiv -// Description: Accepts a pair of DirectionMaps, and returns -// true if they are equivalent, false otherwise. Two -// DirectionMaps are defined to be equivalent if -// all nonidentity members present in one set are -// present and equivalent in the other set, -//////////////////////////////////////////////////////////////////// -template -bool -dmap_equiv(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2); - -//////////////////////////////////////////////////////////////////// -// Function: dmap_compare -// Description: Accepts a pair of DirectionMaps, and returns -// < 0 if the first one sorts before the second one, > 0 -// if the first one sorts after, 0 if they are -// equivalent. -//////////////////////////////////////////////////////////////////// -template -int -dmap_compare(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2); - - -//////////////////////////////////////////////////////////////////// -// Function: dmap_is_identity -// Description: Accepts a DirectionMap, and returns true if all -// elements in the map correspond to the identity -// transition, false otherwise. -//////////////////////////////////////////////////////////////////// -template -bool -dmap_is_identity(InputIterator first, InputIterator last); - - -//////////////////////////////////////////////////////////////////// -// Function: bmap_equiv -// Description: Accepts a pair of BoolMaps, and returns true if they -// are equivalent, false otherwise. Two BoolMaps are -// defined to be equivalent if all 'on' members present -// in one set are present and equivalent in the other -// set, -//////////////////////////////////////////////////////////////////// -template -bool -bmap_equiv(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2); - -//////////////////////////////////////////////////////////////////// -// Function: bmap_compare -// Description: Accepts a pair of BoolMaps, and returns < 0 if the -// first one sorts first, > 0 if the second one sorts -// first, 0 if they are equivalent. -//////////////////////////////////////////////////////////////////// -template -int -bmap_compare(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2); - - -//////////////////////////////////////////////////////////////////// -// Function: bmap_apply -// Description: Accepts a BoolMap and a DirectionMap, and builds a -// new list (another BoolMap) which represents the -// memberwise application of the two input maps. -//////////////////////////////////////////////////////////////////// -template -OutputIterator -bmap_apply(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - bool complete_transition, TransitionDirection want_dirs, - OutputIterator result); - -#ifndef DONT_INLINE_GRAPH -#include "multiTransitionHelpers.I" -#endif - -#endif diff --git a/panda/src/graph/namedNode.I b/panda/src/graph/namedNode.I deleted file mode 100644 index a5e07c49a5..0000000000 --- a/panda/src/graph/namedNode.I +++ /dev/null @@ -1,56 +0,0 @@ -// Filename: namedNode.I -// Created by: drose (23May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: NamedNode::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NamedNode:: -NamedNode(const string &initial_name) : - Namable(initial_name) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: NamedNode::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NamedNode:: -NamedNode(const NamedNode ©) : - Node(copy), Namable(copy) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: NamedNode::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NamedNode:: -operator = (const NamedNode ©) { - Node::operator = (copy); - Namable::operator = (copy); -} - -EXPCL_PANDA INLINE_GRAPH ostream & operator << (ostream &out, const NamedNode &nod) { - nod.output(out); - return out; -} diff --git a/panda/src/graph/namedNode.cxx b/panda/src/graph/namedNode.cxx deleted file mode 100644 index 4ed8c6ebf9..0000000000 --- a/panda/src/graph/namedNode.cxx +++ /dev/null @@ -1,177 +0,0 @@ -// Filename: namedNode.cxx -// Created by: drose (15Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "namedNode.h" -#include "config_graph.h" - -#include "bamWriter.h" -#include "bamReader.h" -#include "datagram.h" -#include "datagramIterator.h" - -TypeHandle NamedNode::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: NamedNode::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -NamedNode:: -~NamedNode() { - if (graph_cat.is_debug()) { - graph_cat.debug() - << "Deleting node " << get_name() << "\n"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NamedNode::make_copy -// Access: Public, Virtual -// Description: Returns a newly-allocated Node that is a shallow copy -// of this one. It will be a different Node pointer, -// but its internal data may or may not be shared with -// that of the original Node. -//////////////////////////////////////////////////////////////////// -Node *NamedNode:: -make_copy() const { - return new NamedNode(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: NamedNode::combine_with -// Access: Public, Virtual -// Description: Collapses this node with the other node, if possible, -// and returns a pointer to the combined node, or NULL -// if the two nodes cannot safely be combined. -// -// The return value may be this, other, or a new node -// altogether. -// -// This function is called from GraphReducer::flatten(), -// and need not deal with children; its job is just to -// decide whether to collapse the two nodes and what the -// collapsed node should look like. -//////////////////////////////////////////////////////////////////// -Node *NamedNode:: -combine_with(Node *other) { - // An unadorned NamedNode combines with other Nodes by yielding - // completely. However, if we are actually some fancy Node type - // that derives from NamedNode but didn't redefine this function, we - // should refuse to combine. - if (is_exact_type(get_class_type())) { - // No, we're an ordinary NamedNode. - if (other->is_exact_type(Node::get_class_type())) { - // And the other node isn't even named, so we override. - return this; - } - // The other node is also a NamedNode, or better, so it wins. - return other; - - } else if (other->is_exact_type(get_class_type())) { - // We're not an ordinary NamedNode, but the other one is. - return this; - } - - // We're something other than an ordinary NamedNode. Don't combine. - return Node::combine_with(other); -} - -//////////////////////////////////////////////////////////////////// -// Function: NamedNode::preserve_name -// Access: Public, Virtual -// Description: Returns true if the node's name has extrinsic meaning -// and must be preserved across a flatten operation, -// false otherwise. -//////////////////////////////////////////////////////////////////// -bool NamedNode:: -preserve_name() const { - return false; -} - - -//////////////////////////////////////////////////////////////////// -// Function: NamedNode::Output -// Access: Public, Virtual -// Description: Writes a brief description of the node to the -// indicated output stream. This is invoked by the << -// operator. It may be overridden in derived classes to -// include some information relevant to the class. -//////////////////////////////////////////////////////////////////// -void NamedNode:: -output(ostream &out) const { - if (get_name().empty()) { - out << get_type(); - } else { - out << get_type() << " " << get_name(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NamedNode::write_object -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void NamedNode:: -write_datagram(BamWriter *manager, Datagram &me) -{ - Node::write_datagram(manager, me); - me.add_string(get_name()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NamedNode::make_NamedNode -// Access: Protected -// Description: Factory method to generate a node object -//////////////////////////////////////////////////////////////////// -TypedWritable* NamedNode:: -make_NamedNode(const FactoryParams ¶ms) -{ - NamedNode *me = new NamedNode; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: NamedNode::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void NamedNode:: -fillin(DatagramIterator& scan, BamReader* manager) -{ - Node::fillin(scan, manager); - set_name(scan.get_string()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NamedNode::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a node object -//////////////////////////////////////////////////////////////////// -void NamedNode:: -register_with_read_factory(void) -{ - BamReader::get_factory()->register_factory(get_class_type(), make_NamedNode); -} diff --git a/panda/src/graph/namedNode.h b/panda/src/graph/namedNode.h deleted file mode 100644 index e8c3347472..0000000000 --- a/panda/src/graph/namedNode.h +++ /dev/null @@ -1,85 +0,0 @@ -// Filename: namedNode.h -// Created by: drose (15Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef NAMEDNODE_H -#define NAMEDNODE_H - -#include - -#include "node.h" -#include - -/////////////////////////////////////////////////////////////////// -// Class : NamedNode -// Description : A base class for all nodes which have names. This -// will be (almost?) all of them. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA NamedNode : public Node, public Namable { -PUBLISHED: - INLINE_GRAPH NamedNode(const string &initial_name = ""); - -public: - INLINE_GRAPH NamedNode(const NamedNode ©); - INLINE_GRAPH void operator = (const NamedNode ©); - virtual ~NamedNode(); - - virtual Node *make_copy() const; - virtual Node *combine_with(Node *other); - - virtual bool preserve_name() const; - - virtual void output(ostream &out) const; - - static void register_with_read_factory(void); - virtual void write_datagram(BamWriter* manager, Datagram &me); - - static TypedWritable *make_NamedNode(const FactoryParams ¶ms); - -protected: - 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() { - Node::init_type(); - Namable::init_type(); - register_type(_type_handle, "NamedNode", - Node::get_class_type(), - Namable::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -// We need this operator to specify which output operator (from Node -// or Namable) that NamedNode uses. -EXPCL_PANDA INLINE_GRAPH ostream & operator << (ostream &out, const NamedNode &nod); - -#ifndef DONT_INLINE_GRAPH -#include "namedNode.I" -#endif - -#endif - diff --git a/panda/src/graph/node.I b/panda/src/graph/node.I deleted file mode 100644 index 2eba289fac..0000000000 --- a/panda/src/graph/node.I +++ /dev/null @@ -1,83 +0,0 @@ -// Filename: node.I -// Created by: drose (26Oct98) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include - - -//////////////////////////////////////////////////////////////////// -// Function: Node::find_connection -// Access: Public -// Description: Returns a const reference to the NodeConnection of -// the indicated graph type, if one exists, or a const -// reference to an empty NodeConnection if a connection -// of the indicated type does not exist. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH const NodeConnection &Node:: -find_connection(TypeHandle graph_type) const { - if (_connections[0].get_graph_type() == graph_type) { - return _connections[0]; - } - if (max_node_graphs > 1) { - return p_find_connection(graph_type); - } else { - return _empty_connection; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::update_connection -// Access: Public -// Description: Returns a non-const pointer to the NodeConnection of -// the indicated graph type, if one exists. If a -// NodeConnection of the indicated type does not already -// exist, creates one if possible and returns its -// pointer. Otherwise, returns NULL. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeConnection *Node:: -update_connection(TypeHandle graph_type) { - if (_connections[0].get_graph_type() == graph_type) { - return &_connections[0]; - } - if (max_node_graphs > 1) { - return p_update_connection(graph_type); - } else { - return (NodeConnection *)NULL; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: remove_child -// Description: Finds the arc that connects the indicated nodes and -// removes it. Returns true if the arc was found and -// removed, false if it did not exist. -//////////////////////////////////////////////////////////////////// -EXPCL_PANDA INLINE_GRAPH bool -remove_child(Node *parent, Node *child, TypeHandle graph_type) { - NodeRelation *arc = find_arc(parent, child, graph_type); - if (arc != (NodeRelation *)NULL) { - remove_arc(arc); - return true; - } - return false; -} - -EXPCL_PANDA INLINE_GRAPH ostream & -operator << (ostream &out, const Node &node) { - node.output(out); - return out; -} diff --git a/panda/src/graph/node.cxx b/panda/src/graph/node.cxx deleted file mode 100644 index 0d80961783..0000000000 --- a/panda/src/graph/node.cxx +++ /dev/null @@ -1,719 +0,0 @@ -// Filename: node.cxx -// Created by: drose (27Oct98) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "node.h" -#include "nodeRelation.h" - -#include -#include -#include -#include -#include - -NodeConnection Node::_empty_connection; -TypeHandle Node::_type_handle; -Node* const Node::Null = (Node*)0L; - - -//////////////////////////////////////////////////////////////////// -// Function: Node::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -Node:: -Node() { -#ifdef DO_MEMORY_USAGE - MemoryUsage::update_type(this, this); -#endif -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::Copy Constructor -// Access: Public -// Description: The Node copy constructor does not copy children. -// Use copy_subgraph() if you want a deep copy of the -// node and all of its children. Also, you should use -// make_copy() if you just want a typed copy of the Node -// (without children). -//////////////////////////////////////////////////////////////////// -Node:: -Node(const Node ©) : - TypedWritable(copy), - BoundedObject(copy), - ReferenceCount(copy) -{ -#ifdef DO_MEMORY_USAGE - MemoryUsage::update_type(this, this); -#endif -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void Node:: -operator = (const Node ©) { - TypedWritable::operator = (copy); - BoundedObject::operator = (copy); - ReferenceCount::operator = (copy); -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::Destructor -// Access: Public, Virtual -// Description: When a Node destructs, all of its arcs must be -// deleted as well. -//////////////////////////////////////////////////////////////////// -Node:: -~Node() { - // We'd better not have any arcs pointing into this node, since - // we're destructing it now. If we do, the destructor was called in - // error. - int i; - for (i = 0; i < max_node_graphs; i++) { - UpRelationPointers &urp = _connections[i].get_up(); - nassertv(urp.empty()); - } - - // Now disconnect all the child arcs. - for (i = 0; i < max_node_graphs; i++) { - DownRelationPointers &drp = _connections[i].get_down(); - - DownRelationPointers::iterator drpi; - for (drpi = drp.begin(); drpi != drp.end(); ++drpi) { - NodeRelation *arc = (*drpi); - nassertv(arc != (NodeRelation *)NULL); - - // This deletes the arc and anything below it through the magic - // of reference-counting. - arc->detach_below(); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::make_copy -// Access: Public, Virtual -// Description: Returns a newly-allocated Node that is a shallow copy -// of this one. It will be a different Node pointer, -// but its internal data may or may not be shared with -// that of the original Node. No children will be -// copied. -//////////////////////////////////////////////////////////////////// -Node *Node:: -make_copy() const { - return new Node(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::copy_subgraph -// Access: Public -// Description: Allocates and returns a complete copy of this node -// and the entire scene graph rooted at this node. Some -// data may still be shared from the original -// (e.g. vertex index tables), but nothing that will -// impede normal use of the node. -//////////////////////////////////////////////////////////////////// -Node *Node:: -copy_subgraph(TypeHandle graph_type) const { - InstanceMap inst_map; - return r_copy_subgraph(graph_type, inst_map); -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::safe_to_flatten -// Access: Public, Virtual -// Description: Returns true if it is generally safe to flatten out -// this particular kind of Node by duplicating -// instances, false otherwise (for instance, a Camera -// cannot be safely flattened, because the Camera -// pointer itself is meaningful). -//////////////////////////////////////////////////////////////////// -bool Node:: -safe_to_flatten() const { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::safe_to_transform -// Access: Public, Virtual -// Description: Returns true if it is generally safe to transform -// this particular kind of Node by calling the xform() -// method, false otherwise. For instance, it's usually -// a bad idea to attempt to xform a Character. -//////////////////////////////////////////////////////////////////// -bool Node:: -safe_to_transform() const { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::safe_to_combine -// Access: Public, Virtual -// Description: Returns true if it is generally safe to combine -// this particular kind of Node with other kinds of -// Nodes, adding children or whatever. For instance, an -// LODNode should not be combined with any other node, -// because its set of children is meaningful. -//////////////////////////////////////////////////////////////////// -bool Node:: -safe_to_combine() const { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::xform -// Access: Public, Virtual -// Description: Transforms the contents of this node by the indicated -// matrix, if it means anything to do so. For most -// kinds of nodes, this does nothing. -//////////////////////////////////////////////////////////////////// -void Node:: -xform(const LMatrix4f &) { -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::combine_with -// Access: Public, Virtual -// Description: Collapses this node with the other node, if possible, -// and returns a pointer to the combined node, or NULL -// if the two nodes cannot safely be combined. -// -// The return value may be this, other, or a new node -// altogether. -// -// This function is called from GraphReducer::flatten(), -// and need not deal with children; its job is just to -// decide whether to collapse the two nodes and what the -// collapsed node should look like. -//////////////////////////////////////////////////////////////////// -Node *Node:: -combine_with(Node *other) { - // An unadorned Node always combines with any other Nodes by - // yielding completely. However, if we are actually some fancy Node - // type that derives from Node but didn't redefine this function, we - // should refuse to combine. - if (is_exact_type(get_class_type())) { - // No, we're an ordinary Node. - return other; - - } else if (other->is_exact_type(get_class_type())) { - // We're not an ordinary Node, but the other one is. - return this; - } - - // We're something other than an ordinary Node. Don't combine. - return (Node *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::transform_changed -// Access: Public, Virtual -// Description: Called whenever the transform matrix on one of the -// arcs directly above this node has changed. This is -// simply a hook so the node can do something -// appropriate. It does not get called when arcs far -// above the node change. -//////////////////////////////////////////////////////////////////// -void Node:: -transform_changed(NodeRelation *) { -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::get_num_parents -// Access: Public -// Description: Returns the number of parent arcs of the indicated -// type (e.g. RenderRelation::get_class_type()) the node -// has. -//////////////////////////////////////////////////////////////////// -int Node:: -get_num_parents(TypeHandle type) const { - const UpRelationPointers &urp = find_connection(type).get_up(); - return urp.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::get_parent -// Access: Public -// Description: Returns the nth parent arc of the indicated type the -// node has. The index must be in the range 0 <= index -// < get_num_parents(type). -//////////////////////////////////////////////////////////////////// -NodeRelation *Node:: -get_parent(TypeHandle type, int index) const { - const UpRelationPointers &urp = find_connection(type).get_up(); - nassertr(index >= 0 && index < (int)urp.size(), - (NodeRelation *)NULL); - return urp[index]; -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::get_num_children -// Access: Public -// Description: Returns the number of child arcs of the indicated -// type (e.g. RenderRelation::get_class_type()) the node -// has. -//////////////////////////////////////////////////////////////////// -int Node:: -get_num_children(TypeHandle type) const { - const DownRelationPointers &drp = find_connection(type).get_down(); - return drp.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::get_child -// Access: Public -// Description: Returns the nth child arc of the indicated type the -// node has. The index must be in the range 0 <= index -// < get_num_children(type). -//////////////////////////////////////////////////////////////////// -NodeRelation *Node:: -get_child(TypeHandle type, int index) const { - const DownRelationPointers &drp = find_connection(type).get_down(); - nassertr(index >= 0 && index < (int)drp.size(), - (NodeRelation *)NULL); - return drp[index]; -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::app_traverse -// Access: Public, Virtual -// Description: This hook function is called on each node visited -// during the App traversal. The ArcChain passed in -// represents the complete chain from the root of the -// graph to this node, if it is known. -//////////////////////////////////////////////////////////////////// -void Node:: -app_traverse(const ArcChain &) { -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::draw_traverse -// Access: Public, Virtual -// Description: This hook function is called on each node visited -// during the Draw traversal. The ArcChain passed in -// represents the complete chain from the root of the -// graph to this node, if it is known. -//////////////////////////////////////////////////////////////////// -void Node:: -draw_traverse(const ArcChain &) { -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::dgraph_traverse -// Access: Public, Virtual -// Description: This hook function is called on each node visited -// during the data graph traversal. The ArcChain passed -// in represents the complete chain from the root of the -// graph to this node, if it is known. -//////////////////////////////////////////////////////////////////// -void Node:: -dgraph_traverse(const ArcChain &) { -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::sub_render -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -bool Node:: -sub_render(const AllTransitionsWrapper &, AllTransitionsWrapper &, - RenderTraverser *) { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::has_sub_render -// Access: Public, Virtual -// Description: Should be redefined to return true if the function -// sub_render(), above, expects to be called during -// traversal. -//////////////////////////////////////////////////////////////////// -bool Node:: -has_sub_render() const { - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::output -// Access: Public, Virtual -// Description: Writes a brief description of the node to the -// indicated output stream. This is invoked by the << -// operator. It may be overridden in derived classes to -// include some information relevant to the class. -//////////////////////////////////////////////////////////////////// -void Node:: -output(ostream &out) const { - out << get_type(); -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void Node:: -write(ostream &out, int indent_level) const { - indent(out, indent_level) << *this << "\n"; -} - - -//////////////////////////////////////////////////////////////////// -// Function: Node::p_find_connection -// Access: Private -// Description: The non-inline implementation of find_connection(). -//////////////////////////////////////////////////////////////////// -const NodeConnection &Node:: -p_find_connection(TypeHandle graph_type) const { - // _connections[0] is already tested by the inline implementation. - for (int i = 1; i < max_node_graphs; i++) { - if (_connections[i].get_graph_type() == graph_type) { - return _connections[i]; - } - } - return _empty_connection; -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::p_update_connection -// Access: Private -// Description: The non-inline implementation of update_connection(). -//////////////////////////////////////////////////////////////////// -NodeConnection *Node:: -p_update_connection(TypeHandle graph_type) { - // _connections[0] is already tested by the inline implementation. - int i; - for (i = 1; i < max_node_graphs; i++) { - if (_connections[i].get_graph_type() == graph_type) { - return &_connections[i]; - } - } - - // No such connection; can we create a new one? - for (i = 0; i < max_node_graphs; i++) { - if (_connections[i].is_empty()) { - _connections[i].set_graph_type(graph_type); - return &_connections[i]; - } - } - - // Too bad. - return (NodeConnection *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::propagate_stale_bound -// Access: Protected, Virtual -// Description: Called by BoundedObject::mark_bound_stale(), this -// should make sure that all bounding volumes that -// depend on this one are marked stale also. -//////////////////////////////////////////////////////////////////// -void Node:: -propagate_stale_bound() { - // Mark all of our parent arcs, in all graphs, stale as well. - for (int i = 0; i < max_node_graphs; i++) { - const UpRelationPointers &urp = _connections[i].get_up(); - UpRelationPointers::const_iterator urpi; - for (urpi = urp.begin(); urpi != urp.end(); ++urpi) { - (*urpi)->mark_bound_stale(); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::r_copy_subgraph -// Access: Protected, Virtual -// Description: This is the recursive implementation of copy_subgraph(). -// It returns a copy of the entire subgraph rooted at -// this node. -// -// Note that it includes the parameter inst_map, which -// is a map type, and is not (and cannot be) exported -// from PANDA.DLL. Thus, any derivative of Node that is -// not also a member of PANDA.DLL *cannot* access this -// map. -//////////////////////////////////////////////////////////////////// -Node *Node:: -r_copy_subgraph(TypeHandle graph_type, Node::InstanceMap &inst_map) const { - Node *copy = make_copy(); - nassertr(copy != (Node *)NULL, NULL); - if (copy->get_type() != get_type()) { - graph_cat.warning() - << "Don't know how to copy nodes of type " << get_type() << "\n"; - } - - copy->r_copy_children(this, graph_type, inst_map); - return copy; -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::r_copy_children -// Access: Protected, Virtual -// Description: This is called by r_copy_subgraph(); the copy has -// already been made of this particular node (and this -// is the copy); this function's job is to copy all of -// the children from the original. -// -// Note that it includes the parameter inst_map, which -// is a map type, and is not (and cannot be) exported -// from PANDA.DLL. Thus, any derivative of Node that is -// not also a member of PANDA.DLL *cannot* access this -// map, and probably should not even override this -// function. -//////////////////////////////////////////////////////////////////// -void Node:: -r_copy_children(const Node *from, TypeHandle graph_type, - Node::InstanceMap &inst_map) { - const DownRelationPointers &drp = - from->find_connection(graph_type).get_down(); - DownRelationPointers::const_iterator drpi; - for (drpi = drp.begin(); drpi != drp.end(); ++drpi) { - NodeRelation *source_arc = (*drpi); - Node *source_child = source_arc->get_child(); - nassertv(source_child != (Node *)NULL); - - Node *dest_child; - - // Check to see if we have already copied this child. If we - // have, use the copy. In this way, a subgraph that contains - // instances will be correctly duplicated into another subgraph - // that also contains its own instances. - InstanceMap::const_iterator ci; - ci = inst_map.find(source_child); - if (ci != inst_map.end()) { - dest_child = (*ci).second; - } else { - dest_child = source_child->r_copy_subgraph(graph_type, inst_map); - inst_map[source_child] = dest_child; - } - - NodeRelation *dest_arc = - NodeRelation::create_typed_arc(graph_type, this, dest_child); - nassertv(dest_arc != (NodeRelation *)NULL); - nassertv(dest_arc->is_exact_type(graph_type)); - - dest_arc->copy_transitions_from(source_arc); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void Node:: -write_datagram(BamWriter *manager, Datagram &me) { - // A node should not write out its UpRelations. This is because if - // a node is written out from the middle of the graph, then most - // likely we only want to write it and its children. If we did - // write out all of the UpRelations then writing any node in a graph - // would cause the entire graph to be written out. - - // First, count up the number of NodeConnections that are nonempty. - int num_connections = 0; - int i; - for (i = 0; i < max_node_graphs; i++) { - if (!_connections[i].is_empty()) { - num_connections++; - } - } - - me.add_uint16(num_connections); - - // Now write them out. - for (i = 0; i < max_node_graphs; i++) { - if (!_connections[i].is_empty()) { - manager->write_handle(me, _connections[i].get_graph_type()); - - const DownRelationPointers &drp = _connections[i].get_down(); - me.add_uint16(drp.size()); - DownRelationPointers::const_iterator drpi; - for (drpi = drp.begin(); drpi != drp.end(); ++drpi) { - NodeRelation *relation = (*drpi); - manager->write_pointer(me, relation); - } - } - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: Node::complete_pointers -// Access: Public -// Description: Takes in a vector of pointers to TypedWritable -// objects that correspond to all the requests for -// pointers that this object made to BamReader. -//////////////////////////////////////////////////////////////////// -int Node:: -complete_pointers(TypedWritable **p_list, BamReader *manager) { - if (manager->get_file_minor_ver() < 3) { - // In bam versions before 3.3, this function does nothing (since - // the arcs are completely responsible for adding themselves to - // our list); we only need to return the number of pointers we - // expected to receive. - - // As of 5/7/01, we no longer store this number, as a memory - // optimization. This means bams before 3.3 cannot be reliably - // loaded. - - graph_cat.warning() - << "Unable to reliably load bam version " - << manager->get_file_major_ver() << "." - << manager->get_file_minor_ver() << "\n"; - - return 0; - } - - // Beginning at bam version 3.3, we are responsible for adding our - // child arcs directly. - - int count = 0; - - for (int i = 0; i < max_node_graphs; i++) { - if (!_connections[i].is_empty()) { - DownRelationPointers &drp = _connections[i].get_down(); - - DownRelationPointers::iterator drpi; - for (drpi = drp.begin(); drpi != drp.end(); ++drpi) { - (*drpi) = DCAST(NodeRelation, p_list[count]); - count++; - } - } - } - - return count; -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::make_Node -// Access: Protected -// Description: Factory method to generate a node object -//////////////////////////////////////////////////////////////////// -TypedWritable* Node:: -make_Node(const FactoryParams ¶ms) { - Node *me = new Node; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void Node:: -fillin(DatagramIterator &scan, BamReader *manager) { - if (manager->get_file_minor_ver() < 3) { - // In bam versions before 3.3, we only need to count up the total - // number of arcs across all types, because we don't add the arc - // pointers explicitly here. - int num_types = scan.get_uint16(); - - while (num_types > 0) { - int num_arcs = scan.get_uint16(); - while (num_arcs > 0) { - manager->read_pointer(scan); - num_arcs--; - } - num_types--; - } - - } else { - // Beginning at bam version 3.3, we do all the reading of our - // children arcs of all types, which means we need to record the - // numbers of each type of children. We do this by recording a - // series of NULL pointers in our NodeConnections. - - int num_connections = scan.get_uint16(); - if (num_connections > max_node_graphs) { - // Oops, too many graph types in this bam file. We'll have to - // discard some. - graph_cat.error() - << "Bam file specifies " << num_connections << " graph types for " - << *this << "; this version of Panda can only support " - << max_node_graphs << " simultaneous graph types.\n"; - } - for (int i = 0; i < num_connections; i++) { - TypeHandle type = manager->read_handle(scan); - - if (i < max_node_graphs) { - _connections[i].set_graph_type(type); - - DownRelationPointers &drp = _connections[i].get_down(); - int num_arcs = scan.get_uint16(); - while (num_arcs > 0) { - manager->read_pointer(scan); - drp.push_back((NodeRelation *)NULL); - num_arcs--; - } - } else { - // Read and discard. - int num_arcs = scan.get_uint16(); - while (num_arcs > 0) { - manager->skip_pointer(scan); - num_arcs--; - } - } - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: Node::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a node object -//////////////////////////////////////////////////////////////////// -void Node:: -register_with_read_factory(void) { - BamReader::get_factory()->register_factory(get_class_type(), make_Node); -} - -//////////////////////////////////////////////////////////////////// -// Function: find_arc -// Description: Searches for the arc of the indicated type that -// connects the two indicated nodes. Returns the arc if -// it exists, or NULL if does not. -//////////////////////////////////////////////////////////////////// -NodeRelation * -find_arc(Node *parent, Node *child, TypeHandle graph_type) { - // We must now walk the RelationPointers list, looking for the - // matching parent-child arc. We'll start in the child looking for - // the parent arc, on the assumption there are likely to be fewer - // parents than children. - - const UpRelationPointers &urp = child->find_connection(graph_type).get_up(); - UpRelationPointers::const_iterator urpi; - for (urpi = urp.begin(); urpi != urp.end(); ++urpi) { - NodeRelation *arc = (*urpi); - if (arc->get_parent() == parent && arc->get_child() == child) { - return arc; - } - } - - // There is no matching arc. - return (NodeRelation *)NULL; -} diff --git a/panda/src/graph/node.h b/panda/src/graph/node.h deleted file mode 100644 index de4fc030ea..0000000000 --- a/panda/src/graph/node.h +++ /dev/null @@ -1,171 +0,0 @@ -// Filename: node.h -// Created by: drose (26Oct98) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef NODE_H -#define NODE_H - -#include - -#include "nodeRelation.h" -#include "boundedObject.h" -#include "nodeConnection.h" - -#include -#include -#include - -class RenderTraverser; -class AllTransitionsWrapper; -class BamWriter; -class BamReader; -class Datagram; -class DatagramIterator; -class ArcChain; - -// This is the maximum number of graph types a node may simultaneously -// exist in. -static const int max_node_graphs = 2; - -//////////////////////////////////////////////////////////////////// -// Class : Node -// Description : The base class for all scene graph nodes. A Node may -// be joined to any number of other nodes, as a parent -// or as a child, with any kind of relation arcs. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA Node : public TypedWritable, public BoundedObject, - virtual public ReferenceCount { - // We can't simply inherit from TypedWritableReferenceCount, because we need - // to inherit virtually from ReferenceCount. -public: - static Node* const Null; - -PUBLISHED: - Node(); - Node(const Node ©); - -public: - void operator = (const Node ©); - virtual ~Node(); - - virtual Node *make_copy() const; - Node *copy_subgraph(TypeHandle graph_type) const; - - virtual bool safe_to_flatten() const; - virtual bool safe_to_transform() const; - virtual bool safe_to_combine() const; - virtual void xform(const LMatrix4f &mat); - virtual Node *combine_with(Node *other); - - virtual void transform_changed(NodeRelation *arc); - -PUBLISHED: - int get_num_parents(TypeHandle type) const; - NodeRelation *get_parent(TypeHandle type, int index) const; - int get_num_children(TypeHandle type) const; - NodeRelation *get_child(TypeHandle type, int index) const; - -public: - // These functions will be called when the node is visited during - // the indicated traversal. - virtual void app_traverse(const ArcChain &chain); - virtual void draw_traverse(const ArcChain &chain); - virtual void dgraph_traverse(const ArcChain &chain); - - // This function is similar to another function in NodeTransition. - // It may or may not intercept the render traversal. - virtual bool sub_render(const AllTransitionsWrapper &input_trans, - AllTransitionsWrapper &modify_trans, - RenderTraverser *trav); - virtual bool has_sub_render() const; - -PUBLISHED: - virtual void output(ostream &out) const; - virtual void write(ostream &out, int indent_level = 0) const; - -public: - // These members define the actual connection of arcs to the nodes. - // Generally, you should not monkey with them, unless you know what - // you're doing; the get_parent()/get_child() interface above is - // simpler to use. - - INLINE_GRAPH const NodeConnection &find_connection(TypeHandle graph_type) const; - INLINE_GRAPH NodeConnection *update_connection(TypeHandle graph_type); - - NodeConnection _connections[max_node_graphs]; - -private: - const NodeConnection &p_find_connection(TypeHandle graph_type) const; - NodeConnection *p_update_connection(TypeHandle graph_type); - static NodeConnection _empty_connection; - -protected: - virtual void propagate_stale_bound(); - - typedef pmap InstanceMap; - virtual Node *r_copy_subgraph(TypeHandle graph_type, - InstanceMap &inst_map) const; - virtual void r_copy_children(const Node *from, TypeHandle graph_type, - InstanceMap &inst_map); - -public: - static void register_with_read_factory(void); - virtual void write_datagram(BamWriter* manager, Datagram &me); - virtual int complete_pointers(TypedWritable **plist, - BamReader *manager); - - static TypedWritable *make_Node(const FactoryParams ¶ms); - -protected: - void fillin(DatagramIterator& scan, BamReader* manager); - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - TypedWritable::init_type(); - BoundedObject::init_type(); - ReferenceCount::init_type(); - register_type(_type_handle, "Node", - TypedWritable::get_class_type(), - BoundedObject::get_class_type(), - ReferenceCount::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -EXPCL_PANDA INLINE_GRAPH ostream & operator << (ostream &out, const Node &node); - -EXPCL_PANDA NodeRelation * -find_arc(Node *parent, Node *child, TypeHandle graph_type); - -EXPCL_PANDA INLINE_GRAPH bool -remove_child(Node *parent, Node *child, TypeHandle graph_type); - -#ifndef DONT_INLINE_GRAPH -#include "node.I" -#endif - -#endif - diff --git a/panda/src/graph/nodeConnection.I b/panda/src/graph/nodeConnection.I deleted file mode 100644 index 18268c3597..0000000000 --- a/panda/src/graph/nodeConnection.I +++ /dev/null @@ -1,140 +0,0 @@ -// Filename: nodeConnection.I -// Created by: drose (07May01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - - -//////////////////////////////////////////////////////////////////// -// Function: NodeConnection::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeConnection:: -NodeConnection(TypeHandle graph_type) : _graph_type(graph_type) { -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeConnection::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeConnection:: -~NodeConnection() { -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeConnection::Copy Constructor -// Access: Private -// Description: The copy constructor is private. Copying -// NodeConnections is not a good idea. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeConnection:: -NodeConnection(const NodeConnection ©) { -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeConnection::Copy Assignment Operator -// Access: Private -// Description: The assignment constructor is private. Copying -// NodeConnections is not a good idea. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeConnection:: -operator = (const NodeConnection ©) { -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeConnection::is_empty -// Access: Public -// Description: Returns true if the NodeConnection has no arcs, false -// otherwise. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool NodeConnection:: -is_empty() const { - return _up.empty() && _down.empty(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeConnection::get_graph_type -// Access: Public -// Description: Returns the type of graph represented by this -// NodeConnection. A node can coexist simultaneously in -// several different graphs of different types; each -// type requires a NodeConnection object to be stored -// with the node. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH TypeHandle NodeConnection:: -get_graph_type() const { - return _graph_type; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeConnection::set_graph_type -// Access: Public -// Description: Changes the type of graph represented by this -// NodeConnection. It is legal to do this only when the -// NodeConnection is empty, i.e. is_empty() returns -// true. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeConnection:: -set_graph_type(TypeHandle graph_type) { - nassertv(is_empty()); - _graph_type = graph_type; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeConnection::get_up -// Access: Public -// Description: Returns the list of arcs pointing to the node's -// parent(s). -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH UpRelationPointers &NodeConnection:: -get_up() { - return _up; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeConnection::get_up -// Access: Public -// Description: Returns the list of arcs pointing to the node's -// parent(s). -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH const UpRelationPointers &NodeConnection:: -get_up() const { - return _up; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeConnection::get_down -// Access: Public -// Description: Returns the list of arcs pointing to the node's -// child(ren). -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH DownRelationPointers &NodeConnection:: -get_down() { - return _down; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeConnection::get_down -// Access: Public -// Description: Returns the list of arcs pointing to the node's -// child(ren). -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH const DownRelationPointers &NodeConnection:: -get_down() const { - return _down; -} diff --git a/panda/src/graph/nodeConnection.cxx b/panda/src/graph/nodeConnection.cxx deleted file mode 100644 index eaee05383d..0000000000 --- a/panda/src/graph/nodeConnection.cxx +++ /dev/null @@ -1,20 +0,0 @@ -// Filename: nodeConnection.cxx -// Created by: drose (07May01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "node.h" -#include "nodeConnection.h" diff --git a/panda/src/graph/nodeConnection.h b/panda/src/graph/nodeConnection.h deleted file mode 100644 index 3e4203c179..0000000000 --- a/panda/src/graph/nodeConnection.h +++ /dev/null @@ -1,71 +0,0 @@ -// Filename: nodeConnection.h -// Created by: drose (07May01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef NODECONNECTION_H -#define NODECONNECTION_H - -#include - -#include "nodeRelation.h" -#include "config_graph.h" -#include "vector_PT_NodeRelation.h" -#include "vector_NodeRelation_star.h" - -typedef vector_PT_NodeRelation DownRelationPointers; -typedef vector_NodeRelation_star UpRelationPointers; - - -/////////////////////////////////////////////////////////////////// -// Class : NodeConnection -// Description : This class represents the table, stored within each -// Node, of all the connected NodeRelations (arcs) of a -// particular graph type. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA NodeConnection { -public: - INLINE_GRAPH NodeConnection(TypeHandle graph_type = TypeHandle::none()); - INLINE_GRAPH ~NodeConnection(); - -private: - INLINE_GRAPH NodeConnection(const NodeConnection ©); - INLINE_GRAPH void operator = (const NodeConnection ©); - -public: - INLINE_GRAPH bool is_empty() const; - - INLINE_GRAPH TypeHandle get_graph_type() const; - INLINE_GRAPH void set_graph_type(TypeHandle graph_type); - - INLINE_GRAPH UpRelationPointers &get_up(); - INLINE_GRAPH const UpRelationPointers &get_up() const; - - INLINE_GRAPH DownRelationPointers &get_down(); - INLINE_GRAPH const DownRelationPointers &get_down() const; - -private: - TypeHandle _graph_type; - UpRelationPointers _up; - DownRelationPointers _down; -}; - -#ifndef DONT_INLINE_GRAPH -#include "nodeConnection.I" -#endif - -#endif - diff --git a/panda/src/graph/nodeRelation.I b/panda/src/graph/nodeRelation.I deleted file mode 100644 index f07555907a..0000000000 --- a/panda/src/graph/nodeRelation.I +++ /dev/null @@ -1,384 +0,0 @@ -// Filename: nodeRelation.I -// Created by: drose (30Sep99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: remove_arc -// Description: Removes the arc from the graph, which incidentally -// will also delete the arc unless there are some -// additional outstanding pointers to it. -//////////////////////////////////////////////////////////////////// -EXPCL_PANDA INLINE_GRAPH void -remove_arc(NodeRelation *arc) { - PT(TypedWritableReferenceCount) hold_ptr = arc->detach(); - arc->_parent = NULL; - arc->_child = NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::output_transitions -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeRelation:: -output_transitions(ostream &out) const { - out << _transitions; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::write_transitions -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeRelation:: -write_transitions(ostream &out, int indent_level) const { - _transitions.write(out, indent_level); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::get_parent -// Access: Public -// Description: Returns the node above the arc in the scene graph. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH Node *NodeRelation:: -get_parent() const { - return _parent; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::get_child -// Access: Public -// Description: Returns the node below the arc in the scene graph. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH Node *NodeRelation:: -get_child() const { - return _child; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::get_sort -// Access: Public -// Description: Returns the sorting index of the arc. This affects -// its apparent position among its list of siblings. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH int NodeRelation:: -get_sort() const { - return _sort; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::get_graph_type -// Access: Public -// Description: Returns the type of graph this arc represents. This -// is normally the same value as get_type(), i.e. the -// class type of the arc, but it may be set to any type. -// A node may simultaneously have many arcs of different -// types. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH TypeHandle NodeRelation:: -get_graph_type() const { - return _graph_type; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::is_attached -// Access: Public -// Description: Returns true if this arc is attached to the scene -// graph, false otherwise. Normally, an arc should -// always be attached; generally you will only see an -// unattached arc if the arc (or some parent of the arc) -// has been disconnected from all nodes via -// remove_arc(). -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool NodeRelation:: -is_attached() const { - return _attached; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::change_parent -// Access: Public -// Description: Changes the parent of the arc to a different node. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeRelation:: -change_parent(Node *parent) { - PT(TypedWritableReferenceCount) hold_ptr = detach(); - _parent = parent; - attach(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::change_parent -// Access: Public -// Description: Changes the parent of the arc to a different node, -// simultaneously changing the sort index. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeRelation:: -change_parent(Node *parent, int sort) { - PT(TypedWritableReferenceCount) hold_ptr = detach(); - _parent = parent; - _sort = sort; - attach(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::change_child -// Access: Public -// Description: Changes the child of the arc to a different node. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeRelation:: -change_child(Node *child) { - PT(TypedWritableReferenceCount) hold_ptr = detach(); - _child = child; - attach(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::change_parent_and_child -// Access: Public -// Description: Simultaneously moves both the parent and child of the -// arc to different nodes. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeRelation:: -change_parent_and_child(Node *parent, Node *child) { - PT(TypedWritableReferenceCount) hold_ptr = detach(); - _parent = parent; - _child = child; - attach(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::set_sort -// Access: Public -// Description: Changes the sorting index of the arc. This affects -// its apparent position among its list of siblings. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeRelation:: -set_sort(int sort) { - PT(TypedWritableReferenceCount) hold_ptr = detach(); - _sort = sort; - attach(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::set_graph_type -// Access: Public -// Description: Changes the graph type of the arc. This moves the -// arc into a totally different graph; it may now be -// detected only by a special traversal. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeRelation:: -set_graph_type(TypeHandle graph_type) { - PT(TypedWritableReferenceCount) hold_ptr = detach(); - _graph_type = graph_type; - attach(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::set_transition -// Access: Public -// Description: This flavor of set_transition() accepts a pointer to -// a NodeTransition only. It infers the type of the -// NodeTransition from the pointer. However, it is not -// valid to pass a NULL pointer to this flavor of -// set_transition; if the pointer might be NULL, use the -// above flavor instead (or just call clear_transition). -// -// The return value is a pointer to the *previous* -// transition in the set, if any, or NULL if there was -// none. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH PT(NodeTransition) NodeRelation:: -set_transition(NodeTransition *trans) { - nassertr(trans != (NodeTransition *)NULL, NULL); - nassertr(trans->get_handle() != TypeHandle::none(), NULL); - return set_transition(trans->get_handle(), trans); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::set_transition -// Access: Public -// Description: This is a convenience flavor. It automatically -// applies the indicated priority to the given -// transition before setting the transition. Generally, -// this will be used for creating override transitions -// on-the-fly. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH PT(NodeTransition) NodeRelation:: -set_transition(NodeTransition *trans, int priority) { - nassertr(trans != (NodeTransition *)NULL, NULL); - nassertr(trans->get_handle() != TypeHandle::none(), NULL); - trans->set_priority(priority); - return set_transition(trans->get_handle(), trans); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::has_transition -// Access: Public -// Description: Returns true if a transition associated with the -// indicated handle has been stored on the arc (even if -// it is the identity transition), or false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool NodeRelation:: -has_transition(TypeHandle handle) const { - return _transitions.has_transition(handle); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::has_any_transition -// Access: Public -// Description: Returns true if a any transition has been stored on -// the arc (even if it is the identity transition), or -// false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool NodeRelation:: -has_any_transition() const { - return !_transitions.is_empty(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::get_transition -// Access: Public -// Description: Returns the transition associated with the indicated -// handle, or NULL if no such transition has been stored -// on the arc. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransition *NodeRelation:: -get_transition(TypeHandle handle) const { - return _transitions.get_transition(handle); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::compare_transitions_to -// Access: Public -// Description: Returns a negative number if the transitions on the -// other arc sort before those on this arc, positive if -// they sort after, or zero if the sets of transitions -// are equivalent. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH int NodeRelation:: -compare_transitions_to(const NodeRelation *arc) const { - return _transitions.compare_to(arc->_transitions); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::get_last_update -// Access: Public -// Description: Returns the sequence number associated with the last -// time this arc was changed, for instance to change its -// state or to reparent it. The only sensible thing you -// can do with this is store it and note whether it -// increases. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH UpdateSeq NodeRelation:: -get_last_update() const { - return _last_update; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::clear_wrt_cache -// Access: Public -// Description: Blows away the wrt cache information on this arc. -// This forces the wrt to be recomputed next time it is -// asked for. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeRelation:: -clear_wrt_cache() { - _net_transitions.clear(); - _top_subtree = (Node *)NULL; - _all_verified = UpdateSeq::initial(); - _last_update = ++last_graph_update(_graph_type); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::create_typed_arc -// Access: Public, Static -// Description: Creates a new arc of the scene graph of the indicated -// type, and immediately attaches it. Returns NULL if -// the type is unknown. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeRelation *NodeRelation:: -create_typed_arc(TypeHandle type, Node *parent, Node *child, int sort) { - NodeRelation *arc = get_factory().make_instance(type); - if (arc != (NodeRelation *)NULL) { - arc->_parent = parent; - arc->_child = child; - arc->_sort = sort; - arc->attach(); - } - return arc; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::register_with_factory -// Access: Public, Static -// Description: Registers the type NodeRelation with the factory. -// This is only intended to be called at initialization -// time; don't call it directly. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeRelation:: -register_with_factory() { - get_factory().register_factory(get_class_type(), make_arc); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::get_factory -// Access: Protected, Static -// Description: Returns a reference to the NodeRelation factory. -// Creates one if this is the first time this function -// has been called. This is necessary to guarantee -// ordering at static init time. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH Factory &NodeRelation:: -get_factory() { - if (_factory == (Factory *)NULL) { - _factory = new Factory; - } - return *_factory; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::get_class_type -// Access: Public, Static -// Description: Returns the TypeHandle associated with this type. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH TypeHandle NodeRelation:: -get_class_type() { - return _type_handle; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::get_stashed_type -// Access: Public, Static -// Description: Returns a special TypeHandle that, by convention, -// arcs that wish to remove themselves from normal -// consideration during any traversal (including -// rendering and collision traversals), as well as -// removing themselves from the bounding volumes of -// their parents, should set their graph_type to. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH TypeHandle NodeRelation:: -get_stashed_type() { - return _stashed_type_handle; -} - -EXPCL_PANDA INLINE_GRAPH ostream & -operator << (ostream &out, const NodeRelation &arc) { - arc.output(out); - return out; -} - diff --git a/panda/src/graph/nodeRelation.N b/panda/src/graph/nodeRelation.N deleted file mode 100644 index 1a62d38995..0000000000 --- a/panda/src/graph/nodeRelation.N +++ /dev/null @@ -1,2 +0,0 @@ -ignoremember create_typed_arc -ignoremember register_with_factory diff --git a/panda/src/graph/nodeRelation.T b/panda/src/graph/nodeRelation.T deleted file mode 100644 index b82ef06d4b..0000000000 --- a/panda/src/graph/nodeRelation.T +++ /dev/null @@ -1,47 +0,0 @@ -// Filename: nodeRelation.T -// Created by: drose (30Sep99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: get_transition_into -// Description: This external template function is handy for -// extracting a transition of a particular type from the -// arc. If the transition exists, it is automatically -// downcasted to the correct type and stored in the -// pointer given in the first parameter, and the return -// value is true. If the transition does not exist, the -// pointer is filled with NULL and the return value is -// false. -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH bool -get_transition_into(Transition *&ptr, const NodeRelation *arc, - TypeHandle transition_type) { - NodeTransition *nt = arc->get_transition(transition_type); - if (nt == (NodeTransition *)NULL) { - ptr = (Transition *)NULL; - return false; - } - DCAST_INTO_R(ptr, nt, false); - return true; -} - -template -INLINE_GRAPH bool -get_transition_into(Transition *&ptr, const NodeRelation *arc) { - return get_transition_into(ptr, arc, Transition::get_class_type()); -} diff --git a/panda/src/graph/nodeRelation.cxx b/panda/src/graph/nodeRelation.cxx deleted file mode 100644 index 2037a27c17..0000000000 --- a/panda/src/graph/nodeRelation.cxx +++ /dev/null @@ -1,1106 +0,0 @@ -// Filename: nodeRelation.cxx -// Created by: drose (26Oct98) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "nodeRelation.h" -#include "node.h" -#include "config_graph.h" - -#include -#include - -#include - -TypeHandle NodeRelation::_type_handle; -TypeHandle NodeRelation::_stashed_type_handle; - -Factory *NodeRelation::_factory = NULL; - -typedef pmap LastGraphUpdate; -static LastGraphUpdate *last_graph_update_map = NULL; - -//////////////////////////////////////////////////////////////////// -// Function: last_graph_update -// Description: Returns a modifiable reference to the sequence number -// indicating the last update to the indicated type of -// graph. -//////////////////////////////////////////////////////////////////// -UpdateSeq & -last_graph_update(TypeHandle graph_type) { -#ifndef NDEBUG - static UpdateSeq initial; - nassertr(last_graph_update_map != (LastGraphUpdate *)NULL, initial); -#endif - return (*last_graph_update_map)[graph_type]; -} - -//////////////////////////////////////////////////////////////////// -// Function: init_last_graph_update -// Description: Initializes the last_graph_update map. This call -// must be made before last_graph_update() can be safely -// called. -//////////////////////////////////////////////////////////////////// -void -init_last_graph_update() { - if (last_graph_update_map == NULL) { - last_graph_update_map = new LastGraphUpdate; - } -} - -// Following are a handful of local template functions that provide -// support for manipulating the list of arcs on nodes. They are -// template functions because they work as well on UpRelationPointers -// as as they do on DownRelationPointers, which are slightly different -// things (DownRelationPointers are reference-counting). - -//////////////////////////////////////////////////////////////////// -// Function: verify_arc_list -// Description: A local template function that verifies that the list -// of arcs (either UpRelationPointers or -// DownRelationPointers) is correctly sorted, if -// paranoid_graph is set. Otherwise, it does nothing. -//////////////////////////////////////////////////////////////////// -#ifdef NDEBUG -template -INLINE_GRAPH void -verify_arc_list(Iterator, Iterator) { -} -#else // NDEBUG -template -static void -verify_arc_list(Iterator begin, Iterator end) { - if (paranoid_graph) { - if (begin < end) { - Iterator i = begin; - int sort = (*i)->get_sort(); - ++i; - while (i < end) { - nassertv(sort <= (*i)->get_sort()); - sort = (*i)->get_sort(); - ++i; - } - } - } -} -#endif // NDEBUG - -//////////////////////////////////////////////////////////////////// -// Function: find_insert_position -// Description: A local template function that performs a binary -// search on the arcs list (either UpRelationPointers or -// DownRelationPointers) and finds the place to insert -// the indicated arc. -// -// This place will be at the end of the similarly-sorted -// arcs. -//////////////////////////////////////////////////////////////////// -template -static Iterator -r_find_insert_position(Iterator begin, Iterator end, NodeRelation *arc) { - if (begin == end) { - // The list is empty; the insert position is the end of the list. - return end; - } - - Iterator center = begin + (end - begin) / 2; - nassertr(center < end, end); - - if ((*center)->get_sort() > arc->get_sort()) { - // Insert before the center. - return r_find_insert_position(begin, center, arc); - - } else { // (*center)->get_sort() <= arc->get_sort(); - // Insert after the center. - return r_find_insert_position(center + 1, end, arc); - } -} - -template -static Iterator -find_insert_position(Iterator begin, Iterator end, NodeRelation *arc) { - Iterator result = r_find_insert_position(begin, end, arc); -#ifndef NDEBUG - // Verify the result. - if (paranoid_graph) { - // If there is a node before the indicated position, it must have - // a sort value either less than or equal to this arc's value. - if (begin < result) { - nassertr((*(result - 1))->get_sort() <= arc->get_sort(), result); - } - - // If there is a node after the indicated position, it must have a - // sort value greater than this arc's value. - if (result < end) { - nassertr((*result)->get_sort() > arc->get_sort(), result); - } - } -#endif - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: find_arc -// Description: A local template function that performs a binary -// search on the arcs list (either UpRelationPointers or -// DownRelationPointers) and finds the arc's position -// within the list. It returns end if the arc is not -// within the list. -//////////////////////////////////////////////////////////////////// -template -static Iterator -find_arc(Iterator begin, Iterator end, NodeRelation *arc) { - if (begin == end) { - // The list is empty; the arc is not on the list. - return end; - } - - Iterator center = begin + (end - begin) / 2; - nassertr(center < end, end); - - if ((*center)->get_sort() > arc->get_sort()) { - // It must be before the center. - return find_arc(begin, center, arc); - - } else if ((*center)->get_sort() < arc->get_sort()) { - // It must be after the center. - return find_arc(center + 1, end, arc); - - } else { - // The center's sort matches the arc's sort. It could be either - // before or after the center. First try after. - Iterator i = center; - while (i < end && (*i)->get_sort() == arc->get_sort()) { - if ((*i) == arc) { - return i; - } - ++i; - } - - // No, try before. - i = center; - --i; - while (i >= begin && (*i)->get_sort() == arc->get_sort()) { - if ((*i) == arc) { - return i; - } - --i; - } - - // No such arc! - return end; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: internal_insert_arc -// Description: A local template function that inserts the arc into -// its appropriate place in the list and returns true if -// successful, false if there was some kind of error. -//////////////////////////////////////////////////////////////////// -template -static bool -internal_insert_arc(ArcList &alist, NodeRelation *arc) { - nassertr(arc != (NodeRelation *)NULL, false); - - TYPENAME ArcList::iterator position = - find_insert_position(alist.begin(), alist.end(), arc); - nassertr(position >= alist.begin() && position <= alist.end(), false); - - /* - if (graph_cat.is_debug()) { - if (position == alist.end()) { - graph_cat.debug() - << "Inserting " << *arc << " at end\n"; - } else { - graph_cat.debug() - << "Inserting " << *arc << " before " << *(*position) << "\n"; - } - } - */ - - alist.insert(position, arc); - verify_arc_list(alist.begin(), alist.end()); - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: internal_remove_arc -// Description: A local template function that removes the arc from -// its place in the list and returns true if successful, -// false if there was some kind of error. -//////////////////////////////////////////////////////////////////// -template -static bool -internal_remove_arc(ArcList &alist, NodeRelation *arc) { - nassertr(arc != (NodeRelation *)NULL, false); - - TYPENAME ArcList::iterator position = - find_arc(alist.begin(), alist.end(), arc); - nassertr(position >= alist.begin() && position <= alist.end(), false); - nassertr(position != alist.end(), false); - - /* - if (graph_cat.is_debug()) { - TYPENAME ArcList::iterator next = position + 1; - if (next == list.end()) { - graph_cat.debug() - << "Removing " << *arc << " from end\n"; - } else { - graph_cat.debug() - << "Removing " << *arc << " from before " << *(*next) << "\n"; - } - } - */ - - alist.erase(position); - verify_arc_list(alist.begin(), alist.end()); - - return true; -} - - - - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::Constructor -// Access: Public -// Description: Creates a new arc of the scene graph, and immediately -// attaches it. -//////////////////////////////////////////////////////////////////// -NodeRelation:: -NodeRelation(Node *parent, Node *to, int sort, TypeHandle graph_type) : - _parent(parent), _child(to), _sort(sort), - _graph_type(graph_type), _num_transitions(0) -{ - _top_subtree = NULL; - _attached = false; - _parent_ref = 0; - attach(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::Constructor -// Access: Protected -// Description: Creates a new, unattached arc. This constructor is -// only intended for passing through the factory to -// create an arc based on a particular type using -// create_typed_arc(), below. You shouldn't, in -// general, attempt to create an unattached arc. -//////////////////////////////////////////////////////////////////// -NodeRelation:: -NodeRelation(TypeHandle graph_type) : - _graph_type(graph_type) -{ - _parent = NULL; - _child = NULL; - _sort = 0; - _top_subtree = NULL; - _attached = false; - _parent_ref = 0; - _num_transitions = 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::Copy Constructor -// Access: Private -// Description: It's not legal to copy a NodeRelation. -//////////////////////////////////////////////////////////////////// -NodeRelation:: -NodeRelation(const NodeRelation &) { - graph_cat.error() - << "NodeRelation copy constructor called!\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::Copy Assignment Operator -// Access: Private -// Description: It's not legal to copy a NodeRelation. -//////////////////////////////////////////////////////////////////// -void NodeRelation:: -operator = (const NodeRelation &) { - graph_cat.error() - << "NodeRelation copy assignment operator called!\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -NodeRelation:: -~NodeRelation() { - // An attached arc should never be deleted. If this assertion - // fails, it's most likely that someone attempted to explicitly - // delete an arc. You should use remove_arc() instead. - nassertv(!_attached); - - // Similarly, we shouldn't be deleting arcs with a nonzero - // parent_ref. This means someone lost a reference count somewhere, - // or someone was sloppy calling ref_parent()/unref_parent(). - nassertv(_parent_ref == 0); - - _transitions.remove_all_from_arc(this); -} - - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::output -// Access: Public -// Description: Writes a brief description of the arc to the -// indicated output stream. This function is called by -// the << operator. -//////////////////////////////////////////////////////////////////// -void NodeRelation:: -output(ostream &out) const { - if (_parent == (Node*)NULL) { - out << "(null)"; - } else { - out << *_parent; - } - out << " -> "; - if (_child == (Node*)NULL) { - out << "(null)"; - } else { - out << *_child; - } - - if (!_attached) { - out << " (unattached)"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::ref_parent -// Access: Public -// Description: Normally, the arc keeps a reference count to its -// child node, but not to its parent node. This allows -// the arc (and all of its children) to be destructed -// when its parent node destructs. -// -// Sometimes this behavior is not desirable, and you'd -// like to have an arc keep a reference count to its -// parent. This is particularly true when you have a -// reference-counting pointer to the arc in some other -// context, and you'd like to ensure that its parent and -// child node pointers are always valid while you keep -// the pointer. -// -// In this case, you should call ref_parent() to -// increment the reference count on the parent node. Be -// sure to call unref_parent() explicitly when you lose -// your reference to the arc, or you will leak reference -// counts. -// -// Note that if the parent of the arc changes while -// ref_parent() is held, the old parent will -// automatically be dereferenced and the new parent will -// be referenced instead, as if it were a normal -// reference-counting pointer. -//////////////////////////////////////////////////////////////////// -void NodeRelation:: -ref_parent() { - nassertv(_parent_ref >= 0); - if (_parent_ref == 0 && _attached) { - // If we are the first to request a reference count on the parent, - // actually increment it now. - _parent->ref(); - } - _parent_ref++; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::unref_parent -// Access: Public -// Description: Removes the reference count on the arc's parent node -// and allows the arc to be deleted normally. See -// ref_parent(). -//////////////////////////////////////////////////////////////////// -void NodeRelation:: -unref_parent() { - nassertv(_parent_ref > 0); - - _parent_ref--; - if (_parent_ref == 0 && _attached) { - // If we are the last to request a reference count on the parent, - // actually decrement it now. - unref_delete(_parent); - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::copy_transitions_from -// Access: Public -// Description: Copies all of the transitions stored on the other arc -// to this arc. Any existing transitions on this arc, -// for which there was not a corresponding transition of -// the same type on the other arc, are left undisturbed. -//////////////////////////////////////////////////////////////////// -void NodeRelation:: -copy_transitions_from(const NodeRelation *arc) { - copy_transitions_from(arc->_transitions); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::compose_transitions_from -// Access: Public -// Description: Similar to copy_transitions_from(), except that if -// the same type of transition exists on both arcs, the -// composition of the two is stored. The result -// represents the same set of transitions that would -// result from composing the two individual sets of -// transitions. -//////////////////////////////////////////////////////////////////// -void NodeRelation:: -compose_transitions_from(const NodeRelation *arc) { - compose_transitions_from(arc->_transitions); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::copy_transitions_from -// Access: Public -// Description: Copies all of the transitions stored in the indicated -// set to this arc. Any existing transitions on this -// arc, for which there was not a corresponding -// transition of the same type on the other arc, are -// left undisturbed. -//////////////////////////////////////////////////////////////////// -void NodeRelation:: -copy_transitions_from(const NodeTransitions &trans) { - if (!trans.is_empty()) { - _transitions.copy_transitions_from(trans, this); - - // Now mark that *all* transitions have changed, even though many - // of them might not have, because we're not really sure. - _net_transitions.clear(); - NodeTransitions::const_iterator ti; - for (ti = _transitions.begin(); ti != _transitions.end(); ++ti) { - changed_transition((*ti).first); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::compose_transitions_from -// Access: Public -// Description: Similar to copy_transitions_from(), except that if -// the same type of transition exists in both places, -// the composition of the two is stored. The result -// represents the same set of transitions that would -// result from composing the two individual sets of -// transitions. -//////////////////////////////////////////////////////////////////// -void NodeRelation:: -compose_transitions_from(const NodeTransitions &trans) { - if (!trans.is_empty()) { - _transitions.compose_transitions_from(trans, this); - - // Now mark that *all* transitions have changed, even though many - // of them might not have, because we're not really sure. - _net_transitions.clear(); - NodeTransitions::const_iterator ti; - for (ti = _transitions.begin(); ti != _transitions.end(); ++ti) { - changed_transition((*ti).first); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::adjust_all_proriorities -// Access: Public -// Description: Adds the indicated adjustment amount (which may be -// negative) to the priority for all transitions on the -// arc. If the priority would drop below zero, it is -// set to zero. -//////////////////////////////////////////////////////////////////// -void NodeRelation:: -adjust_all_priorities(int adjustment) { - _net_transitions.clear(); - _transitions.adjust_all_priorities(adjustment, this); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::sub_render_trans -// Access: Public -// Description: Calls sub_render() on each transition assigned to the -// arc. Returns true if all transitions returned true, -// false if any returned false. -//////////////////////////////////////////////////////////////////// -bool NodeRelation:: -sub_render_trans(const AllTransitionsWrapper &input_trans, - AllTransitionsWrapper &modify_trans, - RenderTraverser *trav) { - bool all_true = true; - NodeTransitions::const_iterator ti; - for (ti = _transitions.begin(); ti != _transitions.end(); ++ti) { - if (!(*ti).second->sub_render(this, input_trans, modify_trans, trav)) { - all_true = false; - } - } - - return all_true; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::has_sub_render_trans -// Access: Public -// Description: Returns true if any transition on the arc has a -// sub_render() function. -//////////////////////////////////////////////////////////////////// -bool NodeRelation:: -has_sub_render_trans() const { - NodeTransitions::const_iterator ti; - for (ti = _transitions.begin(); ti != _transitions.end(); ++ti) { - if ((*ti).second->has_sub_render()) { - return true; - } - } - - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::get_num_sub_render_trans -// Access: Public -// Description: Returns the number of transitions on the arc that -// have a sub_render() function. -//////////////////////////////////////////////////////////////////// -int NodeRelation:: -get_num_sub_render_trans() const { - int count = 0; - - NodeTransitions::const_iterator ti; - for (ti = _transitions.begin(); ti != _transitions.end(); ++ti) { - if ((*ti).second->has_sub_render()) { - count++; - } - } - - return count; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::make_arc -// Access: Public, Static -// Description: This function is passed to the Factory to make a new -// NodeRelation by type. Don't try to call this -// function directly. -//////////////////////////////////////////////////////////////////// -NodeRelation *NodeRelation:: -make_arc(const FactoryParams &) { - return new NodeRelation(NodeRelation::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::attach -// Access: Protected -// Description: Makes the arc an official part of the graph by -// informing the nodes that it connects of its -// existence. It is an error to attach an arc that has -// already been attached. -// -// It is also an error to attach an arc that is not -// grounded at both ends. -//////////////////////////////////////////////////////////////////// -void NodeRelation:: -attach() { - nassertv(_parent != (Node*)NULL); - nassertv(_child != (Node*)NULL); - nassertv(!_attached); - - NodeConnection *parent_connection = _parent->update_connection(_graph_type); - NodeConnection *child_connection = _child->update_connection(_graph_type); - - if (parent_connection == (NodeConnection *)NULL) { - graph_cat.error() - << "Attempt to attach " << *_parent << " simultaneously to more than " - << max_node_graphs << " different graph types.\n"; - nassertv(false); - } - - if (child_connection == (NodeConnection *)NULL) { - graph_cat.error() - << "Attempt to attach " << *_child << " simultaneously to more than " - << max_node_graphs << " different graph types.\n"; - nassertv(false); - } - - DownRelationPointers &parent_list = parent_connection->get_down(); - UpRelationPointers &child_list = child_connection->get_up(); - - bool inserted_one = internal_insert_arc(parent_list, this); - bool inserted_two = internal_insert_arc(child_list, this); - nassertv(inserted_one && inserted_two); - - // Blow out the cache and increment the current update sequence. - _net_transitions.clear(); - _last_update = ++last_graph_update(_graph_type); - - // If we have just added a new parent arc to a node that previously - // had exactly one parent, we also need to set the update sequence - // counter for the other parent arc, since we have fundamentally - // changed the nature of the node from non-instanced to instanced. - if (child_list.size() == 2) { - child_list[0]->_last_update = _last_update; - child_list[1]->_last_update = _last_update; - } - - _attached = true; - if (_parent_ref != 0) { - _parent->ref(); - } - - _parent->force_bound_stale(); - mark_bound_stale(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::detach -// Access: Protected -// Description: Removes the arc from the graph. The arc remains and -// still refers to its connected nodes, but the nodes -// themselves no longer know about the arc. It is an -// error to detach an arc that is not already attached. -// -// detach() returns a PointerTo for the arc itself. -// This is useful not so much for the return value -// itself, but more to prevent the arc from destructing -// until detach() returns, since the arc will destruct -// when its last reference count is removed, and it is -// generally a bad idea to destruct a class within its -// own method. -// -// It must be a PT(TypedWritableReferenceCount), and -// not PT_NodeRelation, because of circularity problems -// trying to export the template class PT_NodeRelation. -//////////////////////////////////////////////////////////////////// -PT(TypedWritableReferenceCount) NodeRelation:: -detach() { - PT(TypedWritableReferenceCount) result = this; - - nassertr(_parent != (Node*)NULL, result); - nassertr(_child != (Node*)NULL, result); - nassertr(_attached, result); - - force_bound_stale(); - - NodeConnection *parent_connection = _parent->update_connection(_graph_type); - NodeConnection *child_connection = _child->update_connection(_graph_type); - - // These should never be NULL, because we're already attached, after - // all. - nassertr(parent_connection != (NodeConnection *)NULL && - child_connection != (NodeConnection *)NULL, result); - - DownRelationPointers &parent_list = parent_connection->get_down(); - UpRelationPointers &child_list = child_connection->get_up(); - - bool removed_one = internal_remove_arc(parent_list, this); - bool removed_two = internal_remove_arc(child_list, this); - - nassertr(removed_one, result); - nassertr(removed_two, result); - - _attached = false; - if (_parent_ref != 0) { - unref_delete(_parent); - } - - // Blow out the cache and increment the current update sequence. - _net_transitions.clear(); - _last_update = ++last_graph_update(_graph_type); - - // If we have just removed a parent arc from a node, leaving exactly - // one parent, we also need to set the update sequence - // counter for the other parent arc, since we have fundamentally - // changed the nature of the node from instanced to non-instanced. - if (child_list.size() == 1) { - child_list[0]->_last_update = _last_update; - } - - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::detach_below -// Access: Protected -// Description: This is a special method that is only called from the -// Node destructor. It detaches the arc, but does not -// remove it from its parent's arc list, which is -// presumably about to be destroyed anyway. -//////////////////////////////////////////////////////////////////// -PT(TypedWritableReferenceCount) NodeRelation:: -detach_below() { - PT(TypedWritableReferenceCount) result = this; - - nassertr(_parent != (Node*)NULL, result); - nassertr(_child != (Node*)NULL, result); - nassertr(_attached, result); - - force_bound_stale(); - - NodeConnection *child_connection = _child->update_connection(_graph_type); - nassertr(child_connection != (NodeConnection *)NULL, result); - - UpRelationPointers &child_list = child_connection->get_up(); - bool removed = internal_remove_arc(child_list, this); - - nassertr(removed, result); - - _attached = false; - - // Blow out the cache and increment the current update sequence. - _net_transitions.clear(); - _last_update = ++last_graph_update(_graph_type); - - return result; -} - - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::changed_transition -// Access: Public, Virtual -// Description: This is called by set_transition() or -// clear_transition() whenever a transition is added, -// updated, or removed from the arc. It is just a -// callback to the arc so it can decide whether it needs -// to update any internal data as a response to this -// adjustment (for instance, by marking the bounding -// sphere stale). -//////////////////////////////////////////////////////////////////// -void NodeRelation:: -changed_transition(TypeHandle trans_type) { - if (_net_transitions != (NodeTransitionCache *)NULL) { - _net_transitions->clear_transition(trans_type); - } - _last_update = ++last_graph_update(_graph_type); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::propagate_stale_bound -// Access: Protected, Virtual -// Description: Called by BoundedObject::mark_bound_stale(), this -// should make sure that all bounding volumes that -// depend on this one are marked stale also. -//////////////////////////////////////////////////////////////////// -void NodeRelation:: -propagate_stale_bound() { - // Mark all of our parent arcs stale as well. - Node *node = _parent; - nassertv(node != (Node*)NULL); - - const UpRelationPointers &urp = node->find_connection(_graph_type).get_up(); - UpRelationPointers::const_iterator urpi; - for (urpi = urp.begin(); urpi != urp.end(); ++urpi) { - (*urpi)->mark_bound_stale(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::recompute_bound -// Access: Protected, Virtual -// Description: Recomputes the dynamic bounding volume for this arc -// (and all of its descendants). -//////////////////////////////////////////////////////////////////// -BoundingVolume *NodeRelation:: -recompute_bound() { - // First, get ourselves a fresh, empty bounding volume. - BoundingVolume *bound = BoundedObject::recompute_bound(); - nassertr(bound != (BoundingVolume*)NULL, bound); - - // Now actually compute the bounding volume by putting it around all - // of our child bounding volumes. - pvector child_volumes; - - Node *node = _child; - nassertr(node != (Node*)NULL, bound); - - child_volumes.push_back(&node->get_bound()); - - const DownRelationPointers &drp = - node->find_connection(_graph_type).get_down(); - DownRelationPointers::const_iterator drpi; - for (drpi = drp.begin(); drpi != drp.end(); ++drpi) { - child_volumes.push_back(&(*drpi)->get_bound()); - } - - const BoundingVolume **child_begin = &child_volumes[0]; - const BoundingVolume **child_end = child_begin + child_volumes.size(); - - bool success = - bound->around(child_begin, child_end); - -#ifndef NDEBUG - if (!success) { - graph_cat.error() - << "Unable to recompute bounding volume for " << *this << ":\n" - << "Cannot put " << bound->get_type() << " around:\n"; - for (int i = 0; i < (int)child_volumes.size(); i++) { - graph_cat.error(false) - << " " << *child_volumes[i] << "\n"; - } - } -#endif - - return bound; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void NodeRelation:: -write_datagram(BamWriter *manager, Datagram &me) -{ - //Write out the "dynamic" type - manager->write_handle(me, _graph_type); - - //We should always be attached if we are trying to write out - nassertv(_attached); - //Neither the Child nor the Parent should be NULL - nassertv(get_parent() != Node::Null && get_child() != Node::Null); - - //Write out the pointer to my parent - manager->write_pointer(me, _parent); - //Write out the pointer to my child - manager->write_pointer(me, _child); - - //Write out the sort relation for this object - me.add_uint16(_sort); - - //Now write out all the Transitions on this arc - me.add_uint16(_transitions.size()); - NodeTransitions::iterator ci; - for(ci = _transitions.begin(); ci != _transitions.end(); ci++) { - manager->write_pointer(me, (*ci).second); - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::complete_pointers -// Access: Public -// Description: Takes in a vector of pointers to TypedWritable -// objects that correspond to all the requests for -// pointers that this object made to BamReader. -//////////////////////////////////////////////////////////////////// -int NodeRelation:: -complete_pointers(TypedWritable **p_list, BamReader *manager) { - nassertr(p_list[0] != TypedWritable::Null && - p_list[1] != TypedWritable::Null, 0); - _parent = DCAST(Node, p_list[0]); - _child = DCAST(Node, p_list[1]); - - if (manager->get_file_minor_ver() < 3) { - // In bam versions before 3.3, we let the NodeRelation completely - // handle its attachment to its parents. - attach(); - - } else { - // Beginning in bam version 3.3, we let the parent Node handle the - // attachment of its children arcs, so we can guarantee correct - // ordering of children. - - // We must explicitly add the arc to its child node, but not to - // its parent node. - NodeConnection *child_connection = _child->update_connection(_graph_type); - if (child_connection != (NodeConnection *)NULL) { - UpRelationPointers &child_list = child_connection->get_up(); - bool inserted = internal_insert_arc(child_list, this); - nassertr(inserted, _num_transitions + 2); - _attached = true; - } - } - - //The rest of this is the list of Transitions - for(int i = 2; i < _num_transitions + 2; i++) - { - //Ignore Null pointers. This SHOULD mean that - //we have received a Transition that the current - //version doesn't know about, so we want to be able - //to gracefully handle new functionality being thrown - //at old code - if (p_list[i] == TypedWritable::Null) - { - graph_cat->warning() - << get_type().get_name() - << ": Ignoring null Transition" << endl; - } - else - { - //Let set_transition do the work for storing - //a reference to this transition, determing it's - //exact type, telling the transition about me, etc... - set_transition(DCAST(NodeTransition, p_list[i])); - } - } - return _num_transitions+2; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::make_NodeRelation -// Access: Protected, Static -// Description: Factory method to generate a NodeRelation object -//////////////////////////////////////////////////////////////////// -TypedWritable* NodeRelation:: -make_NodeRelation(const FactoryParams ¶ms) -{ - NodeRelation *me = new NodeRelation(get_class_type()); - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void NodeRelation:: -fillin(DatagramIterator& scan, BamReader* manager) -{ - _graph_type = manager->read_handle(scan); - //Read in my parent - manager->read_pointer(scan); - //Read in my child - manager->read_pointer(scan); - //Get my sort relation - _sort = scan.get_uint16(); - - //Now read in all of my transitions - _num_transitions = scan.get_uint16(); - for(int i = 0; i < _num_transitions; i++) - { - manager->read_pointer(scan); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::register_with_read_factory -// Access: Public, Static -// Description: Factory method to generate a NodeRelation object -//////////////////////////////////////////////////////////////////// -void NodeRelation:: -register_with_read_factory(void) -{ - BamReader::get_factory()->register_factory(get_class_type(), make_NodeRelation); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::init_type -// Access: Public, Static -// Description: Initializes the TypeHandles associated with this -// class. -//////////////////////////////////////////////////////////////////// -void NodeRelation:: -init_type() { - TypedWritableReferenceCount::init_type(); - BoundedObject::init_type(); - register_type(_type_handle, "NodeRelation", - TypedWritableReferenceCount::get_class_type(), - BoundedObject::get_class_type()); - register_type(_stashed_type_handle, "StashedNodeRelation", - get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::get_type -// Access: Public, Virtual -// Description: Returns the particular type represented by this -// instance of the class. -//////////////////////////////////////////////////////////////////// -TypeHandle NodeRelation:: -get_type() const { - return get_class_type(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::force_init_type -// Access: Public, Virtual -// Description: Called by the TypeHandle system when it is detected -// that init_type() was not called for some reason. -// This is only called in an error situation, and it -// attempts to remedy the problem so we can recover and -// continue. -//////////////////////////////////////////////////////////////////// -TypeHandle NodeRelation:: -force_init_type() { - init_type(); - return get_class_type(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::set_transition -// Access: Public -// Description: This flavor of set_transition() accepts a specific -// TypeHandle, indicating the type of transition that we -// are setting, and a NodeTransition pointer indicating -// the value of the transition. The NodeTransition may -// be NULL indicating that the transition should be -// cleared. If the NodeTransition is not NULL, it must -// match the type indicated by the TypeHandle. -// -// The return value is a pointer to the *previous* -// transition in the set, if any, or NULL if there was -// none. -//////////////////////////////////////////////////////////////////// -PT(NodeTransition) NodeRelation:: -set_transition(TypeHandle handle, NodeTransition *trans) { - PT(NodeTransition) old_trans = - _transitions.set_transition(handle, trans); - - if (old_trans != (NodeTransition *)NULL) { - old_trans->removed_from_arc(this); - } - if (trans != (NodeTransition *)NULL) { - trans->added_to_arc(this); - } - - changed_transition(handle); - return old_trans; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeRelation::clear_transition -// Access: Public -// Description: Removes any transition associated with the indicated -// handle from the arc. -// -// The return value is a pointer to the previous -// transition in the set, if any, or NULL if there was -// none. -//////////////////////////////////////////////////////////////////// -PT(NodeTransition) NodeRelation:: -clear_transition(TypeHandle handle) { - PT(NodeTransition) old_trans = - _transitions.clear_transition(handle); - if (old_trans != (NodeTransition *)NULL) { - old_trans->removed_from_arc(this); - } - - changed_transition(handle); - return old_trans; -} diff --git a/panda/src/graph/nodeRelation.h b/panda/src/graph/nodeRelation.h deleted file mode 100644 index b6a7fdd3c9..0000000000 --- a/panda/src/graph/nodeRelation.h +++ /dev/null @@ -1,258 +0,0 @@ -// Filename: nodeRelation.h -// Created by: drose (26Oct98) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef NODERELATION_H -#define NODERELATION_H - -#include - -#include "nodeTransitions.h" -#include "nodeTransitionCache.h" -#include "boundedObject.h" -#include "pt_Node.h" - -#include -#include -#include -#include -#include -#include - -#include "pset.h" -#include "pmap.h" -#include - -class Node; - -// This function keeps a monotonically incrementing sequence number -// for each change made to the graph, for the purpose of invalidating -// wrt cache values. A different sequence number is kept for each -// type of graph, hence the parameter. -extern EXPCL_PANDA UpdateSeq &last_graph_update(TypeHandle graph_type); - -EXPCL_PANDA INLINE_GRAPH void remove_arc(NodeRelation *arc); - -/////////////////////////////////////////////////////////////////// -// Class : NodeRelation -// Description : The base class for all scene graph arcs. This is the -// glue between Nodes that defines the scene graph. -// There are no arcs of type NodeRelation per se, but -// there may be any number of types of arcs that inherit -// from NodeRelation. -// -// All arcs are directed binary relations, from a parent -// node to a child node, and may include any number of -// NodeTransitions which affect the attributes of the -// child node and later descendants. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA NodeRelation : public TypedWritableReferenceCount, public BoundedObject { -public: - NodeRelation(Node *from, Node *to, int sort, TypeHandle graph_type); - -protected: - // Normally, this should only be used from derived classes for - // passing to the factory. Don't attempt to create an unattached - // arc directly. - NodeRelation(TypeHandle graph_type); - -private: - // It is an error to attempt to copy an arc. - NodeRelation(const NodeRelation ©); - void operator = (const NodeRelation ©); - -public: - // The destructor needs to be virtual so that we can delete the - // NodeRelations of various types when the Node they're attached to - // destructs. However, a NodeRelation should not generally be - // deleted directly, because it is reference-counted in the tree; - // instead, you should call remove_arc(). - virtual ~NodeRelation(); - -PUBLISHED: - void output(ostream &out) const; - INLINE_GRAPH void output_transitions(ostream &out) const; - INLINE_GRAPH void write_transitions(ostream &out, int indent = 0) const; - - INLINE_GRAPH Node *get_parent() const; - INLINE_GRAPH Node *get_child() const; - INLINE_GRAPH int get_sort() const; - INLINE_GRAPH TypeHandle get_graph_type() const; - - INLINE_GRAPH bool is_attached() const; - - void ref_parent(); - void unref_parent(); - - INLINE_GRAPH void change_parent(Node *parent); - INLINE_GRAPH void change_parent(Node *parent, int sort); - INLINE_GRAPH void change_child(Node *child); - INLINE_GRAPH void change_parent_and_child(Node *parent, Node *child); - INLINE_GRAPH void set_sort(int sort); - INLINE_GRAPH void set_graph_type(TypeHandle graph_type); - - PT(NodeTransition) set_transition(TypeHandle handle, NodeTransition *trans); /*DONT INLINE_GRAPH THIS*/ - INLINE_GRAPH PT(NodeTransition) set_transition(NodeTransition *trans); - INLINE_GRAPH PT(NodeTransition) set_transition(NodeTransition *trans, int priority); - PT(NodeTransition) clear_transition(TypeHandle handle); /*DONT INLINE_GRAPH THIS*/ - - INLINE_GRAPH bool has_transition(TypeHandle handle) const; - INLINE_GRAPH bool has_any_transition() const; - INLINE_GRAPH NodeTransition *get_transition(TypeHandle handle) const; - void copy_transitions_from(const NodeRelation *arc); - void compose_transitions_from(const NodeRelation *arc); - void copy_transitions_from(const NodeTransitions &trans); - void compose_transitions_from(const NodeTransitions &trans); - void adjust_all_priorities(int adjustment); - - INLINE_GRAPH int compare_transitions_to(const NodeRelation *arc) const; - - INLINE_GRAPH UpdateSeq get_last_update() const; - INLINE_GRAPH void clear_wrt_cache(); - -public: - bool sub_render_trans(const AllTransitionsWrapper &input_trans, - AllTransitionsWrapper &modify_trans, - RenderTraverser *trav); - bool has_sub_render_trans() const; - int get_num_sub_render_trans() const; - -public: - // Factory stuff: to create a new NodeRelation based on its - // TypeHandle. - INLINE_GRAPH static NodeRelation * - create_typed_arc(TypeHandle type, Node *parent, Node *child, int sort = 0); - - // This is just to be called at initialization time; don't try to - // call this directly. - INLINE_GRAPH static void register_with_factory(); - -protected: - INLINE_GRAPH static Factory &get_factory(); - -private: - static NodeRelation *make_arc(const FactoryParams ¶ms); - static Factory *_factory; - -protected: - void attach(); - PT(TypedWritableReferenceCount) detach(); - PT(TypedWritableReferenceCount) detach_below(); - -private: - // We reference-count the child pointer, but not the parent pointer, - // to avoid circular reference counting. - - Node *_parent; - PT_Node _child; - int _sort; - TypeHandle _graph_type; - bool _attached; - int _parent_ref; - -private: - // This is the set of transitions assigned to the arc. You should - // never access this directly; use set_transition() and friends - // instead. - NodeTransitions _transitions; - - // This stores the known net transitions from the _top_subtree node, - // which is either NULL to indicate the root of the graph, or a - // pointer to the nearest descendent with multiple parents. You - // should never even attempt to access it directly; it exists only - // to support caching in wrt(). - PT(NodeTransitionCache) _net_transitions; - Node *_top_subtree; - - // This is updated with the current update sequence whenever we - // verify that *all* the transitions to this arc are accurately - // reflected in the above set. - UpdateSeq _all_verified; - - // This is updated with the current update sequence each time the - // arc is changed (for instance, to change its state or to reparent - // it or something). It exists to support caching in the cull - // traversal. - UpdateSeq _last_update; - -public: - static void register_with_read_factory(void); - virtual void write_datagram(BamWriter* manager, Datagram &me); - virtual int complete_pointers(TypedWritable **plist, - BamReader *manager); - - static TypedWritable *make_NodeRelation(const FactoryParams ¶ms); - -protected: - void fillin(DatagramIterator& scan, BamReader* manager); - -private: - //This value is only used for the process of re-construction - //from a binary source. DO NOT ACCESS. The value is only - //guaranteed to be accurate during that process - int _num_transitions; - -public: - virtual void changed_transition(TypeHandle transition_type); - -protected: - virtual void propagate_stale_bound(); - virtual BoundingVolume *recompute_bound(); - -PUBLISHED: - INLINE_GRAPH static TypeHandle get_class_type(); - INLINE_GRAPH static TypeHandle get_stashed_type(); - -public: - static void init_type(); - virtual TypeHandle get_type() const; - virtual TypeHandle force_init_type(); - -private: - static TypeHandle _type_handle; - static TypeHandle _stashed_type_handle; - - // Should not include storage class specifiers in friend declaration. - friend EXPCL_PANDA void remove_arc(NodeRelation *arc); - - friend class Node; - friend class NodeTransitionWrapper; - friend class AllTransitionsWrapper; - friend class GraphPriorityAdjuster; -}; - -EXPCL_PANDA INLINE_GRAPH ostream & -operator << (ostream &out, const NodeRelation &arc); - -#include "nodeRelation.T" - -#ifndef DONT_INLINE_GRAPH -#include "nodeRelation.I" -#endif - -// We include node.h here at the end, so we'll know that nodes are of -// type ReferenceCount and will be able to compile anything that uses -// a NodeRelation. We have to include it here at the end instead of -// the beginning because node.h also includes nodeRelation.h. - -// This comment tells ppremake that we know this is a circular -// #include reference, and please don't bother us about it. The line -// must be exactly as shown. -/* okcircular */ -#include "node.h" - -#endif diff --git a/panda/src/graph/nodeTransition.I b/panda/src/graph/nodeTransition.I deleted file mode 100644 index 6e46bf7feb..0000000000 --- a/panda/src/graph/nodeTransition.I +++ /dev/null @@ -1,181 +0,0 @@ -// Filename: nodeTransition.I -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransition:: -NodeTransition() { - _priority = 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransition:: -NodeTransition(const NodeTransition ©) : - TypedWritableReferenceCount(copy), - _priority(copy._priority) -{ - // We specifically do *not* copy the _arcs list. -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransition:: -operator = (const NodeTransition ©) { - TypedWritableReferenceCount::operator = (copy); - _priority = copy._priority; - // We specifically do *not* copy the _arcs list. -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::Equality Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool NodeTransition:: -operator == (const NodeTransition &other) const { - return compare_to(other) == 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::Inequality Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool NodeTransition:: -operator != (const NodeTransition &other) const { - return compare_to(other) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::Inequality Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool NodeTransition:: -operator < (const NodeTransition &other) const { - return compare_to(other) < 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::Inequality Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool NodeTransition:: -operator <= (const NodeTransition &other) const { - return compare_to(other) <= 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::Inequality Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool NodeTransition:: -operator > (const NodeTransition &other) const { - return compare_to(other) > 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::Inequality Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool NodeTransition:: -operator >= (const NodeTransition &other) const { - return compare_to(other) >= 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::generate_hash -// Access: Public -// Description: Adds the transition to the indicated hash generator. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransition:: -generate_hash(GraphHashGenerator &hashgen) const { - hashgen.add_int(get_handle().get_index()); - internal_generate_hash(hashgen); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::set_priority -// Access: Public -// Description: Changes the priority associated with this transition. -// The transition will always override transitions with -// a lower priority. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransition:: -set_priority(int priority) { - _priority = priority; - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::get_priority -// Access: Public -// Description: Returns the priority associated with this transition. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH int NodeTransition:: -get_priority() const { - return _priority; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::add_to_arc -// Access: Protected -// Description: Intended to be called only by the arc's -// set_transition() method to indicate that the -// transition has been assigned to the arc. Further -// state changes on the transition will now notify the -// arc. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransition:: -added_to_arc(NodeRelation *arc) { - bool inserted = _arcs.insert(arc).second; - nassertv(inserted); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::add_to_arc -// Access: Protected -// Description: Intended to be called by the arc's -// set_transition() or clear_transition() method (or by -// the arc's destructor) to indicate that the transition -// is no longer assigned to the arc. Further state -// changes on the transition will *not* notify the arc. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransition:: -removed_from_arc(NodeRelation *arc) { - size_t num_erased = _arcs.erase(arc); - nassertv(num_erased == 1); -} - -INLINE_GRAPH ostream &operator << (ostream &out, const NodeTransition &ntb) { - ntb.output(out); - return out; -} diff --git a/panda/src/graph/nodeTransition.N b/panda/src/graph/nodeTransition.N deleted file mode 100644 index 4efaa99498..0000000000 --- a/panda/src/graph/nodeTransition.N +++ /dev/null @@ -1 +0,0 @@ -ignoremember get_handle diff --git a/panda/src/graph/nodeTransition.cxx b/panda/src/graph/nodeTransition.cxx deleted file mode 100644 index 6e596a4b96..0000000000 --- a/panda/src/graph/nodeTransition.cxx +++ /dev/null @@ -1,217 +0,0 @@ -// Filename: nodeTransition.cxx -// Created by: drose (26Oct98) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "nodeTransition.h" -#include "nodeTransitions.h" -#include "nodeRelation.h" -#include "config_graph.h" - -#include "indent.h" - -TypeHandle NodeTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::compare_to -// Access: Public -// Description: This function works like strcmp(): it compares the -// two transitions and returns a number less than zero -// if this transition sorts before the other one, equal -// to zero if they are equivalent, or greater than zero -// if this transition sorts after the other one. -// -// This imposes an arbitrary sorting order across all -// transitions, whose sole purpose is to allow grouping -// of equivalent transitions together in STL structures -// like maps and sets. -//////////////////////////////////////////////////////////////////// -int NodeTransition:: -compare_to(const NodeTransition &other) const { - TypeHandle my_handle = get_handle(); - TypeHandle other_handle = other.get_handle(); - - if (my_handle != other_handle) { - return (my_handle < other_handle) ? -1 : 1; - - } else if (_priority != other._priority) { - return _priority - other._priority; - - } else { - return internal_compare_to(&other); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::compare_to_ignore_priority -// Access: Public -// Description: This is equivalent to compare_to() but it does not -// consider different priorities to be relevant. -//////////////////////////////////////////////////////////////////// -int NodeTransition:: -compare_to_ignore_priority(const NodeTransition &other) const { - TypeHandle my_handle = get_handle(); - TypeHandle other_handle = other.get_handle(); - - if (my_handle != other_handle) { - return (my_handle < other_handle) ? -1 : 1; - - } else { - return internal_compare_to(&other); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::get_handle -// Access: Public, Virtual -// Description: Returns the TypeHandle that is used to identify this -// particular transition (and its attribute) on the -// graph arcs. Normally this will be the same as the -// transition's type, e.g. get_type(), but certain -// transition types may want to redefine this. -//////////////////////////////////////////////////////////////////// -TypeHandle NodeTransition:: -get_handle() const { - return get_type(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::make_initial -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -NodeTransition *NodeTransition:: -make_initial() const { - graph_cat.warning() - << "make_initial() not defined for " << get_type() << "\n"; - return (NodeTransition *)this; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::sub_render -// Access: Public, Virtual -// Description: This virtual function is normally a no-op. It is -// called during the render traversal to allow a special -// transition (e.g. a ShaderTransition) to intercept the -// normal render traversal with some fancy rendering -// process. -//////////////////////////////////////////////////////////////////// -bool NodeTransition:: -sub_render(NodeRelation *, const AllTransitionsWrapper &, - AllTransitionsWrapper &, RenderTraverser *) { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::has_sub_render -// Access: Public, Virtual -// Description: Should be redefined to return true if the function -// sub_render(), above, expects to be called during -// traversal. -//////////////////////////////////////////////////////////////////// -bool NodeTransition:: -has_sub_render() const { - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void NodeTransition:: -output(ostream &out) const { - out << get_handle(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void NodeTransition:: -write(ostream &out, int indent_level) const { - indent(out, indent_level) << *this << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void NodeTransition:: -issue(GraphicsStateGuardianBase *) { -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::internal_generate_hash -// Access: Protected, Virtual -// Description: Should be overridden by particular NodeTransitions to -// generate a hash value uniquifying this particular -// transition. -//////////////////////////////////////////////////////////////////// -void NodeTransition:: -internal_generate_hash(GraphHashGenerator &) const { -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::state_changed -// Access: Protected -// Description: This should be called by any internal method (like -// set_priority() or set_value()) that changes the state -// of the transition and may thus affect the state cache -// on the scene graph. It notifies all arcs that this -// transition has been applied to of the change. -//////////////////////////////////////////////////////////////////// -void NodeTransition:: -state_changed() { - TypeHandle handle = get_handle(); - - Arcs::const_iterator ai; - for (ai = _arcs.begin(); ai != _arcs.end(); ++ai) { - (*ai)->changed_transition(handle); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void NodeTransition:: -write_datagram(BamWriter *, Datagram &me) -{ - me.add_uint16(_priority); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransition::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void NodeTransition:: -fillin(DatagramIterator& scan, BamReader*) -{ - _priority = scan.get_uint16(); -} - diff --git a/panda/src/graph/nodeTransition.h b/panda/src/graph/nodeTransition.h deleted file mode 100644 index b36cc74f62..0000000000 --- a/panda/src/graph/nodeTransition.h +++ /dev/null @@ -1,165 +0,0 @@ -// Filename: nodeTransition.h -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef NODETRANSITION_H -#define NODETRANSITION_H - -#include "pandabase.h" - -#include "graphHashGenerator.h" - -#include "pset.h" -#include "typedWritableReferenceCount.h" - -class Node; -class NodeTransitions; -class NodeRelation; -class RenderTraverser; -class AllTransitionsWrapper; -class BamWriter; -class BamReader; -class Datagram; -class DatagramIterator; -class GraphicsStateGuardianBase; - -//////////////////////////////////////////////////////////////////// -// Class : NodeTransition -// Description : This is an abstract class defining the basic -// interface to a Transition--the type of state change -// request that is stored on the arcs of the scene -// graph. -// -// In general, the scene graph represents state by -// encoding transitions between various states on the -// arcs of the graph. The state of a particular node is -// determined by the composition of all the transitions -// on arcs between that node and the root. -// -// A NodeTransition represents a particular state, or a -// change from any one state to another. For example, -// it might represent the change from the untextured -// state to rendering with a particular texture, which -// can also be thought of as representing the state of -// rendering with that texture. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA NodeTransition : public TypedWritableReferenceCount { -protected: - INLINE_GRAPH NodeTransition(); - INLINE_GRAPH NodeTransition(const NodeTransition ©); - INLINE_GRAPH void operator = (const NodeTransition ©); - -public: - typedef GraphHashGenerator HashGenerator; - - INLINE_GRAPH bool operator == (const NodeTransition &other) const; - INLINE_GRAPH bool operator != (const NodeTransition &other) const; - INLINE_GRAPH bool operator < (const NodeTransition &other) const; - INLINE_GRAPH bool operator <= (const NodeTransition &other) const; - INLINE_GRAPH bool operator > (const NodeTransition &other) const; - INLINE_GRAPH bool operator >= (const NodeTransition &other) const; - - int compare_to(const NodeTransition &other) const; - int compare_to_ignore_priority(const NodeTransition &other) const; - INLINE_GRAPH void generate_hash(GraphHashGenerator &hashgen) const; - -PUBLISHED: - INLINE_GRAPH void set_priority(int priority); - INLINE_GRAPH int get_priority() const; - -public: - virtual NodeTransition *make_copy() const=0; - virtual NodeTransition *make_initial() const; - - virtual TypeHandle get_handle() const; - - virtual NodeTransition *compose(const NodeTransition *other) const=0; - virtual NodeTransition *invert() const=0; - - virtual bool sub_render(NodeRelation *arc, - const AllTransitionsWrapper &input_trans, - AllTransitionsWrapper &modify_trans, - RenderTraverser *trav); - virtual bool has_sub_render() const; - -PUBLISHED: - virtual void output(ostream &out) const; - virtual void write(ostream &out, int indent_level = 0) const; - -public: - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual int internal_compare_to(const NodeTransition *other) const=0; - virtual void internal_generate_hash(GraphHashGenerator &hashgen) const; - - // And this is the internal function we'll call whenever our value - // changes. - void state_changed(); - -public: - // We need to keep a list of all of the arcs we're assigned to, so - // that if our value changes we can keep the cache up-to-date. - // These functions will be called by the arcs when appropriate. - // Don't attempt to call them directly; they're public only to make - // it convenient to call them from non-class template functions. - INLINE_GRAPH void added_to_arc(NodeRelation *arc); - INLINE_GRAPH void removed_from_arc(NodeRelation *arc); - -protected: - int _priority; - - typedef pset Arcs; - Arcs _arcs; - -public: - virtual void write_datagram(BamWriter* manager, Datagram &me); - - //NodeTransition has no factory methods as it is not directly made - -protected: - virtual 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() { - TypedWritableReferenceCount::init_type(); - register_type(_type_handle, "NodeTransition", - TypedWritableReferenceCount::get_class_type()); - } - -private: - static TypeHandle _type_handle; - friend class NodeRelation; - friend class NodeTransitions; - friend class NodeTransitionCache; -}; - -EXPCL_PANDA INLINE_GRAPH ostream & -operator << (ostream &out, const NodeTransition &ntb); - -#ifndef DONT_INLINE_GRAPH -#include "nodeTransition.I" -#endif - -#endif diff --git a/panda/src/graph/nodeTransitionCache.I b/panda/src/graph/nodeTransitionCache.I deleted file mode 100644 index 63ac36f046..0000000000 --- a/panda/src/graph/nodeTransitionCache.I +++ /dev/null @@ -1,70 +0,0 @@ -// Filename: nodeTransitionCache.I -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::set_transition -// Access: Public -// Description: This flavor of set_transition() accepts a pointer to -// a NodeTransition only. It infers the type of the -// NodeTransition from the pointer. However, it is not -// valid to pass a NULL pointer to this flavor of -// set_transition; if the pointer might be NULL, use the -// above flavor instead (or just call clear_transition). -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH PT(NodeTransition) NodeTransitionCache:: -set_transition(NodeTransition *trans) { - nassertr(trans != (NodeTransition *)NULL, NULL); - nassertr(trans->get_handle() != TypeHandle::none(), NULL); - return set_transition(trans->get_handle(), trans); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::size -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitionCache::size_type NodeTransitionCache:: -size() const { - return _cache.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::begin -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitionCache::const_iterator NodeTransitionCache:: -begin() const { - return _cache.begin(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::end -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitionCache::const_iterator NodeTransitionCache:: -end() const { - return _cache.end(); -} - -INLINE_GRAPH ostream &operator << (ostream &out, const NodeTransitionCache &ntc) { - ntc.output(out); - return out; -} diff --git a/panda/src/graph/nodeTransitionCache.cxx b/panda/src/graph/nodeTransitionCache.cxx deleted file mode 100644 index b91ae5e88c..0000000000 --- a/panda/src/graph/nodeTransitionCache.cxx +++ /dev/null @@ -1,588 +0,0 @@ -// Filename: nodeTransitionCache.cxx -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "nodeTransitionCache.h" -#include "nodeTransitions.h" -#include "config_graph.h" -#include "setTransitionHelpers.h" - -#include "indent.h" - -#include - -TypeHandle NodeTransitionCache::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -NodeTransitionCache:: -NodeTransitionCache() { -#ifdef DO_MEMORY_USAGE - MemoryUsage::update_type(this, get_class_type()); -#endif -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -NodeTransitionCache:: -NodeTransitionCache(const NodeTransitionCache ©) : - _cache(copy._cache) -{ -#ifdef DO_MEMORY_USAGE - MemoryUsage::update_type(this, get_class_type()); -#endif -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void NodeTransitionCache:: -operator = (const NodeTransitionCache ©) { - _cache = copy._cache; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::Constructor from NodeTransitions -// Access: Public -// Description: Adds an entry into the cache for each non-identity -// Transition in the NodeTransitions set. -//////////////////////////////////////////////////////////////////// -NodeTransitionCache:: -NodeTransitionCache(const NodeTransitions &nt) { -#ifdef DO_MEMORY_USAGE - MemoryUsage::update_type(this, get_class_type()); -#endif - - NodeTransitions::Transitions::const_iterator ti; - for (ti = nt._transitions.begin(); - ti != nt._transitions.end(); - ++ti) { - TypeHandle handle = (*ti).first; - NodeTransition *trans = (*ti).second; - - if (trans != (NodeTransition *)NULL) { - _cache.push_back(CacheEntry(handle, NodeTransitionCacheEntry(trans))); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -NodeTransitionCache:: -~NodeTransitionCache() { -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::is_identity -// Access: Public -// Description: Returns true if all of the transitions in the cache -// are the identity transition. -//////////////////////////////////////////////////////////////////// -bool NodeTransitionCache:: -is_identity() const { - Cache::const_iterator ci; - for (ci = _cache.begin(); ci != _cache.end(); ++ci) { - if (!(*ci).second.is_identity()) { - return false; - } - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::compare_to -// Access: Public -// Description: This only compares the set of transitions in the -// cache; it does not compare timestamps. -//////////////////////////////////////////////////////////////////// -int NodeTransitionCache:: -compare_to(const NodeTransitionCache &other) const { - return tmap_compare_cache(_cache.begin(), _cache.end(), - other._cache.begin(), other._cache.end()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::generate_hash -// Access: Public -// Description: Adds the transitions to the indicated hash generator. -//////////////////////////////////////////////////////////////////// -void NodeTransitionCache:: -generate_hash(GraphHashGenerator &hashgen) const { - Cache::const_iterator ci; - for (ci = _cache.begin(); ci != _cache.end(); ++ci) { - (*ci).second.generate_hash(hashgen); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::is_empty -// Access: Public -// Description: Returns true if there are no Transitions stored in -// the cache, or false if there are any (even identity) -// Transitions. -//////////////////////////////////////////////////////////////////// -bool NodeTransitionCache:: -is_empty() const { - return _cache.empty(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::set_transition -// Access: Public -// Description: This flavor of set_transition() accepts a specific -// TypeHandle, indicating the type of transition that we -// are setting, and a NodeTransition pointer indicating -// the value of the transition. The NodeTransition may -// be NULL indicating that the transition should be -// cleared. If the NodeTransition is not NULL, it must -// match the type indicated by the TypeHandle. -// -// The return value is a pointer to the *previous* -// transition in the cache, if any, or NULL if there was -// none. -//////////////////////////////////////////////////////////////////// -PT(NodeTransition) NodeTransitionCache:: -set_transition(TypeHandle handle, NodeTransition *trans) { - if (trans == (NodeTransition *)NULL) { - return clear_transition(handle); - - } else { - Cache::iterator ci = - lower_bound(_cache.begin(), _cache.end(), - CacheEntry(handle, NodeTransitionCacheEntry()), - SortCache()); - - if (ci != _cache.end() && (*ci).first == handle) { - PT(NodeTransition) result = (*ci).second.get_trans(); - (*ci).second = NodeTransitionCacheEntry(trans); - return result; - } - - _cache.insert(ci, Cache::value_type(handle, trans)); - return NULL; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::clear_transition -// Access: Public -// Description: Removes any transition associated with the indicated -// handle from the set. -// -// The return value is a pointer to the previous -// transition in the set, if any, or NULL if there was -// none. -//////////////////////////////////////////////////////////////////// -PT(NodeTransition) NodeTransitionCache:: -clear_transition(TypeHandle handle) { - nassertr(handle != TypeHandle::none(), NULL); - - Cache::iterator ci = - lower_bound(_cache.begin(), _cache.end(), - CacheEntry(handle, NodeTransitionCacheEntry()), - SortCache()); - - if (ci != _cache.end() && (*ci).first == handle) { - PT(NodeTransition) result = (*ci).second.get_trans(); - (*ci).second.clear_trans(); - return result; - } - - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::has_transition -// Access: Public -// Description: Returns true if a transition associated with the -// indicated handle has been stored in the cache, or -// false otherwise. -//////////////////////////////////////////////////////////////////// -bool NodeTransitionCache:: -has_transition(TypeHandle handle) const { - nassertr(handle != TypeHandle::none(), false); - - Cache::const_iterator ci = - lower_bound(_cache.begin(), _cache.end(), - CacheEntry(handle, NodeTransitionCacheEntry()), - SortCache()); - if (ci != _cache.end() && (*ci).first == handle) { - return (*ci).second.has_trans(); - } - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::get_transition -// Access: Public -// Description: Returns the transition associated with the indicated -// handle, or NULL if no such transition has been stored -// in the cache. -//////////////////////////////////////////////////////////////////// -NodeTransition *NodeTransitionCache:: -get_transition(TypeHandle handle) const { - nassertr(handle != TypeHandle::none(), NULL); - - Cache::const_iterator ci = - lower_bound(_cache.begin(), _cache.end(), - CacheEntry(handle, NodeTransitionCacheEntry()), - SortCache()); - if (ci != _cache.end() && (*ci).first == handle) { - return (*ci).second.get_trans(); - } - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::clear -// Access: Public -// Description: Blows away all entries in the cache. -//////////////////////////////////////////////////////////////////// -void NodeTransitionCache:: -clear() { - _cache.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::lookup_entry -// Access: Public -// Description: Looks up the indicated entry in the cache. If the -// entry is defined in the cache, copies it to the -// 'entry' parameter and returns true; otherwise, -// reinitializes the 'entry' parameter and returns -// false. -//////////////////////////////////////////////////////////////////// -bool NodeTransitionCache:: -lookup_entry(TypeHandle handle, NodeTransitionCacheEntry &entry) const { - Cache::const_iterator ci = - lower_bound(_cache.begin(), _cache.end(), - CacheEntry(handle, NodeTransitionCacheEntry()), - SortCache()); - if (ci != _cache.end() && (*ci).first == handle) { - entry = (*ci).second; - return true; - } - - entry.clear(); - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::store_entry -// Access: Public -// Description: Adds or updates an entry in the cache for a -// particular Transition type. -//////////////////////////////////////////////////////////////////// -void NodeTransitionCache:: -store_entry(TypeHandle handle, const NodeTransitionCacheEntry &entry) { - CacheEntry search_entry(handle, entry); - Cache::iterator ci = - lower_bound(_cache.begin(), _cache.end(), search_entry, - SortCache()); - if (ci != _cache.end() && (*ci).first == handle) { - (*ci).second = entry; - } else { - _cache.insert(ci, search_entry); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::store_to -// Access: Public, Static -// Description: Adds a transition to the NodeTransitions set for each -// entry in the cache, and tells the transition that it -// has been added to the indicated arc. -//////////////////////////////////////////////////////////////////// -void NodeTransitionCache:: -store_to(const NodeTransitionCache *a, NodeRelation *arc, - NodeTransitions &nt) { - if (a == (NodeTransitionCache *)NULL || a->_cache.empty()) { - // a is empty: no change. - return; - } - - // First, tell all of the entries in the cache that they're about - // the be added to the arc. - Cache::const_iterator ci; - for (ci = a->_cache.begin(); ci != a->_cache.end(); ++ci) { - NodeTransition *trans = (*ci).second.get_trans(); - trans->added_to_arc(arc); - } - - // And now actually add them. - NodeTransitions temp; - tmap_override_union(nt._transitions.begin(), nt._transitions.end(), - a->_cache.begin(), a->_cache.end(), - inserter(temp._transitions, temp._transitions.begin())); - nt._transitions.swap(temp._transitions); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::union -// Access: Public, Static -// Description: Returns a pointer to a new NodeTransitionCache (or -// perhaps a pointer to one of the two source caches) -// that represents the union of the two caches. Either -// or both pointers may be NULL, indicating identity, -// and the return value might also be NULL. -//////////////////////////////////////////////////////////////////// -NodeTransitionCache *NodeTransitionCache:: -c_union(const NodeTransitionCache *a, const NodeTransitionCache *b) { - if (a == (NodeTransitionCache *)NULL || a->_cache.empty()) { - // a is empty, therefore identity: the result is the same as b. - return (NodeTransitionCache *)b; - - } else if (b == (NodeTransitionCache *)NULL || b->_cache.empty()) { - // b is empty, therefore identity: the result is the same as a. - return (NodeTransitionCache *)a; - - } else { - // Neither is empty. Build and return a new list. - NodeTransitionCache *result = new NodeTransitionCache; - - tmap_override_union(a->_cache.begin(), a->_cache.end(), - b->_cache.begin(), b->_cache.end(), - back_inserter(result->_cache)); - - return result; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::compose -// Access: Public, Static -// Description: Returns a pointer to a new NodeTransitionCache (or -// perhaps a pointer to one of the two source caches) -// that represents the memberwise composition of the two -// caches. Either or both pointers may be NULL, -// indicating identity, and the return value might also -// be NULL. -//////////////////////////////////////////////////////////////////// -NodeTransitionCache *NodeTransitionCache:: -compose(const NodeTransitionCache *a, const NodeTransitionCache *b) { - // Since the absence of a transition from the object implies the - // identity transition, we can make a quick special case for either - // object being empty: - - if (a == (NodeTransitionCache *)NULL || a->_cache.empty()) { - // a is empty, therefore identity: the result is the same as b. - return (NodeTransitionCache *)b; - - } else if (b == (NodeTransitionCache *)NULL || b->_cache.empty()) { - // b is empty, therefore identity: the result is the same as a. - return (NodeTransitionCache *)a; - - } else { - // Neither is empty. Build and return a new list. - NodeTransitionCache *result = new NodeTransitionCache; - - tmap_compose(a->_cache.begin(), a->_cache.end(), - b->_cache.begin(), b->_cache.end(), - back_inserter(result->_cache)); - - return result; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::invert -// Access: Public, Static -// Description: Returns a pointer to a new NodeTransitionCache (or -// perhaps a pointer to the source caches) that -// represents the memberwise inversion of the caches. -// The source pointer may be NULL, indicating identity, -// and the return value might also be NULL. -//////////////////////////////////////////////////////////////////// -NodeTransitionCache *NodeTransitionCache:: -invert(const NodeTransitionCache *a) { - if (a == (NodeTransitionCache *)NULL || a->_cache.empty()) { - // a is empty, therefore identity: the result is identity. - return NULL; - } - - // Build and return a new list. - NodeTransitionCache *result = new NodeTransitionCache; - - tmap_invert(a->_cache.begin(), a->_cache.end(), - back_inserter(result->_cache)); - - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::invert_compose -// Access: Public, Static -// Description: Returns a pointer to a new NodeTransitionCache (or -// perhaps a pointer to one of the two source caches) -// that represents the memberwise invert-compose of the -// two caches. Either or both pointers may be NULL, -// indicating identity, and the return value might also -// be NULL. -//////////////////////////////////////////////////////////////////// -NodeTransitionCache *NodeTransitionCache:: -invert_compose(const NodeTransitionCache *a, const NodeTransitionCache *b) { - // Since the absence of a transition from the object implies the - // identity transition, we can make a quick special case for either - // object being empty: - - if (a == (NodeTransitionCache *)NULL || a->_cache.empty()) { - // a is empty, therefore identity: the result is the same as b. - return (NodeTransitionCache *)b; - - } else if (b == (NodeTransitionCache *)NULL || b->_cache.empty()) { - // b is empty, therefore identity: the result is the inverse of a. - return invert(a); - - } else { - // Neither is empty. Build and return a new list. - NodeTransitionCache *result = new NodeTransitionCache; - - tmap_invert_compose(a->_cache.begin(), a->_cache.end(), - b->_cache.begin(), b->_cache.end(), - back_inserter(result->_cache)); - - return result; - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::cached_compose -// Access: Public, Static -// Description: Returns a cache pointer (which might be a pointer to -// the same cache object, or to a newly allocated -// object) that represents the result of compose(a, b), -// as computed using the cache value as a hint. Mark -// the result as computed at time 'now'. -//////////////////////////////////////////////////////////////////// -NodeTransitionCache *NodeTransitionCache:: -cached_compose(const NodeTransitionCache *a, - const NodeTransitionCache *cache, - const NodeTransitionCache *b, - UpdateSeq now) { - // Since the absence of a transition from the object implies the - // identity transition, we can make a quick special case for either - // object being empty: - - if (a == (NodeTransitionCache *)NULL || a->_cache.empty()) { - // a is empty, therefore identity: the result is the same as b. - return set_computed_verified(b, now); - - } else if (b == (NodeTransitionCache *)NULL || b->_cache.empty()) { - // b is empty, therefore identity: the result is the same as a. - return set_computed_verified(a, now); - - } else { - // Neither is empty. Build and return a new list. - NodeTransitionCache *result = new NodeTransitionCache; - - if (cache == (NodeTransitionCache *)NULL) { - // If the cache is NULL, we must send in an empty list for the - // cache list. We'll use [a.begin .. a.begin). - tmap_cached_compose(a->_cache.begin(), a->_cache.end(), - a->_cache.begin(), a->_cache.begin(), - b->_cache.begin(), b->_cache.end(), - now, - back_inserter(result->_cache)); - - } else { - tmap_cached_compose(a->_cache.begin(), a->_cache.end(), - cache->_cache.begin(), cache->_cache.end(), - b->_cache.begin(), b->_cache.end(), - now, - back_inserter(result->_cache)); - } - - return result; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::set_computed_verified -// Access: Public, Static -// Description: Returns a new pointer that represents the adjustment -// of the given cache to set each computed and verified -// value to the current now value. This may modify the -// source cache only if there are no other pointers to -// it. -//////////////////////////////////////////////////////////////////// -NodeTransitionCache *NodeTransitionCache:: -set_computed_verified(const NodeTransitionCache *a, UpdateSeq now) { - if (a == (NodeTransitionCache *)NULL || a->_cache.empty()) { - return NULL; - } - - NodeTransitionCache *result = (NodeTransitionCache *)a; - if (a->get_ref_count() > 1) { - // Copy-on-write. - result = new NodeTransitionCache(*a); - } - - Cache::iterator ci; - for (ci = result->_cache.begin(); ci != result->_cache.end(); ++ci) { - (*ci).second.set_computed_verified(now); - } - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void NodeTransitionCache:: -output(ostream &out) const { - bool written_any = false; - Cache::const_iterator ci; - for (ci = _cache.begin(); ci != _cache.end(); ++ci) { - if (!(*ci).second.is_identity()) { - if (written_any) { - out << " "; - } - out << (*ci).second; - written_any = true; - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCache::write -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void NodeTransitionCache:: -write(ostream &out, int indent_level) const { - Cache::const_iterator ci; - for (ci = _cache.begin(); ci != _cache.end(); ++ci) { - indent(out, indent_level) - << (*ci).first << ", ptr = " - << (const PT(NodeTransition) &)(*ci).second << "\n"; - (*ci).second.write(out, indent_level + 2); - } -} diff --git a/panda/src/graph/nodeTransitionCache.h b/panda/src/graph/nodeTransitionCache.h deleted file mode 100644 index 54e914857f..0000000000 --- a/panda/src/graph/nodeTransitionCache.h +++ /dev/null @@ -1,144 +0,0 @@ -// Filename: nodeTransitionCache.h -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef NODETRANSITIONCACHE_H -#define NODETRANSITIONCACHE_H - -#include "pandabase.h" - -#include "nodeTransitionCacheEntry.h" -#include "graphHashGenerator.h" -#include "nodeTransitions.h" - -#include "referenceCount.h" -#include "firstOfPairLess.h" -#include "pvector.h" - -//////////////////////////////////////////////////////////////////// -// Class : NodeTransitionCache -// Description : This represents the cached values of accumulated -// NodeTransitions values, associated with a particular -// arc. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA NodeTransitionCache : public ReferenceCount { -public: - typedef GraphHashGenerator HashGenerator; - - NodeTransitionCache(); - NodeTransitionCache(const NodeTransitionCache ©); - void operator = (const NodeTransitionCache ©); - NodeTransitionCache(const NodeTransitions &nt); - ~NodeTransitionCache(); - - bool is_identity() const; - int compare_to(const NodeTransitionCache &other) const; - void generate_hash(GraphHashGenerator &hashgen) const; - - bool is_empty() const; - PT(NodeTransition) set_transition(TypeHandle handle, NodeTransition *trans); - INLINE_GRAPH PT(NodeTransition) set_transition(NodeTransition *trans); - PT(NodeTransition) clear_transition(TypeHandle handle); - bool has_transition(TypeHandle handle) const; - NodeTransition *get_transition(TypeHandle handle) const; - - void clear(); - - bool - lookup_entry(TypeHandle handle, NodeTransitionCacheEntry &entry) const; - - void - store_entry(TypeHandle handle, const NodeTransitionCacheEntry &entry); - -private: - typedef pair CacheEntry; - typedef FirstOfPairLess SortCache; - typedef pvector Cache; - -public: - // STL-like definitions to allow read-only traversal of the - // individual transitions. Note that each of these is a - // NodeTransitionCacheEntry, not simply a PT(NodeTransition). - // Beware! These are not safe to use outside of PANDA.DLL. - typedef Cache::const_iterator iterator; - typedef Cache::const_iterator const_iterator; - typedef Cache::value_type value_type; - typedef Cache::size_type size_type; - - INLINE_GRAPH size_type size() const; - INLINE_GRAPH const_iterator begin() const; - INLINE_GRAPH const_iterator end() const; - - -public: - // The following functions are support functions for - // AllTransitionsWrapper; they have limited utility elsewhere. - - static void - store_to(const NodeTransitionCache *a, NodeRelation *arc, - NodeTransitions &nt); - - static NodeTransitionCache * - c_union(const NodeTransitionCache *a, const NodeTransitionCache *b); - - static NodeTransitionCache * - compose(const NodeTransitionCache *a, const NodeTransitionCache *b); - - static NodeTransitionCache * - invert(const NodeTransitionCache *a); - - static NodeTransitionCache * - invert_compose(const NodeTransitionCache *a, const NodeTransitionCache *b); - - static NodeTransitionCache * - cached_compose(const NodeTransitionCache *a, - const NodeTransitionCache *cache, - const NodeTransitionCache *b, - UpdateSeq now); - - static NodeTransitionCache * - set_computed_verified(const NodeTransitionCache *a, UpdateSeq now); - - -public: - void output(ostream &out) const; - void write(ostream &out, int indent_level = 0) const; - -private: - Cache _cache; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - ReferenceCount::init_type(); - register_type(_type_handle, "NodeTransitionCache", - ReferenceCount::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -INLINE_GRAPH ostream &operator << (ostream &out, const NodeTransitionCache &ntc); - -#ifndef DONT_INLINE_GRAPH -#include "nodeTransitionCache.I" -#endif - -#endif diff --git a/panda/src/graph/nodeTransitionCacheEntry.I b/panda/src/graph/nodeTransitionCacheEntry.I deleted file mode 100644 index cb76d0460c..0000000000 --- a/panda/src/graph/nodeTransitionCacheEntry.I +++ /dev/null @@ -1,360 +0,0 @@ -// Filename: nodeTransitionCacheEntry.I -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "config_graph.h" - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitionCacheEntry:: -NodeTransitionCacheEntry(NodeTransition *trans) : _trans(trans) { -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitionCacheEntry:: -NodeTransitionCacheEntry(const NodeTransitionCacheEntry ©) : - _trans(copy._trans), - _computed(copy._computed), - _verified(copy._verified) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransitionCacheEntry:: -operator = (const NodeTransitionCacheEntry ©) { - _trans = copy._trans; - _computed = copy._computed; - _verified = copy._verified; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::is_identity -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool NodeTransitionCacheEntry:: -is_identity() const { - return (_trans == (NodeTransition *)NULL); - // || _trans->is_identity(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::compare_to -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH int NodeTransitionCacheEntry:: -compare_to(const NodeTransitionCacheEntry &other) const { - bool this_ident = is_identity(); - bool other_ident = other.is_identity(); - if (this_ident && other_ident) { - return 0; - } - if (this_ident) { - return -1; - } - if (other_ident) { - return 1; - } - - // This should be guaranteed by the above logic. - nassertr(_trans != (NodeTransition *)NULL && - other._trans != (NodeTransition *)NULL, false); - - return _trans->compare_to(*other._trans); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::generate_hash -// Access: Public -// Description: Adds the transition to the indicated hash generator. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransitionCacheEntry:: -generate_hash(GraphHashGenerator &hashgen) const { - if (_trans != (NodeTransition *)NULL) { - _trans->generate_hash(hashgen); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::clear -// Access: Public -// Description: Reinitializes the cache entry to its original state. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransitionCacheEntry:: -clear() { - _trans.clear(); - _computed.clear(); - _verified.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::set_trans -// Access: Public -// Description: Changes the transition associated with the cache -// entry without changing the associated time stamps. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransitionCacheEntry:: -set_trans(NodeTransition *trans) { - _trans = trans; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::clear_trans -// Access: Public -// Description: Removes the transitoin associated with the cache -// entry without changing the associated time stamps. -// This is of limited usefulness. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransitionCacheEntry:: -clear_trans() { - _trans.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::has_trans -// Access: Public -// Description: Returns true if the cache entry has an associated -// NodeTransition, false if it doesn't (and the -// transition should be assumed to be identity). -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool NodeTransitionCacheEntry:: -has_trans() const { - return _trans != (NodeTransition *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::get_trans -// Access: Public -// Description: Returns the NodeTransition associated with the cache -// entry, or NULL if there is no associated -// NodeTransition (in which case it should be assumed to -// be identity). -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransition *NodeTransitionCacheEntry:: -get_trans() const { - return _trans; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::is_cache_verified -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool NodeTransitionCacheEntry:: -is_cache_verified(UpdateSeq as_of) const { - if (wrt_cat.is_spam()) { - wrt_cat.spam() - << "NodeTransitionCacheEntry::is_cache_verified(" << as_of - << "), _verified = " << _verified << ", result = " - << (as_of <= _verified) << "\n"; - } - return as_of <= _verified; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::is_freshly_computed -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool NodeTransitionCacheEntry:: -is_freshly_computed(UpdateSeq changed) const { - return changed < _computed; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::set_computed_verified -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransitionCacheEntry:: -set_computed_verified(UpdateSeq now) { - _computed = now; - _verified = now; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::Typecast Operator -// Access: Public -// Description: This typecast operator allows the cache entry to be -// directly assigned to a NodeTransition pointer. It's -// primarily useful for using the code in -// setTransitionHelpers.h interchangeably between -// NodeTransitions and NodeTransitionCaches. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitionCacheEntry:: -operator const PT(NodeTransition) &() const { - return _trans; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::get_computed -// Access: Public -// Description: Returns the timestamp at which this cache entry was -// computed. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH UpdateSeq NodeTransitionCacheEntry:: -get_computed() const { - return _computed; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::get_verified -// Access: Public -// Description: Returns the last timestamp at which this cache entry -// was verified; i.e. when the graph was last walked up -// to the root to ensure the cache entry is still valid. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH UpdateSeq NodeTransitionCacheEntry:: -get_verified() const { - return _verified; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::invert -// Access: Public, Static -// Description: Returns a new cache entry that represents the inverse -// of a. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitionCacheEntry NodeTransitionCacheEntry:: -invert(const NodeTransitionCacheEntry &a) { - if (a.is_identity()) { - return a; - } - return NodeTransitionCacheEntry(a._trans->invert()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::compose -// Access: Public, Static -// Description: Returns a new cache entry that represents the -// composition of a and b. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitionCacheEntry NodeTransitionCacheEntry:: -compose(const NodeTransitionCacheEntry &a, - const NodeTransitionCacheEntry &b) { - if (a.is_identity()) { - return b; - } - if (b.is_identity()) { - return a; - } - return NodeTransitionCacheEntry(a._trans->compose(b._trans)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::invert_compose -// Access: Public, Static -// Description: Returns a new cache entry that represents the -// composition of invert(a) and b. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitionCacheEntry NodeTransitionCacheEntry:: -invert_compose(const NodeTransitionCacheEntry &a, - const NodeTransitionCacheEntry &b) { - if (a.is_identity()) { - return b; - } - if (b.is_identity()) { - return NodeTransitionCacheEntry(a._trans->invert()); - } - if (a._trans->compare_to(*b._trans) == 0) { - return NodeTransitionCacheEntry(); - } - - PT(NodeTransition) inv = a._trans->invert(); - if (inv == (NodeTransition *)NULL) { - return b; - } - - // We don't care about priority for this operation. - - // This is broken! We don't have the right the change the priority - // on this node. For now, leave this out, since we aren't using - // priority on any transitions for which we're computing wrt() at - // the moment. Fix me soon. - // inv->set_priority(b._trans->get_priority()); - - return NodeTransitionCacheEntry(inv->compose(b._trans)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::cached_compose -// Access: Public, Static -// Description: Sets this cache entry to the result of compose(a, b), -// as computed using the cache value as a hint. Mark -// the result as computed at time 'now'. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitionCacheEntry NodeTransitionCacheEntry:: -cached_compose(const NodeTransitionCacheEntry &a, - const NodeTransitionCacheEntry &cache, - const NodeTransitionCacheEntry &b, - UpdateSeq now) { - if (wrt_cat.is_spam()) { - wrt_cat.spam() - << "Composing:\n" - << " a) " << a << " = " << a._computed << "\n" - << " cache) " << cache << " = " << cache._computed << "\n" - << " b) " << b << " = " << b._computed << "\n"; - } - - if (cache._computed == UpdateSeq::initial() || - (a._computed == UpdateSeq::initial() && - b._computed == UpdateSeq::initial()) || - cache._computed < a._computed) { - - // If the cache value has not yet been computed, or if the values - // in a and b are both empty, or if the cache is older than the - // source value (a), discard the cache and compute the composition - // directly. - NodeTransitionCacheEntry result = compose(a, b); - result.set_computed_verified(now); - - if (wrt_cat.is_spam()) { - wrt_cat.spam() << "computed result is " << result << "\n"; - } - - return result; - - } else { - // Otherwise, the cache value is recent and we can simply use it - // directly. - NodeTransitionCacheEntry result = cache; - result._verified = now; - - if (wrt_cat.is_spam()) { - wrt_cat.spam() << "cached result is " << result << "\n"; - } - - return result; - } -} - -INLINE_GRAPH ostream &operator << (ostream &out, const NodeTransitionCacheEntry &e) { - e.output(out); - return out; -} diff --git a/panda/src/graph/nodeTransitionCacheEntry.cxx b/panda/src/graph/nodeTransitionCacheEntry.cxx deleted file mode 100644 index 2a5e861f4e..0000000000 --- a/panda/src/graph/nodeTransitionCacheEntry.cxx +++ /dev/null @@ -1,46 +0,0 @@ -// Filename: nodeTransitionCacheEntry.cxx -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "nodeTransitionCacheEntry.h" - -#include - - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void NodeTransitionCacheEntry:: -output(ostream &out) const { - if (_trans != (NodeTransition *)NULL) { - out << *_trans; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionCacheEntry::write -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void NodeTransitionCacheEntry:: -write(ostream &out, int indent_level) const { - if (_trans != (NodeTransition *)NULL) { - _trans->write(out, indent_level); - } -} diff --git a/panda/src/graph/nodeTransitionCacheEntry.h b/panda/src/graph/nodeTransitionCacheEntry.h deleted file mode 100644 index 5133be7060..0000000000 --- a/panda/src/graph/nodeTransitionCacheEntry.h +++ /dev/null @@ -1,104 +0,0 @@ -// Filename: nodeTransitionCacheEntry.h -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef NODETRANSITIONCACHEENTRY_H -#define NODETRANSITIONCACHEENTRY_H - -#include - -#include "nodeTransition.h" -#include "config_graph.h" -#include "graphHashGenerator.h" - -#include -#include - -//////////////////////////////////////////////////////////////////// -// Class : NodeTransitionCacheEntry -// Description : This is a single cached accumulated NodeTransition -// value, representing the net Transition for one -// particular transition type on an arc. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA NodeTransitionCacheEntry { -public: - typedef GraphHashGenerator HashGenerator; - - INLINE_GRAPH NodeTransitionCacheEntry(NodeTransition *trans = NULL); - INLINE_GRAPH NodeTransitionCacheEntry(const NodeTransitionCacheEntry ©); - INLINE_GRAPH void operator = (const NodeTransitionCacheEntry ©); - - INLINE_GRAPH bool is_identity() const; - INLINE_GRAPH int compare_to(const NodeTransitionCacheEntry &other) const; - INLINE_GRAPH void generate_hash(GraphHashGenerator &hashgen) const; - - INLINE_GRAPH void clear(); - - INLINE_GRAPH void set_trans(NodeTransition *trans); - INLINE_GRAPH void clear_trans(); - INLINE_GRAPH bool has_trans() const; - INLINE_GRAPH NodeTransition *get_trans() const; - - INLINE_GRAPH bool is_cache_verified(UpdateSeq as_of) const; - INLINE_GRAPH bool is_freshly_computed(UpdateSeq changed) const; - INLINE_GRAPH void set_computed_verified(UpdateSeq now); - - INLINE_GRAPH operator const PT(NodeTransition) &() const; - - INLINE_GRAPH UpdateSeq get_computed() const; - INLINE_GRAPH UpdateSeq get_verified() const; - -public: - // The following functions perform the basic transition operations - // on the entry's _trans pointer. In general, they don't bother to - // keep the _computed and _verified members consistent across these - // operations. - - INLINE_GRAPH static NodeTransitionCacheEntry - invert(const NodeTransitionCacheEntry &a); - - INLINE_GRAPH static NodeTransitionCacheEntry - compose(const NodeTransitionCacheEntry &a, - const NodeTransitionCacheEntry &b); - - INLINE_GRAPH static NodeTransitionCacheEntry - invert_compose(const NodeTransitionCacheEntry &a, - const NodeTransitionCacheEntry &b); - - INLINE_GRAPH static NodeTransitionCacheEntry - cached_compose(const NodeTransitionCacheEntry &a, - const NodeTransitionCacheEntry &cache, - const NodeTransitionCacheEntry &b, - UpdateSeq now); - -public: - void output(ostream &out) const; - void write(ostream &out, int indent_level = 0) const; - -private: - PT(NodeTransition) _trans; - UpdateSeq _computed; - UpdateSeq _verified; -}; - -INLINE_GRAPH ostream &operator << (ostream &out, const NodeTransitionCacheEntry &e); - -#ifndef DONT_INLINE_GRAPH -#include "nodeTransitionCacheEntry.I" -#endif - -#endif diff --git a/panda/src/graph/nodeTransitionWrapper.I b/panda/src/graph/nodeTransitionWrapper.I deleted file mode 100644 index fe90cab352..0000000000 --- a/panda/src/graph/nodeTransitionWrapper.I +++ /dev/null @@ -1,273 +0,0 @@ -// Filename: nodeTransitionWrapper.I -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "nodeRelation.h" -#include "nodeTransitionCacheEntry.h" - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitionWrapper:: -NodeTransitionWrapper(TypeHandle handle) : _handle(handle) { - nassertv(_handle != TypeHandle::none()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitionWrapper:: -NodeTransitionWrapper(const NodeTransitionWrapper ©) : - _handle(copy._handle), - _entry(copy._entry) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransitionWrapper:: -operator = (const NodeTransitionWrapper ©) { - _handle = copy._handle; - _entry = copy._entry; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::init_from -// Access: Public, Static -// Description: This is a named constructor that creates an empty -// NodeTransitionWrapper ready to access the same type -// of NodeTransition as the other. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitionWrapper NodeTransitionWrapper:: -init_from(const NodeTransitionWrapper &other) { - return NodeTransitionWrapper(other._handle); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::get_handle -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH TypeHandle NodeTransitionWrapper:: -get_handle() const { - return _handle; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::has_trans -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool NodeTransitionWrapper:: -has_trans() const { - return _entry.has_trans(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::get_trans -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransition *NodeTransitionWrapper:: -get_trans() const { - return _entry.get_trans(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::set_trans -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransitionWrapper:: -set_trans(NodeTransition *trans) { - _entry.set_trans(trans); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::is_identity -// Access: Public -// Description: Returns true if the wrapper represents an identity -// transition. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool NodeTransitionWrapper:: -is_identity() const { - return _entry.is_identity(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::compare_to -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH int NodeTransitionWrapper:: -compare_to(const NodeTransitionWrapper &other) const { - return _entry.compare_to(other._entry); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::make_identity -// Access: Public -// Description: Resets the wrapper to the identity transition. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransitionWrapper:: -make_identity() { - _entry.clear_trans(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::extract_from -// Access: Public -// Description: Sets the wrapper to the transition contained on the -// arc. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransitionWrapper:: -extract_from(const NodeRelation *arc) { - nassertv(arc != (NodeRelation *)NULL); - nassertv(_handle != TypeHandle::none()); - _entry.set_trans(arc->get_transition(_handle)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::store_to -// Access: Public -// Description: Stores the transition in the wrapper to the arc. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransitionWrapper:: -store_to(NodeRelation *arc) const { - nassertv(arc != (NodeRelation *)NULL); - arc->set_transition(_handle, _entry.get_trans()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::compose_in_place -// Access: Public -// Description: Sets this transition to the composition of this -// transition and the following one. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransitionWrapper:: -compose_in_place(const NodeTransitionWrapper &other) { - nassertv(_handle == other._handle); - _entry = NodeTransitionCacheEntry::compose(_entry, other._entry); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::invert_in_place -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransitionWrapper:: -invert_in_place() { - _entry = NodeTransitionCacheEntry::invert(_entry); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::invert_compose_in_place -// Access: Public -// Description: Sets this transition to the composition of this -// transition and the following one. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransitionWrapper:: -invert_compose_in_place(const NodeTransitionWrapper &other) { - _entry = NodeTransitionCacheEntry::invert_compose(_entry, other._entry); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::extract_from_cache -// Access: Public -// Description: Sets this transition to the value indicated in the -// cache on the arc. Also returns the arc's top_subtree -// indication. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH Node *NodeTransitionWrapper:: -extract_from_cache(const NodeRelation *arc) { - nassertr(_handle != TypeHandle::none(), NULL); - - if (arc->_net_transitions == (NodeTransitionCache *)NULL) { - _entry.clear(); - } else { - arc->_net_transitions->lookup_entry(_handle, _entry); - } - return arc->_top_subtree; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::store_to_cache -// Access: Public -// Description: Stores this transition into the arc's cache, and -// updates the arc's top_subtree. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransitionWrapper:: -store_to_cache(NodeRelation *arc, Node *top_subtree) { - arc->_top_subtree = top_subtree; - if (arc->_net_transitions == (NodeTransitionCache *)NULL) { - arc->_net_transitions = new NodeTransitionCache; - - } else if (arc->_net_transitions->get_ref_count() > 1) { - // Copy-on-write. - arc->_net_transitions = new NodeTransitionCache(*arc->_net_transitions); - } - - arc->_net_transitions->store_entry(_handle, _entry); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::is_cache_verified -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool NodeTransitionWrapper:: -is_cache_verified(UpdateSeq as_of) const { - return _entry.is_cache_verified(as_of); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::set_computed_verified -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransitionWrapper:: -set_computed_verified(UpdateSeq now) { - _entry.set_computed_verified(now); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::cached_compose -// Access: Public -// Description: Computes the composition of this wrapper's value with -// that indicated by value, using the cache as a helper, -// and stores the result in this wrapper. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransitionWrapper:: -cached_compose(const NodeTransitionWrapper &cache, - const NodeTransitionWrapper &value, - UpdateSeq now) { - _entry = - NodeTransitionCacheEntry::cached_compose(_entry, cache._entry, - value._entry, now); -} - -INLINE_GRAPH ostream &operator << (ostream &out, const NodeTransitionWrapper &ntw) { - ntw.output(out); - return out; -} diff --git a/panda/src/graph/nodeTransitionWrapper.T b/panda/src/graph/nodeTransitionWrapper.T deleted file mode 100644 index 31b0816bc0..0000000000 --- a/panda/src/graph/nodeTransitionWrapper.T +++ /dev/null @@ -1,40 +0,0 @@ -// Filename: nodeTransitionWrapper.T -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: get_transition_into -// Description: This external template function is handy for -// extracting the transition (of a known type) from the -// wrapper. If the transition exists, it is -// automatically downcasted to the correct type and -// stored in the pointer given in the first parameter, -// and the return value is true. If the transition does -// not exist, the pointer is filled with NULL and the -// return value is false. -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH bool -get_transition_into(Transition *&ptr, const NodeTransitionWrapper &trans) { - NodeTransition *nt = trans.get_trans(); - if (nt == (NodeTransition *)NULL) { - ptr = (Transition *)NULL; - return false; - } - DCAST_INTO_R(ptr, nt, false); - return true; -} diff --git a/panda/src/graph/nodeTransitionWrapper.cxx b/panda/src/graph/nodeTransitionWrapper.cxx deleted file mode 100644 index 9b5c4d50cd..0000000000 --- a/panda/src/graph/nodeTransitionWrapper.cxx +++ /dev/null @@ -1,50 +0,0 @@ -// Filename: nodeTransitionWrapper.cxx -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "nodeTransitionWrapper.h" -#include "nodeRelation.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void NodeTransitionWrapper:: -output(ostream &out) const { - if (!_entry.has_trans()) { - out << "identity-" << _handle; - } else { - out << *_entry.get_trans(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitionWrapper::write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void NodeTransitionWrapper:: -write(ostream &out, int indent_level) const { - if (!_entry.has_trans()) { - indent(out, indent_level) << "identity-" << _handle << "\n"; - } else { - _entry.get_trans()->write(out, indent_level); - } -} diff --git a/panda/src/graph/nodeTransitionWrapper.h b/panda/src/graph/nodeTransitionWrapper.h deleted file mode 100644 index f6b2fae922..0000000000 --- a/panda/src/graph/nodeTransitionWrapper.h +++ /dev/null @@ -1,101 +0,0 @@ -// Filename: nodeTransitionWrapper.h -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef NODETRANSITIONWRAPPER_H -#define NODETRANSITIONWRAPPER_H - -// -// There are several flavors of TransitionWrappers. These are classes -// that represent one or a number of transitions simultaneously and -// are passed to template functions like df_traverse() and wrt() so -// that the same functions can be used to operate on either one -// transition type or a number of them. -// -// Since these classes are used as template parameters, they do not -// need to use inheritance or virtual functions; but they all must -// have a similar interface. -// - -#include - -#include "nodeTransition.h" -#include "nodeTransitionCacheEntry.h" - -class Node; -class NodeRelation; - -//////////////////////////////////////////////////////////////////// -// Class : NodeTransitionWrapper -// Description : This is a wrapper around a single transition type, -// selected at runtime by its handle. It is useful when -// computing a wrt() based on one transition type only -// (for instance, a MatrixTransition). -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA NodeTransitionWrapper { -public: - typedef NodeTransitionWrapper TransitionWrapper; - - INLINE_GRAPH NodeTransitionWrapper(TypeHandle handle); - INLINE_GRAPH NodeTransitionWrapper(const NodeTransitionWrapper ©); - INLINE_GRAPH void operator = (const NodeTransitionWrapper ©); - - INLINE_GRAPH static NodeTransitionWrapper - init_from(const NodeTransitionWrapper &other); - - INLINE_GRAPH TypeHandle get_handle() const; - INLINE_GRAPH bool has_trans() const; - INLINE_GRAPH NodeTransition *get_trans() const; - INLINE_GRAPH void set_trans(NodeTransition *trans); - - INLINE_GRAPH bool is_identity() const; - INLINE_GRAPH int compare_to(const NodeTransitionWrapper &other) const; - - INLINE_GRAPH void make_identity(); - INLINE_GRAPH void extract_from(const NodeRelation *arc); - INLINE_GRAPH void store_to(NodeRelation *arc) const; - - INLINE_GRAPH void compose_in_place(const NodeTransitionWrapper &other); - INLINE_GRAPH void invert_in_place(); - INLINE_GRAPH void invert_compose_in_place(const NodeTransitionWrapper &other); - - INLINE_GRAPH Node *extract_from_cache(const NodeRelation *arc); - INLINE_GRAPH void store_to_cache(NodeRelation *arc, Node *top_subtree); - INLINE_GRAPH bool is_cache_verified(UpdateSeq as_of) const; - INLINE_GRAPH void set_computed_verified(UpdateSeq now); - - INLINE_GRAPH void cached_compose(const NodeTransitionWrapper &cache, - const NodeTransitionWrapper &value, - UpdateSeq now); - - void output(ostream &out) const; - void write(ostream &out, int indent_level = 0) const; - -private: - TypeHandle _handle; - NodeTransitionCacheEntry _entry; -}; - -EXPCL_PANDA INLINE_GRAPH ostream &operator << (ostream &out, const NodeTransitionWrapper &ntw); - -#ifndef DONT_INLINE_GRAPH -#include "nodeTransitionWrapper.I" -#endif - -#include "nodeTransitionWrapper.T" - -#endif diff --git a/panda/src/graph/nodeTransitions.I b/panda/src/graph/nodeTransitions.I deleted file mode 100644 index 68cdb1de87..0000000000 --- a/panda/src/graph/nodeTransitions.I +++ /dev/null @@ -1,120 +0,0 @@ -// Filename: nodeTransitions.I -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::set_transition -// Access: Public -// Description: This flavor of set_transition() accepts a pointer to -// a NodeTransition only. It infers the type of the -// NodeTransition from the pointer. However, it is not -// valid to pass a NULL pointer to this flavor of -// set_transition; if the pointer might be NULL, use the -// above flavor instead (or just call clear_transition). -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH PT(NodeTransition) NodeTransitions:: -set_transition(NodeTransition *trans) { - nassertr(trans != (NodeTransition *)NULL, NULL); - nassertr(trans->get_handle() != TypeHandle::none(), NULL); - return set_transition(trans->get_handle(), trans); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::size -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitions::size_type NodeTransitions:: -size() const { - return _transitions.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::begin -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitions::iterator NodeTransitions:: -begin() { - return _transitions.begin(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::end -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitions::iterator NodeTransitions:: -end() { - return _transitions.end(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::begin -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitions::const_iterator NodeTransitions:: -begin() const { - return _transitions.begin(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::end -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitions::const_iterator NodeTransitions:: -end() const { - return _transitions.end(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::insert -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitions::iterator NodeTransitions:: -insert(NodeTransitions::iterator position, - const NodeTransitions::value_type &x) { - return _transitions.insert(position, x); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::find -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH NodeTransitions::iterator NodeTransitions:: -find(const key_type &k) { - return _transitions.find(k); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::erase -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void NodeTransitions:: -erase(NodeTransitions::iterator position) { - _transitions.erase(position); -} - -INLINE_GRAPH ostream &operator << (ostream &out, const NodeTransitions &nts) { - nts.output(out); - return out; -} diff --git a/panda/src/graph/nodeTransitions.T b/panda/src/graph/nodeTransitions.T deleted file mode 100644 index 26060a014a..0000000000 --- a/panda/src/graph/nodeTransitions.T +++ /dev/null @@ -1,47 +0,0 @@ -// Filename: nodeTransitions.T -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: get_transition_into -// Description: This external template function is handy for -// extracting a transition of a particular type from the -// set. If the transition exists, it is automatically -// downcasted to the correct type and stored in the -// pointer given in the first parameter, and the return -// value is true. If the transition does not exist, the -// pointer is filled with NULL and the return value is -// false. -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH bool -get_transition_into(Transition *&ptr, const NodeTransitions &trans, - TypeHandle transition_type) { - NodeTransition *nt = trans.get_transition(transition_type); - if (nt == (NodeTransition *)NULL) { - ptr = (Transition *)NULL; - return false; - } - DCAST_INTO_R(ptr, nt, false); - return true; -} - -template -INLINE_GRAPH bool -get_transition_into(Transition *&ptr, const NodeTransitions &trans) { - return get_transition_into(ptr, trans, Transition::get_class_type()); -} diff --git a/panda/src/graph/nodeTransitions.cxx b/panda/src/graph/nodeTransitions.cxx deleted file mode 100644 index 1dd52f8727..0000000000 --- a/panda/src/graph/nodeTransitions.cxx +++ /dev/null @@ -1,322 +0,0 @@ -// Filename: nodeTransitions.cxx -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "nodeTransitions.h" -#include "config_graph.h" -#include "setTransitionHelpers.h" -#include "nodeRelation.h" - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -NodeTransitions:: -NodeTransitions() { -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -NodeTransitions:: -NodeTransitions(const NodeTransitions ©) : - _transitions(copy._transitions) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void NodeTransitions:: -operator = (const NodeTransitions ©) { - _transitions = copy._transitions; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -NodeTransitions:: -~NodeTransitions() { -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::is_empty -// Access: Public -// Description: Returns true if there are no Transitions stored in -// the set, or false if there are any (even identity) -// Transitions. -//////////////////////////////////////////////////////////////////// -bool NodeTransitions:: -is_empty() const { - return _transitions.empty(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::set_transition -// Access: Public -// Description: This flavor of set_transition() accepts a specific -// TypeHandle, indicating the type of transition that we -// are setting, and a NodeTransition pointer indicating -// the value of the transition. The NodeTransition may -// be NULL indicating that the transition should be -// cleared. If the NodeTransition is not NULL, it must -// match the type indicated by the TypeHandle. -// -// The return value is a pointer to the *previous* -// transition in the set, if any, or NULL if there was -// none. -//////////////////////////////////////////////////////////////////// -PT(NodeTransition) NodeTransitions:: -set_transition(TypeHandle handle, NodeTransition *trans) { - if (trans == (NodeTransition *)NULL) { - return clear_transition(handle); - - } else { - Transitions::iterator ti; - ti = _transitions.find(handle); - if (ti != _transitions.end()) { - PT(NodeTransition) result = (*ti).second; - (*ti).second = trans; - return result; - } - - _transitions.insert(Transitions::value_type(handle, trans)); - return NULL; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::clear_transition -// Access: Public -// Description: Removes any transition associated with the indicated -// handle from the set. -// -// The return value is a pointer to the previous -// transition in the set, if any, or NULL if there was -// none. -//////////////////////////////////////////////////////////////////// -PT(NodeTransition) NodeTransitions:: -clear_transition(TypeHandle handle) { - nassertr(handle != TypeHandle::none(), NULL); - - Transitions::iterator ti; - ti = _transitions.find(handle); - if (ti != _transitions.end()) { - PT(NodeTransition) result = (*ti).second; - _transitions.erase(ti); - return result; - } - - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::has_transition -// Access: Public -// Description: Returns true if a transition associated with the -// indicated handle has been stored in the set (even if -// it is the identity transition), or false otherwise. -//////////////////////////////////////////////////////////////////// -bool NodeTransitions:: -has_transition(TypeHandle handle) const { - nassertr(handle != TypeHandle::none(), false); - return _transitions.count(handle) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::get_transition -// Access: Public -// Description: Returns the transition associated with the indicated -// handle, or NULL if no such transition has been stored -// in the set. -//////////////////////////////////////////////////////////////////// -NodeTransition *NodeTransitions:: -get_transition(TypeHandle handle) const { - nassertr(handle != TypeHandle::none(), NULL); - Transitions::const_iterator ti; - ti = _transitions.find(handle); - if (ti != _transitions.end()) { - return (*ti).second; - } - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::clear -// Access: Public -// Description: Removes all transitions from the set. -//////////////////////////////////////////////////////////////////// -void NodeTransitions:: -clear() { - _transitions.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::copy_transitions_from -// Access: Public -// Description: Copies all of the transitions stored in the other set -// to this set. Any existing transitions in this set, -// for which there was not a corresponding transition of -// the same type in the other set, are left undisturbed. -//////////////////////////////////////////////////////////////////// -void NodeTransitions:: -copy_transitions_from(const NodeTransitions &other) { - Transitions temp; - tmap_override_union(_transitions.begin(), _transitions.end(), - other._transitions.begin(), other._transitions.end(), - inserter(temp, temp.begin())); - _transitions.swap(temp); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::copy_transitions_from -// Access: Public -// Description: As above, but updates the transitions on the way to -// indicated they are being attached to (or removed -// from) the indicated arc. This is intended only to be -// called from NodeRelation::copy_transitions(); don't -// call it directly. -//////////////////////////////////////////////////////////////////// -void NodeTransitions:: -copy_transitions_from(const NodeTransitions &other, - NodeRelation *to_arc) { - Transitions temp; - tmap_arc_union(_transitions.begin(), _transitions.end(), - other._transitions.begin(), other._transitions.end(), - to_arc, inserter(temp, temp.begin())); - _transitions.swap(temp); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::compose_transitions_from -// Access: Public -// Description: Similar to copy_transitions_from(), except that if -// the same type of transition exists on both arcs, the -// composition of the two is stored. The result -// represents the same set of transitions that would -// result from composing the two individual sets of -// transitions. -//////////////////////////////////////////////////////////////////// -void NodeTransitions:: -compose_transitions_from(const NodeTransitions &other, - NodeRelation *to_arc) { - Transitions temp; - tmap_arc_compose(_transitions.begin(), _transitions.end(), - other._transitions.begin(), other._transitions.end(), - to_arc, inserter(temp, temp.begin())); - _transitions.swap(temp); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::compare_to -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -int NodeTransitions:: -compare_to(const NodeTransitions &other) const { - return tmap_compare_trans(_transitions.begin(), _transitions.end(), - other._transitions.begin(), other._transitions.end()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::adjust_all_proriorities -// Access: Public -// Description: Adds the indicated adjustment amount (which may be -// negative) to the priority for all transitions on the -// arc. If the priority would drop below zero, it is -// set to zero. -//////////////////////////////////////////////////////////////////// -void NodeTransitions:: -adjust_all_priorities(int adjustment, NodeRelation *arc) { - Transitions::iterator ti; - for (ti = _transitions.begin(); ti != _transitions.end(); ++ti) { - nassertv((*ti).second != (NodeTransition *)NULL); - PT(NodeTransition) &trans = (*ti).second; - int new_priority = max(trans->_priority + adjustment, 0); - - if (trans->_priority != new_priority) { - if (trans->get_ref_count() > 1) { - // Copy-on-write. - trans->removed_from_arc(arc); - trans = trans->make_copy(); - trans->added_to_arc(arc); - } - trans->_priority = new_priority; - arc->changed_transition((*ti).first); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::remove_all_from_arc -// Access: Public -// Description: Marks all of the transitions in the set as removed -// from the indicated arc. This is intended to be -// called only by the arc's destructor. -//////////////////////////////////////////////////////////////////// -void NodeTransitions:: -remove_all_from_arc(NodeRelation *arc) { - Transitions::iterator ti; - for (ti = _transitions.begin(); ti != _transitions.end(); ++ti) { - nassertv((*ti).second != (NodeTransition *)NULL); - (*ti).second->removed_from_arc(arc); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void NodeTransitions:: -output(ostream &out) const { - bool written_any = false; - Transitions::const_iterator ti; - for (ti = _transitions.begin(); ti != _transitions.end(); ++ti) { - if ((*ti).second != (NodeTransition *)NULL) { - if (written_any) { - out << " "; - } - out << *(*ti).second; - written_any = true; - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodeTransitions::write -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void NodeTransitions:: -write(ostream &out, int indent_level) const { - Transitions::const_iterator ti; - for (ti = _transitions.begin(); ti != _transitions.end(); ++ti) { - if ((*ti).second != (NodeTransition *)NULL) { - indent(out, indent_level) - << (*ti).first << " = " << *(*ti).second << "\n"; - // (*ti).second->write(out, indent_level + 2); - } - } -} diff --git a/panda/src/graph/nodeTransitions.h b/panda/src/graph/nodeTransitions.h deleted file mode 100644 index 55fd47fece..0000000000 --- a/panda/src/graph/nodeTransitions.h +++ /dev/null @@ -1,113 +0,0 @@ -// Filename: nodeTransitions.h -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef NODETRANSITIONS_H -#define NODETRANSITIONS_H - -#include "pandabase.h" - -#include "nodeTransition.h" - -#include "pointerTo.h" -#include "dcast.h" - -#include "pmap.h" - -class NodeRelation; - -//////////////////////////////////////////////////////////////////// -// Class : NodeTransitions -// Description : This represents a set of zero or more NodeTransition -// pointers, organized by the transitions' get_handle() -// value. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA NodeTransitions { -public: - NodeTransitions(); - NodeTransitions(const NodeTransitions ©); - void operator = (const NodeTransitions ©); - ~NodeTransitions(); - - bool is_empty() const; - PT(NodeTransition) set_transition(TypeHandle handle, NodeTransition *trans); - INLINE_GRAPH PT(NodeTransition) set_transition(NodeTransition *trans); - PT(NodeTransition) clear_transition(TypeHandle handle); - bool has_transition(TypeHandle handle) const; - NodeTransition *get_transition(TypeHandle handle) const; - void copy_transitions_from(const NodeTransitions &other); - void copy_transitions_from(const NodeTransitions &other, - NodeRelation *to_arc); - void compose_transitions_from(const NodeTransitions &other, - NodeRelation *to_arc); - void adjust_all_priorities(int adjustment, NodeRelation *arc); - - void clear(); - - int compare_to(const NodeTransitions &other) const; - - void remove_all_from_arc(NodeRelation *arc); - -private: - typedef pmap Transitions; - -public: - // STL-like definitions to allow read-write traversal of the - // individual transitions. Beware! These are not safe to use - // outside of PANDA.DLL. - typedef Transitions::iterator iterator; - typedef Transitions::const_iterator const_iterator; - typedef Transitions::key_type key_type; - typedef Transitions::value_type value_type; - typedef Transitions::size_type size_type; - - INLINE_GRAPH size_type size() const; - INLINE_GRAPH iterator begin(); - INLINE_GRAPH iterator end(); - INLINE_GRAPH const_iterator begin() const; - INLINE_GRAPH const_iterator end() const; - INLINE_GRAPH iterator insert(iterator position, const value_type &x); - INLINE_GRAPH iterator find(const key_type &k); - INLINE_GRAPH void erase(iterator position); - -public: - void output(ostream &out) const; - void write(ostream &out, int indent_level = 0) const; - -private: - Transitions _transitions; - friend class NodeTransitionCache; -}; - -INLINE_GRAPH ostream &operator << (ostream &out, const NodeTransitions &nts); - -template -INLINE_GRAPH bool -get_transition_into(Transition *&ptr, const NodeTransitions &trans, - TypeHandle transition_type); - -template -INLINE_GRAPH bool -get_transition_into(Transition *&ptr, const NodeTransitions &trans); - -#ifndef DONT_INLINE_GRAPH -#include "nodeTransitions.I" -#endif - -#include "nodeTransitions.T" - -#endif diff --git a/panda/src/graph/nullLevelState.cxx b/panda/src/graph/nullLevelState.cxx deleted file mode 100644 index 2bfa7c20ad..0000000000 --- a/panda/src/graph/nullLevelState.cxx +++ /dev/null @@ -1,19 +0,0 @@ -// Filename: nullLevelState.cxx -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "nullLevelState.h" diff --git a/panda/src/graph/nullLevelState.h b/panda/src/graph/nullLevelState.h deleted file mode 100644 index 536d15fad0..0000000000 --- a/panda/src/graph/nullLevelState.h +++ /dev/null @@ -1,38 +0,0 @@ -// Filename: nullLevelState.h -// Created by: drose (17Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef NULLLEVELSTATE_H -#define NULLLEVELSTATE_H - -#include - -/////////////////////////////////////////////////////////////////// -// Class : NullLevelState -// Description : This is an empty class designed to be passed to a -// traverser that doesn't care about tracking states -// between levels. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA NullLevelState { -public: - INLINE NullLevelState() { } - INLINE NullLevelState(const NullLevelState &) { } - INLINE void operator = (const NullLevelState &) { } -}; - -#endif - diff --git a/panda/src/graph/nullTransitionWrapper.I b/panda/src/graph/nullTransitionWrapper.I deleted file mode 100644 index bac307e260..0000000000 --- a/panda/src/graph/nullTransitionWrapper.I +++ /dev/null @@ -1,206 +0,0 @@ -// Filename: nullTransitionWrapper.I -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "nodeRelation.h" -#include "nodeTransitionCacheEntry.h" - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE NullTransitionWrapper:: -NullTransitionWrapper() { -} - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE NullTransitionWrapper:: -NullTransitionWrapper(const NullTransitionWrapper &) { -} - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void NullTransitionWrapper:: -operator = (const NullTransitionWrapper &) { -} - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::init_from -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -INLINE NullTransitionWrapper NullTransitionWrapper:: -init_from(const NullTransitionWrapper &) { - return NullTransitionWrapper(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::is_identity -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool NullTransitionWrapper:: -is_identity() const { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::compare_to -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int NullTransitionWrapper:: -compare_to(const NullTransitionWrapper &) const { - return 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::make_identity -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void NullTransitionWrapper:: -make_identity() { -} - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::extract_from -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void NullTransitionWrapper:: -extract_from(const NodeRelation *) { -} - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::store_to -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void NullTransitionWrapper:: -store_to(NodeRelation *) const { -} - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::compose_in_place -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void NullTransitionWrapper:: -compose_in_place(const NullTransitionWrapper &) { -} - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::invert_in_place -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void NullTransitionWrapper:: -invert_in_place() { -} - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::invert_compose_in_place -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void NullTransitionWrapper:: -invert_compose_in_place(const NullTransitionWrapper &) { -} - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::extract_from_cache -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE Node *NullTransitionWrapper:: -extract_from_cache(const NodeRelation *) { - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::store_to_cache -// Access: Public -// Description: Stores this transition into the arc's cache, and -// updates the arc's top_subtree. -//////////////////////////////////////////////////////////////////// -INLINE void NullTransitionWrapper:: -store_to_cache(NodeRelation *, Node *) { -} - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::is_cache_verified -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool NullTransitionWrapper:: -is_cache_verified(UpdateSeq) const { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::set_computed_verified -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void NullTransitionWrapper:: -set_computed_verified(UpdateSeq) { -} - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::cached_compose -// Access: Public -// Description: Computes the composition of this wrapper's value with -// that indicated by value, using the cache as a helper, -// and stores the result in this wrapper. -//////////////////////////////////////////////////////////////////// -INLINE void NullTransitionWrapper:: -cached_compose(const NullTransitionWrapper &, - const NullTransitionWrapper &, - UpdateSeq) { -} - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void NullTransitionWrapper:: -output(ostream &) const { -} - -//////////////////////////////////////////////////////////////////// -// Function: NullTransitionWrapper::write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void NullTransitionWrapper:: -write(ostream &, int) const { -} - -INLINE ostream &operator << (ostream &out, const NullTransitionWrapper &ntw) { - ntw.output(out); - return out; -} diff --git a/panda/src/graph/nullTransitionWrapper.cxx b/panda/src/graph/nullTransitionWrapper.cxx deleted file mode 100644 index 433c64ca52..0000000000 --- a/panda/src/graph/nullTransitionWrapper.cxx +++ /dev/null @@ -1,20 +0,0 @@ -// Filename: nullTransitionWrapper.cxx -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "nullTransitionWrapper.h" - diff --git a/panda/src/graph/nullTransitionWrapper.h b/panda/src/graph/nullTransitionWrapper.h deleted file mode 100644 index 839c646392..0000000000 --- a/panda/src/graph/nullTransitionWrapper.h +++ /dev/null @@ -1,96 +0,0 @@ -// Filename: nullTransitionWrapper.h -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef NULLTRANSITIONWRAPPER_H -#define NULLTRANSITIONWRAPPER_H - -// -// There are several flavors of TransitionWrappers. These are classes -// that represent one or a number of transitions simultaneously and -// are passed to template functions like df_traverse() and wrt() so -// that the same functions can be used to operate on either one -// transition type or a number of them. -// -// Since these classes are used as template parameters, they do not -// need to use inheritance or virtual functions; but they all must -// have a similar interface. -// - -#include - -#include "nodeTransition.h" -#include "nodeTransitionCacheEntry.h" - -class Node; -class NodeRelation; - -//////////////////////////////////////////////////////////////////// -// Class : NullTransitionWrapper -// Description : This is a wrapper around *no* transitions at all. It -// does absolutely nothing. It's pointless to pass to -// wrt(), but it's useful for passing to df_traverse() -// to perform a traversal without bothering to keep -// track of state. - -// It is important that these functions be honestly -// flagged INLINE, instead of INLINE_GRAPH, so that they -// honestly get flagged as inline functions, so they can -// be optimized away by the compiler. They don't hide -// anything that can't be exported anyway. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA NullTransitionWrapper { -public: - typedef NullTransitionWrapper TransitionWrapper; - - INLINE NullTransitionWrapper(); - INLINE NullTransitionWrapper(const NullTransitionWrapper ©); - INLINE void operator = (const NullTransitionWrapper ©); - - INLINE static NullTransitionWrapper - init_from(const NullTransitionWrapper &other); - - INLINE bool is_identity() const; - INLINE int compare_to(const NullTransitionWrapper &other) const; - - INLINE void make_identity(); - INLINE void extract_from(const NodeRelation *arc); - INLINE void store_to(NodeRelation *arc) const; - - INLINE void compose_in_place(const NullTransitionWrapper &other); - INLINE void invert_in_place(); - INLINE void invert_compose_in_place(const NullTransitionWrapper &other); - - INLINE Node *extract_from_cache(const NodeRelation *arc); - INLINE void store_to_cache(NodeRelation *arc, Node *top_subtree); - INLINE bool is_cache_verified(UpdateSeq now) const; - INLINE void set_computed_verified(UpdateSeq now); - - INLINE void cached_compose(const NullTransitionWrapper &cache, - const NullTransitionWrapper &value, - UpdateSeq now); - - INLINE void output(ostream &out) const; - INLINE void write(ostream &out, int indent_level = 0) const; -}; - -INLINE ostream &operator << (ostream &out, const NullTransitionWrapper &ntw); - -#include "nullTransitionWrapper.I" - -#endif - diff --git a/panda/src/graph/onOffTransition.I b/panda/src/graph/onOffTransition.I deleted file mode 100644 index 710e9306ea..0000000000 --- a/panda/src/graph/onOffTransition.I +++ /dev/null @@ -1,130 +0,0 @@ -// Filename: onOffTransition.I -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH OnOffTransition:: -OnOffTransition(TransitionDirection direction) { - _direction = direction; -} - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH OnOffTransition:: -OnOffTransition(const OnOffTransition ©) : - NodeTransition(copy), - _direction(copy._direction) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void OnOffTransition:: -operator = (const OnOffTransition ©) { - NodeTransition::operator = (copy); - _direction = copy._direction; -} - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::set_identity -// Access: Public -// Description: Changes the transition to an identity transition; -// this has no effect on the attribute for any nodes at -// this point and below. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void OnOffTransition:: -set_identity() { - _direction = TD_identity; - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::set_on -// Access: Public -// Description: Changes the transition to an 'on' transition; -// this turns on the attribute for all nodes at this -// point and below. However, this particular function -// does not change the attribute value itself, and is -// thus only appropriate for derived transition types -// that do not actually carry an attribute value. -// Derived types that *do* have an attribute value -// should override this function to accept a value -// parameter of the appropriate type. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void OnOffTransition:: -set_on() { - _direction = TD_on; - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::set_off -// Access: Public -// Description: Changes the transition to an 'off' transition; this -// turns off the attribute for all nodes at this point -// and below. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void OnOffTransition:: -set_off() { - _direction = TD_off; - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::is_identity -// Access: Public -// Description: Returns true if this is the identity transition, -// false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool OnOffTransition:: -is_identity() const { - return _direction == TD_identity; -} - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::is_on -// Access: Public -// Description: Returns true if this transition is 'on', false -// otherwise. If the derived transition type carries a -// value, it should define a get_value() function which -// allows you to query the on value. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool OnOffTransition:: -is_on() const { - return _direction == TD_on; -} - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::is_off -// Access: Public -// Description: Returns true if this transition is the 'off' -// transition, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH bool OnOffTransition:: -is_off() const { - return _direction == TD_off; -} diff --git a/panda/src/graph/onOffTransition.cxx b/panda/src/graph/onOffTransition.cxx deleted file mode 100644 index 9e87df01dd..0000000000 --- a/panda/src/graph/onOffTransition.cxx +++ /dev/null @@ -1,230 +0,0 @@ -// Filename: onOffTransition.cxx -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "onOffTransition.h" - -#include -#include -#include -#include -#include - -TypeHandle OnOffTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::compose -// Access: Public, Virtual -// Description: Returns a new transition that corresponds to the -// composition of this transition with the second -// transition (which must be of an equivalent type). -// This may return the same pointer as either source -// transition. Applying the transition returned from -// this function to an attribute attribute will produce -// the same effect as applying each transition -// separately. -//////////////////////////////////////////////////////////////////// -NodeTransition *OnOffTransition:: -compose(const NodeTransition *other) const { - const OnOffTransition *ot; - DCAST_INTO_R(ot, other, NULL); - - if (ot->_priority < _priority || ot->_direction == TD_identity) { - // The other transition is identity or too low-priority; the - // result is unchanged. - return (OnOffTransition *)this; - } - - // In any other case, for an OnOffTransition, the result is the same - // as the second operand. - return (OnOffTransition *)ot; -} - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::invert -// Access: Public, Virtual -// Description: Returns a new transition that corresponds to the -// inverse of this transition. If the transition was -// identity, this may return the same pointer. Returns -// NULL if the transition cannot be inverted. -//////////////////////////////////////////////////////////////////// -NodeTransition *OnOffTransition:: -invert() const { - switch (_direction) { - case TD_identity: - return (OnOffTransition *)this; - - case TD_on: - OnOffTransition *result; - DCAST_INTO_R(result, make_copy(), NULL); - result->_direction = TD_off; - return result; - - case TD_off: - return NULL; - } - - // Invalid direction flag. - nassertr(false, NULL); - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void OnOffTransition:: -output(ostream &out) const { - switch (_direction) { - case TD_identity: - out << "identity-" << get_handle(); - return; - - case TD_on: - out << "on-" << get_handle() << ":"; - output_value(out); - return; - - case TD_off: - out << "off-" << get_handle(); - return; - } - - // Invalid direction flag. - nassertv(false); -} - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void OnOffTransition:: -write(ostream &out, int indent_level) const { - switch (_direction) { - case TD_identity: - indent(out, indent_level) << "identity-" << get_handle() << "\n"; - return; - - case TD_on: - indent(out, indent_level) << "on-" << get_handle() << ":\n"; - write_value(out, indent_level + 2); - return; - - case TD_off: - indent(out, indent_level) << "off-" << get_handle() << "\n"; - return; - } - - // Invalid direction flag. - nassertv(false); -} - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::internal_compare_to -// Access: Protected, Virtual -// Description: Returns a number < 0 if this transition sorts before -// the other transition, > 0 if it sorts after, 0 if -// they are equivalent (except for priority). -//////////////////////////////////////////////////////////////////// -int OnOffTransition:: -internal_compare_to(const NodeTransition *other) const { - const OnOffTransition *ot; - DCAST_INTO_R(ot, other, false); - - if (_direction != ot->_direction) { - return (_direction < ot->_direction) ? -1 : 1; - } - if (_direction == TD_on) { - return compare_values(ot); - } - return 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::set_value_from -// Access: Protected, Virtual -// Description: Assigns the value from the corresponding value of the -// other transition, which is assumed to be of an -// equivalent type. -//////////////////////////////////////////////////////////////////// -void OnOffTransition:: -set_value_from(const OnOffTransition *) { -} - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::compare_values -// Access: Protected, Virtual -// Description: Returns 0 if the two transitions share the same -// value, or < 0 or > 0 otherwise. It is given that -// they are of equivalent types and that they are both -// "on" transitions. -//////////////////////////////////////////////////////////////////// -int OnOffTransition:: -compare_values(const OnOffTransition *) const { - return 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::output_value -// Access: Protected, Virtual -// Description: Outputs the value on one line. -//////////////////////////////////////////////////////////////////// -void OnOffTransition:: -output_value(ostream &) const { -} - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::write_value -// Access: Protected, Virtual -// Description: Outputs the value on multiple lines. -//////////////////////////////////////////////////////////////////// -void OnOffTransition:: -write_value(ostream &, int) const { -} - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void OnOffTransition:: -write_datagram(BamWriter *manager, Datagram &me) -{ - NodeTransition::write_datagram(manager, me); - me.add_uint8(_direction); -} - -//////////////////////////////////////////////////////////////////// -// Function: OnOffTransition::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void OnOffTransition:: -fillin(DatagramIterator& scan, BamReader* manager) -{ - NodeTransition::fillin(scan, manager); - _direction = (enum TransitionDirection) scan.get_uint8(); -} - - - diff --git a/panda/src/graph/onOffTransition.h b/panda/src/graph/onOffTransition.h deleted file mode 100644 index 5a6278d98b..0000000000 --- a/panda/src/graph/onOffTransition.h +++ /dev/null @@ -1,112 +0,0 @@ -// Filename: onOffTransition.h -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef ONOFFTRANSITION_H -#define ONOFFTRANSITION_H - -#include - -#include "nodeTransition.h" -#include "transitionDirection.h" - -class NodeRelation; - -//////////////////////////////////////////////////////////////////// -// Class : OnOffTransition -// Description : This is an abstract class that encapsulates a family -// of transitions for states that are either on or off -// (and, when on, may or may not have some particular -// value). This is typically useful for things like -// Texture, which have a definite value when on, and -// also have a definite off condition. -// -// See also OnTransition, which is used for states that -// are always on in some sense, or whose value itself -// can encode the case of being off. -// -// The transition may be either 'on', turning on a -// particular state, 'off', turning *off* a state that -// was previously turned on, or 'identity', not -// affecting the state. If two 'on' transitions are -// composed together, the second one overrides the -// first. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA OnOffTransition : public NodeTransition { -protected: - INLINE_GRAPH OnOffTransition(TransitionDirection direction = TD_identity); - INLINE_GRAPH OnOffTransition(const OnOffTransition ©); - INLINE_GRAPH void operator = (const OnOffTransition ©); - -PUBLISHED: - INLINE_GRAPH void set_identity(); - INLINE_GRAPH void set_on(); - INLINE_GRAPH void set_off(); - - INLINE_GRAPH bool is_identity() const; - INLINE_GRAPH bool is_on() const; - INLINE_GRAPH bool is_off() const; - -public: - virtual NodeTransition *compose(const NodeTransition *other) const; - virtual NodeTransition *invert() const; - - virtual void output(ostream &out) const; - virtual void write(ostream &out, int indent_level = 0) const; - -protected: - virtual int internal_compare_to(const NodeTransition *other) const; - - virtual void set_value_from(const OnOffTransition *other); - virtual int compare_values(const OnOffTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - TransitionDirection _direction; - -public: - //No Read/Write factory methods are defined since this is - //only an abstract clas - virtual void write_datagram(BamWriter* manager, Datagram &me); - -protected: - 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() { - NodeTransition::init_type(); - register_type(_type_handle, "OnOffTransition", - NodeTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#ifndef DONT_INLINE_GRAPH -#include "onOffTransition.I" -#endif - -#endif diff --git a/panda/src/graph/onTransition.I b/panda/src/graph/onTransition.I deleted file mode 100644 index 82c1fff7fc..0000000000 --- a/panda/src/graph/onTransition.I +++ /dev/null @@ -1,47 +0,0 @@ -// Filename: onTransition.I -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: OnTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH OnTransition:: -OnTransition() { -} - -//////////////////////////////////////////////////////////////////// -// Function: OnTransition::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH OnTransition:: -OnTransition(const OnTransition ©) : - NodeTransition(copy) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: OnTransition::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE_GRAPH void OnTransition:: -operator = (const OnTransition ©) { - NodeTransition::operator = (copy); -} diff --git a/panda/src/graph/onTransition.cxx b/panda/src/graph/onTransition.cxx deleted file mode 100644 index e11fc748e8..0000000000 --- a/panda/src/graph/onTransition.cxx +++ /dev/null @@ -1,99 +0,0 @@ -// Filename: onTransition.cxx -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "onTransition.h" - -#include - -TypeHandle OnTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: OnTransition::compose -// Access: Public, Virtual -// Description: Returns a new transition that corresponds to the -// composition of this transition with the second -// transition (which must be of an equivalent type). -// This may return the same pointer as either source -// transition. Applying the transition returned from -// this function to an attribute attribute will produce -// the same effect as applying each transition -// separately. -//////////////////////////////////////////////////////////////////// -NodeTransition *OnTransition:: -compose(const NodeTransition *other) const { - const OnTransition *ot; - DCAST_INTO_R(ot, other, NULL); - - if (ot->_priority < _priority) { - // The other transition is too low-priority; the result is - // unchanged. - return (OnTransition *)this; - } - - // In any other case, for an OnTransition, the result is the same - // as the second operand. - return (OnTransition *)ot; -} - -//////////////////////////////////////////////////////////////////// -// Function: OnTransition::invert -// Access: Public, Virtual -// Description: Returns a new transition that corresponds to the -// inverse of this transition. If the transition was -// identity, this may return the same pointer. Returns -// NULL if the transition cannot be inverted. -//////////////////////////////////////////////////////////////////// -NodeTransition *OnTransition:: -invert() const { - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: OnTransition::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void OnTransition:: -output(ostream &out) const { - output_value(out); -} - -//////////////////////////////////////////////////////////////////// -// Function: OnTransition::write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void OnTransition:: -write(ostream &out, int indent_level) const { - write_value(out, indent_level); -} - -//////////////////////////////////////////////////////////////////// -// Function: OnTransition::internal_compare_to -// Access: Protected, Virtual -// Description: Returns a number < 0 if this transition sorts before -// the other transition, > 0 if it sorts after, 0 if -// they are equivalent (except for priority). -//////////////////////////////////////////////////////////////////// -int OnTransition:: -internal_compare_to(const NodeTransition *other) const { - const OnTransition *ot; - DCAST_INTO_R(ot, other, false); - - return compare_values(ot); -} diff --git a/panda/src/graph/onTransition.h b/panda/src/graph/onTransition.h deleted file mode 100644 index 6b030b26df..0000000000 --- a/panda/src/graph/onTransition.h +++ /dev/null @@ -1,92 +0,0 @@ -// Filename: onTransition.h -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef ONTRANSITION_H -#define ONTRANSITION_H - -#include - -#include "nodeTransition.h" - -class NodeRelation; - -//////////////////////////////////////////////////////////////////// -// Class : OnTransition -// Description : This is an abstract class that encapsulates a family -// of transitions for states that are always on, in one -// state or another. It's similar to OnOffTransition, -// except the state can never be 'off'; it is always on -// in some sense. -// -// Most scene graph attributes that have an enumerated -// set of states fall into this category. -// -// There is no explicit identity transition. Each -// transition always changes the state. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA OnTransition : public NodeTransition { -protected: - INLINE_GRAPH OnTransition(); - INLINE_GRAPH OnTransition(const OnTransition ©); - INLINE_GRAPH void operator = (const OnTransition ©); - -public: - virtual NodeTransition *compose(const NodeTransition *other) const; - virtual NodeTransition *invert() const; - - virtual void output(ostream &out) const; - virtual void write(ostream &out, int indent_level = 0) const; - -protected: - virtual int internal_compare_to(const NodeTransition *other) const; - - virtual void set_value_from(const OnTransition *other)=0; - virtual int compare_values(const OnTransition *other) const=0; - virtual void output_value(ostream &out) const=0; - virtual void write_value(ostream &out, int indent_level) const=0; - - //No new data is defined in OnTransition, and OnTransition is only - //an Abstract class, so no Read/Write methods are defined - -public: - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -PUBLISHED: - static TypeHandle get_class_type() { - return _type_handle; - } - -public: - static void init_type() { - NodeTransition::init_type(); - register_type(_type_handle, "OnTransition", - NodeTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#ifndef DONT_INLINE_GRAPH -#include "onTransition.I" -#endif - -#endif diff --git a/panda/src/graph/pointerNameClass.h b/panda/src/graph/pointerNameClass.h deleted file mode 100644 index 2848a8daba..0000000000 --- a/panda/src/graph/pointerNameClass.h +++ /dev/null @@ -1,40 +0,0 @@ -// Filename: pointerNameClass.h -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef POINTERNAMECLASS_H -#define POINTERNAMECLASS_H - -#include - -//////////////////////////////////////////////////////////////////// -// Class : PointerNameClass -// Description : This is a stupid little class that's used by -// MultiNodeTransition to define the name of its -// PT(Node) class, so the MultiTransition it -// inherits from can initialize itself properly. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA PointerNameClass { -public: - static string get_class_name() { - return "PT(Node)"; - } -}; - -#endif - - diff --git a/panda/src/graph/pt_NamedNode.N b/panda/src/graph/pt_NamedNode.N deleted file mode 100644 index 80c260bf74..0000000000 --- a/panda/src/graph/pt_NamedNode.N +++ /dev/null @@ -1,3 +0,0 @@ -ignorefile boundedObject.h - -forcetype PT_NamedNode diff --git a/panda/src/graph/pt_NamedNode.cxx b/panda/src/graph/pt_NamedNode.cxx deleted file mode 100644 index e188bc94ef..0000000000 --- a/panda/src/graph/pt_NamedNode.cxx +++ /dev/null @@ -1,24 +0,0 @@ -// Filename: pt_NamedNode.cxx -// Created by: drose (16May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "pt_NamedNode.h" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif diff --git a/panda/src/graph/pt_NamedNode.h b/panda/src/graph/pt_NamedNode.h deleted file mode 100644 index 85ea19fca2..0000000000 --- a/panda/src/graph/pt_NamedNode.h +++ /dev/null @@ -1,47 +0,0 @@ -// Filename: pt_NamedNode.h -// Created by: drose (16May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef PT_NAMEDNODE_H -#define PT_NAMEDNODE_H - -#include - -#include "namedNode.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : PT_NamedNode -// Description : A PT(NamedNode). This is defined here solely we can -// explicitly export the template class. It's not -// strictly necessary, but it doesn't hurt. -//////////////////////////////////////////////////////////////////// - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, PointerToBase) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, PointerTo) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, ConstPointerTo) - -typedef PointerTo PT_NamedNode; -typedef ConstPointerTo CPT_NamedNode; - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/graph/pt_Node.N b/panda/src/graph/pt_Node.N deleted file mode 100644 index 71e110d3de..0000000000 --- a/panda/src/graph/pt_Node.N +++ /dev/null @@ -1,3 +0,0 @@ -ignorefile boundedObject.h - -forcetype PT_Node diff --git a/panda/src/graph/pt_Node.cxx b/panda/src/graph/pt_Node.cxx deleted file mode 100644 index 45c0bbd168..0000000000 --- a/panda/src/graph/pt_Node.cxx +++ /dev/null @@ -1,25 +0,0 @@ -// Filename: pt_Node.cxx -// Created by: drose (16May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "node.h" -#include "pt_Node.h" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif diff --git a/panda/src/graph/pt_Node.h b/panda/src/graph/pt_Node.h deleted file mode 100644 index 2dd63f119c..0000000000 --- a/panda/src/graph/pt_Node.h +++ /dev/null @@ -1,50 +0,0 @@ -// Filename: pt_Node.h -// Created by: drose (16May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef PT_NODE_H -#define PT_NODE_H - -#include - -// We can't include node.h, because we need to include this in -// nodeRelation.h. - -#include - -class Node; - -//////////////////////////////////////////////////////////////////// -// Class : PT_Node -// Description : A PT(Node). This is defined here solely we can -// explicitly export the template class. It's not -// strictly necessary, but it doesn't hurt. -//////////////////////////////////////////////////////////////////// - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, PointerToBase) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, PointerTo) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, ConstPointerTo) - -typedef PointerTo PT_Node; -typedef ConstPointerTo CPT_Node; - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/graph/pt_NodeRelation.cxx b/panda/src/graph/pt_NodeRelation.cxx deleted file mode 100644 index b07221436e..0000000000 --- a/panda/src/graph/pt_NodeRelation.cxx +++ /dev/null @@ -1,25 +0,0 @@ -// Filename: pt_NodeRelation.cxx -// Created by: drose (07May01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "nodeRelation.h" -#include "pt_NodeRelation.h" - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif diff --git a/panda/src/graph/pt_NodeRelation.h b/panda/src/graph/pt_NodeRelation.h deleted file mode 100644 index 0c8ab78d2f..0000000000 --- a/panda/src/graph/pt_NodeRelation.h +++ /dev/null @@ -1,46 +0,0 @@ -// Filename: pt_NodeRelation.h -// Created by: drose (07May01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef PT_NODERELATION_H -#define PT_NODERELATION_H - -#include - -#include "nodeRelation.h" -#include - -//////////////////////////////////////////////////////////////////// -// Class : PT_NodeRelation -// Description : PT(NodeRelation). This is defined here solely we can -// explicitly export the template class. It's not -// strictly necessary, but it doesn't hurt. -//////////////////////////////////////////////////////////////////// - -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, PointerToBase) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, PointerTo) -EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, ConstPointerTo) - -typedef PointerTo PT_NodeRelation; -typedef ConstPointerTo CPT_NodeRelation; - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/graph/setTransitionHelpers.T b/panda/src/graph/setTransitionHelpers.T deleted file mode 100644 index e1111bbfc2..0000000000 --- a/panda/src/graph/setTransitionHelpers.T +++ /dev/null @@ -1,895 +0,0 @@ -// Filename: setTransitionHelpers.T -// Created by: drose (25Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "nodeTransitionCacheEntry.h" -#include "config_graph.h" - -//////////////////////////////////////////////////////////////////// -// Function: tmap_get_interest -// Description: Returns the NodeTransition elements of interest to -// us. These are the elements of the first sequence--a -// NodeTransition map--whose keys appear in the second -// sequence, a sorted list of NodeTransition -// TypeHandles. -//////////////////////////////////////////////////////////////////// -template -OutputIterator -tmap_get_interest(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result) { - while (first1 != last1 && first2 != last2) { - if ((*first1).first < *first2) { - ++first1; - ++result; - } else if (*first2 < (*first1).first) { - ++first2; - ++result; - } else { - *result = *first1; - ++first1; - ++first2; - ++result; - } - } - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: tmap_override_union -// Description: Accepts two NodeTransition maps, and -// builds a new map which is the union of the first two. -// If an element appears in both maps, the entry from -// the second is preferred. -//////////////////////////////////////////////////////////////////// -template -OutputIterator -tmap_override_union(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result) { - while (first1 != last1 && first2 != last2) { - if ((*first1).first < (*first2).first) { - *result = *first1; - ++first1; - ++result; - } else if ((*first2).first < (*first1).first) { - *result = *first2; - ++first2; - ++result; - } else { - *result = *first2; - ++first1; - ++first2; - ++result; - } - } - - while (first1 != last1) { - *result = *first1; - ++first1; - ++result; - } - - while (first2 != last2) { - *result = *first2; - ++first2; - ++result; - } - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: tmap_arc_union -// Description: As above, but updates the transitions on the way to -// indicate they are being attached to (or removed from) -// the indicated arc. -//////////////////////////////////////////////////////////////////// -template -OutputIterator -tmap_arc_union(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - NodeRelation *to_arc, OutputIterator result) { - while (first1 != last1 && first2 != last2) { - if ((*first1).first < (*first2).first) { - *result = *first1; - ++first1; - ++result; - } else if ((*first2).first < (*first1).first) { - (*first2).second->added_to_arc(to_arc); - *result = *first2; - ++first2; - ++result; - } else { - (*first1).second->removed_from_arc(to_arc); - (*first2).second->added_to_arc(to_arc); - *result = *first2; - ++first1; - ++first2; - ++result; - } - } - - while (first1 != last1) { - *result = *first1; - ++first1; - ++result; - } - - while (first2 != last2) { - (*first2).second->added_to_arc(to_arc); - *result = *first2; - ++first2; - ++result; - } - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: tmap_arc_compose -// Description: -//////////////////////////////////////////////////////////////////// -template -OutputIterator -tmap_arc_compose(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - NodeRelation *to_arc, OutputIterator result) { - while (first1 != last1 && first2 != last2) { - if ((*first1).first < (*first2).first) { - *result = *first1; - ++first1; - ++result; - } else if ((*first2).first < (*first1).first) { - (*first2).second->added_to_arc(to_arc); - *result = *first2; - ++first2; - ++result; - } else { - (*first1).second->removed_from_arc(to_arc); - - PT(NodeTransition) c = (*first1).second->compose((*first2).second); - if (c != (NodeTransition *)NULL) { - c->added_to_arc(to_arc); - *result = pair((*first1).first, c); - ++result; - } - ++first1; - ++first2; - } - } - - while (first1 != last1) { - *result = *first1; - ++first1; - ++result; - } - - while (first2 != last2) { - (*first2).second->added_to_arc(to_arc); - *result = *first2; - ++first2; - ++result; - } - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: tmap_arc_compose -// Description: -//////////////////////////////////////////////////////////////////// -template -OutputIterator -tmap_arc_compose(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result) { - while (first1 != last1 && first2 != last2) { - if ((*first1).first < (*first2).first) { - *result = *first1; - ++first1; - ++result; - } else if ((*first2).first < (*first1).first) { - *result = *first2; - ++first2; - ++result; - } else { - NodeTransition *c = (*first1).second->compose((*first2).second); - if (c != (NodeTransition *)NULL) { - *result = pair - ((*first1).first, c); - ++result; - } - ++first1; - ++first2; - } - } - - while (first1 != last1) { - *result = *first1; - ++first1; - ++result; - } - - while (first2 != last2) { - *result = *first2; - ++first2; - ++result; - } - return result; -} - - -//////////////////////////////////////////////////////////////////// -// Function: tmap_compose -// Description: Accepts two NodeTransition maps, and builds a new -// list (a NodeTransition map) which represents the -// memberwise composition of the two input maps. -//////////////////////////////////////////////////////////////////// -template -OutputIterator -tmap_compose(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result) { - while (first1 != last1 && first2 != last2) { - if ((*first1).first < (*first2).first) { - *result = *first1; - ++first1; - ++result; - } else if ((*first2).first < (*first1).first) { - *result = *first2; - ++first2; - ++result; - } else { - *result = pair - ((*first1).first, - NodeTransitionCacheEntry::compose((*first1).second, (*first2).second)); - ++first1; - ++first2; - ++result; - } - } - - while (first1 != last1) { - *result = *first1; - ++first1; - ++result; - } - - while (first2 != last2) { - *result = *first2; - ++first2; - ++result; - } - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: tmap_invert_compose -// Description: Accepts two NodeTransition maps, and builds a new -// list (a NodeTransition map) which represents the -// memberwise result of invert_compose of the two input -// maps. -//////////////////////////////////////////////////////////////////// -template -OutputIterator -tmap_invert_compose(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result) { - while (first1 != last1 && first2 != last2) { - if ((*first1).first < (*first2).first) { - *result = pair - ((*first1).first, NodeTransitionCacheEntry::invert((*first1).second)); - ++first1; - ++result; - } else if ((*first2).first < (*first1).first) { - *result = *first2; - ++first2; - ++result; - } else { - NodeTransitionCacheEntry ic = - NodeTransitionCacheEntry::invert_compose((*first1).second, - (*first2).second); - if (!ic.is_identity()) { - // Only bother to store the result if it's not identity. - *result = pair((*first1).first, ic); - ++result; - } - ++first1; - ++first2; - } - } - - while (first1 != last1) { - *result = pair - ((*first1).first, NodeTransitionCacheEntry::invert((*first1).second)); - ++first1; - ++result; - } - - while (first2 != last2) { - *result = *first2; - ++first2; - ++result; - } - return result; -} - -// This macro is used in the various cached_compose functions to -// possibly output debug statements about which pieces we're -// composing. - -#ifndef NDEBUG -#define OUTPUT_CC_ELEM(desc, type) \ -{ \ - if (wrt_cat.is_spam()) { \ - wrt_cat.spam() << "in " << desc << ": " << (type) << "\n"; \ - } \ -} -#else -#define OUTPUT_CC_ELEM(desc, type) -#endif - -//////////////////////////////////////////////////////////////////// -// Function: tmap_cached_compose_not_1 -// Description: One of several support functions for -// tmap_cached_compose(), below, this handles the case -// of tmap_cached_compose() for a NodeTransition that -// is already known not to be present in list 1, but may -// be in one or both of lists 2 and 3. -//////////////////////////////////////////////////////////////////// -template -void -tmap_cached_compose_not_1(InputIterator2 &first2, InputIterator3 &first3, - UpdateSeq now, OutputIterator &result) { - if ((*first2).first < (*first3).first) { - // Here's an element in list 2 that is not in lists 1 or 3. - OUTPUT_CC_ELEM("2", (*first2).first); - - *result = pair - ((*first2).first, - NodeTransitionCacheEntry::cached_compose - (NodeTransitionCacheEntry(), - (*first2).second, - NodeTransitionCacheEntry(), - now)); - ++first2; - ++result; - - } else if ((*first3).first < (*first2).first) { - // Here's an element in list 3 that is not lists 2 or 1. - OUTPUT_CC_ELEM("3", (*first3).first); - - *result = pair - ((*first3).first, - NodeTransitionCacheEntry::cached_compose - (NodeTransitionCacheEntry(), - NodeTransitionCacheEntry(), - (*first3).second, - now)); - ++first3; - ++result; - - } else { // (*first2).first == (*first3).first - // Here's an element in lists 2 and 3 that is not in list 1. - OUTPUT_CC_ELEM("2, 3", (*first2).first); - - *result = pair - ((*first2).first, - NodeTransitionCacheEntry::cached_compose - (NodeTransitionCacheEntry(), - (*first2).second, - (*first3).second, - now)); - ++first2; - ++first3; - ++result; - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: tmap_cached_compose_not_2 -// Description: One of several support functions for -// tmap_cached_compose(), below, this handles the case -// of tmap_cached_compose() for an NodeTransition that -// is already known not to be present in list 2, but may -// be in one or both of lists 1 and 3. -//////////////////////////////////////////////////////////////////// -template -void -tmap_cached_compose_not_2(InputIterator1 &first1, InputIterator3 &first3, - UpdateSeq now, OutputIterator &result) { - if ((*first1).first < (*first3).first) { - // Here's an element in list 1 that is not in lists 2 or 3. - OUTPUT_CC_ELEM("1", (*first1).first); - - *result = pair - ((*first1).first, - NodeTransitionCacheEntry::cached_compose - ((*first1).second, - NodeTransitionCacheEntry(), - NodeTransitionCacheEntry(), - now)); - ++first1; - ++result; - - } else if ((*first3).first < (*first1).first) { - // Here's an element in list 3 that is not lists 1 or 2. - OUTPUT_CC_ELEM("3", (*first3).first); - - *result = pair - ((*first3).first, - NodeTransitionCacheEntry::cached_compose - (NodeTransitionCacheEntry(), - NodeTransitionCacheEntry(), - (*first3).second, - now)); - ++first3; - ++result; - - } else { // (*first1).first == (*first3).first - // Here's an element in lists 1 and 3 that is not in list 2. - OUTPUT_CC_ELEM("1, 3", (*first1).first); - - *result = pair - ((*first1).first, - NodeTransitionCacheEntry::cached_compose - ((*first1).second, - NodeTransitionCacheEntry(), - (*first3).second, - now)); - ++first1; - ++first3; - ++result; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: tmap_cached_compose_not_3 -// Description: One of several support functions for -// tmap_cached_compose(), below, this handles the case -// of tmap_cached_compose() for an NodeTransition that -// is already known not to be present in list 3, but may -// be in one or both of lists 1 and 2. -//////////////////////////////////////////////////////////////////// -template -void -tmap_cached_compose_not_3(InputIterator1 &first1, InputIterator2 &first2, - UpdateSeq now, OutputIterator &result) { - if ((*first1).first < (*first2).first) { - // Here's an element in list 1 that is not in lists 2 or 3. - OUTPUT_CC_ELEM("1", (*first1).first); - - *result = pair - ((*first1).first, - NodeTransitionCacheEntry::cached_compose - ((*first1).second, - NodeTransitionCacheEntry(), - NodeTransitionCacheEntry(), - now)); - ++first1; - ++result; - - } else if ((*first2).first < (*first1).first) { - // Here's an element in list 2 that is not lists 1 or 3. - OUTPUT_CC_ELEM("2", (*first2).first); - - *result = pair - ((*first2).first, - NodeTransitionCacheEntry::cached_compose - (NodeTransitionCacheEntry(), - (*first2).second, - NodeTransitionCacheEntry(), - now)); - ++first2; - ++result; - - } else { // (*first1).first == (*first2).first - // Here's an element in lists 1 and 2 that is not in list 3. - OUTPUT_CC_ELEM("1, 2", (*first1).first); - - *result = pair - ((*first1).first, - NodeTransitionCacheEntry::cached_compose - ((*first1).second, - (*first2).second, - NodeTransitionCacheEntry(), - now)); - ++first1; - ++first2; - ++result; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: tmap_cached_compose_12 -// Description: One of several support functions for -// tmap_cached_compose(), below, this handles the case -// of tmap_cached_compose() for an NodeTransition that -// is already known to be in both lists 1 and 2, and may -// or may not also be in list 3. -//////////////////////////////////////////////////////////////////// -template -void -tmap_cached_compose_12(InputIterator1 &first1, InputIterator2 &first2, - InputIterator3 &first3, - UpdateSeq now, OutputIterator &result) { - if ((*first1).first < (*first3).first) { - // Here's an element in lists 1 and 2 that is not in list 3. - OUTPUT_CC_ELEM("1, 2", (*first1).first); - - *result = pair - ((*first1).first, - NodeTransitionCacheEntry::cached_compose - ((*first1).second, - (*first2).second, - NodeTransitionCacheEntry(), - now)); - ++first1; - ++first2; - ++result; - - } else if ((*first3).first < (*first1).first) { - // Here's an element in list 3 that is not lists 1 or 2. - OUTPUT_CC_ELEM("3", (*first3).first); - - *result = pair - ((*first3).first, - NodeTransitionCacheEntry::cached_compose - (NodeTransitionCacheEntry(), - NodeTransitionCacheEntry(), - (*first3).second, - now)); - ++first3; - ++result; - - } else { // (*first1).first == (*first3).first - // Here's an element in lists 1, 2, and 3. - OUTPUT_CC_ELEM("1, 2, 3", (*first1).first); - - *result = pair - ((*first1).first, - NodeTransitionCacheEntry::cached_compose - ((*first1).second, - (*first2).second, - (*first3).second, - now)); - ++first1; - ++first2; - ++first3; - ++result; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: tmap_cached_compose -// Description: Calls dynamic_cached_compose() on each matching -// element of [first1 .. last1), [cached_first -// .. cached_last), and [value_first .. value_last). -// -// This function is big and complicated because it has -// to do a parallel merge on three separate lists. Any -// NodeTransition type may appear in any or all of the -// lists; if a particular type appears in any list but -// is absent from the others, an implicit identity -// transition should be inferred where it is absent. -//////////////////////////////////////////////////////////////////// -template -OutputIterator -tmap_cached_compose(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - InputIterator3 first3, InputIterator3 last3, - UpdateSeq now, OutputIterator result) { - while (first1 != last1 && first2 != last2 && first3 != last3) { - if ((*first1).first < (*first2).first) { - tmap_cached_compose_not_2(first1, first3, now, result); - - } else if ((*first2).first < (*first1).first) { - tmap_cached_compose_not_1(first2, first3, now, result); - - } else { // (*first1).first == (*first2).first - tmap_cached_compose_12(first1, first2, first3, now, result); - } - } - - // Now pick up everything else. - if (first1 == last1) { - while (first2 != last2 && first3 != last3) { - tmap_cached_compose_not_1(first2, first3, now, result); - } - - } else if (first2 == last2) { - while (first1 != last1 && first3 != last3) { - tmap_cached_compose_not_2(first1, first3, now, result); - } - - } else if (first3 == last3) { - while (first1 != last1 && first2 != last2) { - tmap_cached_compose_not_3(first1, first2, now, result); - } - } - - while (first1 != last1) { - // Here's an element in list 1 that is not in lists 2 or 3. - OUTPUT_CC_ELEM("1", (*first1).first); - - *result = pair - ((*first1).first, - NodeTransitionCacheEntry::cached_compose - ((*first1).second, - NodeTransitionCacheEntry(), - NodeTransitionCacheEntry(), - now)); - ++first1; - ++result; - } - - while (first2 != last2) { - // Here's an element in list 2 that is not in lists 1 or 3. - OUTPUT_CC_ELEM("2", (*first2).first); - - *result = pair - ((*first2).first, - NodeTransitionCacheEntry::cached_compose - (NodeTransitionCacheEntry(), - (*first2).second, - NodeTransitionCacheEntry(), - now)); - ++first2; - ++result; - } - - while (first3 != last3) { - // Here's an element in list 3 that is not lists 1 or 2. - OUTPUT_CC_ELEM("3", (*first3).first); - - *result = pair - ((*first3).first, - NodeTransitionCacheEntry::cached_compose - (NodeTransitionCacheEntry(), - NodeTransitionCacheEntry(), - (*first3).second, - now)); - ++first3; - ++result; - } - - return result; -} - - - -//////////////////////////////////////////////////////////////////// -// Function: tmap_invert -// Description: Accepts a NodeTransition map, and builds a new list -// which represents the memberwise inversion of the -// input. Guarantees that the new list will have -// exactly the same length as the input list. -//////////////////////////////////////////////////////////////////// -template -OutputIterator -tmap_invert(InputIterator first, InputIterator last, - OutputIterator result) { - while (first != last) { - *result = pair - ((*first).first, NodeTransitionCacheEntry::invert((*first).second)); - ++first; - ++result; - } - return result; -} - - -//////////////////////////////////////////////////////////////////// -// Function: tmap_equiv_trans -// Description: Accepts a pair of NodeTransition maps, and returns -// true if they are equivalent, false otherwise. Two -// NodeTransition maps are defined to be equivalent if -// all nonidentity members present in one set are -// present and equivalent in the other set, -//////////////////////////////////////////////////////////////////// -template -bool -tmap_equiv_trans(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2) { - while (first1 != last1 && first2 != last2) { - if ((*first1).first < (*first2).first) { - if (!(*first1).second.is_identity()) { - return false; - } - ++first1; - } else if ((*first2).first < (*first1).first) { - if (!(*first2).second.is_identity()) { - return false; - } - ++first2; - } else { - if (!(*first1).second.compare_to((*first2).second) == 0) { - return false; - } - ++first1; - ++first2; - } - } - - while (first1 != last1) { - if (!(*first1).second.is_identity()) { - return false; - } - ++first1; - } - - while (first2 != last2) { - if (!(*first2).second.is_identity()) { - return false; - } - ++first2; - } - return true; -} - - -//////////////////////////////////////////////////////////////////// -// Function: tmap_compare_cache -// Description: Accepts a pair of NodeTransition maps, and returns -// -1 if the first one sorts before the second one, -// 1 if it sorts after, or 0 if they are equivalent. -//////////////////////////////////////////////////////////////////// -template -int -tmap_compare_cache(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2) { - while (first1 != last1 && first2 != last2) { - if ((*first1).first < (*first2).first) { - if (!(*first1).second.is_identity()) { - return 1; - } - ++first1; - } else if ((*first2).first < (*first1).first) { - if (!(*first2).second.is_identity()) { - return -1; - } - ++first2; - } else { - int result; - result = (*first1).second.compare_to((*first2).second); - if (result != 0) { - return result; - } - ++first1; - ++first2; - } - } - - while (first1 != last1) { - if (!(*first1).second.is_identity()) { - // list1 is longer. - return -1; - } - ++first1; - } - - while (first2 != last2) { - if (!(*first2).second.is_identity()) { - // list2 is longer. - return 1; - } - ++first2; - } - - return 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: tmap_compare_trans -// Description: Accepts a pair of NodeTransition maps, and returns -// -1 if the first one sorts before the second one, -// 1 if it sorts after, or 0 if they are equivalent. -//////////////////////////////////////////////////////////////////// -template -int -tmap_compare_trans(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2) { - while (first1 != last1 && first2 != last2) { - if ((*first1).first < (*first2).first) { - if ((*first1).second != (NodeTransition *)NULL) { - return 1; - } - ++first1; - } else if ((*first2).first < (*first1).first) { - if ((*first2).second != (NodeTransition *)NULL) { - return -1; - } - ++first2; - } else { - if ((*first1).second != (*first2).second) { - if ((*first1).second == (NodeTransition *)NULL) { - return -1; - } else if ((*first2).second == (NodeTransition *)NULL) { - return 1; - } else { - int result; - result = (*first1).second->compare_to(*(*first2).second); - if (result != 0) { - return result; - } - } - } - ++first1; - ++first2; - } - } - - while (first1 != last1) { - if ((*first1).second != (NodeTransition *)NULL) { - // list1 is longer. - return -1; - } - ++first1; - } - - while (first2 != last2) { - if ((*first2).second != (NodeTransition *)NULL) { - // list2 is longer. - return 1; - } - ++first2; - } - - return 0; -} - - - -//////////////////////////////////////////////////////////////////// -// Function: tmap_is_identity -// Description: Accepts a NodeTransition map, and returns true if all -// elements in the map correspond to the identity -// transition, false otherwise. -//////////////////////////////////////////////////////////////////// -template -bool -tmap_is_identity(InputIterator first, InputIterator last) { - while (first != last) { - if (!(*first).second.is_identity()) { - return false; - } - ++first; - } - return true; -} - - -//////////////////////////////////////////////////////////////////// -// Function: tmap_output -// Description: Accepts a NodeTransition map and -// writes each element to the given output stream with a -// single space separating them. -//////////////////////////////////////////////////////////////////// -template -ostream & -tmap_output(InputIterator first, InputIterator last, ostream &out) { - if (first != last) { - out << *((*first).second); - ++first; - while (first != last) { - out << " " << *((*first).second); - ++first; - } - } - return out; -} diff --git a/panda/src/graph/setTransitionHelpers.h b/panda/src/graph/setTransitionHelpers.h deleted file mode 100644 index 6b7e69bc41..0000000000 --- a/panda/src/graph/setTransitionHelpers.h +++ /dev/null @@ -1,134 +0,0 @@ -// Filename: setTransitionHelpers.h -// Created by: drose (25Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef SETTRANSITIONHELPERS_H -#define SETTRANSITIONHELPERS_H - -#include - -#include - - -//////////////////////////////////////////////////////////////////// -// -// tmap_* functions -// -// The SetTransition classes are implemented with the help of a -// handful of template functions that operate on NodeTransition maps. -// -// Each of these follows the standard STL calling conventions for -// operating on one or two sequences, and/or storing the results into -// an output sequence. -// -//////////////////////////////////////////////////////////////////// - -template -OutputIterator -tmap_get_interest(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result); - -template -OutputIterator -tmap_union(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result); - -template -OutputIterator -tmap_arc_union(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - NodeRelation *to_arc, OutputIterator result); - -template -OutputIterator -tmap_arc_compose(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - NodeRelation *to_arc, OutputIterator result); - -template -OutputIterator -tmap_compose(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result); - -template -OutputIterator -tmap_invert_compose(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result); - -template -OutputIterator -tmap_cached_compose(InputIterator1 first1, InputIterator1 last1, - InputIterator2 cached_first, InputIterator2 cached_last, - InputIterator3 value_first, InputIterator3 value_last, - UpdateSeq now, OutputIterator result); - -template -OutputIterator -tmap_apply(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, - OutputIterator result); - -template -OutputIterator -tmap_invert(InputIterator first, InputIterator last, - OutputIterator result); - -template -bool -tmap_equiv_trans(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2); - -template -bool -tmap_equiv_attr(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2); - -template -int -tmap_compare_cache(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2); - -template -int -tmap_compare_trans(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2); - -template -int -tmap_compare_attr(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2); - -template -bool -tmap_is_identity(InputIterator first, InputIterator last); - -template -bool -tmap_is_initial(InputIterator first, InputIterator last); - -template -ostream & -tmap_output(InputIterator first, InputIterator last, ostream &out); - -#include "setTransitionHelpers.T" - -#endif diff --git a/panda/src/graph/test_graph.cxx b/panda/src/graph/test_graph.cxx deleted file mode 100644 index 61a79cf425..0000000000 --- a/panda/src/graph/test_graph.cxx +++ /dev/null @@ -1,579 +0,0 @@ -// Filename: test_graph.cxx -// Created by: drose (02Feb00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "nodeRelation.h" -#include "onOffTransition.h" -#include "onTransition.h" -#include "namedNode.h" -#include "pt_NamedNode.h" -#include "wrt.h" -#include "nodeTransitionWrapper.h" -#include "allTransitionsWrapper.h" -#include "nullTransitionWrapper.h" -#include "traverserVisitor.h" -#include "dftraverser.h" -#include "multiTransition.h" -#include "nullLevelState.h" - -#include - -typedef int TestType; - -//#define USE_ONOFF - -#ifdef USE_ONOFF -typedef OnOffTransition BaseTransition; -#else -typedef OnTransition BaseTransition; -#endif - -class TestTransition : public BaseTransition { -public: - TestTransition(); - TestTransition(TestType value); -#ifdef USE_ONOFF - static TestTransition off(); -#endif - - virtual NodeTransition *make_copy() const; - - TestType get_value() const; - -protected: - virtual void set_value_from(const BaseTransition *other); - virtual int compare_values(const BaseTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - - TestType _value; - -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() { - BaseTransition::init_type(); - register_type(_type_handle, "TestTransition", - BaseTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -class Test2Transition : public TestTransition { -public: - Test2Transition(); - Test2Transition(TestType value); -#ifdef USE_ONOFF - static Test2Transition off(); -#endif - - virtual NodeTransition *make_copy() const; - -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() { - TestTransition::init_type(); - register_type(_type_handle, "Test2Transition", - TestTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -class TestMName { -public: - static string get_class_name() { - return "TestType"; - } -}; - -class TestMTransition : public MultiTransition { -protected: - - virtual NodeTransition *make_copy() const { - return new TestMTransition(*this); - } - virtual NodeTransition *make_identity() const { - return new TestMTransition; - } - virtual void output_property(ostream &out, const TestType &prop) const { - out << prop; - } - virtual void write_property(ostream &out, const TestType &prop, - int indent_level) const { - indent(out, indent_level) << prop << "\n"; - } - -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() { - MultiTransition::init_type(); - register_type(_type_handle, "TestMTransition", - MultiTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - - -template -class PrintNodes : public TraverserVisitor { -public: - PrintNodes() { - _indent_level = 0; - } - bool reached_node(Node *node, TransitionWrapper &state, NullLevelState &) { - indent(nout, _indent_level) - << "Reached " << *node << ", state is " << state << "\n"; - return true; - } - bool forward_arc(NodeRelation *arc, TransitionWrapper &trans, - TransitionWrapper &pre, TransitionWrapper &post, - NullLevelState &) { - // indent(nout, _indent_level + 1) - // << "Passing " << *arc << ", trans is " << trans << "\n"; - _indent_level += 2; - return true; - } - void backward_arc(NodeRelation *arc, TransitionWrapper &trans, - TransitionWrapper &pre, TransitionWrapper &post, - const NullLevelState &) { - _indent_level -= 2; - } - int _indent_level; -}; - - -TestTransition:: -TestTransition() { -} - -TestTransition:: -TestTransition(TestType value) { - _value = value; -#ifdef USE_ONOFF - set_on(); -#endif -} - -#ifdef USE_ONOFF -TestTransition TestTransition:: -off() { - TestTransition tt; - tt._direction = D_off; - return tt; -} -#endif - -NodeTransition *TestTransition:: -make_copy() const { - return new TestTransition(*this); -} - -TestType TestTransition:: -get_value() const { - return _value; -} - -void TestTransition:: -set_value_from(const BaseTransition *other) { - const TestTransition *ot; - DCAST_INTO_V(ot, other); - _value = ot->_value; -} - -int TestTransition:: -compare_values(const BaseTransition *other) const { - const TestTransition *ot; - DCAST_INTO_R(ot, other, false); - return _value - ot->_value; -} - -void TestTransition:: -output_value(ostream &out) const { - out << _value; -} - -void TestTransition:: -write_value(ostream &out, int indent_level) const { - indent(out, indent_level) << _value << "\n"; -} - -Test2Transition:: -Test2Transition() { -} - -Test2Transition:: -Test2Transition(TestType value) : TestTransition(value) { -} - -#ifdef USE_ONOFF -Test2Transition Test2Transition:: -off() { - Test2Transition tt; - tt._direction = D_off; - return tt; -} -#endif USE_ONOFF - -NodeTransition *Test2Transition:: -make_copy() const { - return new Test2Transition(*this); -} - -TypeHandle TestTransition::_type_handle; -TypeHandle Test2Transition::_type_handle; -TypeHandle TestMTransition::_type_handle; - - -int main() { - TestTransition::init_type(); - Test2Transition::init_type(); - TestMTransition::init_type(); - - PT_NamedNode r = new NamedNode("r"); - - PT_NamedNode a = new NamedNode("a"); - PT_NamedNode b = new NamedNode("b"); - - PT_NamedNode aa = new NamedNode("aa"); - PT_NamedNode ab = new NamedNode("ab"); - PT_NamedNode ba = new NamedNode("ba"); - - NodeRelation *r_a = - new NodeRelation(r, a, 0, NodeRelation::get_class_type()); - NodeRelation *r_b = - new NodeRelation(r, b, 0, NodeRelation::get_class_type()); - - NodeRelation *a_aa = - new NodeRelation(a, aa, 0, NodeRelation::get_class_type()); - NodeRelation *a_ab = - new NodeRelation(a, ab, 0, NodeRelation::get_class_type()); - NodeRelation *b_ba = - new NodeRelation(b, ba, 0, NodeRelation::get_class_type()); - - r_a->set_transition(new TestTransition(1)); - // a_aa->set_transition(new TestTransition(2)); - a_aa->set_transition(new Test2Transition(3)); - -#ifdef USE_ONOFF - a_aa->set_transition(new Test2Transition()); - a_ab->set_transition(new Test2Transition(Test2Transition::off())); -#endif - - /* - TestMTransition *tm = new TestMTransition; - tm->set_on(101); - tm->set_off(102); - tm->set_identity(103); - r_a->set_transition(tm); - - tm = new TestMTransition; - tm->set_on(102); - a_aa->set_transition(tm); - - tm = new TestMTransition; - tm->set_complete(true); - a_ab->set_transition(tm); - */ - - nout << "\nr to a has "; - r_a->output_transitions(nout); - nout << "\nr to b has "; - r_b->output_transitions(nout); - nout << "\na to aa has "; - a_aa->output_transitions(nout); - nout << "\na to ab has "; - a_ab->output_transitions(nout); - nout << "\nb to ba has "; - b_ba->output_transitions(nout); - nout << "\n"; - -#if 0 - { - nout << "\n"; - PrintNodes pn; - df_traverse(r, pn, - NullTransitionWrapper(), - NullLevelState(), - NodeRelation::get_class_type()); - nout << "\n"; - - NullTransitionWrapper result; - - wrt(r, aa, result, NodeRelation::get_class_type()); - nout << "wrt of r to aa is " << result << "\n"; - - wrt(aa, r, result, NodeRelation::get_class_type()); - nout << "wrt of aa to r is " << result << "\n"; - - wrt(r, ab, result, NodeRelation::get_class_type()); - nout << "wrt of r to ab is " << result << "\n"; - - wrt(ab, r, result, NodeRelation::get_class_type()); - nout << "wrt of ab to r is " << result << "\n"; - - wrt(ab, aa, result, NodeRelation::get_class_type()); - nout << "wrt of ab to aa is " << result << "\n"; - - wrt(aa, ab, result, NodeRelation::get_class_type()); - nout << "wrt of aa to ab is " << result << "\n"; - - wrt(r, ba, result, NodeRelation::get_class_type()); - nout << "wrt of r to ba is " << result << "\n"; - - wrt(ba, r, result, NodeRelation::get_class_type()); - nout << "wrt of ba to r is " << result << "\n"; - - wrt(aa, ba, result, NodeRelation::get_class_type()); - nout << "wrt of aa to ba is " << result << "\n"; - - wrt(ba, aa, result, NodeRelation::get_class_type()); - nout << "wrt of ba to aa is " << result << "\n"; - - wrt(ab, ba, result, NodeRelation::get_class_type()); - nout << "wrt of ab to ba is " << result << "\n"; - - wrt(ba, ab, result, NodeRelation::get_class_type()); - nout << "wrt of ba to ab is " << result << "\n"; - } - - { - nout << "\n"; - PrintNodes pn; - df_traverse(r, pn, - NodeTransitionWrapper(TestTransition::get_class_type()), - NullLevelState(), - NodeRelation::get_class_type()); - nout << "\n"; - - NodeTransitionWrapper result(TestTransition::get_class_type()); - - wrt(r, aa, result, NodeRelation::get_class_type()); - nout << "wrt of r to aa is " << result << "\n"; - - wrt(aa, r, result, NodeRelation::get_class_type()); - nout << "wrt of aa to r is " << result << "\n"; - - wrt(r, ab, result, NodeRelation::get_class_type()); - nout << "wrt of r to ab is " << result << "\n"; - - wrt(ab, r, result, NodeRelation::get_class_type()); - nout << "wrt of ab to r is " << result << "\n"; - - wrt(ab, aa, result, NodeRelation::get_class_type()); - nout << "wrt of ab to aa is " << result << "\n"; - - wrt(aa, ab, result, NodeRelation::get_class_type()); - nout << "wrt of aa to ab is " << result << "\n"; - - wrt(r, ba, result, NodeRelation::get_class_type()); - nout << "wrt of r to ba is " << result << "\n"; - - wrt(ba, r, result, NodeRelation::get_class_type()); - nout << "wrt of ba to r is " << result << "\n"; - - wrt(aa, ba, result, NodeRelation::get_class_type()); - nout << "wrt of aa to ba is " << result << "\n"; - - wrt(ba, aa, result, NodeRelation::get_class_type()); - nout << "wrt of ba to aa is " << result << "\n"; - - wrt(ab, ba, result, NodeRelation::get_class_type()); - nout << "wrt of ab to ba is " << result << "\n"; - - wrt(ba, ab, result, NodeRelation::get_class_type()); - nout << "wrt of ba to ab is " << result << "\n"; - } - - { - nout << "\n"; - PrintNodes pn; - df_traverse(r, pn, - NodeTransitionWrapper(Test2Transition::get_class_type()), - NullLevelState(), - NodeRelation::get_class_type()); - nout << "\n"; - - NodeTransitionWrapper result(Test2Transition::get_class_type()); - - wrt(r, aa, result, NodeRelation::get_class_type()); - nout << "wrt of r to aa is " << result << "\n"; - - wrt(aa, r, result, NodeRelation::get_class_type()); - nout << "wrt of aa to r is " << result << "\n"; - - wrt(r, ab, result, NodeRelation::get_class_type()); - nout << "wrt of r to ab is " << result << "\n"; - - wrt(ab, r, result, NodeRelation::get_class_type()); - nout << "wrt of ab to r is " << result << "\n"; - - wrt(ab, aa, result, NodeRelation::get_class_type()); - nout << "wrt of ab to aa is " << result << "\n"; - - wrt(aa, ab, result, NodeRelation::get_class_type()); - nout << "wrt of aa to ab is " << result << "\n"; - - wrt(r, ba, result, NodeRelation::get_class_type()); - nout << "wrt of r to ba is " << result << "\n"; - - wrt(ba, r, result, NodeRelation::get_class_type()); - nout << "wrt of ba to r is " << result << "\n"; - - wrt(aa, ba, result, NodeRelation::get_class_type()); - nout << "wrt of aa to ba is " << result << "\n"; - - wrt(ba, aa, result, NodeRelation::get_class_type()); - nout << "wrt of ba to aa is " << result << "\n"; - - wrt(ab, ba, result, NodeRelation::get_class_type()); - nout << "wrt of ab to ba is " << result << "\n"; - - wrt(ba, ab, result, NodeRelation::get_class_type()); - nout << "wrt of ba to ab is " << result << "\n"; - } - - { - nout << "\n"; - PrintNodes pn; - df_traverse(r, pn, - NodeTransitionWrapper(TestMTransition::get_class_type()), - NullLevelState(), - NodeRelation::get_class_type()); - nout << "\n"; - - NodeTransitionWrapper result(TestMTransition::get_class_type()); - - wrt(r, aa, result, NodeRelation::get_class_type()); - nout << "wrt of r to aa is " << result << "\n"; - - wrt(aa, r, result, NodeRelation::get_class_type()); - nout << "wrt of aa to r is " << result << "\n"; - - wrt(r, ab, result, NodeRelation::get_class_type()); - nout << "wrt of r to ab is " << result << "\n"; - - wrt(ab, r, result, NodeRelation::get_class_type()); - nout << "wrt of ab to r is " << result << "\n"; - - wrt(ab, aa, result, NodeRelation::get_class_type()); - nout << "wrt of ab to aa is " << result << "\n"; - - wrt(aa, ab, result, NodeRelation::get_class_type()); - nout << "wrt of aa to ab is " << result << "\n"; - - wrt(r, ba, result, NodeRelation::get_class_type()); - nout << "wrt of r to ba is " << result << "\n"; - - wrt(ba, r, result, NodeRelation::get_class_type()); - nout << "wrt of ba to r is " << result << "\n"; - - wrt(aa, ba, result, NodeRelation::get_class_type()); - nout << "wrt of aa to ba is " << result << "\n"; - - wrt(ba, aa, result, NodeRelation::get_class_type()); - nout << "wrt of ba to aa is " << result << "\n"; - - wrt(ab, ba, result, NodeRelation::get_class_type()); - nout << "wrt of ab to ba is " << result << "\n"; - - wrt(ba, ab, result, NodeRelation::get_class_type()); - nout << "wrt of ba to ab is " << result << "\n"; - } - - { - nout << "\n"; - PrintNodes pn; - df_traverse(r, pn, - AllTransitionsWrapper(), - NullLevelState(), - NodeRelation::get_class_type()); - nout << "\n"; - - AllTransitionsWrapper result; - - wrt(r, aa, result, NodeRelation::get_class_type()); - nout << "wrt of r to aa is " << result << "\n"; - - wrt(aa, r, result, NodeRelation::get_class_type()); - nout << "wrt of aa to r is " << result << "\n"; - - wrt(r, ab, result, NodeRelation::get_class_type()); - nout << "wrt of r to ab is " << result << "\n"; - - wrt(ab, r, result, NodeRelation::get_class_type()); - nout << "wrt of ab to r is " << result << "\n"; - - wrt(ab, aa, result, NodeRelation::get_class_type()); - nout << "wrt of ab to aa is " << result << "\n"; - - wrt(aa, ab, result, NodeRelation::get_class_type()); - nout << "wrt of aa to ab is " << result << "\n"; - - wrt(r, ba, result, NodeRelation::get_class_type()); - nout << "wrt of r to ba is " << result << "\n"; - - wrt(ba, r, result, NodeRelation::get_class_type()); - nout << "wrt of ba to r is " << result << "\n"; - - wrt(aa, ba, result, NodeRelation::get_class_type()); - nout << "wrt of aa to ba is " << result << "\n"; - - wrt(ba, aa, result, NodeRelation::get_class_type()); - nout << "wrt of ba to aa is " << result << "\n"; - - wrt(ab, ba, result, NodeRelation::get_class_type()); - nout << "wrt of ab to ba is " << result << "\n"; - - wrt(ba, ab, result, NodeRelation::get_class_type()); - nout << "wrt of ba to ab is " << result << "\n"; - } -#endif - - AllTransitionsWrapper result; - - wrt(aa, r, result, NodeRelation::get_class_type()); - nout << "wrt of aa to r is " << result << "\n"; - a_aa->set_transition(new Test2Transition(4)); - - wrt(aa, r, result, NodeRelation::get_class_type()); - nout << "wrt of aa to r is now " << result << "\n"; - - return 0; -} diff --git a/panda/src/graph/transitionDirection.h b/panda/src/graph/transitionDirection.h deleted file mode 100644 index 073aa859a3..0000000000 --- a/panda/src/graph/transitionDirection.h +++ /dev/null @@ -1,29 +0,0 @@ -// Filename: transitionDirection.h -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef TRANSITIONDIRECTION_H -#define TRANSITIONDIRECTION_H - -enum TransitionDirection { - TD_identity, - TD_on, - TD_off -}; - -#endif - diff --git a/panda/src/graph/traverserVisitor.T b/panda/src/graph/traverserVisitor.T deleted file mode 100644 index 2564d0fc7d..0000000000 --- a/panda/src/graph/traverserVisitor.T +++ /dev/null @@ -1,70 +0,0 @@ -// Filename: traverserVisitor.T -// Created by: drose (20Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: TraverserVisitor::reached_node -// Access: Public -// Description: Called for each node visited. It may return true if -// the traversal is to be continued, or false if it -// should be pruned at this node. -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH bool TraverserVisitor:: -reached_node(Node *, - TraverserVisitor::TransitionWrapper &, - LevelState &) { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: TraverserVisitor::reached_node -// Access: Public -// Description: Called each time an arc is traversed in the forward -// direction. As above, it may return true if the -// traversal should continue, or false if it should be -// pruned and not reach the destination node. -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH bool TraverserVisitor:: -forward_arc(NodeRelation *, - TraverserVisitor::TransitionWrapper &, - TraverserVisitor::TransitionWrapper &, - TraverserVisitor::TransitionWrapper &, - LevelState &) { - return true; -} - - -//////////////////////////////////////////////////////////////////// -// Function: TraverserVisitor::reached_node -// Access: Public -// Description: Called each time an arc is traversed in the backward -// direction. It is guaranteed to be paired stack-wise -// with the corresponding call to forward_arc, so that -// each call to backward_arc matches the previous -// unmatched call to forward_arc. -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH void TraverserVisitor:: -backward_arc(NodeRelation *, - TraverserVisitor::TransitionWrapper &, - TraverserVisitor::TransitionWrapper &, - TraverserVisitor::TransitionWrapper &, - const LevelState &) { -} diff --git a/panda/src/graph/traverserVisitor.h b/panda/src/graph/traverserVisitor.h deleted file mode 100644 index 8bc249bb05..0000000000 --- a/panda/src/graph/traverserVisitor.h +++ /dev/null @@ -1,53 +0,0 @@ -// Filename: traverserVisitor.h -// Created by: drose (26Oct98) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef TRAVERSERVISITOR_H -#define TRAVERSERVISITOR_H - -#include - -class Node; -class NodeRelation; - -template -class TraverserVisitor { -public: - typedef TW TransitionWrapper; - - INLINE_GRAPH bool reached_node(Node *node, - TransitionWrapper &render_state, - LevelState &level_state); - - // Some traversers (notably DFTraverser) will also call the - // following two functions to mark the crossing of arcs. This will - // allow the Visitor to maintain its own internal state as needed. - - INLINE_GRAPH bool forward_arc(NodeRelation *arc, TransitionWrapper &trans, - TransitionWrapper &pre, TransitionWrapper &post, - LevelState &level_state); - INLINE_GRAPH void backward_arc(NodeRelation *arc, TransitionWrapper &trans, - TransitionWrapper &pre, TransitionWrapper &post, - const LevelState &level_state); -}; - -#include "traverserVisitor.T" - -#endif - - - diff --git a/panda/src/graph/vector_NodeRelation_star.cxx b/panda/src/graph/vector_NodeRelation_star.cxx deleted file mode 100644 index 73b47212b9..0000000000 --- a/panda/src/graph/vector_NodeRelation_star.cxx +++ /dev/null @@ -1,31 +0,0 @@ -// Filename: vector_NodeRelation_star.cxx -// Created by: drose (07May01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "vector_NodeRelation_star.h" - -#define EXPCL EXPCL_PANDA -#define EXPTP EXPTP_PANDA -#define TYPE NodeRelation * -#define NAME vector_NodeRelation_star - -#include - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif diff --git a/panda/src/graph/vector_NodeRelation_star.h b/panda/src/graph/vector_NodeRelation_star.h deleted file mode 100644 index 396dd67d36..0000000000 --- a/panda/src/graph/vector_NodeRelation_star.h +++ /dev/null @@ -1,49 +0,0 @@ -// Filename: vector_NodeRelation_star.h -// Created by: drose (07May01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef VECTOR_NODERELATION_STAR_H -#define VECTOR_NODERELATION_STAR_H - -#include - -#include "pvector.h" - -class NodeRelation; - -//////////////////////////////////////////////////////////////////// -// Class : vector_NodeRelation_star -// Description : A vector of NodeRelation*'s. This class is defined -// once here, and exported to PANDA.DLL; other packages -// that want to use a vector of this type (whether they -// need to export it or not) should include this header -// file, rather than defining the vector again. -//////////////////////////////////////////////////////////////////// - -#define EXPCL EXPCL_PANDA -#define EXPTP EXPTP_PANDA -#define TYPE NodeRelation * -#define NAME vector_NodeRelation_star - -#include - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/graph/vector_PT_Node.cxx b/panda/src/graph/vector_PT_Node.cxx deleted file mode 100644 index ae9ee637f4..0000000000 --- a/panda/src/graph/vector_PT_Node.cxx +++ /dev/null @@ -1,31 +0,0 @@ -// Filename: vector_PT_Node.cxx -// Created by: drose (16May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "vector_PT_Node.h" - -#define EXPCL EXPCL_PANDA -#define EXPTP EXPTP_PANDA -#define TYPE PT_Node -#define NAME vector_PT_Node - -#include - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif diff --git a/panda/src/graph/vector_PT_Node.h b/panda/src/graph/vector_PT_Node.h deleted file mode 100644 index 796bbfc857..0000000000 --- a/panda/src/graph/vector_PT_Node.h +++ /dev/null @@ -1,50 +0,0 @@ -// Filename: vector_PT_Node.h -// Created by: drose (16May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef VECTOR_PT_NODE_H -#define VECTOR_PT_NODE_H - -#include - -#include "node.h" -#include "pt_Node.h" - -#include "pvector.h" - -//////////////////////////////////////////////////////////////////// -// Class : vector_PT_Node -// Description : A vector of PT(Node)'s. This class is defined once -// here, and exported to PANDA.DLL; other packages that -// want to use a vector of this type (whether they need -// to export it or not) should include this header file, -// rather than defining the vector again. -//////////////////////////////////////////////////////////////////// - -#define EXPCL EXPCL_PANDA -#define EXPTP EXPTP_PANDA -#define TYPE PT_Node -#define NAME vector_PT_Node - -#include - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/graph/vector_PT_NodeRelation.cxx b/panda/src/graph/vector_PT_NodeRelation.cxx deleted file mode 100644 index 686d3c56cc..0000000000 --- a/panda/src/graph/vector_PT_NodeRelation.cxx +++ /dev/null @@ -1,32 +0,0 @@ -// Filename: vector_PT_NodeRelation.cxx -// Created by: drose (07May01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "node.h" -#include "vector_PT_NodeRelation.h" - -#define EXPCL EXPCL_PANDA -#define EXPTP EXPTP_PANDA -#define TYPE PT_NodeRelation -#define NAME vector_PT_NodeRelation - -#include - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma implementation -#endif diff --git a/panda/src/graph/vector_PT_NodeRelation.h b/panda/src/graph/vector_PT_NodeRelation.h deleted file mode 100644 index f850084d6f..0000000000 --- a/panda/src/graph/vector_PT_NodeRelation.h +++ /dev/null @@ -1,50 +0,0 @@ -// Filename: vector_PT_NodeRelation.h -// Created by: drose (07May01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef VECTOR_PT_NODERELATION_H -#define VECTOR_PT_NODERELATION_H - -#include - -#include "nodeRelation.h" -#include "pt_NodeRelation.h" - -#include "pvector.h" - -//////////////////////////////////////////////////////////////////// -// Class : vector_PT_NodeRelation -// Description : A vector of PT(NodeRelation)'s. This class is defined once -// here, and exported to PANDA.DLL; other packages that -// want to use a vector of this type (whether they need -// to export it or not) should include this header file, -// rather than defining the vector again. -//////////////////////////////////////////////////////////////////// - -#define EXPCL EXPCL_PANDA -#define EXPTP EXPTP_PANDA -#define TYPE PT_NodeRelation -#define NAME vector_PT_NodeRelation - -#include - -// Tell GCC that we'll take care of the instantiation explicitly here. -#ifdef __GNUC__ -#pragma interface -#endif - -#endif diff --git a/panda/src/graph/wrt.T b/panda/src/graph/wrt.T deleted file mode 100644 index 6b36b6b7ef..0000000000 --- a/panda/src/graph/wrt.T +++ /dev/null @@ -1,902 +0,0 @@ -// Filename: wrt.T -// Created by: drose (26Oct98) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifdef NOTIFY_DEBUG -//////////////////////////////////////////////////////////////////// -// Function: describe_ambiguous_wrt -// Description: Writes an error message to wrt_cat describing an -// attempt to compute an ambiguous wrt() without -// specifying enough arcs to resolve the ambiguity. -//////////////////////////////////////////////////////////////////// -template -void -describe_ambiguous_wrt(const Node *node, - InputIterator arc_list_begin, - InputIterator arc_list_end, - TypeHandle graph_type) { - if (wrt_cat.is_warning()) { - const UpRelationPointers &urp = node->find_connection(graph_type).get_up(); - int num_parents = urp.size(); - wrt_cat.warning() - << *node << " has " << num_parents << " parents; wrt() ambiguous.\n" - << " parents are: "; - nassertv(num_parents > 1); - - NodeRelation *parent_arc = urp[0]; - wrt_cat.warning(false) << *parent_arc->get_parent(); - for (int i = 1; i < num_parents; i++) { - parent_arc = urp[i]; - wrt_cat.warning(false) - << ", " << *parent_arc->get_parent(); - } - wrt_cat.warning(false) << "\n"; - - // Show the chain of arcs specified. - if (arc_list_begin == arc_list_end) { - wrt_cat.warning(false) - << " no arcs specified.\n"; - } else { - wrt_cat.warning(false) - << " arcs specified:\n"; - InputIterator ri = arc_list_begin; - wrt_cat.warning(false) - << " " << *(*ri)->get_parent() << "/" - << *(*ri)->get_child(); - - InputIterator ri_last = ri; - ++ri; - while (ri != arc_list_end) { - if ((*ri)->get_parent() == (*ri_last)->get_child()) { - wrt_cat.warning(false) - << "/" << *(*ri)->get_child(); - } else { - wrt_cat.warning(false) - << "\n " << *(*ri)->get_parent() << "/" - << *(*ri)->get_child(); - } - ri_last = ri; - ++ri; - } - wrt_cat.warning(false) << "\n"; - } - } - if (ambiguous_wrt_abort) { - abort(); - } -} -#endif - - -//////////////////////////////////////////////////////////////////// -// Function: get_cached_net_transition -// Description: Returns the net transition from the root of the -// graph, or the nearest ancestor with multiple parents, -// to and including the indicated arc. This is a -// support function for wrt() and should not be called -// directly. -// -// This flavor of get_cached_net_transition() gets the -// transition up to an arc, instead of a node, and does -// not necessarily start at the root of the scene graph. -// By starting at the nearest ancestor with multiple -// parents, we allow ambiguous paths in the scene graph -// without interfering with state caching. Since there -// are no nodes with multiple parents in the chain of -// transitions returned by this function, the result is -// always unambiguous; any wrt() ambiguity is resolved -// later. -// -// as_of is the most recent update so far on this branch -// of the scene graph; now is the stamp to use to mark -// any computed cache values. -//////////////////////////////////////////////////////////////////// -template -void -get_cached_net_transition(NodeRelation *arc, Node *&root, - UpdateSeq as_of, UpdateSeq now, - TransitionWrapper &net, TypeHandle graph_type) { - TransitionWrapper cur_cache = TransitionWrapper::init_from(net); - Node *top_subtree = cur_cache.extract_from_cache(arc); - - if (cur_cache.is_cache_verified(as_of)) { - // This arc's cached value has recently been verified, so we don't - // even need to go anywhere--we trust it's still good. - root = top_subtree; - net = cur_cache; - - if (wrt_cat.is_debug()) { - wrt_cat.debug() - << "get_cached_net_transition(" << *arc->get_child() << ", "; - if (root == (Node *)NULL) { - wrt_cat.debug(false) << "(top)"; - } else { - wrt_cat.debug(false) << *root; - } - wrt_cat.debug(false) - << ") is current as of " << as_of << " (now is " - << now << ")\n"; - if (wrt_cat.is_spam()) { - wrt_cat.spam() << "result of " << *arc << " is " << net << "\n"; - } - } - - } else { - // This arc's cache hasn't recently been verified, and we need to - // verify it now. This will entail at least walking up the scene - // graph to the root, and possibly recomputing the cache as we go. - - // Get the node above the arc. - Node *node = arc->get_parent(); - - const UpRelationPointers &urp = node->find_connection(graph_type).get_up(); - int num_parents = urp.size(); - - if (num_parents != 1) { - // The node has zero or multiple parents. It's thus either the - // top of the scene graph, or it's the first ancestor with - // multiple parents; in either case, it's as far as we can take - // the caching. Stop here. - - if (num_parents == 0) { - // The node is the very top of the scene graph. We'll treat - // this as a special case by setting the node to NULL. This - // will tell our calling function that there's no need to look - // further. - node = NULL; - } - - root = node; - net.extract_from(arc); - net.set_computed_verified(now); - net.store_to_cache(arc, node); - - } else { - // The node has exactly one parent. Carry on. - - NodeRelation *parent_arc = urp[0]; - get_cached_net_transition(parent_arc, root, as_of, now, net, graph_type); - - // Now recompute our own cache. - TransitionWrapper cur_value = TransitionWrapper::init_from(net); - cur_value.extract_from(arc); - - net.cached_compose(cur_cache, cur_value, now); - net.store_to_cache(arc, root); - } - - if (wrt_cat.is_debug()) { - wrt_cat.debug() - << "get_cached_net_transition(" << *arc->get_child() << ", "; - if (root == (Node *)NULL) { - wrt_cat.debug(false) << "(top)"; - } else { - wrt_cat.debug(false) << *root; - } - wrt_cat.debug(false) - << ") is recomputed as of " << as_of << " (now is " - << now << ")\n"; - if (wrt_cat.is_spam()) { - wrt_cat.spam() << "result of " << *arc << " is " << net << "\n"; - } - } - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: get_cached_net_transition -// Description: Returns the net transition from the root of the graph -// to the indicated node. This is a support function -// for wrt() and should not be called directly. -// -// If [arc_list_begin..arc_list_end) is nonempty, it -// contains a list of NodeRelation pointers to resolve -// ambiguities when a node with multiple parents is -// encountered. -// -// as_of is the most recent update so far on this branch -// of the scene graph; now is the stamp to use to mark -// any computed cache values. -//////////////////////////////////////////////////////////////////// -template -void -get_cached_net_transition(const Node *node, - InputIterator arc_list_begin, - InputIterator arc_list_end, - UpdateSeq as_of, UpdateSeq now, - TransitionWrapper &result, - TypeHandle graph_type) { - if (node == NULL) { - // the NULL node is by convention equivalent to the root. - result.make_identity(); - - if (wrt_cat.is_debug()) { - wrt_cat.debug() - << "get_cached_net_transition((top))\n"; - } - return; - } - - const UpRelationPointers &urp = node->find_connection(graph_type).get_up(); - int num_parents = urp.size(); - - const NodeRelation *parent_arc = (const NodeRelation *)NULL; - - if (num_parents == 1) { - // There is only one parent, so there's no doubt as to which arc - // to choose. - parent_arc = urp[0]; - - } else if (num_parents == 0) { - // This node has no parents. Stop here. - result.make_identity(); - - if (wrt_cat.is_debug()) { - wrt_cat.debug() - << "get_cached_net_transition(" << *node << ") has no parents.\n"; - } - return; - - } else { - // The node has multiple parents, and we have a list of arcs in - // arc_list_begin .. arc_list_end. If any of the parents is - // mentioned in the list, we must choose that parent. - for (InputIterator ri = arc_list_begin; - parent_arc == (NodeRelation *)NULL && ri != arc_list_end; - ++ri) { - if ((*ri)->get_child() == node) { - parent_arc = (*ri); - } - } - - if (parent_arc == (NodeRelation *)NULL) { -#ifdef NOTIFY_DEBUG - // No, it wasn't mentioned. Issue a warning and use the first - // one. - describe_ambiguous_wrt(node, arc_list_begin, arc_list_end, graph_type); -#endif - parent_arc = urp[0]; - } - } - - // Get the net transition leading into this node. - Node *root; - get_cached_net_transition((NodeRelation *)parent_arc, root, - as_of, now, result, graph_type); - - if (root != NULL) { - // There's more to get. The above function call was forced to - // stop at a node with multiple parents. - TransitionWrapper more = TransitionWrapper::init_from(result); - get_cached_net_transition(root, arc_list_begin, arc_list_end, - as_of, now, more, graph_type); - more.compose_in_place(result); - result = more; - } -} - -#ifndef NDEBUG -//////////////////////////////////////////////////////////////////// -// Function: get_uncached_net_transition -// Description: Returns the net transition from the root of the graph -// to the indicated node. This is a support function -// for wrt() and should not be called directly. -// -// If [arc_list_begin..arc_list_end) is nonempty, it -// contains a list of NodeRelation pointers to resolve -// ambiguities when a node with multiple parents is -// encountered. -// -// This variant of get_cached_net_transition() does not -// respect or update the cache values stored in the -// arcs. It's intended only as a debugging doublecheck -// against the normal get_cached_net_transition() -// function that does do this. -//////////////////////////////////////////////////////////////////// -template -void -get_uncached_net_transition(const Node *node, - InputIterator arc_list_begin, - InputIterator arc_list_end, - TransitionWrapper &result, - TypeHandle graph_type) { - if (node == NULL) { - // the NULL node is by convention equivalent to the root. - if (wrt_cat.is_spam()) { - wrt_cat.spam() - << "get_uncached_net_transition(top)" << *node; - } - result.make_identity(); - return; - } - - const UpRelationPointers &urp = node->find_connection(graph_type).get_up(); - int num_parents = urp.size(); - - const NodeRelation *parent_arc = (const NodeRelation *)NULL; - - if (num_parents == 1) { - // There is only one parent, so there's no doubt as to which arc - // to choose. - parent_arc = urp[0]; - - } else if (num_parents == 0) { - // This node has no parents. Stop here. - if (wrt_cat.is_spam()) { - wrt_cat.spam() - << "get_uncached_net_transition(" << *node << ") has no parents.\n"; - } - result.make_identity(); - return; - - } else { - // The node has multiple parents, and we have a list of arcs in - // arc_list_begin .. arc_list_end. If any of the parents is - // mentioned in the list, we must choose that parent. - for (InputIterator ri = arc_list_begin; - parent_arc == (NodeRelation *)NULL && ri != arc_list_end; - ++ri) { - if ((*ri)->get_child() == node) { - parent_arc = (*ri); - } - } - - if (parent_arc == (NodeRelation *)NULL) { -#ifdef NOTIFY_DEBUG - // No, it wasn't mentioned. Issue a warning and use the first - // one. - describe_ambiguous_wrt(node, arc_list_begin, arc_list_end, graph_type); -#endif - parent_arc = urp[0]; - } - } - - get_uncached_net_transition(parent_arc->get_parent(), - arc_list_begin, arc_list_end, - result, - graph_type); - - TransitionWrapper next = TransitionWrapper::init_from(result); - next.extract_from(parent_arc); - - result.compose_in_place(next); - - if (wrt_cat.is_spam()) { - wrt_cat.spam() - << "get_uncached_net_transition(" << *node; - InputIterator ri; - for (ri = arc_list_begin; ri != arc_list_end; ++ri) { - wrt_cat.spam(false) << ", " << *(*ri); - } - - wrt_cat.spam(false) - << "), " << num_parents << " parents, is:\n"; - result.write(wrt_cat.spam(false), 2); - } -} -#endif - - -//////////////////////////////////////////////////////////////////// -// Function: cached_wrt_base -// Description: The implementation of wrt_base, below, but always -// uses the cached value. This is the normal behavior. -//////////////////////////////////////////////////////////////////// -template -void -cached_wrt_base(const Node *from, - InputIterator1 from_arcs_begin, InputIterator1 from_arcs_end, - const Node *to, - InputIterator2 to_arcs_begin, InputIterator2 to_arcs_end, - TransitionWrapper &result, - TypeHandle graph_type) { - UpdateSeq now = last_graph_update(graph_type); - - TransitionWrapper net_from_trans = TransitionWrapper::init_from(result); - - if (wrt_cat.is_debug()) { - wrt_cat.debug() - << "Computing wrt("; - if (from == (Node *)NULL) { - wrt_cat.debug(false) << "(top), "; - } else { - wrt_cat.debug(false) << *from << ", "; - } - if (to == (Node *)NULL) { - wrt_cat.debug(false) << "(top)"; - } else { - wrt_cat.debug(false) << *to; - } - wrt_cat.debug(false) - << "), as of " << now << " (now is " - << now << ")\n"; - } - - get_cached_net_transition(from, from_arcs_begin, from_arcs_end, - now, now, net_from_trans, graph_type); - get_cached_net_transition(to, to_arcs_begin, to_arcs_end, - now, now, result, graph_type); - -#ifndef NDEBUG - if (paranoid_wrt) { - // We don't entirely trust the caching to work flawlessly. Go - // ahead and compute the uncached transition just to doublecheck. - TransitionWrapper check_from_trans = - TransitionWrapper::init_from(result); - TransitionWrapper check_to_trans = - TransitionWrapper::init_from(result); - get_uncached_net_transition(from, from_arcs_begin, from_arcs_end, - check_from_trans, graph_type); - if (check_from_trans.compare_to(net_from_trans) != 0) { - wrt_cat.warning() - << "WRT cache from " << *from << " is invalid!\n" - << " cached value is:\n"; - net_from_trans.write(wrt_cat.warning(false), 4); - wrt_cat.warning(false) - << " should be:\n"; - check_from_trans.write(wrt_cat.warning(false), 4); - net_from_trans = check_from_trans; - } - - get_uncached_net_transition(to, to_arcs_begin, to_arcs_end, - check_to_trans, graph_type); - if (check_to_trans.compare_to(result) != 0) { - wrt_cat.warning() - << "WRT cache to " << *to << " is invalid!\n" - << " cached value is:\n"; - result.write(wrt_cat.warning(false), 4); - wrt_cat.warning(false) - << " should be:\n"; - check_to_trans.write(wrt_cat.warning(false), 4); - result = check_to_trans; - } - } -#endif - - result.invert_compose_in_place(net_from_trans); -} - -#ifndef NDEBUG -//////////////////////////////////////////////////////////////////// -// Function: uncached_wrt_base -// Description: The implementation of wrt_base, below, but never -// cached. -//////////////////////////////////////////////////////////////////// -template -void -uncached_wrt_base(const Node *from, - InputIterator1 from_arcs_begin, InputIterator1 from_arcs_end, - const Node *to, - InputIterator2 to_arcs_begin, InputIterator2 to_arcs_end, - TransitionWrapper &result, - TypeHandle graph_type) { - TransitionWrapper net_from_trans = TransitionWrapper::init_from(result); - get_uncached_net_transition(from, from_arcs_begin, from_arcs_end, - net_from_trans, graph_type); - get_uncached_net_transition(to, to_arcs_begin, to_arcs_end, - result, graph_type); - result.invert_compose_in_place(net_from_trans); -} -#endif - -//////////////////////////////////////////////////////////////////// -// Function: wrt_base -// Description: Returns the net transition from the node "to" -// to the node "from". -// -// If [from_arcs_begin..from_arcs_end) is nonempty, it -// contains a list of NodeRelation pointers to resolve -// ambiguities when a node with multiple parents is -// encountered as an ancestor of the from node. If any -// of the parents is listed, that parent will be chosen. -// -// Similarly with [to_arcs_begin..to_arcs_end). -// -// wrt_base() is a low-level implementation; use the -// various wrt() wrappers instead. -//////////////////////////////////////////////////////////////////// -template -INLINE_GRAPH void -wrt_base(const Node *from, - InputIterator1 from_arcs_begin, InputIterator1 from_arcs_end, - const Node *to, - InputIterator2 to_arcs_begin, InputIterator2 to_arcs_end, - TransitionWrapper &result, - TypeHandle graph_type) { - PStatTimer timer(_wrt_pcollector); - -#ifndef NDEBUG - if (!cache_wrt) { - uncached_wrt_base(from, from_arcs_begin, from_arcs_end, - to, to_arcs_begin, to_arcs_end, - result, graph_type); - return; - } -#endif - cached_wrt_base(from, from_arcs_begin, from_arcs_end, - to, to_arcs_begin, to_arcs_end, - result, graph_type); -} - -template -INLINE_GRAPH void -wrt(const Node *from, const Node *to, - TransitionWrapper &result, TypeHandle graph_type) { - // In the normal wrt() interface, we have no from_arcs or to_arcs - // list. Supply empty lists for both. - const NodeRelation *arc = NULL; - wrt_base(from, &arc, &arc, to, &arc, &arc, result, graph_type); -} - -template -INLINE_GRAPH void -wrt(const Node *from, - InputIterator from_arcs_begin, InputIterator from_arcs_end, - const Node *to, - TransitionWrapper &result, TypeHandle graph_type) { - const NodeRelation *arc = NULL; - wrt_base(from, from_arcs_begin, from_arcs_end, to, &arc, &arc, - result, graph_type); -} - -template -INLINE_GRAPH void -wrt(const Node *from, - const Node *to, - InputIterator to_arcs_begin, InputIterator to_arcs_end, - TransitionWrapper &result, TypeHandle graph_type) { - const NodeRelation *arc = NULL; - wrt_base(from, &arc, &arc, to, to_arcs_begin, to_arcs_end, - result, graph_type); -} - -template -INLINE_GRAPH void -wrt(const Node *from, - InputIterator1 from_arcs_begin, InputIterator1 from_arcs_end, - const Node *to, - InputIterator2 to_arcs_begin, InputIterator2 to_arcs_end, - TransitionWrapper &result, TypeHandle graph_type) { - wrt_base(from, from_arcs_begin, from_arcs_end, - to, to_arcs_begin, to_arcs_end, - result, graph_type); -} - -#ifndef NDEBUG -template -INLINE_GRAPH void -uncached_wrt(const Node *from, const Node *to, - TransitionWrapper &result, TypeHandle graph_type) { - const NodeRelation *arc = NULL; - uncached_wrt_base(from, &arc, &arc, to, &arc, &arc, result, graph_type); -} - -template -INLINE_GRAPH void -uncached_wrt(const Node *from, - InputIterator from_arcs_begin, InputIterator from_arcs_end, - const Node *to, - TransitionWrapper &result, TypeHandle graph_type) { - const NodeRelation *arc = NULL; - uncached_wrt_base(from, from_arcs_begin, from_arcs_end, to, &arc, &arc, - result, graph_type); -} - -template -INLINE_GRAPH void -uncached_wrt(const Node *from, - const Node *to, - InputIterator to_arcs_begin, InputIterator to_arcs_end, - TransitionWrapper &result, TypeHandle graph_type) { - const NodeRelation *arc = NULL; - uncached_wrt_base(from, &arc, &arc, to, to_arcs_begin, to_arcs_end, - result, graph_type); -} - -template -INLINE_GRAPH void -uncached_wrt(const Node *from, - InputIterator1 from_arcs_begin, InputIterator1 from_arcs_end, - const Node *to, - InputIterator2 to_arcs_begin, InputIterator2 to_arcs_end, - TransitionWrapper &result, TypeHandle graph_type) { - uncached_wrt_base(from, from_arcs_begin, from_arcs_end, - to, to_arcs_begin, to_arcs_end, - result, graph_type); -} -#endif - -#ifndef NDEBUG -template -Node * -get_uncached_wrt_subtree(Node *node, Node *to, TransitionWrapper &result, - TypeHandle graph_type) { - nassertr(node != (Node *)NULL, to); - - const UpRelationPointers &urp = node->find_connection(graph_type).get_up(); - int num_parents = urp.size(); - - if (num_parents == 0) { - // This node has no parents. Stop here. - if (wrt_cat.is_spam()) { - wrt_cat.spam() - << "get_uncached_wrt_subtree(" << *node << ") has no parents.\n"; - } - result.make_identity(); - return (Node *)NULL; - } - - if (num_parents != 1) { - // There are multiple parents, so stop here. - if (wrt_cat.is_spam()) { - wrt_cat.spam() - << "get_uncached_wrt_subtree(" << *node << ") has " << num_parents - << " parents.\n"; - } - result.make_identity(); - return node; - } - - if (node == to) { - // We've reached our stopping point. Stop here. - if (wrt_cat.is_spam()) { - wrt_cat.spam() - << "get_uncached_wrt_subtree(" << *node << ") is at stopping point.\n"; - } - result.make_identity(); - - // Actually, we do need to keep walking up till we find the actual - // top of the instanced subtree, so we can return the correct - // pointer. - num_parents = node->get_num_parents(graph_type); - while (num_parents == 1) { - node = node->get_parent(graph_type, 0)->get_parent(); - num_parents = node->get_num_parents(graph_type); - } - - if (num_parents == 0) { - return (Node *)NULL; - } else { - return node; - } - } - - const NodeRelation *parent_arc = urp[0]; - - Node *stop = - get_uncached_wrt_subtree(parent_arc->get_parent(), to, - result, graph_type); - - TransitionWrapper next = TransitionWrapper::init_from(result); - next.extract_from(parent_arc); - - result.compose_in_place(next); - - if (wrt_cat.is_spam()) { - wrt_cat.spam() - << "get_uncached_wrt_subtree(" << *node - << "), top at "; - if (stop == (Node *)NULL) { - wrt_cat.spam(false) << "(top)"; - } else { - wrt_cat.spam(false) << *stop; - } - wrt_cat.spam(false) << " is:\n"; - result.write(wrt_cat.spam(false), 2); - } - - return stop; -} - -template -INLINE_GRAPH Node * -uncached_wrt_subtree(NodeRelation *arc, Node *to, - TransitionWrapper &result, TypeHandle graph_type) { - Node *stop = - get_uncached_wrt_subtree(arc->get_parent(), to, - result, graph_type); - - TransitionWrapper next = TransitionWrapper::init_from(result); - next.extract_from(arc); - - result.compose_in_place(next); - - if (wrt_cat.is_spam()) { - wrt_cat.spam() - << "uncached_wrt_subtree(" << *arc - << "), top at "; - if (stop == (Node *)NULL) { - wrt_cat.spam(false) << "(top)"; - } else { - wrt_cat.spam(false) << *stop; - } - wrt_cat.spam(false) << " is:\n"; - result.write(wrt_cat.spam(false), 2); - } - - return stop; -} - -#endif - -template -Node * -cached_wrt_subtree(NodeRelation *arc, Node *to, UpdateSeq as_of, UpdateSeq now, - TransitionWrapper &result, TypeHandle graph_type) { - // First, determine the net transition up to the top of the current - // subtree. - Node *top_subtree; - get_cached_net_transition(arc, top_subtree, as_of, now, result, graph_type); - - if (top_subtree == to || to == (Node *)NULL) { - // If the top of the subtree is the node we asked to wrt to, - // excellent! Stop here. - - if (wrt_cat.is_spam()) { - wrt_cat.spam() - << "cached_wrt_subtree(" << *arc << ", "; - if (to == (Node *)NULL) { - wrt_cat.spam(false) << "(top)"; - } else { - wrt_cat.spam(false) << *to; - } - wrt_cat.spam(false) << ") stops at top, result is:\n"; - result.write(wrt_cat.spam(false), 2); - } - - } else { - - // Otherwise, it must be the case that the node we want to wrt to is - // some descendent of the top_subtree node. It also therefore - // follows that this node has exactly one parent. - - if (wrt_cat.is_spam()) { - wrt_cat.spam() - << "cached_wrt_subtree(" << *arc << ", " << *to << ") stops at "; - if (top_subtree == (Node *)NULL) { - wrt_cat.spam(false) << "(top)"; - } else { - wrt_cat.spam(false) << *top_subtree; - } - wrt_cat.spam(false) << ", first result is:\n"; - result.write(wrt_cat.spam(false), 2); - } - - if (to->get_num_parents(graph_type) != 1) { - // Oops! We *don't* have exactly one parent. This means our - // cache is stale in some surprising way. To recover, we'll - // force a recompute of the cache by asking for the wrt() from - // the very latest timestamp. - - // This, of course, assumes we haven't just asked for the wrt() - // from the very latest timestamp. - if (wrt_cat.is_warning()) { - wrt_cat.warning() - << "Recovering from stale cache.\n"; - } - - nassertr(as_of != UpdateSeq::fresh(), NULL); - return cached_wrt_subtree(arc, to, UpdateSeq::fresh(), now, - result, graph_type); - } - - nassertr(to->get_num_parents(graph_type) == 1, NULL); - NodeRelation *to_arc = to->get_parent(graph_type, 0); - - // Save the result from the first pass. - TransitionWrapper net_from_trans = result; - - // Now determine the net transition to the top of the subtree from - // this arc. It had better be the same subtree! - Node *top_subtree_2; - get_cached_net_transition(to_arc, top_subtree_2, as_of, now, - result, graph_type); - nassertr(top_subtree == top_subtree_2, NULL); - - // And now compute the actual wrt. - result.invert_compose_in_place(net_from_trans); - - if (wrt_cat.is_spam()) { - wrt_cat.spam() - << "cached_wrt_subtree(" << *arc << ", " << *to << ") stops at "; - if (top_subtree == (Node *)NULL) { - wrt_cat.spam(false) << "(top)"; - } else { - wrt_cat.spam(false) << *top_subtree; - } - wrt_cat.spam() << ", second result is:\n"; - net_from_trans.write(wrt_cat.spam(false), 2); - wrt_cat.spam() << ", final result is:\n"; - result.write(wrt_cat.spam(false), 2); - } - } - -#ifndef NDEBUG - if (paranoid_wrt) { - // Now check the results. - TransitionWrapper check_trans = - TransitionWrapper::init_from(result); - Node *top_subtree_3 = - uncached_wrt_subtree(arc, to, check_trans, graph_type); - - if (top_subtree_3 != top_subtree) { - wrt_cat.warning() - << "WRT subtree cache from " << *arc->get_child() << " to "; - if (to == (Node *)NULL) { - wrt_cat.warning(false) << "(top)"; - } else { - wrt_cat.warning(false) << *to; - } - wrt_cat.warning(false) - << " computes incorrect top_subtree!\n" - << " computed "; - if (top_subtree == (Node *)NULL) { - wrt_cat.warning(false) << "(top)\n"; - } else { - wrt_cat.warning(false) << *top_subtree << "\n"; - } - wrt_cat.warning(false) - << " should be "; - if (top_subtree_3 == (Node *)NULL) { - wrt_cat.warning(false) << "(top)\n"; - } else { - wrt_cat.warning(false) << *top_subtree_3 << "\n"; - } - top_subtree = top_subtree_3; - } - - int compare = check_trans.compare_to(result); - if (compare != 0) { - wrt_cat.warning() - << "WRT subtree cache from " << *arc->get_child() << " to "; - if (to == (Node *)NULL) { - wrt_cat.warning(false) << "(top)"; - } else { - wrt_cat.warning(false) << *to; - } - wrt_cat.warning(false) - << " is invalid!\n" - << " cached value is:\n"; - result.write(wrt_cat.warning(false), 4); - wrt_cat.warning(false) - << " should be:\n"; - check_trans.write(wrt_cat.warning(false), 4); - result = check_trans; - } - } -#endif - - return top_subtree; -} - -template -INLINE_GRAPH Node * -wrt_subtree(NodeRelation *arc, Node *to, UpdateSeq as_of, UpdateSeq now, - TransitionWrapper &result, TypeHandle graph_type) { - PStatTimer timer(_wrt_subtree_pcollector); - -#ifndef NDEBUG - if (!cache_wrt) { - // If we aren't caching wrt, compute it explicitly. - return uncached_wrt_subtree(arc, to, result, graph_type); - } -#endif - return cached_wrt_subtree(arc, to, as_of, now, result, graph_type); -} - - diff --git a/panda/src/graph/wrt.cxx b/panda/src/graph/wrt.cxx deleted file mode 100644 index 792f9aee86..0000000000 --- a/panda/src/graph/wrt.cxx +++ /dev/null @@ -1,24 +0,0 @@ -// Filename: wrt.cxx -// Created by: drose (16Apr01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "wrt.h" - -#ifndef CPPPARSER -PStatCollector _wrt_pcollector("WRT"); -PStatCollector _wrt_subtree_pcollector("WRT:subtree"); -#endif diff --git a/panda/src/graph/wrt.h b/panda/src/graph/wrt.h deleted file mode 100644 index 4d7e47dd27..0000000000 --- a/panda/src/graph/wrt.h +++ /dev/null @@ -1,151 +0,0 @@ -// Filename: wrt.h -// Created by: drose (26Oct98) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef WRT_H -#define WRT_H - -#include - -#include "nodeRelation.h" -#include "node.h" -#include "config_graph.h" - -#include -#include -#include - -class Node; - -// The normal wrt() call, with-respect-to, computes the transition -// necessary to convert from the state at "to" to the state at "from". -// (If this seems backwards, think of it as returning the state at -// "from" with respect to the node "to", or in other words, the node -// "from" as seen from "to".) - -// It's most useful for TransformTransitions, but it is meaningful to -// use wrt() with any kind of NodeTransition at all. - -// The various additional flavors of wrt() are provided to resolve -// ambiguities in the case of a node having multiple parents in the -// scene graph. If a given node in the ancestry of node "from" has -// multiple parents, and one of those parents is in the set -// from_arcs_begin..from_arcs_end, that arc is chosen. Otherwise, a -// warning is issued and an arc is chosen arbitrarily. Similarly for -// multiple parenthood in the ancestry of node "to" and -// to_arcs_begin..to_arcs_end. - -template -INLINE_GRAPH void -wrt(const Node *from, const Node *to, - TransitionWrapper &result, TypeHandle graph_type); - -template -INLINE_GRAPH void -wrt(const Node *from, - InputIterator from_arcs_begin, InputIterator from_arcs_end, - const Node *to, - TransitionWrapper &result, TypeHandle graph_type); - -template -INLINE_GRAPH void -wrt(const Node *from, - const Node *to, - InputIterator to_arcs_begin, InputIterator to_arcs_end, - TransitionWrapper &result, TypeHandle graph_type); - -template -INLINE_GRAPH void -wrt(const Node *from, - InputIterator1 from_arcs_begin, InputIterator1 from_arcs_end, - const Node *to, - InputIterator2 to_arcs_begin, InputIterator2 to_arcs_end, - TransitionWrapper &result, TypeHandle graph_type); - -#ifndef NDEBUG -// Similar to the above, but always uncached. Useful mainly for -// debugging, or when you suspect the cache is invalid. Also note -// that you can configure 'cache-wrt' or 'paranoid-wrt' to disable or -// force verification of the cache implicitly. -template -INLINE_GRAPH void -uncached_wrt(const Node *from, const Node *to, - TransitionWrapper &result, TypeHandle graph_type); - -template -INLINE_GRAPH void -uncached_wrt(const Node *from, - InputIterator from_arcs_begin, InputIterator from_arcs_end, - const Node *to, - TransitionWrapper &result, TypeHandle graph_type); - -template -INLINE_GRAPH void -uncached_wrt(const Node *from, - const Node *to, - InputIterator to_arcs_begin, InputIterator to_arcs_end, - TransitionWrapper &result, TypeHandle graph_type); - -template -INLINE_GRAPH void -uncached_wrt(const Node *from, - InputIterator1 from_arcs_begin, InputIterator1 from_arcs_end, - const Node *to, - InputIterator2 to_arcs_begin, InputIterator2 to_arcs_end, - TransitionWrapper &result, TypeHandle graph_type); -#endif - - -// The following function is a bit different. Rather than computing -// the relative transform between two nodes, it computes the net -// transform along the shortest unambiguous path from the indicated -// arc towards the root. That is, this is the wrt between the child -// of the indicated arc and the closest ancestor node that has -// multiple parents, or the root of the scene graph if the arc only -// appears once in the scene graph. The return value is the -// particular node with multiple parents at which the wrt stopped, or -// NULL if it went all the way to the root. - -// This is extended just a bit further by allowing the user to specify -// a "to" node. This must be either NULL, or the expected top node, -// or some node in between. If it is a node in between, it indicates -// the point at which the relative computation should stop. In -// effect, this makes wrt_subtree(arc, to) equivalent to -// wrt(arc->get_child(), to), except that it must be true that "to" is -// a linear ancestor of arc. - -// This concept is important within the computation of wrt itself to -// manage cached state between multiple instances, but is of limited -// general utility; it is of primary interest to code (like the -// CullTraverser) that needs to cache a wrt-type value for many nodes -// across the entire tree. - -// as_of is the most recent update between 'arc' and 'to'; now is the -// current most recent update sequence anywhere, used to use to mark -// any computed cache values. -template -INLINE_GRAPH Node * -wrt_subtree(NodeRelation *arc, Node *to, UpdateSeq as_of, UpdateSeq now, - TransitionWrapper &result, TypeHandle graph_type); - -// This is used to count the amount of time spend in calls to wrt(). -extern EXPCL_PANDA PStatCollector _wrt_pcollector; -extern EXPCL_PANDA PStatCollector _wrt_subtree_pcollector; - -#include "wrt.T" - -#endif diff --git a/panda/src/grutil/Sources.pp b/panda/src/grutil/Sources.pp index 5a77227b0b..f9a68ae96e 100644 --- a/panda/src/grutil/Sources.pp +++ b/panda/src/grutil/Sources.pp @@ -4,28 +4,22 @@ #begin lib_target #define TARGET grutil #define LOCAL_LIBS \ - sgraphutil sgattrib sgraph gobj linmath putil + pgraph gobj linmath putil #define COMBINED_SOURCES $[TARGET]_composite1.cxx #define SOURCES \ - cardMaker.I cardMaker.h \ qpcardMaker.I qpcardMaker.h \ config_grutil.h \ - lineSegs.I lineSegs.h \ qplineSegs.I qplineSegs.h #define INCLUDED_SOURCES \ - cardMaker.cxx \ qpcardMaker.cxx \ config_grutil.cxx \ - qplineSegs.cxx \ - lineSegs.cxx + qplineSegs.cxx #define INSTALL_HEADERS \ - cardMaker.I cardMaker.h \ qpcardMaker.I qpcardMaker.h \ - lineSegs.I lineSegs.h \ qplineSegs.I qplineSegs.h #define IGATESCAN all diff --git a/panda/src/grutil/cardMaker.I b/panda/src/grutil/cardMaker.I deleted file mode 100644 index 8981b3b706..0000000000 --- a/panda/src/grutil/cardMaker.I +++ /dev/null @@ -1,136 +0,0 @@ -// Filename: cardMaker.I -// Created by: drose (06Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: CardMaker::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CardMaker:: -CardMaker() { - reset(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CardMaker::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CardMaker:: -~CardMaker() { -} - -//////////////////////////////////////////////////////////////////// -// Function: CardMaker::set_uv_range -// Access: Public -// Description: Sets the range of UV's that will be applied to the -// vertices. If set_has_uvs() is true (as it is by -// default), the vertices will be generated with the -// indicated range of UV's, which will be useful if a -// texture is applied. -//////////////////////////////////////////////////////////////////// -INLINE void CardMaker:: -set_uv_range(const TexCoordf &ll, const TexCoordf &ur) { - _ll = ll; - _ur = ur; -} - -//////////////////////////////////////////////////////////////////// -// Function: CardMaker::set_has_uvs -// Access: Public -// Description: Sets the flag indicating whether vertices will be -// generated with UV's or not. -//////////////////////////////////////////////////////////////////// -INLINE void CardMaker:: -set_has_uvs(bool flag) { - _has_uvs = flag; -} - -//////////////////////////////////////////////////////////////////// -// Function: CardMaker::set_frame -// Access: Public -// Description: Sets the size of the card. -//////////////////////////////////////////////////////////////////// -INLINE void CardMaker:: -set_frame(float left, float right, float bottom, float top) { - set_frame(LVecBase4f(left, right, bottom, top)); -} - -//////////////////////////////////////////////////////////////////// -// Function: CardMaker::set_frame -// Access: Public -// Description: Sets the size of the card. -//////////////////////////////////////////////////////////////////// -INLINE void CardMaker:: -set_frame(const LVecBase4f &frame) { - _frame = frame; -} - -//////////////////////////////////////////////////////////////////// -// Function: CardMaker::set_color -// Access: Public -// Description: Sets the color of the card. -//////////////////////////////////////////////////////////////////// -INLINE void CardMaker:: -set_color(float r, float g, float b, float a) { - set_color(LVecBase4f(r, g, b, a)); -} - -//////////////////////////////////////////////////////////////////// -// Function: CardMaker::set_color -// Access: Public -// Description: Sets the color of the card. -//////////////////////////////////////////////////////////////////// -INLINE void CardMaker:: -set_color(const LVecBase4f &color) { - _color = color; - _has_color = true; -} - -//////////////////////////////////////////////////////////////////// -// Function: CardMaker::set_source_geometry -// Access: Published -// Description: Sets a node that will be copied (and scaled and -// translated) to generate the frame, instead of -// generating a new polygon. The node may contain -// arbitrary geometry that describes a flat polygon -// contained within the indicated left, right, bottom, -// top frame. -// -// When generate() is called, the geometry in this node -// will be scaled and translated appropriately to give -// it the size and aspect ratio specified by -// set_frame(). -//////////////////////////////////////////////////////////////////// -INLINE void CardMaker:: -set_source_geometry(Node *node, const LVecBase4f &frame) { - _source_geometry = node; - _source_frame = frame; -} - -//////////////////////////////////////////////////////////////////// -// Function: CardMaker::clear_source_geometry -// Access: Published -// Description: Removes the node specified by an earlier call to -// set_source_geometry(). -//////////////////////////////////////////////////////////////////// -INLINE void CardMaker:: -clear_source_geometry() { - _source_geometry = (Node *)NULL; -} diff --git a/panda/src/grutil/cardMaker.cxx b/panda/src/grutil/cardMaker.cxx deleted file mode 100644 index 2924801c98..0000000000 --- a/panda/src/grutil/cardMaker.cxx +++ /dev/null @@ -1,150 +0,0 @@ -// Filename: cardMaker.cxx -// Created by: drose (06Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "cardMaker.h" -#include "geomNode.h" -#include "geomTristrip.h" -#include "renderRelation.h" -#include "transformTransition.h" -#include "colorTransition.h" -#include "sceneGraphReducer.h" - - -//////////////////////////////////////////////////////////////////// -// Function: CardMaker::reset -// Access: Public -// Description: Resets all the parameters to their initial defaults. -//////////////////////////////////////////////////////////////////// -void CardMaker:: -reset() { - _has_uvs = true; - _ll.set(0.0f, 0.0f); - _ur.set(1.0f, 1.0f); - _frame.set(0.0f, 1.0f, 0.0f, 1.0f); - _has_color = false; - _color.set(1.0f, 1.0f, 1.0f, 1.0f); - _source_geometry = (Node *)NULL; - _source_frame.set(0.0f, 0.0f, 0.0f, 0.0f); -} - - -//////////////////////////////////////////////////////////////////// -// Function: CardMaker::generate -// Access: Public -// Description: Generates a GeomNode that renders the specified -// geometry. -//////////////////////////////////////////////////////////////////// -PT_Node CardMaker:: -generate() { - if (_source_geometry != (Node *)NULL) { - return rescale_source_geometry(); - } - - PT(GeomNode) gnode = new GeomNode("card"); - Geom *geom = new GeomTristrip; - gnode->add_geom(geom); - - float left = _frame[0]; - float right = _frame[1]; - float bottom = _frame[2]; - float top = _frame[3]; - - PTA_int lengths=PTA_int::empty_array(0); - lengths.push_back(4); - - PTA_Vertexf verts; - verts.push_back(Vertexf::rfu(left, 0.0f, top)); - verts.push_back(Vertexf::rfu(left, 0.0f, bottom)); - verts.push_back(Vertexf::rfu(right, 0.0f, top)); - verts.push_back(Vertexf::rfu(right, 0.0f, bottom)); - - geom->set_num_prims(1); - geom->set_lengths(lengths); - - geom->set_coords(verts); - - PTA_Colorf colors; - colors.push_back(_color); - geom->set_colors(colors, G_OVERALL); - - if (_has_uvs) { - PTA_TexCoordf uvs; - uvs.push_back(TexCoordf(_ll[0], _ur[1])); - uvs.push_back(TexCoordf(_ll[0], _ll[1])); - uvs.push_back(TexCoordf(_ur[0], _ur[1])); - uvs.push_back(TexCoordf(_ur[0], _ll[1])); - geom->set_texcoords(uvs, G_PER_VERTEX); - } - - return gnode.p(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CardMaker::rescale_source_geometry -// Access: Private -// Description: Generates the card by rescaling the source geometry -// appropriately. -//////////////////////////////////////////////////////////////////// -PT_Node CardMaker:: -rescale_source_geometry() { - PT_Node root = new NamedNode; - NodeRelation *root_arc = - new RenderRelation(root, _source_geometry->copy_subgraph(RenderRelation::get_class_type())); - - // Determine the translate and scale appropriate for our geometry. - float geom_center_x = (_source_frame[0] + _source_frame[1]) * 0.5f; - float geom_center_y = (_source_frame[2] + _source_frame[3]) * 0.5f; - - float frame_center_x = (_frame[0] + _frame[1]) * 0.5f; - float frame_center_y = (_frame[2] + _frame[3]) * 0.5f; - - float scale_x = - (_frame[1] - _frame[0]) / (_source_frame[1] - _source_frame[0]); - float scale_y = - (_frame[3] - _frame[2]) / (_source_frame[3] - _source_frame[2]); - - LVector3f trans = LVector3f::rfu(frame_center_x - geom_center_x, 0.0f, - frame_center_y - geom_center_y); - LVector3f scale = LVector3f::rfu(scale_x, 1.0f, scale_y); - - LMatrix4f mat = - LMatrix4f::scale_mat(scale) * - LMatrix4f::translate_mat(trans); - - root_arc->set_transition(new TransformTransition(mat)); - - if (_has_color) { - root_arc->set_transition(new ColorTransition(_color)); - } - - // Now flatten out the geometry as much as we can. - SceneGraphReducer reducer; - reducer.apply_transitions(root_arc); - reducer.flatten(root, true); - - if (root->get_num_children(RenderRelation::get_class_type()) == 1) { - // If we ended up with only one child, and no transitions on the - // arc to it, return that child. - NodeRelation *arc = root->get_child(RenderRelation::get_class_type(), 0); - if (!arc->has_any_transition()) { - return arc->get_child(); - } - } - - return root; -} diff --git a/panda/src/grutil/cardMaker.h b/panda/src/grutil/cardMaker.h deleted file mode 100644 index 6f5e3d29cc..0000000000 --- a/panda/src/grutil/cardMaker.h +++ /dev/null @@ -1,70 +0,0 @@ -// Filename: cardMaker.h -// Created by: drose (06Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CARDMAKER_H -#define CARDMAKER_H - -#include "pandabase.h" - -#include "luse.h" -#include "pt_Node.h" - -//////////////////////////////////////////////////////////////////// -// Class : CardMaker -// Description : This class generates 2-d "cards", that is, -// rectangular polygons, particularly useful for showing -// textures etc. in the 2-d scene graph. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA CardMaker { -PUBLISHED: - INLINE CardMaker(); - INLINE ~CardMaker(); - - void reset(); - INLINE void set_uv_range(const TexCoordf &ll, const TexCoordf &ur); - INLINE void set_has_uvs(bool flag); - - INLINE void set_frame(float left, float right, float bottom, float top); - INLINE void set_frame(const LVecBase4f &frame); - - INLINE void set_color(float r, float g, float b, float a); - INLINE void set_color(const Colorf &color); - - INLINE void set_source_geometry(Node *node, const LVecBase4f &frame); - INLINE void clear_source_geometry(); - - PT_Node generate(); - -private: - PT_Node rescale_source_geometry(); - - bool _has_uvs; - TexCoordf _ll, _ur; - LVecBase4f _frame; - - bool _has_color; - Colorf _color; - - PT_Node _source_geometry; - LVecBase4f _source_frame; -}; - -#include "cardMaker.I" - -#endif - diff --git a/panda/src/grutil/grutil_composite1.cxx b/panda/src/grutil/grutil_composite1.cxx index 46910832f9..3eacc9deb0 100644 --- a/panda/src/grutil/grutil_composite1.cxx +++ b/panda/src/grutil/grutil_composite1.cxx @@ -1,8 +1,6 @@ -#include "cardMaker.cxx" #include "qpcardMaker.cxx" #include "config_grutil.cxx" -#include "lineSegs.cxx" #include "qplineSegs.cxx" diff --git a/panda/src/grutil/lineSegs.I b/panda/src/grutil/lineSegs.I deleted file mode 100644 index c9cf8e3701..0000000000 --- a/panda/src/grutil/lineSegs.I +++ /dev/null @@ -1,238 +0,0 @@ -// Filename: lineSegs.I -// Created by: drose (24May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::Point::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE LineSegs::Point:: -Point() { -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::Point::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE LineSegs::Point:: -Point(const LVecBase3f &point, const Colorf &color) : - _point(point[0], point[1], point[2]), - _color(color) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::Point::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE LineSegs::Point:: -Point(const LineSegs::Point ©) : - _point(copy._point), - _color(copy._color) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::Point::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void LineSegs::Point:: -operator = (const LineSegs::Point ©) { - _point = copy._point; - _color = copy._color; -} - - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::set_color -// Access: Public -// Description: Establishes the color that will be assigned to all -// vertices created by future calls to move_to() and -// draw_to(). -//////////////////////////////////////////////////////////////////// -INLINE void LineSegs:: -set_color(float r, float g, float b, float a) { - _color.set(r, g, b, a); -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::set_color -// Access: Public -// Description: Establishes the color that will be assigned to all -// vertices created by future calls to move_to() and -// draw_to(). -//////////////////////////////////////////////////////////////////// -INLINE void LineSegs:: -set_color(const Colorf &color) { - _color = color; -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::set_thickness -// Access: Public -// Description: Establishes the line thickness or point size in -// pixels that will be assigned to all lines and points -// created by future calls to create(). -//////////////////////////////////////////////////////////////////// -INLINE void LineSegs:: -set_thickness(float thick) { - _thick = thick; -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::move_to -// Access: Public -// Description: Moves the pen to the given point without drawing a -// line. When followed by draw_to(), this marks the -// first point of a line segment; when followed by -// move_to() or create(), this creates a single point. -//////////////////////////////////////////////////////////////////// -INLINE void LineSegs:: -move_to(float x, float y, float z) { - move_to(Vertexf(x, y, z)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::draw_to -// Access: Public -// Description: Draws a line segment from the pen's last position -// (the last call to move_to or draw_to) to the -// indicated point. move_to() and draw_to() only update -// tables; the actual drawing is performed when create() -// is called. -//////////////////////////////////////////////////////////////////// -INLINE void LineSegs:: -draw_to(float x, float y, float z) { - draw_to(Vertexf(x, y, z)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::create -// Access: Public -// Description: Creates a new GeomNode that will render the series of -// line segments and points described via calls to -// move_to() and draw_to(). The lines and points are -// created with the color and thickness established by -// calls to set_color() and set_thick(). -// -// If frame_accurate is true, the line segments will be -// created as a frame-accurate index, so that later -// calls to set_vertex or set_vertex_color will be -// visually correct. -//////////////////////////////////////////////////////////////////// -INLINE GeomNode *LineSegs:: -create(bool frame_accurate) { - GeomNode *gnode = new GeomNode; - return create(gnode, frame_accurate); -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::get_num_vertices -// Access: Public -// Description: Returns the total number of line segment and point -// vertices generated by the last call to create(). The -// positions of these vertices may be read and adjusted -// through get_vertex() and set_vertex(). -//////////////////////////////////////////////////////////////////// -INLINE int LineSegs:: -get_num_vertices() const { - return _created_verts.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::get_vertex -// Access: Public -// Description: Returns the nth point or vertex of the line segment -// sequence generated by the last call to create(). The -// first move_to() generates vertex 0; subsequent -// move_to() and draw_to() calls generate consecutively -// higher vertex numbers. -//////////////////////////////////////////////////////////////////// -INLINE Vertexf LineSegs:: -get_vertex(int vertex) const { - nassertr(vertex >= 0 && vertex < (int)_created_verts.size(), - Vertexf(0.0f, 0.0f, 0.0f)); - return _created_verts[vertex]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::set_vertex -// Access: Public -// Description: Moves the nth point or vertex of the line segment -// sequence generated by the last call to create(). The -// first move_to() generates vertex 0; subsequent -// move_to() and draw_to() calls generate consecutively -// higher vertex numbers. -//////////////////////////////////////////////////////////////////// -INLINE void LineSegs:: -set_vertex(int vertex, const Vertexf &vert) { - nassertv(vertex >= 0 && vertex < (int)_created_verts.size()); - _created_verts[vertex] = vert; -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::set_vertex -// Access: Public -// Description: Moves the nth point or vertex of the line segment -// sequence generated by the last call to create(). The -// first move_to() generates vertex 0; subsequent -// move_to() and draw_to() calls generate consecutively -// higher vertex numbers. -//////////////////////////////////////////////////////////////////// -INLINE void LineSegs:: -set_vertex(int vertex, float x, float y, float z) { - set_vertex(vertex, Vertexf(x, y, z)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::get_vertex_color -// Access: Public -// Description: Returns the color of the nth point or vertex/ -//////////////////////////////////////////////////////////////////// -INLINE Colorf LineSegs:: -get_vertex_color(int vertex) const { - nassertr(vertex >= 0 && vertex < (int)_created_colors.size(), - Colorf(0.0f, 0.0f, 0.0f, 0.0f)); - return _created_colors[vertex]; -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::set_vertex_color -// Access: Public -// Description: Changes the vertex color of the nth point or vertex. -// See set_vertex(). -//////////////////////////////////////////////////////////////////// -INLINE void LineSegs:: -set_vertex_color(int vertex, const Colorf &color) { - nassertv(vertex >= 0 && vertex < (int)_created_verts.size()); - _created_colors[vertex] = color; -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::set_vertex_color -// Access: Public -// Description: Changes the vertex color of the nth point or vertex. -// See set_vertex(). -//////////////////////////////////////////////////////////////////// -INLINE void LineSegs:: -set_vertex_color(int vertex, float r, float g, float b, float a) { - set_vertex_color(vertex, Colorf(r, g, b, a)); -} diff --git a/panda/src/grutil/lineSegs.cxx b/panda/src/grutil/lineSegs.cxx deleted file mode 100644 index 740c3bc36e..0000000000 --- a/panda/src/grutil/lineSegs.cxx +++ /dev/null @@ -1,228 +0,0 @@ -// Filename: lineSegs.cxx -// Created by: (24May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "lineSegs.h" - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::Constructor -// Access: Public -// Description: Constructs a LineSegs object, which can be used to -// create any number of disconnected lines or points of -// various thicknesses and colors through the visible -// scene. After creating the object, call move_to() and -// draw_to() repeatedly to describe the path, then call -// create() to create a GeomNode which will render the -// described path. -//////////////////////////////////////////////////////////////////// -LineSegs:: -LineSegs() { - _color.set(1.0f, 1.0f, 1.0f, 1.0f); - _thick = 1.0f; -} - - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::Destructor -// Access: Public -//////////////////////////////////////////////////////////////////// -LineSegs:: -~LineSegs() { -} - - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::reset -// Access: Public -// Description: Removes any lines in progress and resets to the -// initial empty state. -//////////////////////////////////////////////////////////////////// -void LineSegs:: -reset() { - _list.clear(); -} - - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::move_to -// Access: Public -// Description: Moves the pen to the given point without drawing a -// line. When followed by draw_to(), this marks the -// first point of a line segment; when followed by -// move_to() or create(), this creates a single point. -//////////////////////////////////////////////////////////////////// -void LineSegs:: -move_to(const LVecBase3f &v) { - // We create a new SegmentList with the initial point in it. - SegmentList segs; - segs.push_back(Point(v, _color)); - - // And add this list to the list of segments. - _list.push_back(segs); -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::draw_to -// Access: Public -// Description: Draws a line segment from the pen's last position -// (the last call to move_to or draw_to) to the -// indicated point. move_to() and draw_to() only update -// tables; the actual drawing is performed when create() -// is called. -//////////////////////////////////////////////////////////////////// -void LineSegs:: -draw_to(const LVecBase3f &v) { - if (_list.empty()) { - // Let our first call to draw_to() be an implicit move_to(). - move_to(v); - - } else { - // Get the current SegmentList, which was the last one we added to - // the LineList. - SegmentList &segs = _list.back(); - - // Add the new point. - segs.push_back(Point(v, _color)); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::empty -// Access: Public -// Description: Returns true if move_to() or draw_to() have not been -// called since the last reset() or create(), false -// otherwise. -//////////////////////////////////////////////////////////////////// -bool LineSegs:: -is_empty() { - return _list.empty(); -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::get_current_position -// Access: Public -// Description: Returns the pen's current position. The next call to -// draw_to() will draw a line segment from this point. -//////////////////////////////////////////////////////////////////// -const Vertexf &LineSegs:: -get_current_position() { - if (_list.empty()) { - // Our pen isn't anywhere. We'll put it somewhere. - move_to(Vertexf(0.0f, 0.0f, 0.0f)); - } - - return _list.back().back()._point; -} - -//////////////////////////////////////////////////////////////////// -// Function: LineSegs::create -// Access: Public -// Description: Appends to an existing GeomNode a new Geom that -// will render the series of line segments and points -// described via calls to move_to() and draw_to(). The -// lines and points are created with the color and -// thickness established by calls to set_color() and -// set_thick(). -// -// If frame_accurate is true, the line segments will be -// created as a frame-accurate index, so that later -// calls to set_vertex or set_vertex_color will be -// visually correct. -//////////////////////////////////////////////////////////////////// -GeomNode *LineSegs:: -create(GeomNode *previous, bool) { - if (!_list.empty()) { - _created_verts.clear(); - _created_colors.clear(); - - // One array each for the indices into these arrays for points - // and lines, and one for our line-segment lengths array. - PTA_ushort point_index; - PTA_ushort line_index; - PTA_int lengths; - - // Now fill up the arrays. - int v = 0; - LineList::const_iterator ll; - SegmentList::const_iterator sl; - - for (ll = _list.begin(); ll != _list.end(); ll++) { - const SegmentList &segs = (*ll); - - if (segs.size() < 2) { - point_index.push_back(v); - } else { - lengths.push_back(segs.size()); - } - - for (sl = segs.begin(); sl != segs.end(); sl++) { - if (segs.size() >= 2) { - line_index.push_back(v); - } - _created_verts.push_back((*sl)._point); - _created_colors.push_back((*sl)._color); - v++; - nassertr(v == (int)_created_verts.size(), previous); - } - } - - // Now create the lines. - if (line_index.size() > 0) { - // Create a new Geom and add the line segments. - Geom *geom; - if (line_index.size() <= 2) { - // Here's a special case: just one line segment. - GeomLine *geom_line = new GeomLine; - geom_line->set_num_prims(1); - geom_line->set_width(_thick); - geom = geom_line; - - } else { - // The more normal case: multiple line segments, connected - // end-to-end like a series of linestrips. - GeomLinestrip *geom_linestrip = new GeomLinestrip; - geom_linestrip->set_num_prims(lengths.size()); - geom_linestrip->set_lengths(lengths); - geom_linestrip->set_width(_thick); - geom = geom_linestrip; - } - - geom->set_colors(_created_colors, G_PER_VERTEX, line_index); - geom->set_coords(_created_verts, line_index); - - previous->add_geom(geom); - } - - // And now create the points. - if (point_index.size() > 0) { - // Create a new Geom and add the points. - GeomPoint *geom = new GeomPoint; - - geom->set_num_prims(point_index.size()); - geom->set_size(_thick); - geom->set_colors(_created_colors, G_PER_VERTEX, point_index); - geom->set_coords(_created_verts, point_index); - - previous->add_geom(geom); - } - - // And reset for next time. - reset(); - } - - return previous; -} diff --git a/panda/src/grutil/lineSegs.h b/panda/src/grutil/lineSegs.h deleted file mode 100644 index 1061438cdf..0000000000 --- a/panda/src/grutil/lineSegs.h +++ /dev/null @@ -1,99 +0,0 @@ -// Filename: lineSegs.h -// Created by: drose (24May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef LINESEGS_H -#define LINESEGS_H - -#include - -#include -#include -#include -#include -#include -#include - -#include "pvector.h" - -//////////////////////////////////////////////////////////////////// -// Class : LineSegs -// Description : Encapsulates creation of a series of connected or -// disconnected line segments or points, for drawing -// paths or rays. This class doesn't attempt to be the -// smartest it could possibly be; it's intended -// primarily as a visualization and editing tool. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA LineSegs { -PUBLISHED: - LineSegs(); - ~LineSegs(); - - void reset(); - INLINE void set_color(float r, float g, float b, float a = 1.0f); - INLINE void set_color(const Colorf &color); - INLINE void set_thickness(float thick); - - INLINE void move_to(float x, float y, float z); - void move_to(const LVecBase3f &v); - - INLINE void draw_to(float x, float y, float z); - void draw_to(const LVecBase3f &v); - - const Vertexf &get_current_position(); - bool is_empty(); - - INLINE GeomNode *create(bool frame_accurate = false); - GeomNode *create(GeomNode *previous, bool frame_accurate = false); - - // Functions to move the line vertices after they have been created. - INLINE int get_num_vertices() const; - - INLINE Vertexf get_vertex(int vertex) const; - INLINE void set_vertex(int vertex, const Vertexf &vert); - INLINE void set_vertex(int vertex, float x, float y, float z); - - INLINE Colorf get_vertex_color(int vertex) const; - INLINE void set_vertex_color(int vertex, const Colorf &color); - INLINE void set_vertex_color(int vertex, float r, float g, float b, float a = 1.0f); - -private: - class Point { - public: - INLINE Point(); - INLINE Point(const LVecBase3f &point, const Colorf &color); - INLINE Point(const Point ©); - INLINE void operator = (const Point ©); - - Vertexf _point; - Colorf _color; - }; - - typedef pvector SegmentList; - typedef pvector LineList; - - LineList _list; - Colorf _color; - float _thick; - - PTA_Vertexf _created_verts; - PTA_Colorf _created_colors; -}; - -#include "lineSegs.I" - -#endif diff --git a/panda/src/gsgbase/Sources.pp b/panda/src/gsgbase/Sources.pp index 465295302f..35628c83e7 100644 --- a/panda/src/gsgbase/Sources.pp +++ b/panda/src/gsgbase/Sources.pp @@ -4,7 +4,7 @@ #begin lib_target #define TARGET gsgbase #define LOCAL_LIBS \ - putil graph linmath + putil linmath #define COMBINED_SOURCES $[TARGET]_composite1.cxx diff --git a/panda/src/gsgbase/graphicsStateGuardianBase.h b/panda/src/gsgbase/graphicsStateGuardianBase.h index 9189a1c2dd..cd7e8d27c5 100644 --- a/panda/src/gsgbase/graphicsStateGuardianBase.h +++ b/panda/src/gsgbase/graphicsStateGuardianBase.h @@ -22,7 +22,6 @@ #include "pandabase.h" #include "typedReferenceCount.h" -#include "nodeTransitions.h" #include "luse.h" // A handful of forward references. @@ -32,7 +31,7 @@ class GraphicsWindow; class GeomContext; class GeomNodeContext; -class GeomNode; +class qpGeomNode; class Geom; class GeomPoint; class GeomLine; @@ -52,31 +51,6 @@ class RenderState; class TransformState; class Material; -class Fog; - -class TransformTransition; -class ColorMatrixTransition; -class AlphaTransformTransition; -class TexMatrixTransition; -class ColorTransition; -class TextureTransition; -class LightTransition; -class MaterialTransition; -class RenderModeTransition; -class ColorBlendTransition; -class TextureApplyTransition; -class ColorMaskTransition; -class DepthTestTransition; -class DepthWriteTransition; -class TexGenTransition; -class CullFaceTransition; -class StencilTransition; -class ClipPlaneTransition; -class TransparencyTransition; -class FogTransition; -class LinesmoothTransition; -class PointShapeTransition; -class PolygonOffsetTransition; class ColorScaleAttrib; class TexMatrixAttrib; @@ -100,8 +74,6 @@ class LinesmoothAttrib; class PointShapeAttrib; class DepthOffsetAttrib; -class Node; -class GeomNode; class PointLight; class DirectionalLight; class Spotlight; @@ -109,7 +81,6 @@ class AmbientLight; class DisplayRegion; class Lens; -class LensNode; //////////////////////////////////////////////////////////////////// // Class : GraphicsStateGuardianBase @@ -137,8 +108,9 @@ public: virtual void apply_texture(TextureContext *tc)=0; virtual void release_texture(TextureContext *tc)=0; - virtual GeomNodeContext *prepare_geom_node(GeomNode *node)=0; - virtual void draw_geom_node(GeomNode *node, GeomNodeContext *gnc)=0; + virtual GeomNodeContext *prepare_geom_node(qpGeomNode *node)=0; + virtual void draw_geom_node(qpGeomNode *node, const RenderState *state, + GeomNodeContext *gnc)=0; virtual void release_geom_node(GeomNodeContext *gnc)=0; virtual GeomContext *prepare_geom(Geom *geom)=0; @@ -186,9 +158,6 @@ public: virtual void copy_texture(TextureContext *tc, const DisplayRegion *dr)=0; virtual void copy_texture(TextureContext *tc, const DisplayRegion *dr, const RenderBuffer &rb)=0; - virtual void draw_texture(TextureContext *tc, const DisplayRegion *dr)=0; - virtual void draw_texture(TextureContext *tc, const DisplayRegion *dr, - const RenderBuffer &rb)=0; virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb)=0; virtual void texture_to_pixel_buffer(TextureContext *tc, PixelBuffer *pb, @@ -197,38 +166,8 @@ public: virtual void copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr)=0; virtual void copy_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, const RenderBuffer &rb)=0; - virtual void draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, - const NodeTransitions& na=NodeTransitions())=0; - virtual void draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr, - const RenderBuffer &rb, - const NodeTransitions& na=NodeTransitions())=0; virtual void apply_material(const Material *material)=0; - virtual void apply_fog(Fog *fog)=0; - - virtual void issue_transform(const TransformTransition *) { } - virtual void issue_color_transform(const ColorMatrixTransition *) { } - virtual void issue_alpha_transform(const AlphaTransformTransition *) { } - virtual void issue_tex_matrix(const TexMatrixTransition *) { } - virtual void issue_color(const ColorTransition *) { } - virtual void issue_texture(const TextureTransition *) { } - virtual void issue_light(const LightTransition *) { } - virtual void issue_material(const MaterialTransition *) { } - virtual void issue_render_mode(const RenderModeTransition *) { } - virtual void issue_color_blend(const ColorBlendTransition *) { } - virtual void issue_texture_apply(const TextureApplyTransition *) { } - virtual void issue_color_mask(const ColorMaskTransition *) { } - virtual void issue_depth_test(const DepthTestTransition *) { } - virtual void issue_depth_write(const DepthWriteTransition *) { } - virtual void issue_tex_gen(const TexGenTransition *) { } - virtual void issue_cull_face(const CullFaceTransition *) { } - virtual void issue_stencil(const StencilTransition *) { } - virtual void issue_clip_plane(const ClipPlaneTransition *) { } - virtual void issue_transparency(const TransparencyTransition *) { } - virtual void issue_fog(const FogTransition *) { } - virtual void issue_linesmooth(const LinesmoothTransition *) { } - virtual void issue_point_shape(const PointShapeTransition *) { } - virtual void issue_polygon_offset(const PolygonOffsetTransition *) { } virtual void issue_transform(const TransformState *) { } virtual void issue_color_scale(const ColorScaleAttrib *) { } diff --git a/panda/src/gsgmisc/Sources.pp b/panda/src/gsgmisc/Sources.pp index 165c833fb0..ff477d5a1e 100644 --- a/panda/src/gsgmisc/Sources.pp +++ b/panda/src/gsgmisc/Sources.pp @@ -4,7 +4,7 @@ #begin lib_target #define TARGET gsgmisc #define LOCAL_LIBS \ - putil gobj gsgbase graph mathutil + putil gobj gsgbase mathutil #define SOURCES \ geomIssuer.I geomIssuer.cxx geomIssuer.h diff --git a/panda/src/gsgmisc/geomIssuer.h b/panda/src/gsgmisc/geomIssuer.h index 90ee097add..5abd7659c9 100644 --- a/panda/src/gsgmisc/geomIssuer.h +++ b/panda/src/gsgmisc/geomIssuer.h @@ -19,12 +19,11 @@ #ifndef GEOMISSUER_H #define GEOMISSUER_H -#include +#include "pandabase.h" -#include -#include -#include -#include +#include "luse.h" +#include "typedef.h" +#include "geom.h" class GraphicsStateGuardianBase; diff --git a/panda/src/loader/Sources.pp b/panda/src/loader/Sources.pp index 9d52a6b196..79471922b0 100644 --- a/panda/src/loader/Sources.pp +++ b/panda/src/loader/Sources.pp @@ -4,7 +4,7 @@ #begin lib_target #define TARGET loader #define LOCAL_LIBS \ - event pgraph graph ipc putil express downloader + event pgraph ipc putil express downloader #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx @@ -12,19 +12,16 @@ bamFile.I bamFile.h config_loader.h loader.I loader.h \ loaderFileType.h loaderFileTypeBam.h \ loaderFileTypeRegistry.h \ - modelPool.I modelPool.h \ qpmodelPool.I qpmodelPool.h #define INCLUDED_SOURCES \ bamFile.cxx config_loader.cxx loader.cxx loaderFileType.cxx \ loaderFileTypeBam.cxx loaderFileTypeRegistry.cxx \ - modelPool.cxx \ qpmodelPool.cxx #define INSTALL_HEADERS \ bamFile.I bamFile.h loader.I loader.h loaderFileType.h \ loaderFileTypeBam.h loaderFileTypeRegistry.h \ - modelPool.I modelPool.h \ qpmodelPool.I qpmodelPool.h #define IGATESCAN all diff --git a/panda/src/loader/bamFile.h b/panda/src/loader/bamFile.h index 090227f8af..66e3c495c9 100644 --- a/panda/src/loader/bamFile.h +++ b/panda/src/loader/bamFile.h @@ -19,10 +19,10 @@ #ifndef BAMFILE_H #define BAMFILE_H -#include +#include "pandabase.h" -#include -#include +#include "datagramInputFile.h" +#include "datagramOutputFile.h" class BamReader; class BamWriter; diff --git a/panda/src/loader/loader.I b/panda/src/loader/loader.I index 39ec5e0fb1..193162a5b4 100644 --- a/panda/src/loader/loader.I +++ b/panda/src/loader/loader.I @@ -16,18 +16,6 @@ // //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function: Loader::load_sync -// Access: Public -// Description: Loads the file immediately, waiting for it to complete. -//////////////////////////////////////////////////////////////////// -INLINE PT_Node Loader:: -load_sync(const Filename &filename) const { - if (!_file_types_loaded) { - load_file_types(); - } - return load_file(filename); -} //////////////////////////////////////////////////////////////////// // Function: Loader::load_sync diff --git a/panda/src/loader/loader.cxx b/panda/src/loader/loader.cxx index 2ad5d39bd4..a4a2d98da9 100644 --- a/panda/src/loader/loader.cxx +++ b/panda/src/loader/loader.cxx @@ -15,6 +15,7 @@ // panda3d@yahoogroups.com . // //////////////////////////////////////////////////////////////////// + #include "loader.h" #include "loaderFileType.h" #include "loaderFileTypeRegistry.h" @@ -44,14 +45,14 @@ bool Loader::_file_types_loaded = false; class LoaderToken : public ReferenceCount { public: INLINE LoaderToken(uint id, Filename path, const string &event_name, - PT_Node node=NULL) : _id(id), _node(node) { + PandaNode *node=NULL) : _id(id), _node(node) { _path = path; _event_name = event_name; } uint _id; Filename _path; string _event_name; - PT_Node _node; + PT(PandaNode) _node; }; //////////////////////////////////////////////////////////////////// @@ -205,7 +206,7 @@ check_load(uint id) { // number (returned by a previous call to request_load), // or NULL if the request has not yet completed. //////////////////////////////////////////////////////////////////// -PT_Node Loader:: +PT(PandaNode) Loader:: fetch_load(uint id) { PT(LoaderToken) tok = _token_board->get_done_token(id); if (tok.is_null()) { @@ -213,7 +214,7 @@ fetch_load(uint id) { << "Request to fetch id " << id << " which has not yet completed.\n"; return NULL; } - PT_Node node = tok->_node; + PT(PandaNode) node = tok->_node; return node; } @@ -264,7 +265,7 @@ process_request() { while (!_token_board->_waiting.empty()) { PT(LoaderToken) tok = _token_board->_waiting.front(); _token_board->_waiting.pop_front(); - tok->_node = load_file(tok->_path); + tok->_node = qpload_file(tok->_path); if (tok->_node == NULL) { loader_cat.error() << "Loader::callback() - couldn't find file: " @@ -289,51 +290,6 @@ process_request() { return true; } -//////////////////////////////////////////////////////////////////// -// Function: Loader::load_file -// Access: Private -// Description: Loads a single scene graph file, if possible. -// Returns the Node that is the root of the file, or -// NULL if the file cannot be loaded. -//////////////////////////////////////////////////////////////////// -PT_Node Loader:: -load_file(const Filename &filename) const { - string extension = filename.get_extension(); - - if (extension.empty()) { - return load_unknown_file_type(filename); - } - - LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_ptr(); - LoaderFileType *requested_type = - reg->get_type_from_extension(extension); - - if (requested_type == (LoaderFileType *)NULL) { - loader_cat.error() - << "Extension of file " << filename - << " is unrecognized; cannot load.\n"; - loader_cat.error(false) - << "Currently known scene file types are:\n"; - reg->write_types(loader_cat.error(false), 2); - return NULL; - } - - Filename requested_filename = filename; - if (!requested_filename.is_fully_qualified()) { - // Ask the loader type to look for the file along its paths. - requested_type->resolve_filename(requested_filename); - } - - if (loader_cat.is_debug()) { - loader_cat.debug() - << "Loading " << requested_type->get_name() << " file: " - << requested_filename << "\n"; - } - - PT_Node result = requested_type->load_file(requested_filename, true); - return result; -} - //////////////////////////////////////////////////////////////////// // Function: Loader::load_file // Access: Private @@ -389,95 +345,6 @@ public: } }; - -//////////////////////////////////////////////////////////////////// -// Function: Loader::load_unknown_file_type -// Access: Private -// Description: Attempts to guess which file is meant when a file -// with no extension is given. Looks around for a file -// with a suitable extension for each of our known file -// types, and loads the most recent file available of -// any file type. -//////////////////////////////////////////////////////////////////// -PT_Node Loader:: -load_unknown_file_type(const Filename &filename) const { - typedef pvector Files; - Files files; - - // First, build up a list of all of the possible files it could be. - LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_ptr(); - int num_types = reg->get_num_types(); - - if (num_types == 0) { - loader_cat.error() - << "Can't load file " << filename - << "; no scene file types are known.\n"; - return (Node *)NULL; - } - - for (int i = 0; i < num_types; i++) { - LoaderConsiderFile consider; - consider._type = reg->get_type(i); - consider._path = filename; - consider._path.set_extension(consider._type->get_extension()); - - if (!consider._path.is_fully_qualified()) { - // Ask the loader type to look for the file along its paths. - consider._type->resolve_filename(consider._path); - } - - if (consider._path.exists()) { - files.push_back(consider); - } - } - - if (files.empty()) { - loader_cat.error() - << "Couldn't find file " << filename << " as:\n"; - for (int i = 0; i < num_types; i++) { - Filename p = filename; - p.set_extension(reg->get_type(i)->get_extension()); - loader_cat.error(false) - << " " << p << "\n"; - } - return (Node *)NULL; - } - - // Now sort the list into order by timestamp, from newest to oldest. - sort(files.begin(), files.end()); - - // And try to load each file one at a time. - Files::const_iterator fi; - - if (loader_cat.is_debug()) { - loader_cat.debug() - << "Loading " << filename << ", one of " << files.size() - << " possible types:\n"; - for (fi = files.begin(); fi != files.end(); ++fi) { - loader_cat.debug(false) - << " " << (*fi)._path << "\n"; - } - } - - for (fi = files.begin(); fi != files.end(); ++fi) { - const LoaderConsiderFile &consider = (*fi); - PT_Node result = consider._type->load_file(consider._path, false); - if (result != (Node *)NULL) { - return result; - } - if (loader_cat.is_debug()) { - loader_cat.debug() - << "Couldn't read " << consider._type->get_name() - << " file " << consider._path << "\n"; - } - } - - loader_cat.error() - << "Cannot read " << files.front()._path << "\n"; - - return (Node *)NULL; -} - //////////////////////////////////////////////////////////////////// // Function: Loader::load_unknown_file_type // Access: Private diff --git a/panda/src/loader/loader.h b/panda/src/loader/loader.h index f5af97c5fa..ff24b7d980 100644 --- a/panda/src/loader/loader.h +++ b/panda/src/loader/loader.h @@ -21,8 +21,6 @@ #include "pandabase.h" #include "notify.h" -#include "node.h" -#include "pt_Node.h" #include "pandaNode.h" #include "filename.h" #include "tokenBoard.h" @@ -42,20 +40,17 @@ PUBLISHED: void resolve_filename(Filename &filename) const; - INLINE PT_Node load_sync(const Filename &filename) const; INLINE PT(PandaNode) qpload_sync(const Filename &filename) const; uint request_load(const Filename &filename, const string &event_name); bool check_load(uint id); - PT_Node fetch_load(uint id); + PT(PandaNode) fetch_load(uint id); private: static void load_file_types(); static bool _file_types_loaded; virtual bool process_request(void); - PT_Node load_file(const Filename &filename) const; - PT_Node load_unknown_file_type(const Filename &filename) const; PT(PandaNode) qpload_file(const Filename &filename) const; PT(PandaNode) qpload_unknown_file_type(const Filename &filename) const; void resolve_unknown_file_type(Filename &filename) const; diff --git a/panda/src/loader/loaderFileType.cxx b/panda/src/loader/loaderFileType.cxx index 6ed0a7bf57..d600ad435a 100644 --- a/panda/src/loader/loaderFileType.cxx +++ b/panda/src/loader/loaderFileType.cxx @@ -58,8 +58,7 @@ resolve_filename(Filename &) const { // Description: //////////////////////////////////////////////////////////////////// PT(PandaNode) LoaderFileType:: -qpload_file(const Filename &path, bool report_errors) const -{ +qpload_file(const Filename &path, bool report_errors) const { loader_cat.error() << get_type() << " cannot read PandaNode objects.\n"; return NULL; diff --git a/panda/src/loader/loaderFileType.h b/panda/src/loader/loaderFileType.h index 5e3a56a333..7957898913 100644 --- a/panda/src/loader/loaderFileType.h +++ b/panda/src/loader/loaderFileType.h @@ -22,8 +22,6 @@ #include "pandabase.h" #include "typedObject.h" -#include "node.h" -#include "pt_Node.h" #include "filename.h" #include "pandaNode.h" #include "pointerTo.h" @@ -46,7 +44,6 @@ public: virtual string get_extension() const=0; virtual void resolve_filename(Filename &path) const; - virtual PT_Node load_file(const Filename &path, bool report_errors) const=0; virtual PT(PandaNode) qpload_file(const Filename &path, bool report_errors) const; public: diff --git a/panda/src/loader/loaderFileTypeBam.cxx b/panda/src/loader/loaderFileTypeBam.cxx index 3276a10b44..2347f0f9aa 100644 --- a/panda/src/loader/loaderFileTypeBam.cxx +++ b/panda/src/loader/loaderFileTypeBam.cxx @@ -20,8 +20,8 @@ #include "config_loader.h" #include "bamFile.h" -#include -#include +#include "config_util.h" +#include "dcast.h" TypeHandle LoaderFileTypeBam::_type_handle; @@ -70,57 +70,6 @@ resolve_filename(Filename &path) const { path.resolve_filename(get_model_path()); } -//////////////////////////////////////////////////////////////////// -// Function: LoaderFileTypeBam::load_file -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -PT_Node LoaderFileTypeBam:: -load_file(const Filename &path, bool report_errors) const -{ - BamFile bam_file; - if (!bam_file.open_read(path, report_errors)) { - return NULL; - } - - PT_Node result; - - TypedWritable *object = bam_file.read_object(); - if (object == TypedWritable::Null) { - if (report_errors) { - loader_cat.error() << "Bam file " << path << " is empty.\n"; - } - - } else if (!object->is_of_type(Node::get_class_type())) { - if (report_errors) { - loader_cat.error() - << "Bam file " << path - << " contains a " << object->get_type() << ", not a Node.\n"; - } - - } else { - result = DCAST(Node, object); - - if (report_errors) { - bam_file.read_object(); - if (!bam_file.is_eof()) { - loader_cat.warning() - << "Ignoring extra objects in " << path << "\n"; - } - } - } - - if (!bam_file.resolve()) { - if (report_errors) { - loader_cat.error() - << "Unable to resolve Bam file.\n"; - result = (Node *)NULL; - } - } - - return result; -} - //////////////////////////////////////////////////////////////////// // Function: LoaderFileTypeBam::load_file // Access: Public, Virtual diff --git a/panda/src/loader/loaderFileTypeBam.h b/panda/src/loader/loaderFileTypeBam.h index f53f6677ea..90f4324099 100644 --- a/panda/src/loader/loaderFileTypeBam.h +++ b/panda/src/loader/loaderFileTypeBam.h @@ -35,7 +35,6 @@ public: virtual string get_extension() const; virtual void resolve_filename(Filename &path) const; - virtual PT_Node load_file(const Filename &path, bool report_errors) const; virtual PT(PandaNode) qpload_file(const Filename &path, bool report_errors) const; public: diff --git a/panda/src/loader/loader_composite2.cxx b/panda/src/loader/loader_composite2.cxx index bf20d95997..11086251a3 100644 --- a/panda/src/loader/loader_composite2.cxx +++ b/panda/src/loader/loader_composite2.cxx @@ -1,5 +1,4 @@ -#include "modelPool.cxx" #include "qpmodelPool.cxx" #include "loaderFileType.cxx" #include "loaderFileTypeBam.cxx" diff --git a/panda/src/loader/modelPool.I b/panda/src/loader/modelPool.I deleted file mode 100644 index ec6ebd1ae9..0000000000 --- a/panda/src/loader/modelPool.I +++ /dev/null @@ -1,130 +0,0 @@ -// Filename: modelPool.I -// Created by: drose (25Aug00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: ModelPool::has_model -// Access: Public, Static -// Description: Returns true if the model has ever been loaded, -// false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool ModelPool:: -has_model(const string &filename) { - return get_ptr()->ns_has_model(filename); -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelPool::verify_model -// Access: Public, Static -// Description: Loads the given filename up as a model, if it has -// not already been loaded, and returns true to indicate -// success, or false to indicate failure. If this -// returns true, it is guaranteed that a subsequent call -// to load_model() with the same model name will -// return a valid Node pointer. -//////////////////////////////////////////////////////////////////// -INLINE bool ModelPool:: -verify_model(const string &filename) { - return load_model(filename) != (Node *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelPool::load_model -// Access: Public, Static -// Description: Loads the given filename up as a model, if it has -// not already been loaded, and returns the new model. -// If a model with the same filename was previously -// loaded, returns that one instead. If the model -// file cannot be found, returns NULL. -//////////////////////////////////////////////////////////////////// -INLINE PT_Node ModelPool:: -load_model(const string &filename) { - return get_ptr()->ns_load_model(filename); -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelPool::add_model -// Access: Public, Static -// Description: Adds the indicated already-loaded model to the -// pool. The model will always replace any -// previously-loaded model in the pool that had the -// same filename. -//////////////////////////////////////////////////////////////////// -INLINE void ModelPool:: -add_model(const string &filename, Node *model) { - get_ptr()->ns_add_model(filename, model); -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelPool::release_model -// Access: Public, Static -// Description: Removes the indicated model from the pool, -// indicating it will never be loaded again; the model -// may then be freed. If this function is never called, -// a reference count will be maintained on every model -// every loaded, and models will never be freed. -//////////////////////////////////////////////////////////////////// -INLINE void ModelPool:: -release_model(const string &filename) { - get_ptr()->ns_release_model(filename); -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelPool::release_all_models -// Access: Public, Static -// Description: Releases all models in the pool and restores the -// pool to the empty state. -//////////////////////////////////////////////////////////////////// -INLINE void ModelPool:: -release_all_models() { - get_ptr()->ns_release_all_models(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelPool::garbage_collect -// Access: Public, Static -// Description: Releases only those models in the pool that have a -// reference count of exactly 1; i.e. only those -// models that are not being used outside of the pool. -// Returns the number of models released. -//////////////////////////////////////////////////////////////////// -INLINE int ModelPool:: -garbage_collect() { - return get_ptr()->ns_garbage_collect(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelPool::list_contents -// Access: Public, Static -// Description: Lists the contents of the model pool to the -// indicated output stream. -//////////////////////////////////////////////////////////////////// -INLINE void ModelPool:: -list_contents(ostream &out) { - get_ptr()->ns_list_contents(out); -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelPool::Constructor -// Access: Private -// Description: The constructor is not intended to be called -// directly; there's only supposed to be one ModelPool -// in the universe and it constructs itself. -//////////////////////////////////////////////////////////////////// -INLINE ModelPool:: -ModelPool() { -} diff --git a/panda/src/loader/modelPool.cxx b/panda/src/loader/modelPool.cxx deleted file mode 100644 index 8fc77fd9e1..0000000000 --- a/panda/src/loader/modelPool.cxx +++ /dev/null @@ -1,161 +0,0 @@ -// Filename: modelPool.cxx -// Created by: drose (25Aug00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "modelPool.h" -#include "loader.h" -#include "config_loader.h" - - -ModelPool *ModelPool::_global_ptr = (ModelPool *)NULL; - -static Loader _model_loader; - -//////////////////////////////////////////////////////////////////// -// Function: ModelPool::ns_has_model -// Access: Private -// Description: The nonstatic implementation of has_model(). -//////////////////////////////////////////////////////////////////// -bool ModelPool:: -ns_has_model(const string &filename) { - Models::const_iterator ti; - ti = _models.find(filename); - if (ti != _models.end()) { - // This model was previously loaded. - return true; - } - - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelPool::ns_load_model -// Access: Private -// Description: The nonstatic implementation of load_model(). -//////////////////////////////////////////////////////////////////// -PT_Node ModelPool:: -ns_load_model(const string &filename) { - Models::const_iterator ti; - ti = _models.find(filename); - if (ti != _models.end()) { - // This model was previously loaded. - return (*ti).second; - } - - loader_cat.info() - << "Loading model " << filename << "\n"; - PT(Node) node = _model_loader.load_sync(filename); - if (node.is_null()) { - // This model was not found. - return (Node *)NULL; - } - - _models[filename] = node; - return node; -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelPool::ns_add_model -// Access: Private -// Description: The nonstatic implementation of add_model(). -//////////////////////////////////////////////////////////////////// -void ModelPool:: -ns_add_model(const string &filename, Node *model) { - // We blow away whatever model was there previously, if any. - _models[filename] = model; -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelPool::ns_release_model -// Access: Private -// Description: The nonstatic implementation of release_model(). -//////////////////////////////////////////////////////////////////// -void ModelPool:: -ns_release_model(const string &filename) { - Models::iterator ti; - ti = _models.find(filename); - if (ti != _models.end()) { - _models.erase(ti); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelPool::ns_release_all_models -// Access: Private -// Description: The nonstatic implementation of release_all_models(). -//////////////////////////////////////////////////////////////////// -void ModelPool:: -ns_release_all_models() { - _models.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelPool::ns_garbage_collect -// Access: Private -// Description: The nonstatic implementation of garbage_collect(). -//////////////////////////////////////////////////////////////////// -int ModelPool:: -ns_garbage_collect() { - int num_released = 0; - Models new_set; - - Models::iterator ti; - for (ti = _models.begin(); ti != _models.end(); ++ti) { - Node *node = (*ti).second; - if (node->get_ref_count() == 1) { - if (loader_cat.is_debug()) { - loader_cat.debug() - << "Releasing " << (*ti).first << "\n"; - } - num_released++; - } else { - new_set.insert(new_set.end(), *ti); - } - } - - _models.swap(new_set); - return num_released; -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelPool::ns_list_contents -// Access: Private -// Description: The nonstatic implementation of list_contents(). -//////////////////////////////////////////////////////////////////// -void ModelPool:: -ns_list_contents(ostream &out) { - out << _models.size() << " models:\n"; - Models::iterator ti; - for (ti = _models.begin(); ti != _models.end(); ++ti) { - out << " " << (*ti).first - << " (count = " << (*ti).second->get_ref_count() << ")\n"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelPool::get_ptr -// Access: Private, Static -// Description: Initializes and/or returns the global pointer to the -// one ModelPool object in the system. -//////////////////////////////////////////////////////////////////// -ModelPool *ModelPool:: -get_ptr() { - if (_global_ptr == (ModelPool *)NULL) { - _global_ptr = new ModelPool; - } - return _global_ptr; -} diff --git a/panda/src/loader/modelPool.h b/panda/src/loader/modelPool.h deleted file mode 100644 index 6e00e732c0..0000000000 --- a/panda/src/loader/modelPool.h +++ /dev/null @@ -1,84 +0,0 @@ -// Filename: modelPool.h -// Created by: drose (25Aug00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef MODELPOOL_H -#define MODELPOOL_H - -#include - -#include -#include - -#include "pmap.h" - -//////////////////////////////////////////////////////////////////// -// Class : ModelPool -// Description : This is the preferred interface for loading models. -// It unifies all references to the same filename, so -// that multiple attempts to load the same model will -// return the same pointer. Note that the default -// behavior is thus to make instances: use with caution. -// Use the copy_subgraph() method on Node (or use -// NodePath::copy_to) to make modifiable copies of the -// node. -// -// Unlike TexturePool, this class does not automatically -// resolve the model filenames before loading, so a -// relative path and an absolute path to the same model -// will appear to be different filenames. -// -// This does not presently support asynchronous loading, -// although it wouldn't be *too* difficult to add. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ModelPool { -PUBLISHED: - INLINE static bool has_model(const string &filename); - INLINE static bool verify_model(const string &filename); - INLINE static PT_Node load_model(const string &filename); - - INLINE static void add_model(const string &filename, Node *model); - INLINE static void release_model(const string &filename); - INLINE static void release_all_models(); - - INLINE static int garbage_collect(); - - INLINE static void list_contents(ostream &out); - -private: - INLINE ModelPool(); - - bool ns_has_model(const string &filename); - PT_Node ns_load_model(const string &filename); - void ns_add_model(const string &filename, Node *model); - void ns_release_model(const string &filename); - void ns_release_all_models(); - int ns_garbage_collect(); - void ns_list_contents(ostream &out); - - static ModelPool *get_ptr(); - - static ModelPool *_global_ptr; - typedef pmap Models; - Models _models; -}; - -#include "modelPool.I" - -#endif - - diff --git a/panda/src/parametrics/Sources.pp b/panda/src/parametrics/Sources.pp index f02c733057..491f2d4951 100644 --- a/panda/src/parametrics/Sources.pp +++ b/panda/src/parametrics/Sources.pp @@ -6,7 +6,7 @@ #begin lib_target #define TARGET parametrics #define LOCAL_LIBS \ - pgraph grutil sgattrib linmath express putil pandabase + pgraph grutil linmath express putil pandabase #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx diff --git a/panda/src/parametrics/parametricCurve.cxx b/panda/src/parametrics/parametricCurve.cxx index 9e44749a17..2920a2186d 100644 --- a/panda/src/parametrics/parametricCurve.cxx +++ b/panda/src/parametrics/parametricCurve.cxx @@ -22,12 +22,11 @@ #include "classicNurbsCurve.h" #include "parametricCurveDrawer.h" -#include -#include -#include -#include -#include -#include +#include "datagram.h" +#include "datagramIterator.h" +#include "bamWriter.h" +#include "bamReader.h" +#include "omniBoundingVolume.h" TypeHandle ParametricCurve::_type_handle; diff --git a/panda/src/parametrics/parametricCurveCollection.cxx b/panda/src/parametrics/parametricCurveCollection.cxx index 0b2b589849..8f062563ea 100644 --- a/panda/src/parametrics/parametricCurveCollection.cxx +++ b/panda/src/parametrics/parametricCurveCollection.cxx @@ -22,11 +22,10 @@ #include "parametricCurveDrawer.h" #include "nurbsCurve.h" -#include -#include -#include -#include -#include +#include "indent.h" +#include "compose_matrix.h" +#include "string_utils.h" +#include "look_at.h" //////////////////////////////////////////////////////////////////// // Function: ParametricCurveCollection::Constructor diff --git a/panda/src/particlesystem/Sources.pp b/panda/src/particlesystem/Sources.pp index bbe4b02f89..6180b89043 100644 --- a/panda/src/particlesystem/Sources.pp +++ b/panda/src/particlesystem/Sources.pp @@ -4,7 +4,7 @@ #begin lib_target #define TARGET particlesystem #define LOCAL_LIBS \ - sgmanip physics sgraph sgattrib graph sgraphutil + pgraph physics #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx diff --git a/panda/src/particlesystem/geomParticleRenderer.h b/panda/src/particlesystem/geomParticleRenderer.h index e98d7e2182..653f543082 100644 --- a/panda/src/particlesystem/geomParticleRenderer.h +++ b/panda/src/particlesystem/geomParticleRenderer.h @@ -22,10 +22,9 @@ #include "baseParticleRenderer.h" #include "baseParticle.h" -#include -#include -#include -#include +#include "pandaNode.h" +#include "pointerTo.h" +#include "pointerToArray.h" #include "pvector.h" diff --git a/panda/src/particlesystem/orientedParticle.h b/panda/src/particlesystem/orientedParticle.h index 51b74406f5..080fed3b6c 100644 --- a/panda/src/particlesystem/orientedParticle.h +++ b/panda/src/particlesystem/orientedParticle.h @@ -21,8 +21,6 @@ #include "baseParticle.h" -#include - /////////////////////////////////////////////////////////////////// // Class : OrientedParticle // Description : Describes a particle that has angular diff --git a/panda/src/particlesystem/spriteParticleRenderer.cxx b/panda/src/particlesystem/spriteParticleRenderer.cxx index 931ee68326..ab2f8cc1c3 100644 --- a/panda/src/particlesystem/spriteParticleRenderer.cxx +++ b/panda/src/particlesystem/spriteParticleRenderer.cxx @@ -16,11 +16,12 @@ // //////////////////////////////////////////////////////////////////// +#include "spriteParticleRenderer.h" + #include "boundingSphere.h" #include "geom.h" #include "qpnodePath.h" - -#include "spriteParticleRenderer.h" +#include "dcast.h" //////////////////////////////////////////////////////////////////// // Function : SpriteParticleRenderer::SpriteParticleRenderer diff --git a/panda/src/pgraph/Sources.pp b/panda/src/pgraph/Sources.pp index ca9964dd7e..f4ba6bcf50 100644 --- a/panda/src/pgraph/Sources.pp +++ b/panda/src/pgraph/Sources.pp @@ -1,6 +1,6 @@ #define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \ dtoolutil:c dtoolbase:c dtool:m -#define LOCAL_LIBS lerp event gsgbase gobj putil graph linmath express pandabase +#define LOCAL_LIBS lerp event gsgbase gobj putil linmath express pandabase #begin lib_target #define TARGET pgraph @@ -59,6 +59,7 @@ renderEffects.I renderEffects.h \ renderModeAttrib.I renderModeAttrib.h \ renderState.I renderState.h \ + sceneGraphAnalyzer.h \ qpsceneGraphReducer.I qpsceneGraphReducer.h \ sceneSetup.I sceneSetup.h \ selectiveChildNode.I selectiveChildNode.h \ @@ -128,6 +129,7 @@ renderEffects.cxx \ renderModeAttrib.cxx \ renderState.cxx \ + sceneGraphAnalyzer.cxx \ qpsceneGraphReducer.cxx \ sceneSetup.cxx \ selectiveChildNode.cxx \ @@ -199,6 +201,7 @@ renderEffects.I renderEffects.h \ renderModeAttrib.I renderModeAttrib.h \ renderState.I renderState.h \ + sceneGraphAnalyzer.h \ qpsceneGraphReducer.I qpsceneGraphReducer.h \ sceneSetup.I sceneSetup.h \ selectiveChildNode.I selectiveChildNode.h \ diff --git a/panda/src/pgraph/cullFaceAttrib.h b/panda/src/pgraph/cullFaceAttrib.h index b7a83b1cc3..d5b8d29d3c 100644 --- a/panda/src/pgraph/cullFaceAttrib.h +++ b/panda/src/pgraph/cullFaceAttrib.h @@ -40,7 +40,7 @@ private: INLINE CullFaceAttrib(Mode mode = M_cull_clockwise); PUBLISHED: - static CPT(RenderAttrib) make(Mode mode); + static CPT(RenderAttrib) make(Mode mode = M_cull_clockwise); INLINE Mode get_mode() const; diff --git a/panda/src/pgraph/pandaNode.I b/panda/src/pgraph/pandaNode.I index d53bf6ce57..e98d4ebeca 100644 --- a/panda/src/pgraph/pandaNode.I +++ b/panda/src/pgraph/pandaNode.I @@ -624,6 +624,7 @@ set_transform(const TransformState *transform) { CDWriter cdata(_cycler); cdata->_transform = transform; mark_bound_stale(); + transform_changed(); } //////////////////////////////////////////////////////////////////// @@ -650,6 +651,8 @@ INLINE void PandaNode:: clear_transform() { CDWriter cdata(_cycler); cdata->_transform = TransformState::make_identity(); + mark_bound_stale(); + transform_changed(); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pgraph/pandaNode.cxx b/panda/src/pgraph/pandaNode.cxx index 602a938b55..88de25c570 100644 --- a/panda/src/pgraph/pandaNode.cxx +++ b/panda/src/pgraph/pandaNode.cxx @@ -1286,6 +1286,17 @@ void PandaNode:: children_changed() { } +//////////////////////////////////////////////////////////////////// +// Function: PandaNode::transform_changed +// Access: Protected, Virtual +// Description: Called after the node's transform has been changed +// for any reason, this just provides a hook so derived +// classes can do something special in this case. +//////////////////////////////////////////////////////////////////// +void PandaNode:: +transform_changed() { +} + //////////////////////////////////////////////////////////////////// // Function: PandaNode::r_copy_subgraph // Access: Protected, Virtual diff --git a/panda/src/pgraph/pandaNode.h b/panda/src/pgraph/pandaNode.h index dfb613f2a8..117027ad92 100644 --- a/panda/src/pgraph/pandaNode.h +++ b/panda/src/pgraph/pandaNode.h @@ -176,6 +176,7 @@ protected: INLINE void changed_internal_bound(); virtual void parents_changed(); virtual void children_changed(); + virtual void transform_changed(); INLINE void add_net_collide_mask(CollideMask mask); typedef pmap InstanceMap; diff --git a/panda/src/pgraph/pgraph_composite2.cxx b/panda/src/pgraph/pgraph_composite2.cxx index 843dbf7691..d6597886c3 100644 --- a/panda/src/pgraph/pgraph_composite2.cxx +++ b/panda/src/pgraph/pgraph_composite2.cxx @@ -17,6 +17,7 @@ #include "renderEffects.cxx" #include "renderModeAttrib.cxx" #include "renderState.cxx" +#include "sceneGraphAnalyzer.cxx" #include "qpsceneGraphReducer.cxx" #include "selectiveChildNode.cxx" #include "qpsequenceNode.cxx" diff --git a/panda/src/pgraph/qpnodePath.cxx b/panda/src/pgraph/qpnodePath.cxx index 357c5c19e7..f3064fa77b 100644 --- a/panda/src/pgraph/qpnodePath.cxx +++ b/panda/src/pgraph/qpnodePath.cxx @@ -45,6 +45,7 @@ #include "textureCollection.h" #include "globPattern.h" #include "config_gobj.h" +#include "dcast.h" // stack seems to overflow on Intel C++ at 7000. If we need more than // 7000, need to increase stack size. diff --git a/panda/src/pgraph/renderState.cxx b/panda/src/pgraph/renderState.cxx index 4fffbfd61a..4f474bd0b0 100644 --- a/panda/src/pgraph/renderState.cxx +++ b/panda/src/pgraph/renderState.cxx @@ -280,7 +280,7 @@ make(const RenderAttrib *attrib1, const RenderAttrib *attrib2, const RenderAttrib *attrib3, int override) { RenderState *state = new RenderState; - state->_attributes.reserve(2); + state->_attributes.reserve(3); state->_attributes.push_back(Attribute(attrib1, override)); state->_attributes.push_back(Attribute(attrib2, override)); state->_attributes.push_back(Attribute(attrib3, override)); @@ -299,7 +299,7 @@ make(const RenderAttrib *attrib1, const RenderAttrib *attrib3, const RenderAttrib *attrib4, int override) { RenderState *state = new RenderState; - state->_attributes.reserve(2); + state->_attributes.reserve(4); state->_attributes.push_back(Attribute(attrib1, override)); state->_attributes.push_back(Attribute(attrib2, override)); state->_attributes.push_back(Attribute(attrib3, override)); @@ -308,6 +308,21 @@ make(const RenderAttrib *attrib1, return return_new(state); } +//////////////////////////////////////////////////////////////////// +// Function: RenderState::make +// Access: Published, Static +// Description: Returns a RenderState with n attributes set. +//////////////////////////////////////////////////////////////////// +CPT(RenderState) RenderState:: +make(const RenderAttrib * const *attrib, int num_attribs, int override) { + RenderState *state = new RenderState; + state->_attributes.reserve(num_attribs); + for (int i = 0; i < num_attribs; i++) { + state->_attributes.push_back(Attribute(attrib[i], override)); + } + return return_new(state); +} + //////////////////////////////////////////////////////////////////// // Function: RenderState::compose // Access: Published diff --git a/panda/src/pgraph/renderState.h b/panda/src/pgraph/renderState.h index 2c25b329e7..3a8118620c 100644 --- a/panda/src/pgraph/renderState.h +++ b/panda/src/pgraph/renderState.h @@ -75,6 +75,8 @@ PUBLISHED: const RenderAttrib *attrib2, const RenderAttrib *attrib3, const RenderAttrib *attrib4, int override = 0); + static CPT(RenderState) make(const RenderAttrib * const *attrib, + int num_attribs, int override = 0); CPT(RenderState) compose(const RenderState *other) const; CPT(RenderState) invert_compose(const RenderState *other) const; diff --git a/panda/src/sgraphutil/sceneGraphAnalyzer.cxx b/panda/src/pgraph/sceneGraphAnalyzer.cxx similarity index 83% rename from panda/src/sgraphutil/sceneGraphAnalyzer.cxx rename to panda/src/pgraph/sceneGraphAnalyzer.cxx index 1938fc8753..7822d6b02d 100644 --- a/panda/src/sgraphutil/sceneGraphAnalyzer.cxx +++ b/panda/src/pgraph/sceneGraphAnalyzer.cxx @@ -17,14 +17,15 @@ //////////////////////////////////////////////////////////////////// #include "sceneGraphAnalyzer.h" -#include "config_sgraphutil.h" +#include "config_pgraph.h" -#include -#include -#include -#include -#include -#include +#include "indent.h" +#include "qpgeomNode.h" +#include "geom.h" +#include "geomprimitives.h" +#include "transformState.h" +#include "textureAttrib.h" +#include "pta_ushort.h" //////////////////////////////////////////////////////////////////// // Function: SceneGraphAnalyzer::Constructor @@ -32,9 +33,7 @@ // Description: //////////////////////////////////////////////////////////////////// SceneGraphAnalyzer:: -SceneGraphAnalyzer(TypeHandle graph_type) : - _graph_type(graph_type) -{ +SceneGraphAnalyzer() { clear(); } @@ -61,11 +60,9 @@ clear() { _num_nodes = 0; _num_instances = 0; _num_transforms = 0; - _num_arcs = 0; - _num_arcs_with_transitions = 0; + _num_nodes_with_attribs = 0; _num_geom_nodes = 0; _num_geoms = 0; - _num_non_geoms = 0; _num_vertices = 0; _num_normals = 0; @@ -100,7 +97,7 @@ clear() { // all the graphs together. //////////////////////////////////////////////////////////////////// void SceneGraphAnalyzer:: -add_node(Node *node) { +add_node(PandaNode *node) { collect_statistics(node, false); } @@ -118,18 +115,14 @@ write(ostream &out, int indent_level) const { indent(out, indent_level) << _num_transforms << " transforms"; - if (_num_arcs != 0) { - out << "; " << 100 * _num_arcs_with_transitions / _num_arcs - << "% of arcs have some transition."; + if (_num_nodes != 0) { + out << "; " << 100 * _num_nodes_with_attribs / _num_nodes + << "% of nodes have some render attribute."; } out << "\n"; indent(out, indent_level) - << _num_geoms << " Geoms "; - if (_num_non_geoms != 0) { - out << "(plus " << _num_non_geoms << " non-Geom Drawables) "; - } - out << "appear on " << _num_geom_nodes << " GeomNodes.\n"; + << _num_geoms << " Geoms appear on " << _num_geom_nodes << " GeomNodes.\n"; indent(out, indent_level) << _num_vertices << " vertices, " << _num_normals << " normals, " @@ -185,7 +178,7 @@ write(ostream &out, int indent_level) const { // statistics. //////////////////////////////////////////////////////////////////// void SceneGraphAnalyzer:: -collect_statistics(Node *node, bool under_instance) { +collect_statistics(PandaNode *node, bool under_instance) { _num_nodes++; if (!under_instance) { @@ -202,41 +195,30 @@ collect_statistics(Node *node, bool under_instance) { } } - if (node->is_of_type(GeomNode::get_class_type())) { - collect_statistics(DCAST(GeomNode, node)); + if (!node->get_state()->is_empty()) { + _num_nodes_with_attribs++; + const RenderAttrib *attrib = + node->get_attrib(TextureAttrib::get_class_type()); + if (attrib != (RenderAttrib *)NULL) { + const TextureAttrib *ta = DCAST(TextureAttrib, attrib); + if (!ta->is_off()) { + collect_statistics(ta->get_texture()); + } + } } - - int num_children = node->get_num_children(_graph_type); - for (int i = 0; i < num_children; i++) { - NodeRelation *arc = node->get_child(_graph_type, i); - collect_statistics(arc, under_instance); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: SceneGraphAnalyzer::collect_statistics -// Access: Private -// Description: Recursively visits each node, counting up the -// statistics. -//////////////////////////////////////////////////////////////////// -void SceneGraphAnalyzer:: -collect_statistics(NodeRelation *arc, bool under_instance) { - _num_arcs++; - if (arc->has_any_transition()) { - _num_arcs_with_transitions++; - } - if (arc->has_transition(TransformTransition::get_class_type())) { + if (!node->get_transform()->is_identity()) { _num_transforms++; } - TextureTransition *tt; - if (get_transition_into(tt, arc)) { - if (tt->is_on()) { - collect_statistics(tt->get_texture()); - } + if (node->is_geom_node()) { + collect_statistics(DCAST(qpGeomNode, node)); } - collect_statistics(arc->get_child(), under_instance); + int num_children = node->get_num_children(); + for (int i = 0; i < num_children; i++) { + PandaNode *child = node->get_child(i); + collect_statistics(child, under_instance); + } } //////////////////////////////////////////////////////////////////// @@ -246,22 +228,28 @@ collect_statistics(NodeRelation *arc, bool under_instance) { // statistics. //////////////////////////////////////////////////////////////////// void SceneGraphAnalyzer:: -collect_statistics(GeomNode *geom_node) { - nassertv(geom_node != (GeomNode *)NULL); +collect_statistics(qpGeomNode *geom_node) { + nassertv(geom_node != (qpGeomNode *)NULL); _num_geom_nodes++; int num_geoms = geom_node->get_num_geoms(); + _num_geoms += num_geoms; + for (int i = 0; i < num_geoms; i++) { - dDrawable *geom = geom_node->get_geom(i); + Geom *geom = geom_node->get_geom(i); + collect_statistics(DCAST(Geom, geom)); - if (geom->is_of_type(Geom::get_class_type())) { - _num_geoms++; + const RenderState *geom_state = geom_node->get_geom_state(i); - collect_statistics(DCAST(Geom, geom)); - } else { - _num_non_geoms++; - } + const RenderAttrib *attrib = + geom_state->get_attrib(TextureAttrib::get_class_type()); + if (attrib != (RenderAttrib *)NULL) { + const TextureAttrib *ta = DCAST(TextureAttrib, attrib); + if (!ta->is_off()) { + collect_statistics(ta->get_texture()); + } + } } } @@ -355,7 +343,7 @@ collect_statistics(Geom *geom) { _num_spheres += num_prims; } else { - sgraphutil_cat.warning() + pgraph_cat.warning() << "Unknown GeomType in SceneGraphAnalyzer: " << geom->get_type() << "\n"; } @@ -403,10 +391,11 @@ collect_statistics(Texture *texture) { // Description: Examines the indicated set of normals. //////////////////////////////////////////////////////////////////// void SceneGraphAnalyzer:: -consider_normals(const Normalf *norms, const ushort *nindex, int num) { +consider_normals(const Normalf *norms, const unsigned short *nindex, + int num) { _num_normals += num; - if (nindex != (const ushort *)NULL) { + if (nindex != (const unsigned short *)NULL) { // An indexed array. for (int i = 0; i < num; i++) { const Normalf &norm = norms[nindex[i]]; diff --git a/panda/src/sgraphutil/sceneGraphAnalyzer.h b/panda/src/pgraph/sceneGraphAnalyzer.h similarity index 76% rename from panda/src/sgraphutil/sceneGraphAnalyzer.h rename to panda/src/pgraph/sceneGraphAnalyzer.h index a6b22f063c..98c8116cf3 100644 --- a/panda/src/sgraphutil/sceneGraphAnalyzer.h +++ b/panda/src/pgraph/sceneGraphAnalyzer.h @@ -19,15 +19,15 @@ #ifndef SCENEGRAPHANALYZER_H #define SCENEGRAPHANALYZER_H -#include +#include "pandabase.h" -#include -#include +#include "typedObject.h" +#include "luse.h" #include "pmap.h" -class Node; -class GeomNode; +class PandaNode; +class qpGeomNode; class Geom; class Texture; @@ -38,24 +38,24 @@ class Texture; //////////////////////////////////////////////////////////////////// class EXPCL_PANDA SceneGraphAnalyzer { public: - SceneGraphAnalyzer(TypeHandle graph_type = RenderRelation::get_class_type()); + SceneGraphAnalyzer(); ~SceneGraphAnalyzer(); void clear(); - void add_node(Node *node); + void add_node(PandaNode *node); void write(ostream &out, int indent_level = 0) const; private: - void collect_statistics(Node *node, bool under_instance); - void collect_statistics(NodeRelation *arc, bool under_instance); - void collect_statistics(GeomNode *geom_node); + void collect_statistics(PandaNode *node, bool under_instance); + void collect_statistics(qpGeomNode *geom_node); void collect_statistics(Geom *geom); void collect_statistics(Texture *texture); - void consider_normals(const Normalf *norms, const ushort *nindex, int num); + void consider_normals(const Normalf *norms, const unsigned short *nindex, + int num); - typedef pmap Nodes; + typedef pmap Nodes; typedef pmap Textures; Nodes _nodes; @@ -65,11 +65,9 @@ public: int _num_nodes; int _num_instances; int _num_transforms; - int _num_arcs; - int _num_arcs_with_transitions; + int _num_nodes_with_attribs; int _num_geom_nodes; int _num_geoms; - int _num_non_geoms; int _num_vertices; int _num_normals; @@ -92,8 +90,6 @@ public: int _num_long_normals; int _num_short_normals; float _total_normal_length; - - TypeHandle _graph_type; }; #endif diff --git a/panda/src/pgui/Sources.pp b/panda/src/pgui/Sources.pp index 012a8ba662..55069aebe0 100644 --- a/panda/src/pgui/Sources.pp +++ b/panda/src/pgui/Sources.pp @@ -4,65 +4,50 @@ #begin lib_target #define TARGET pgui #define LOCAL_LIBS \ - audio grutil text tform graph linmath event putil gobj \ - mathutil sgraph sgraphutil + audio grutil text tform linmath event putil gobj \ + mathutil #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx #define SOURCES \ config_pgui.h \ - pgButton.I pgButton.h \ qppgButton.I qppgButton.h \ pgCullTraverser.I pgCullTraverser.h \ - pgEntry.I pgEntry.h \ qppgEntry.I qppgEntry.h \ pgMouseWatcherGroup.I pgMouseWatcherGroup.h \ pgMouseWatcherParameter.I pgMouseWatcherParameter.h \ pgFrameStyle.I pgFrameStyle.h \ - pgItem.I pgItem.h \ qppgItem.I qppgItem.h \ pgMouseWatcherBackground.h \ pgMouseWatcherRegion.I pgMouseWatcherRegion.h \ - pgTop.I pgTop.h \ qppgTop.I qppgTop.h \ - pgWaitBar.I pgWaitBar.h \ qppgWaitBar.I qppgWaitBar.h #define INCLUDED_SOURCES \ config_pgui.cxx \ - pgButton.cxx \ qppgButton.cxx \ pgCullTraverser.cxx \ - pgEntry.cxx \ qppgEntry.cxx \ pgMouseWatcherGroup.cxx \ pgMouseWatcherParameter.cxx \ pgFrameStyle.cxx \ - pgItem.cxx \ qppgItem.cxx \ pgMouseWatcherBackground.cxx \ pgMouseWatcherRegion.cxx \ - pgTop.cxx \ qppgTop.cxx \ - pgWaitBar.cxx \ qppgWaitBar.cxx #define INSTALL_HEADERS \ - pgButton.I pgButton.h \ qppgButton.I qppgButton.h \ pgCullTraverser.I pgCullTraverser.h \ - pgEntry.I pgEntry.h \ qppgEntry.I qppgEntry.h \ pgMouseWatcherGroup.I pgMouseWatcherGroup.h \ pgMouseWatcherParameter.I pgMouseWatcherParameter.h \ pgFrameStyle.I pgFrameStyle.h \ - pgItem.I pgItem.h \ qppgItem.I qppgItem.h \ pgMouseWatcherBackground.h \ pgMouseWatcherRegion.I pgMouseWatcherRegion.h \ - pgTop.I pgTop.h \ qppgTop.I qppgTop.h \ - pgWaitBar.I pgWaitBar.h \ qppgWaitBar.I qppgWaitBar.h diff --git a/panda/src/pgui/config_pgui.cxx b/panda/src/pgui/config_pgui.cxx index ac5d01567f..1122860a9c 100644 --- a/panda/src/pgui/config_pgui.cxx +++ b/panda/src/pgui/config_pgui.cxx @@ -17,20 +17,15 @@ //////////////////////////////////////////////////////////////////// #include "config_pgui.h" -#include "pgButton.h" #include "qppgButton.h" #include "pgCullTraverser.h" -#include "pgEntry.h" #include "qppgEntry.h" #include "pgMouseWatcherParameter.h" #include "pgMouseWatcherGroup.h" -#include "pgItem.h" #include "qppgItem.h" #include "pgMouseWatcherBackground.h" #include "pgMouseWatcherRegion.h" -#include "pgTop.h" #include "qppgTop.h" -#include "pgWaitBar.h" #include "qppgWaitBar.h" #include "dconfig.h" @@ -68,19 +63,14 @@ init_libpgui() { } initialized = true; - PGButton::init_type(); qpPGButton::init_type(); PGCullTraverser::init_type(); - PGEntry::init_type(); qpPGEntry::init_type(); PGMouseWatcherParameter::init_type(); PGMouseWatcherGroup::init_type(); - PGItem::init_type(); qpPGItem::init_type(); PGMouseWatcherBackground::init_type(); PGMouseWatcherRegion::init_type(); - PGTop::init_type(); qpPGTop::init_type(); - PGWaitBar::init_type(); qpPGWaitBar::init_type(); } diff --git a/panda/src/pgui/pgButton.I b/panda/src/pgui/pgButton.I deleted file mode 100644 index c93585af8c..0000000000 --- a/panda/src/pgui/pgButton.I +++ /dev/null @@ -1,75 +0,0 @@ -// Filename: pgButton.I -// Created by: drose (03Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::setup -// Access: Published -// Description: Sets up the button using the indicated NodePath as -// arbitrary geometry. -//////////////////////////////////////////////////////////////////// -INLINE void PGButton:: -setup(const ArcChain &ready) { - setup(ready, ready, ready, ready); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::setup -// Access: Published -// Description: Sets up the button using the indicated NodePath as -// arbitrary geometry. -//////////////////////////////////////////////////////////////////// -INLINE void PGButton:: -setup(const ArcChain &ready, const ArcChain &depressed) { - setup(ready, depressed, ready, ready); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::setup -// Access: Published -// Description: Sets up the button using the indicated NodePath as -// arbitrary geometry. -//////////////////////////////////////////////////////////////////// -INLINE void PGButton:: -setup(const ArcChain &ready, const ArcChain &depressed, - const ArcChain &rollover) { - setup(ready, depressed, rollover, ready); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::get_click_prefix -// Access: Published, Static -// Description: Returns the prefix that is used to define the click -// event for all PGButtons. The click event is the -// concatenation of this string followed by get_id(). -//////////////////////////////////////////////////////////////////// -INLINE string PGButton:: -get_click_prefix() { - return "click-"; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::get_click_event -// Access: Published -// Description: Returns the event name that will be thrown when the -// button is clicked normally. -//////////////////////////////////////////////////////////////////// -INLINE string PGButton:: -get_click_event(const ButtonHandle &button) const { - return "click-" + button.get_name() + "-" + get_id(); -} diff --git a/panda/src/pgui/pgButton.cxx b/panda/src/pgui/pgButton.cxx deleted file mode 100644 index 533638f3fd..0000000000 --- a/panda/src/pgui/pgButton.cxx +++ /dev/null @@ -1,295 +0,0 @@ -// Filename: pgButton.cxx -// Created by: drose (03Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "pgButton.h" -#include "pgMouseWatcherParameter.h" - -#include "throw_event.h" -#include "renderRelation.h" -#include "colorTransition.h" -#include "transformTransition.h" -#include "mouseButton.h" -#include "mouseWatcherParameter.h" - -TypeHandle PGButton::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -PGButton:: -PGButton(const string &name) : PGItem(name) -{ - _button_down = false; - _click_buttons.insert(MouseButton::one()); - - set_active(true); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -PGButton:: -~PGButton() { -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -PGButton:: -PGButton(const PGButton ©) : - PGItem(copy) -{ - _button_down = false; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void PGButton:: -operator = (const PGButton ©) { - PGItem::operator = (copy); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::make_copy -// Access: Public, Virtual -// Description: Returns a newly-allocated Node that is a shallow copy -// of this one. It will be a different Node pointer, -// but its internal data may or may not be shared with -// that of the original Node. -//////////////////////////////////////////////////////////////////// -Node *PGButton:: -make_copy() const { - return new PGButton(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::enter -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever the -// mouse enters the region. -//////////////////////////////////////////////////////////////////// -void PGButton:: -enter(const MouseWatcherParameter ¶m) { - if (get_active()) { - set_state(_button_down ? S_depressed : S_rollover); - } - PGItem::enter(param); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::exit -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever the -// mouse exits the region. -//////////////////////////////////////////////////////////////////// -void PGButton:: -exit(const MouseWatcherParameter ¶m) { - if (get_active()) { - set_state(S_ready); - } - PGItem::exit(param); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::press -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever a -// mouse or keyboard button is depressed while the mouse -// is within the region. -//////////////////////////////////////////////////////////////////// -void PGButton:: -press(const MouseWatcherParameter ¶m, bool background) { - if (has_click_button(param.get_button())) { - if (get_active()) { - _button_down = true; - set_state(S_depressed); - } - } - PGItem::press(param, background); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::release -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever a -// mouse or keyboard button previously depressed with -// press() is released. -//////////////////////////////////////////////////////////////////// -void PGButton:: -release(const MouseWatcherParameter ¶m, bool background) { - if (has_click_button(param.get_button())) { - _button_down = false; - if (get_active()) { - if (param.is_outside()) { - set_state(S_ready); - } else { - set_state(S_rollover); - click(param); - } - } - } - PGItem::release(param, background); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::click -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever the -// button is clicked down-and-up by the user normally. -//////////////////////////////////////////////////////////////////// -void PGButton:: -click(const MouseWatcherParameter ¶m) { - PGMouseWatcherParameter *ep = new PGMouseWatcherParameter(param); - string event = get_click_event(param.get_button()); - play_sound(event); - throw_event(event, EventParameter(ep)); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::setup -// Access: Published -// Description: Sets up the button as a default text button using the -// indicated label string. The TextNode defined by -// PGItem::get_text_node() will be used to create the -// label geometry. This automatically sets up the frame -// according to the size of the text. -//////////////////////////////////////////////////////////////////// -void PGButton:: -setup(const string &label) { - clear_state_def(S_ready); - clear_state_def(S_depressed); - clear_state_def(S_rollover); - clear_state_def(S_inactive); - - TextNode *text_node = get_text_node(); - text_node->set_text(label); - PT_Node geom = text_node->generate(); - - LVecBase4f frame = text_node->get_card_actual(); - set_frame(frame[0] - 0.4f, frame[1] + 0.4f, frame[2] - 0.15f, frame[3] + 0.15f); - - new RenderRelation(get_state_def(S_ready), geom); - NodeRelation *down = new RenderRelation(get_state_def(S_depressed), geom); - new RenderRelation(get_state_def(S_rollover), geom); - NodeRelation *inact = new RenderRelation(get_state_def(S_inactive), geom); - - PGFrameStyle style; - style.set_color(0.8f, 0.8f, 0.8f, 1.0); - style.set_width(0.1f, 0.1f); - - style.set_type(PGFrameStyle::T_bevel_out); - set_frame_style(S_ready, style); - - style.set_color(0.9f, 0.9f, 0.9f, 1.0); - set_frame_style(S_rollover, style); - - ColorTransition *ct = new ColorTransition(Colorf(0.8f, 0.8f, 0.8f, 1.0f)); - inact->set_transition(ct); - style.set_color(0.6f, 0.6f, 0.6f, 1.0); - set_frame_style(S_inactive, style); - - style.set_type(PGFrameStyle::T_bevel_in); - style.set_color(0.8f, 0.8f, 0.8f, 1.0); - set_frame_style(S_depressed, style); - LMatrix4f translate = LMatrix4f::translate_mat(0.05f, 0.0f, -0.05f); - TransformTransition *tt = new TransformTransition(translate); - down->set_transition(tt); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::setup -// Access: Published -// Description: Sets up the button using the indicated NodePath as -// arbitrary geometry. -//////////////////////////////////////////////////////////////////// -void PGButton:: -setup(const ArcChain &ready, const ArcChain &depressed, - const ArcChain &rollover, const ArcChain &inactive) { - clear_state_def(S_ready); - clear_state_def(S_depressed); - clear_state_def(S_rollover); - clear_state_def(S_inactive); - - instance_to_state_def(S_ready, ready); - instance_to_state_def(S_depressed, depressed); - instance_to_state_def(S_rollover, rollover); - instance_to_state_def(S_inactive, inactive); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::set_active -// Access: Published, Virtual -// Description: Toggles the active/inactive state of the button. In -// the case of a PGButton, this also changes its visual -// appearance. -//////////////////////////////////////////////////////////////////// -void PGButton:: -set_active(bool active) { - if (active != get_active()) { - PGItem::set_active(active); - set_state(active ? S_ready : S_inactive); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::add_click_button -// Access: Published -// Description: Adds the indicated button to the set of buttons that -// can effectively "click" the PGButton. Normally, this -// is just MouseButton::one(). Returns true if the -// button was added, or false if it was already there. -//////////////////////////////////////////////////////////////////// -bool PGButton:: -add_click_button(const ButtonHandle &button) { - return _click_buttons.insert(button).second; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::remove_click_button -// Access: Published -// Description: Removes the indicated button from the set of buttons -// that can effectively "click" the PGButton. Normally, -// this is just MouseButton::one(). Returns true if the -// button was removed, or false if it was not in the -// set. -//////////////////////////////////////////////////////////////////// -bool PGButton:: -remove_click_button(const ButtonHandle &button) { - return (_click_buttons.erase(button) != 0); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGButton::has_click_button -// Access: Published -// Description: Returns true if the indicated button is on the set of -// buttons that can effectively "click" the PGButton. -// Normally, this is just MouseButton::one(). -//////////////////////////////////////////////////////////////////// -bool PGButton:: -has_click_button(const ButtonHandle &button) { - return (_click_buttons.count(button) != 0); -} diff --git a/panda/src/pgui/pgButton.h b/panda/src/pgui/pgButton.h deleted file mode 100644 index 881d091a9e..0000000000 --- a/panda/src/pgui/pgButton.h +++ /dev/null @@ -1,104 +0,0 @@ -// Filename: pgButton.h -// Created by: drose (03Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef PGBUTTON_H -#define PGBUTTON_H - -#include "pandabase.h" - -#include "pgItem.h" -#include "arcChain.h" -#include "pset.h" - -//////////////////////////////////////////////////////////////////// -// Class : PGButton -// Description : This is a particular kind of PGItem that is -// specialized to behave like a normal button object. -// It keeps track of its own state, and handles mouse -// events sensibly. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA PGButton : public PGItem { -PUBLISHED: - PGButton(const string &name = ""); - virtual ~PGButton(); - -public: - PGButton(const PGButton ©); - void operator = (const PGButton ©); - - virtual Node *make_copy() const; - - virtual void enter(const MouseWatcherParameter ¶m); - virtual void exit(const MouseWatcherParameter ¶m); - virtual void press(const MouseWatcherParameter ¶m, bool background); - virtual void release(const MouseWatcherParameter ¶m, bool background); - - virtual void click(const MouseWatcherParameter ¶m); - -PUBLISHED: - enum State { - S_ready = 0, - S_depressed, - S_rollover, - S_inactive - }; - - void setup(const string &label); - INLINE void setup(const ArcChain &ready); - INLINE void setup(const ArcChain &ready, const ArcChain &depressed); - INLINE void setup(const ArcChain &ready, const ArcChain &depressed, - const ArcChain &rollover); - void setup(const ArcChain &ready, const ArcChain &depressed, - const ArcChain &rollover, const ArcChain &inactive); - - virtual void set_active(bool active); - - bool add_click_button(const ButtonHandle &button); - bool remove_click_button(const ButtonHandle &button); - bool has_click_button(const ButtonHandle &button); - - INLINE static string get_click_prefix(); - INLINE string get_click_event(const ButtonHandle &button) const; - -private: - typedef pset Buttons; - Buttons _click_buttons; - - bool _button_down; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - PGItem::init_type(); - register_type(_type_handle, "PGButton", - PGItem::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "pgButton.I" - -#endif diff --git a/panda/src/pgui/pgEntry.I b/panda/src/pgui/pgEntry.I deleted file mode 100644 index fb70d1dd04..0000000000 --- a/panda/src/pgui/pgEntry.I +++ /dev/null @@ -1,384 +0,0 @@ -// Filename: pgEntry.I -// Created by: drose (10Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::set_text -// Access: Published -// Description: Changes the text currently displayed within the -// entry. This uses the Unicode encoding currently -// specified for the "focus" TextNode; therefore, the -// TextNode must exist before calling set_text(). -//////////////////////////////////////////////////////////////////// -INLINE void PGEntry:: -set_text(const string &text) { - TextNode *text_node = get_text_def(S_focus); - nassertv(text_node != (TextNode *)NULL); - set_wtext(text_node->decode_text(text)); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_text -// Access: Published -// Description: Returns the text currently displayed within the -// entry. This uses the Unicode encoding currently -// specified for the "focus" TextNode; therefore, the -// TextNode must exist before calling get_text(). -//////////////////////////////////////////////////////////////////// -INLINE string PGEntry:: -get_text() const { - TextNode *text_node = get_text_def(S_focus); - nassertr(text_node != (TextNode *)NULL, string()); - return text_node->encode_wtext(get_wtext()); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::set_cursor_position -// Access: Published -// Description: Sets the current position of the cursor. This is the -// position within the text at which the next letter -// typed by the user will be inserted; normally it is -// the same as the length of the text. -//////////////////////////////////////////////////////////////////// -INLINE void PGEntry:: -set_cursor_position(int position) { - if (_cursor_position != position) { - _cursor_position = position; - _cursor_stale = true; - _blink_start = ClockObject::get_global_clock()->get_frame_time(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_cursor_position -// Access: Published -// Description: Returns the current position of the cursor. -//////////////////////////////////////////////////////////////////// -INLINE int PGEntry:: -get_cursor_position() const { - return _cursor_position; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::set_max_chars -// Access: Published -// Description: Sets the maximum number of characters that may be -// typed into the entry. This is a limit on the number -// of characters, as opposed to the width of the entry; -// see also set_max_width(). -// -// If this is 0, there is no limit. -//////////////////////////////////////////////////////////////////// -INLINE void PGEntry:: -set_max_chars(int max_chars) { - _max_chars = max_chars; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_max_chars -// Access: Published -// Description: Returns the current maximum number of characters that -// may be typed into the entry, or 0 if there is no -// limit. See set_max_chars(). -//////////////////////////////////////////////////////////////////// -INLINE int PGEntry:: -get_max_chars() const { - return _max_chars; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::set_max_width -// Access: Published -// Description: Sets the maximum width of all characters that may be -// typed into the entry. This is a limit on the width -// of the formatted text, not a fixed limit on the -// number of characters; also set_max_chars(). -// -// If this is 0, there is no limit. -// -// If _num_lines is more than 1, rather than being a -// fixed width on the whole entry, this becomes instead -// the wordwrap width (and the width limit on the entry -// is essentially _max_width * _num_lines). -//////////////////////////////////////////////////////////////////// -INLINE void PGEntry:: -set_max_width(float max_width) { - _max_width = max_width; - _text_geom_stale = true; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_max_width -// Access: Published -// Description: Returns the current maximum width of the characters -// that may be typed into the entry, or 0 if there is no -// limit. See set_max_width(). -//////////////////////////////////////////////////////////////////// -INLINE float PGEntry:: -get_max_width() const { - return _max_width; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::set_num_lines -// Access: Published -// Description: Sets the number of lines of text the PGEntry will -// use. This only has meaning if _max_width is not 0; -// _max_width indicates the wordwrap width of each line. -//////////////////////////////////////////////////////////////////// -INLINE void PGEntry:: -set_num_lines(int num_lines) { - nassertv(num_lines >= 1); - _num_lines = num_lines; - _text_geom_stale = true; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_num_lines -// Access: Published -// Description: Returns the number of lines of text the PGEntry will -// use, if _max_width is not 0. See set_num_lines(). -//////////////////////////////////////////////////////////////////// -INLINE int PGEntry:: -get_num_lines() const { - return _num_lines; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::set_blink_rate -// Access: Published -// Description: Sets the number of times per second the cursor will -// blink while the entry has keyboard focus. -// -// If this is 0, the cursor does not blink, but is held -// steady. -//////////////////////////////////////////////////////////////////// -INLINE void PGEntry:: -set_blink_rate(float blink_rate) { - _blink_rate = blink_rate; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_blink_rate -// Access: Published -// Description: Returns the number of times per second the cursor -// will blink, or 0 if the cursor is not to blink. -//////////////////////////////////////////////////////////////////// -INLINE float PGEntry:: -get_blink_rate() const { - return _blink_rate; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_cursor_def -// Access: Published -// Description: Returns the Node that will be rendered to represent -// the cursor. You can attach suitable cursor geometry -// to this node. -//////////////////////////////////////////////////////////////////// -INLINE Node *PGEntry:: -get_cursor_def() { - return _cursor_def->get_child(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::clear_cursor_def -// Access: Published -// Description: Removes all the children from the cursor_def Node, in -// preparation for adding a new definition. -//////////////////////////////////////////////////////////////////// -INLINE void PGEntry:: -clear_cursor_def() { - remove_all_children(get_cursor_def()); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::set_cursor_keys_active -// Access: Published -// Description: Sets whether the arrow keys (and home/end) control -// movement of the cursor. If true, they are active; if -// false, they are ignored. -//////////////////////////////////////////////////////////////////// -INLINE void PGEntry:: -set_cursor_keys_active(bool flag) { - _cursor_keys_active = flag; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_cursor_keys_active -// Access: Published -// Description: Returns whether the arrow keys are currently set to -// control movement of the cursor; see -// set_cursor_keys_active(). -//////////////////////////////////////////////////////////////////// -INLINE bool PGEntry:: -get_cursor_keys_active() const { - return _cursor_keys_active; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::set_obscure_mode -// Access: Published -// Description: Specifies whether obscure mode should be enabled. In -// obscure mode, a string of asterisks is displayed -// instead of the literal text, e.g. for entering -// passwords. -// -// In obscure mode, the width of the text is computed -// based on the width of the string of asterisks, not on -// the width of the actual text. This has implications -// on the maximum length of text that may be entered if -// max_width is in effect. -//////////////////////////////////////////////////////////////////// -INLINE void PGEntry:: -set_obscure_mode(bool flag) { - if (_obscure_mode != flag) { - _obscure_mode = flag; - _text_geom_stale = true; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_obscure_mode -// Access: Published -// Description: Specifies whether obscure mode is enabled. See -// set_obscure_mode(). -//////////////////////////////////////////////////////////////////// -INLINE bool PGEntry:: -get_obscure_mode() const { - return _obscure_mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_accept_prefix -// Access: Published, Static -// Description: Returns the prefix that is used to define the accept -// event for all PGEntries. The accept event is the -// concatenation of this string followed by get_id(). -//////////////////////////////////////////////////////////////////// -INLINE string PGEntry:: -get_accept_prefix() { - return "accept-"; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_overflow_prefix -// Access: Published, Static -// Description: Returns the prefix that is used to define the overflow -// event for all PGEntries. The overflow event is the -// concatenation of this string followed by get_id(). -//////////////////////////////////////////////////////////////////// -INLINE string PGEntry:: -get_overflow_prefix() { - return "overflow-"; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_type_prefix -// Access: Published, Static -// Description: Returns the prefix that is used to define the type -// event for all PGEntries. The type event is the -// concatenation of this string followed by get_id(). -//////////////////////////////////////////////////////////////////// -INLINE string PGEntry:: -get_type_prefix() { - return "type-"; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_erase_prefix -// Access: Published, Static -// Description: Returns the prefix that is used to define the erase -// event for all PGEntries. The erase event is the -// concatenation of this string followed by get_id(). -//////////////////////////////////////////////////////////////////// -INLINE string PGEntry:: -get_erase_prefix() { - return "erase-"; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_accept_event -// Access: Published -// Description: Returns the event name that will be thrown when the -// entry is accepted normally. -//////////////////////////////////////////////////////////////////// -INLINE string PGEntry:: -get_accept_event(const ButtonHandle &button) const { - return "accept-" + button.get_name() + "-" + get_id(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_overflow_event -// Access: Published -// Description: Returns the event name that will be thrown when too -// much text is attempted to be entered into the -// PGEntry, exceeding either the limit set via -// set_max_chars() or via set_max_width(). -//////////////////////////////////////////////////////////////////// -INLINE string PGEntry:: -get_overflow_event() const { - return "overflow-" + get_id(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_type_event -// Access: Published -// Description: Returns the event name that will be thrown whenever -// the user extends the text by typing. -//////////////////////////////////////////////////////////////////// -INLINE string PGEntry:: -get_type_event() const { - return "type-" + get_id(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_erase_event -// Access: Published -// Description: Returns the event name that will be thrown whenever -// the user erases characters in the text. -//////////////////////////////////////////////////////////////////// -INLINE string PGEntry:: -get_erase_event() const { - return "erase-" + get_id(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::set_wtext -// Access: Public -// Description: Changes the text currently displayed within the -// entry. -//////////////////////////////////////////////////////////////////// -INLINE void PGEntry:: -set_wtext(const wstring &wtext) { - _wtext = wtext; - _text_geom_stale = true; - _cursor_stale = true; - _blink_start = ClockObject::get_global_clock()->get_frame_time(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_wtext -// Access: Public -// Description: Returns the text currently displayed within the -// entry. -//////////////////////////////////////////////////////////////////// -INLINE const wstring &PGEntry:: -get_wtext() const { - return _wtext; -} diff --git a/panda/src/pgui/pgEntry.cxx b/panda/src/pgui/pgEntry.cxx deleted file mode 100644 index 451a6e455e..0000000000 --- a/panda/src/pgui/pgEntry.cxx +++ /dev/null @@ -1,880 +0,0 @@ -// Filename: pgEntry.cxx -// Created by: drose (10Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "pgEntry.h" -#include "pgMouseWatcherParameter.h" - -#include "throw_event.h" -#include "renderRelation.h" -#include "mouseWatcherParameter.h" -#include "directRenderTraverser.h" -#include "allTransitionsWrapper.h" -#include "transformTransition.h" -#include "pruneTransition.h" -#include "keyboardButton.h" -#include "mouseButton.h" -#include "lineSegs.h" - -#include "math.h" - -TypeHandle PGEntry::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -PGEntry:: -PGEntry(const string &name) : PGItem(name) -{ - _cursor_position = 0; - _cursor_stale = true; - _max_chars = 0; - _max_width = 0.0f; - _num_lines = 1; - _last_text_def = (TextNode *)NULL; - _text_geom_stale = true; - _blink_start = 0.0f; - _blink_rate = 1.0f; - - _text_render_root = new NamedNode("text_root"); - _current_text_arc = (NodeRelation *)NULL; - Node *cursor = new NamedNode("cursor"); - _cursor_def = new RenderRelation(_text_render_root, cursor); - _cursor_visible = true; - - _cursor_keys_active = true; - _obscure_mode = false; - - set_active(true); - update_state(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -PGEntry:: -~PGEntry() { -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -PGEntry:: -PGEntry(const PGEntry ©) : - PGItem(copy), - _wtext(copy._wtext), - _obscured_wtext(copy._obscured_wtext), - _cursor_position(copy._cursor_position), - _max_chars(copy._max_chars), - _max_width(copy._max_width), - _text_defs(copy._text_defs), - _blink_start(copy._blink_start), - _blink_rate(copy._blink_rate), - _cursor_keys_active(copy._cursor_keys_active), - _obscure_mode(copy._obscure_mode) -{ - _cursor_stale = true; - _last_text_def = (TextNode *)NULL; - _text_geom_stale = true; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void PGEntry:: -operator = (const PGEntry ©) { - PGItem::operator = (copy); - _wtext = copy._wtext; - _obscured_wtext = copy._obscured_wtext; - _cursor_position = copy._cursor_position; - _max_chars = copy._max_chars; - _max_width = copy._max_width; - _text_defs = copy._text_defs; - _blink_start = copy._blink_start; - _blink_rate = copy._blink_rate; - - _cursor_keys_active = copy._cursor_keys_active; - _obscure_mode = copy._obscure_mode; - - _cursor_stale = true; - _text_geom_stale = true; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::make_copy -// Access: Public, Virtual -// Description: Returns a newly-allocated Node that is a shallow copy -// of this one. It will be a different Node pointer, -// but its internal data may or may not be shared with -// that of the original Node. -//////////////////////////////////////////////////////////////////// -Node *PGEntry:: -make_copy() const { - return new PGEntry(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::draw_item -// Access: Public, Virtual -// Description: Called by the PGTop's traversal to draw this -// particular item. -//////////////////////////////////////////////////////////////////// -void PGEntry:: -draw_item(PGTop *top, GraphicsStateGuardian *gsg, - const AllTransitionsWrapper &trans) { - PGItem::draw_item(top, gsg, trans); - update_text(); - update_cursor(); - - nassertv(_text_render_root != (Node *)NULL); - - // We'll use a normal DirectRenderTraverser to do the rendering - // of the text. - DirectRenderTraverser drt(gsg, RenderRelation::get_class_type()); - drt.set_view_frustum_cull(false); - drt.traverse(_text_render_root, trans); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::press -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever a -// mouse or keyboard entry is depressed while the mouse -// is within the region. -//////////////////////////////////////////////////////////////////// -void PGEntry:: -press(const MouseWatcherParameter ¶m, bool background) { - if (get_active()) { - if (param.has_button()) { - ButtonHandle button = param.get_button(); - - if (button == MouseButton::one() || - button == MouseButton::two() || - button == MouseButton::three()) { - // Mouse button; set focus. - set_focus(true); - - } else if ((!background && get_focus()) || - (background && get_background_focus())) { - // Keyboard button. - _cursor_position = min(_cursor_position, (int)_wtext.length()); - _blink_start = ClockObject::get_global_clock()->get_frame_time(); - if (button == KeyboardButton::enter()) { - // Enter. Accept the entry. - accept(param); - - } else if (button == KeyboardButton::backspace()) { - // Backspace. Remove the character to the left of the cursor. - if (_cursor_position > 0) { - if (_obscure_mode && _obscured_wtext.length() == _wtext.length()) { - _obscured_wtext.erase(_obscured_wtext.begin() + _obscured_wtext.length() - 1); - } - _wtext.erase(_wtext.begin() + _cursor_position - 1); - _cursor_position--; - _cursor_stale = true; - _text_geom_stale = true; - erase(param); - } - - } else if (button == KeyboardButton::del()) { - // Delete. Remove the character to the right of the cursor. - if (_cursor_position < (int)_wtext.length()) { - if (_obscure_mode && _obscured_wtext.length() == _wtext.length()) { - _obscured_wtext.erase(_obscured_wtext.begin() + _obscured_wtext.length() - 1); - } - _wtext.erase(_wtext.begin() + _cursor_position); - _text_geom_stale = true; - erase(param); - } - - } else if (button == KeyboardButton::left()) { - if (_cursor_keys_active) { - // Left arrow. Move the cursor position to the left. - _cursor_position = max(_cursor_position - 1, 0); - _cursor_stale = true; - } - - } else if (button == KeyboardButton::right()) { - if (_cursor_keys_active) { - // Right arrow. Move the cursor position to the right. - _cursor_position = min(_cursor_position + 1, (int)_wtext.length()); - _cursor_stale = true; - } - - } else if (button == KeyboardButton::home()) { - if (_cursor_keys_active) { - // Home. Move the cursor position to the beginning. - _cursor_position = 0; - _cursor_stale = true; - } - - } else if (button == KeyboardButton::end()) { - if (_cursor_keys_active) { - // End. Move the cursor position to the end. - _cursor_position = _wtext.length(); - _cursor_stale = true; - } - - } else if (!use_keystrokes && button.has_ascii_equivalent()) { - // This part of the code is deprecated and will be removed - // soon. It only supports the old button up/down method of - // sending keystrokes, instead of the new keystroke method. - wchar_t key = button.get_ascii_equivalent(); - if (isprint(key)) { - // A normal visible character. Add a new character to the - // text entry, if there's room. - - if (get_max_chars() > 0 && (int)_wtext.length() >= get_max_chars()) { - overflow(param); - } else { - wstring new_text = - _wtext.substr(0, _cursor_position) + key + - _wtext.substr(_cursor_position); - - // Get a string to measure its length. In normal mode, - // we measure the text itself. In obscure mode, we - // measure a string of n asterisks. - wstring measure_text; - if (_obscure_mode) { - measure_text = get_display_wtext() + (wchar_t)'*'; - } else { - measure_text = new_text; - } - - // Check the length. - bool too_long = false; - if (_max_width > 0.0f) { - TextNode *text_node = get_text_def(S_focus); - if (_num_lines <= 1) { - // If we have only one line, we can check the length - // by simply measuring the width of the text. - too_long = (text_node->calc_width(measure_text) > _max_width); - - } else { - // If we have multiple lines, we have to check the - // length by wordwrapping it and counting up the - // number of lines. - wstring ww_text = text_node->wordwrap_to(measure_text, _max_width, true); - int num_lines = 1; - size_t last_line_start = 0; - for (size_t p = 0; - p < ww_text.length() && !too_long; - ++p) { - if (ww_text[p] == '\n') { - last_line_start = p + 1; - num_lines++; - too_long = (num_lines > _num_lines); - } - } - - if (!too_long) { - // We must also ensure that the last line is not too - // long (it might be, because of additional - // whitespace on the end). - wstring last_line = ww_text.substr(last_line_start); - float last_line_width = text_node->calc_width(last_line); - if (num_lines == _num_lines) { - // Mainly we only care about this if we're on - // the very last line. - too_long = (last_line_width > _max_width); - - } else { - // If we're not on the very last line, the width - // is still important, just so we don't allow an - // infinite number of spaces to accumulate. - // However, we must allow at least *one* space - // on the end of a line. - if (_wtext.length() >= 1 && - _wtext[_wtext.length() - 1] == ' ') { - if (last_line_width > _max_width) { - // In this case, however, it's not exactly - // an overflow; we just want to reject the - // space. - return; - } - } - } - } - } - } - - if (too_long) { - overflow(param); - - } else { - _wtext = new_text; - if (_obscure_mode) { - _obscured_wtext = measure_text; - } - - _cursor_position++; - _cursor_stale = true; - _text_geom_stale = true; - type(param); - } - } - } - } - } - } - } - PGItem::press(param, background); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::keystroke -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever -// the user types a key. -//////////////////////////////////////////////////////////////////// -void PGEntry:: -keystroke(const MouseWatcherParameter ¶m, bool background) { - if (get_active()) { - if (param.has_keycode()) { - int keycode = param.get_keycode(); - - if (use_keystrokes) { - if (!isascii(keycode) || isprint(keycode)) { - // A normal visible character. Add a new character to the - // text entry, if there's room. - wstring new_char(1, (wchar_t)keycode); - - if (get_max_chars() > 0 && (int)_wtext.length() >= get_max_chars()) { - overflow(param); - } else { - _cursor_position = min(_cursor_position, (int)_wtext.length()); - wstring new_text = - _wtext.substr(0, _cursor_position) + new_char + - _wtext.substr(_cursor_position); - - // Get a string to measure its length. In normal mode, - // we measure the text itself. In obscure mode, we - // measure a string of n asterisks. - wstring measure_text; - if (_obscure_mode) { - measure_text = get_display_wtext() + (wchar_t)'*'; - } else { - measure_text = new_text; - } - - // Check the length. - bool too_long = false; - if (_max_width > 0.0f) { - TextNode *text_node = get_text_def(S_focus); - if (_num_lines <= 1) { - // If we have only one line, we can check the length - // by simply measuring the width of the text. - too_long = (text_node->calc_width(measure_text) > _max_width); - - } else { - // If we have multiple lines, we have to check the - // length by wordwrapping it and counting up the - // number of lines. - wstring ww_text = text_node->wordwrap_to(measure_text, _max_width, true); - int num_lines = 1; - size_t last_line_start = 0; - for (size_t p = 0; - p < ww_text.length() && !too_long; - ++p) { - if (ww_text[p] == '\n') { - last_line_start = p + 1; - num_lines++; - too_long = (num_lines > _num_lines); - } - } - - if (!too_long) { - // We must also ensure that the last line is not too - // long (it might be, because of additional - // whitespace on the end). - wstring last_line = ww_text.substr(last_line_start); - float last_line_width = text_node->calc_width(last_line); - if (num_lines == _num_lines) { - // Mainly we only care about this if we're on - // the very last line. - too_long = (last_line_width > _max_width); - - } else { - // If we're not on the very last line, the width - // is still important, just so we don't allow an - // infinite number of spaces to accumulate. - // However, we must allow at least *one* space - // on the end of a line. - if (_wtext.length() >= 1 && - _wtext[_wtext.length() - 1] == ' ') { - if (last_line_width > _max_width) { - // In this case, however, it's not exactly - // an overflow; we just want to reject the - // space. - return; - } - } - } - } - } - } - - if (too_long) { - overflow(param); - - } else { - _wtext = new_text; - if (_obscure_mode) { - _obscured_wtext = measure_text; - } - - _cursor_position += new_char.length(); - _cursor_stale = true; - _text_geom_stale = true; - type(param); - } - } - } - } - } - } - PGItem::keystroke(param, background); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::accept -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever the -// entry is accepted by the user pressing Enter normally. -//////////////////////////////////////////////////////////////////// -void PGEntry:: -accept(const MouseWatcherParameter ¶m) { - PGMouseWatcherParameter *ep = new PGMouseWatcherParameter(param); - string event = get_accept_event(param.get_button()); - play_sound(event); - throw_event(event, EventParameter(ep)); - set_focus(false); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::overflow -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever the -// entry is overflowed because the user attempts to type -// too many characters, exceeding either set_max_chars() -// or set_max_width(). -//////////////////////////////////////////////////////////////////// -void PGEntry:: -overflow(const MouseWatcherParameter ¶m) { - PGMouseWatcherParameter *ep = new PGMouseWatcherParameter(param); - string event = get_overflow_event(); - play_sound(event); - throw_event(event, EventParameter(ep)); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::type -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever the -// user extends the text by typing. -//////////////////////////////////////////////////////////////////// -void PGEntry:: -type(const MouseWatcherParameter ¶m) { - PGMouseWatcherParameter *ep = new PGMouseWatcherParameter(param); - string event = get_type_event(); - play_sound(event); - throw_event(event, EventParameter(ep)); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::erase -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever the -// user erase characters in the text. -//////////////////////////////////////////////////////////////////// -void PGEntry:: -erase(const MouseWatcherParameter ¶m) { - PGMouseWatcherParameter *ep = new PGMouseWatcherParameter(param); - string event = get_erase_event(); - play_sound(event); - throw_event(event, EventParameter(ep)); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::setup -// Access: Published -// Description: Sets up the entry for normal use. The width is the -// maximum width of characters that will be typed, and -// num_lines is the integer number of lines of text of -// the entry. Both of these together determine the size -// of the entry, based on the TextNode in effect. -//////////////////////////////////////////////////////////////////// -void PGEntry:: -setup(float width, int num_lines) { - set_text(string()); - _cursor_position = 0; - set_max_chars(0); - set_max_width(width); - set_num_lines(num_lines); - - TextNode *text_node = get_text_def(S_focus); - float line_height = text_node->get_line_height(); - - // Define determine the four corners of the frame. - LPoint3f ll(0.0f, 0.0f, -0.3f * line_height - (line_height * (num_lines - 1))); - LPoint3f ur(width, 0.0f, line_height); - LPoint3f lr(ur[0], 0.0f, ll[2]); - LPoint3f ul(ll[0], 0.0f, ur[2]); - - // Transform each corner by the TextNode's transform. - LMatrix4f mat = text_node->get_transform(); - ll = ll * mat; - ur = ur * mat; - lr = lr * mat; - ul = ul * mat; - - // And get the new minmax to define the frame. We do all this work - // instead of just using the lower-left and upper-right corners, - // just in case the text was rotated. - LVecBase4f frame; - frame[0] = min(min(ll[0], ur[0]), min(lr[0], ul[0])); - frame[1] = max(max(ll[0], ur[0]), max(lr[0], ul[0])); - frame[2] = min(min(ll[2], ur[2]), min(lr[2], ul[2])); - frame[3] = max(max(ll[2], ur[2]), max(lr[2], ul[2])); - - switch (text_node->get_align()) { - case TextNode::A_left: - // The default case. - break; - - case TextNode::A_center: - frame[0] = -width / 2.0; - frame[1] = width / 2.0; - break; - - case TextNode::A_right: - frame[0] = -width; - frame[1] = 0.0f; - break; - } - - set_frame(frame[0] - 0.15f, frame[1] + 0.15f, frame[2], frame[3]); - - PGFrameStyle style; - style.set_width(0.1f, 0.1f); - style.set_type(PGFrameStyle::T_bevel_in); - style.set_color(0.8f, 0.8f, 0.8f, 1.0f); - - set_frame_style(S_no_focus, style); - - style.set_color(0.9f, 0.9f, 0.9f, 1.0f); - set_frame_style(S_focus, style); - - style.set_color(0.6f, 0.6f, 0.6f, 1.0f); - set_frame_style(S_inactive, style); - - // Set up a default cursor: a vertical bar. - clear_cursor_def(); - LineSegs ls; - ls.set_color(0.0f, 0.0f, 0.0f, 1.0f); - ls.move_to(0.0f, 0.0f, -0.15f * line_height); - ls.draw_to(0.0f, 0.0f, 0.85f * line_height); - new RenderRelation(get_cursor_def(), ls.create()); - - // An underscore cursor would work too. - // text_node->set_text("_"); - // new RenderRelation(get_cursor_def(), text_node->generate()); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::set_text_def -// Access: Published -// Description: Changes the TextNode that will be used to render the -// text within the entry when the entry is in the -// indicated state. The default if nothing is specified -// is the same TextNode returned by -// PGItem::get_text_node(). -// -// It is the responsibility of the user to ensure that -// this TextNode has been frozen by a call to freeze(). -// Passing in an unfrozen TextNode will result in -// needless work. -//////////////////////////////////////////////////////////////////// -void PGEntry:: -set_text_def(int state, TextNode *node) { - nassertv(state >= 0 && state < 1000); // Sanity check. - if (node == (TextNode *)NULL && state >= (int)_text_defs.size()) { - // If we're setting it to NULL, we don't need to slot a new one. - return; - } - slot_text_def(state); - - _text_defs[state] = node; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_text_def -// Access: Published -// Description: Returns the TextNode that will be used to render the -// text within the entry when the entry is in the -// indicated state. See set_text_def(). -//////////////////////////////////////////////////////////////////// -TextNode *PGEntry:: -get_text_def(int state) const { - if (state < 0 || state >= (int)_text_defs.size()) { - // If we don't have a definition, use the global one. - return get_text_node(); - } - if (_text_defs[state] == (TextNode *)NULL) { - return get_text_node(); - } - return _text_defs[state]; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::set_active -// Access: Published, Virtual -// Description: Toggles the active/inactive state of the entry. In -// the case of a PGEntry, this also changes its visual -// appearance. -//////////////////////////////////////////////////////////////////// -void PGEntry:: -set_active(bool active) { - PGItem::set_active(active); - update_state(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::set_focus -// Access: Published, Virtual -// Description: Toggles the focus state of the entry. In the case of -// a PGEntry, this also changes its visual appearance. -//////////////////////////////////////////////////////////////////// -void PGEntry:: -set_focus(bool focus) { - PGItem::set_focus(focus); - _blink_start = ClockObject::get_global_clock()->get_frame_time(); - update_state(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::get_display_wtext -// Access: Private -// Description: Returns the string that should be displayed within -// the entry. This is normally _wtext, but it may be -// _obscured_wtext. -//////////////////////////////////////////////////////////////////// -const wstring &PGEntry:: -get_display_wtext() { - if (_obscure_mode) { - // If obscure mode is enabled, we should just display a bunch of - // asterisks. - if (_obscured_wtext.length() != _wtext.length()) { - _obscured_wtext = wstring(); - wstring::const_iterator ti; - for (ti = _wtext.begin(); ti != _wtext.end(); ++ti) { - _obscured_wtext += (wchar_t)'*'; - } - } - - return _obscured_wtext; - - } else { - // In normal, non-obscure mode, we display the actual text. - return _wtext; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::slot_text_def -// Access: Private -// Description: Ensures there is a slot in the array for the given -// text definition. -//////////////////////////////////////////////////////////////////// -void PGEntry:: -slot_text_def(int state) { - while (state >= (int)_text_defs.size()) { - _text_defs.push_back((TextNode *)NULL); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::update_text -// Access: Private -// Description: Causes the PGEntry to recompute its text, if -// necessary. -//////////////////////////////////////////////////////////////////// -void PGEntry:: -update_text() { - TextNode *node = get_text_def(get_state()); - nassertv(node != (TextNode *)NULL); - - if (_text_geom_stale || node != _last_text_def) { - const wstring &display_wtext = get_display_wtext(); - - // We need to regenerate. - _last_text_def = node; - - if (_max_width > 0.0f && _num_lines > 1) { - // Fold the text into multiple lines. - wstring ww_text = - _last_text_def->wordwrap_to(display_wtext, _max_width, true); - - // And chop the lines up into pieces. - _ww_lines.clear(); - size_t p = 0; - size_t q = ww_text.find((wchar_t)'\n'); - while (q != string::npos) { - _ww_lines.push_back(WWLine()); - WWLine &line = _ww_lines.back(); - line._str = ww_text.substr(p, q - p); - - // Get the left edge of the text at this line. - line._left = 0.0f; - if (_last_text_def->get_align() != TextNode::A_left) { - _last_text_def->set_wtext(line._str); - line._left = _last_text_def->get_left(); - } - - p = q + 1; - q = ww_text.find('\n', p); - } - _ww_lines.push_back(WWLine()); - WWLine &line = _ww_lines.back(); - line._str = ww_text.substr(p); - - // Get the left edge of the text at this line. - line._left = 0.0f; - if (_last_text_def->get_align() != TextNode::A_left) { - _last_text_def->set_wtext(line._str); - line._left = _last_text_def->get_left(); - } - - _last_text_def->set_wtext(ww_text); - - } else { - // Only one line. - _ww_lines.clear(); - _ww_lines.push_back(WWLine()); - WWLine &line = _ww_lines.back(); - line._str = display_wtext; - - _last_text_def->set_wtext(display_wtext); - line._left = _last_text_def->get_left(); - } - - if (_current_text_arc != (NodeRelation *)NULL) { - remove_arc(_current_text_arc); - } - PT_Node text = _last_text_def->generate(); - _current_text_arc = new RenderRelation(_text_render_root, text); - _text_geom_stale = false; - _cursor_stale = true; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::update_cursor -// Access: Private -// Description: Moves the cursor to its correct position. -//////////////////////////////////////////////////////////////////// -void PGEntry:: -update_cursor() { - TextNode *node = get_text_def(get_state()); - nassertv(node != (TextNode *)NULL); - - if (_cursor_stale || node != _last_text_def) { - update_text(); - - _cursor_position = min(_cursor_position, (int)_wtext.length()); - - // Determine the row and column of the cursor. - int row = 0; - int column = _cursor_position; - while (row + 1 < (int)_ww_lines.size() && - column > (int)_ww_lines[row]._str.length()) { - column -= _ww_lines[row]._str.length(); - row++; - } - - nassertv(row >= 0 && row < (int)_ww_lines.size()); - nassertv(column >= 0 && column <= (int)_ww_lines[row]._str.length()); - - float width = - _last_text_def->calc_width(_ww_lines[row]._str.substr(0, column)); - float line_height = _last_text_def->get_line_height(); - - LVecBase3f trans(_ww_lines[row]._left + width, 0.0f, -line_height * row); - LMatrix4f mat = LMatrix4f::translate_mat(trans) * node->get_transform(); - _cursor_def->set_transition(new TransformTransition(mat)); - - _cursor_stale = false; - } - - // Should the cursor be visible? - if (!get_focus()) { - show_hide_cursor(false); - } else { - double elapsed_time = - ClockObject::get_global_clock()->get_frame_time() - _blink_start; - int cycle = (int)(elapsed_time * _blink_rate * 2.0f); - bool visible = ((cycle & 1) == 0); - show_hide_cursor(visible); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::show_hide_cursor -// Access: Private -// Description: Makes the cursor visible or invisible, e.g. during a -// blink cycle. -//////////////////////////////////////////////////////////////////// -void PGEntry:: -show_hide_cursor(bool visible) { - if (visible != _cursor_visible) { - if (visible) { - // Reveal the cursor. - _cursor_def->clear_transition(PruneTransition::get_class_type()); - } else { - // Hide the cursor. - _cursor_def->set_transition(new PruneTransition()); - } - _cursor_visible = visible; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGEntry::update_state -// Access: Private -// Description: Determines what the correct state for the PGEntry -// should be. -//////////////////////////////////////////////////////////////////// -void PGEntry:: -update_state() { - if (get_active()) { - if (get_focus()) { - set_state(S_focus); - } else { - set_state(S_no_focus); - } - } else { - set_state(S_inactive); - } -} diff --git a/panda/src/pgui/pgEntry.h b/panda/src/pgui/pgEntry.h deleted file mode 100644 index 7b73ce0b80..0000000000 --- a/panda/src/pgui/pgEntry.h +++ /dev/null @@ -1,196 +0,0 @@ -// Filename: pgEntry.h -// Created by: drose (10Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef PGENTRY_H -#define PGENTRY_H - -#include "pandabase.h" - -#include "pgItem.h" - -#include "textNode.h" -#include "pointerTo.h" -#include "pvector.h" -#include "clockObject.h" - -//////////////////////////////////////////////////////////////////// -// Class : PGEntry -// Description : This is a particular kind of PGItem that handles -// simple one-line text entries, of the sort where the -// user can type any string. -// -// A PGEntry does all of its internal manipulation on a -// wide string, so it can store the full Unicode -// character set. The interface can support either the -// wide string getters and setters, or the normal 8-bit -// string getters and setters, which use whatever -// encoding method is specified by the associated -// TextNode. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA PGEntry : public PGItem { -PUBLISHED: - PGEntry(const string &name = ""); - virtual ~PGEntry(); - -public: - PGEntry(const PGEntry ©); - void operator = (const PGEntry ©); - - virtual Node *make_copy() const; - - virtual void draw_item(PGTop *top, GraphicsStateGuardian *gsg, - const AllTransitionsWrapper &trans); - - virtual void press(const MouseWatcherParameter ¶m, bool background); - virtual void keystroke(const MouseWatcherParameter ¶m, bool background); - - virtual void accept(const MouseWatcherParameter ¶m); - virtual void overflow(const MouseWatcherParameter ¶m); - virtual void type(const MouseWatcherParameter ¶m); - virtual void erase(const MouseWatcherParameter ¶m); - -PUBLISHED: - enum State { - S_focus = 0, - S_no_focus, - S_inactive - }; - - void setup(float width, int num_lines); - - INLINE void set_text(const string &text); - INLINE string get_text() const; - - INLINE void set_cursor_position(int position); - INLINE int get_cursor_position() const; - - INLINE void set_max_chars(int max_chars); - INLINE int get_max_chars() const; - INLINE void set_max_width(float max_width); - INLINE float get_max_width() const; - INLINE void set_num_lines(int num_lines); - INLINE int get_num_lines() const; - - INLINE void set_blink_rate(float blink_rate); - INLINE float get_blink_rate() const; - - INLINE Node *get_cursor_def(); - INLINE void clear_cursor_def(); - - INLINE void set_cursor_keys_active(bool flag); - INLINE bool get_cursor_keys_active() const; - - INLINE void set_obscure_mode(bool flag); - INLINE bool get_obscure_mode() const; - - void set_text_def(int state, TextNode *node); - TextNode *get_text_def(int state) const; - - virtual void set_active(bool active); - virtual void set_focus(bool focus); - - INLINE static string get_accept_prefix(); - INLINE static string get_overflow_prefix(); - INLINE static string get_type_prefix(); - INLINE static string get_erase_prefix(); - - INLINE string get_accept_event(const ButtonHandle &button) const; - INLINE string get_overflow_event() const; - INLINE string get_type_event() const; - INLINE string get_erase_event() const; - -public: - INLINE void set_wtext(const wstring &wtext); - INLINE const wstring &get_wtext() const; - - -private: - const wstring &get_display_wtext(); - void slot_text_def(int state); - void update_text(); - void update_cursor(); - void show_hide_cursor(bool visible); - void update_state(); - - wstring _wtext; - wstring _obscured_wtext; - int _cursor_position; - bool _cursor_stale; - bool _cursor_visible; - - int _max_chars; - float _max_width; - int _num_lines; - - typedef pvector< PT(TextNode) > TextDefs; - TextDefs _text_defs; - - // This node is the root of the subgraph that renders both the text - // and the cursor. - PT_Node _text_render_root; - - // This is the arc that is attached to the above node when the text - // is generated. - NodeRelation *_current_text_arc; - TextNode *_last_text_def; - bool _text_geom_stale; - - // This is a list of each row of text in the entry, after it has - // been wordwrapped by update_text(). It's used by update_cursor() - // to compute the correct cursor position. - class WWLine { - public: - wstring _str; - float _left; - }; - typedef pvector WWLines; - WWLines _ww_lines; - - // This is the arc above the node that represents the cursor - // geometry. It is also attached to the above node, and is - // transformed around and/or hidden according to the cursor's - // position and blink state. - NodeRelation *_cursor_def; - - double _blink_start; - double _blink_rate; - - bool _cursor_keys_active; - bool _obscure_mode; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - PGItem::init_type(); - register_type(_type_handle, "PGEntry", - PGItem::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "pgEntry.I" - -#endif diff --git a/panda/src/pgui/pgFrameStyle.cxx b/panda/src/pgui/pgFrameStyle.cxx index f3efa2c236..4d9a2c2371 100644 --- a/panda/src/pgui/pgFrameStyle.cxx +++ b/panda/src/pgui/pgFrameStyle.cxx @@ -25,11 +25,6 @@ #include "pointerTo.h" #include "qpnodePath.h" -#include "geomNode.h" -#include "transparencyProperty.h" -#include "transparencyTransition.h" -#include "renderRelation.h" - ostream & operator << (ostream &out, PGFrameStyle::Type type) { switch (type) { @@ -104,64 +99,6 @@ xform(const LMatrix4f &mat) { return true; } -//////////////////////////////////////////////////////////////////// -// Function: PGFrameStyle::generate_into -// Access: Public -// Description: Generates geometry representing a frame of the -// indicated size, and parents it to the indicated node, -// with a scene graph sort order of -1. -// -// The return value is the generated arc, if any, or -// NULL if nothing is generated. -//////////////////////////////////////////////////////////////////// -NodeRelation *PGFrameStyle:: -generate_into(Node *node, const LVecBase4f &frame) { - NodeRelation *arc = (NodeRelation *)NULL; - PT_Node gnode; - - switch (_type) { - case T_none: - return (NodeRelation *)NULL; - - case T_flat: - gnode = generate_flat_geom(frame); - break; - - case T_bevel_out: - gnode = generate_bevel_geom(frame, false); - break; - - case T_bevel_in: - gnode = generate_bevel_geom(frame, true); - break; - - case T_groove: - gnode = generate_groove_geom(frame, true); - break; - - case T_ridge: - gnode = generate_groove_geom(frame, false); - break; - - default: - break; - } - - if (gnode != (GeomNode *)NULL) { - // We've got a GeomNode. - arc = new RenderRelation(node, gnode, -1); - } - - if (arc != (NodeRelation *)NULL && _color[3] != 1.0f) { - // We've got some alpha on the color; we need transparency. - TransparencyProperty::Mode mode = TransparencyProperty::M_alpha; - TransparencyTransition *tt = new TransparencyTransition(mode); - arc->set_transition(tt); - } - - return arc; -} - //////////////////////////////////////////////////////////////////// // Function: PGFrameStyle::generate_into // Access: Public @@ -213,433 +150,6 @@ generate_into(const qpNodePath &parent, const LVecBase4f &frame) { return parent.attach_new_node(new_node); } -//////////////////////////////////////////////////////////////////// -// Function: PGFrameStyle::generate_flat_geom -// Access: Private -// Description: Generates the GeomNode appropriate to a T_flat -// frame. -//////////////////////////////////////////////////////////////////// -PT_Node PGFrameStyle:: -generate_flat_geom(const LVecBase4f &frame) { - PT(GeomNode) gnode = new GeomNode("flat"); - Geom *geom = new GeomTristrip; - gnode->add_geom(geom); - - float left = frame[0]; - float right = frame[1]; - float bottom = frame[2]; - float top = frame[3]; - - PTA_int lengths=PTA_int::empty_array(0); - lengths.push_back(4); - - PTA_Vertexf verts; - verts.push_back(Vertexf(left, 0.0f, top)); - verts.push_back(Vertexf(left, 0.0f, bottom)); - verts.push_back(Vertexf(right, 0.0f, top)); - verts.push_back(Vertexf(right, 0.0f, bottom)); - - geom->set_num_prims(1); - geom->set_lengths(lengths); - - geom->set_coords(verts); - - PTA_Colorf colors; - colors.push_back(_color); - geom->set_colors(colors, G_OVERALL); - - return gnode.p(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGFrameStyle::generate_bevel_geom -// Access: Private -// Description: Generates the GeomNode appropriate to a T_bevel_in or -// T_bevel_out frame. -//////////////////////////////////////////////////////////////////// -PT_Node PGFrameStyle:: -generate_bevel_geom(const LVecBase4f &frame, bool in) { - // - // Colors: - // - // - // * * * * * * * * * * * * * * * * * * * * * * * - // * * * * - // * * ctop * * - // * * * * - // * * * * * * * * * * * * * * * * * - // * * * * - // * * * * - // * cleft * _color * cright* - // * * * * - // * * * * - // * * * * * * * * * * * * * * * * * - // * * * * - // * * cbottom * * - // * * * * - // * * * * * * * * * * * * * * * * * * * * * * * - // - // - // Vertices: - // - // tristrip 1: - // 4 * * * * * * * * * * * * * * * * * * * * * 6 - // * * * - // * * * - // * * * - // * 5 * * * * * * * * * * * * * 7 - // * * - // * * - // * * - // * * - // * * - // * 3 * * * * * * * * * * * * * 1 - // * * * - // * * * - // * * * - // 2 * * * * * * * * * * * * * * * * * * * * * 0 - // - // tristrip 2: - // 1 - // * * - // * * - // * * - // 5 * * * * * * * * * * * * * 3 * - // * * * - // * * * - // * * * - // * * * - // * * * - // 4 * * * * * * * * * * * * * 2 * - // * * - // * * - // * * - // 0 - - PT(GeomNode) gnode = new GeomNode("bevel"); - - float left = frame[0]; - float right = frame[1]; - float bottom = frame[2]; - float top = frame[3]; - - float inner_left = left + _width[0]; - float inner_right = right - _width[0]; - float inner_bottom = bottom + _width[1]; - float inner_top = top - _width[1]; - - float left_color_scale = 1.2; - float right_color_scale = 0.8; - float bottom_color_scale = 0.7; - float top_color_scale = 1.3; - - if (in) { - right_color_scale = 1.2; - left_color_scale = 0.8; - top_color_scale = 0.7; - bottom_color_scale = 1.3; - } - - // Clamp all colors at white, and don't scale the alpha. - Colorf cleft(min(_color[0] * left_color_scale, 1.0f), - min(_color[1] * left_color_scale, 1.0f), - min(_color[2] * left_color_scale, 1.0f), - _color[3]); - - Colorf cright(min(_color[0] * right_color_scale, 1.0f), - min(_color[1] * right_color_scale, 1.0f), - min(_color[2] * right_color_scale, 1.0f), - _color[3]); - - Colorf cbottom(min(_color[0] * bottom_color_scale, 1.0f), - min(_color[1] * bottom_color_scale, 1.0f), - min(_color[2] * bottom_color_scale, 1.0f), - _color[3]); - - Colorf ctop(min(_color[0] * top_color_scale, 1.0f), - min(_color[1] * top_color_scale, 1.0f), - min(_color[2] * top_color_scale, 1.0f), - _color[3]); - - // Now make the tristrips. - Geom *geom = new GeomTristrip; - gnode->add_geom(geom); - - PTA_int lengths; - PTA_Vertexf verts; - PTA_Colorf colors; - - // Tristrip 1. - lengths.push_back(8); - - verts.push_back(Vertexf(right, 0.0f, bottom)); - verts.push_back(Vertexf(inner_right, 0.0f, inner_bottom)); - verts.push_back(Vertexf(left, 0.0f, bottom)); - verts.push_back(Vertexf(inner_left, 0.0f, inner_bottom)); - verts.push_back(Vertexf(left, 0.0f, top)); - verts.push_back(Vertexf(inner_left, 0.0f, inner_top)); - verts.push_back(Vertexf(right, 0.0f, top)); - verts.push_back(Vertexf(inner_right, 0.0f, inner_top)); - - colors.push_back(cbottom); - colors.push_back(cbottom); - colors.push_back(cleft); - colors.push_back(cleft); - colors.push_back(ctop); - colors.push_back(ctop); - - // Tristrip 2. - lengths.push_back(6); - - verts.push_back(Vertexf(right, 0.0f, bottom)); - verts.push_back(Vertexf(right, 0.0f, top)); - verts.push_back(Vertexf(inner_right, 0.0f, inner_bottom)); - verts.push_back(Vertexf(inner_right, 0.0f, inner_top)); - verts.push_back(Vertexf(inner_left, 0.0f, inner_bottom)); - verts.push_back(Vertexf(inner_left, 0.0f, inner_top)); - - colors.push_back(cright); - colors.push_back(cright); - colors.push_back(_color); - colors.push_back(_color); - - geom->set_num_prims(2); - geom->set_lengths(lengths); - geom->set_coords(verts); - geom->set_colors(colors, G_PER_COMPONENT); - - return gnode.p(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGFrameStyle::generate_groove_geom -// Access: Private -// Description: Generates the GeomNode appropriate to a T_groove or -// T_ridge frame. -//////////////////////////////////////////////////////////////////// -PT_Node PGFrameStyle:: -generate_groove_geom(const LVecBase4f &frame, bool in) { - // - // Colors: - // - // - // * * * * * * * * * * * * * * * * * * * * * * * * * * * - // * * * * - // * * ctop * * - // * * * * - // * * * * * * * * * * * * * * * * * * * * * - // * * * * * * - // * * * cbottom * * * - // * * * * * * - // * * * * * * * * * * * * * * * - // * * * * * * - // * * * * * * - // * cleft * cright* _color * cleft * cright* - // * * * * * * - // * * * * * * - // * * * * * * * * * * * * * * * - // * * * * * * - // * * * ctop * * * - // * * * * * * - // * * * * * * * * * * * * * * * * * * * * * - // * * * * - // * * cbottom * * - // * * * * - // * * * * * * * * * * * * * * * * * * * * * * * * * * * - // - // - // Vertices: - // - // tristrip 1: - // 4 * * * * * * * * * * * * * * * * * * * * * * * * * 6 - // * * * - // * * * - // * * * - // * 5 * * * * * * * * * * * * * * * * * 7 - // * * - // * * - // * * - // * * - // * * - // * * - // * * - // * * - // * * - // * * - // * * - // * * - // * * - // * 3 * * * * * * * * * * * * * * * * * 1 - // * * * - // * * * - // * * * - // 2 * * * * * * * * * * * * * * * * * * * * * * * * * 0 - // - // tristrip 2: - // 4 * * * * * * * * * * * * * * * * * 6 - // * * * - // * * * - // * * * - // * 5 * * * * * * * * * 7 - // * * - // * * - // * * - // * * - // * * - // * 3 * * * * * * * * * 1 - // * * * - // * * * - // * * * - // 2 * * * * * * * * * * * * * * * * * 0 - // - // tristrip 3: - // 1 - // * * - // * * - // * * - // 3 * - // * * * - // * * * - // * * * - // 7 * * * * * * * * * 5 * * - // * * * * - // * * * * - // * * * * - // * * * * - // * * * * - // 6 * * * * * * * * * 4 * * - // * * * - // * * * - // * * * - // 2 * - // * * - // * * - // * * - // 0 - - PT(GeomNode) gnode = new GeomNode("groove"); - - float left = frame[0]; - float right = frame[1]; - float bottom = frame[2]; - float top = frame[3]; - - float mid_left = left + 0.5f * _width[0]; - float mid_right = right - 0.5f * _width[0]; - float mid_bottom = bottom + 0.5f * _width[1]; - float mid_top = top - 0.5f * _width[1]; - - float inner_left = left + _width[0]; - float inner_right = right - _width[0]; - float inner_bottom = bottom + _width[1]; - float inner_top = top - _width[1]; - - float left_color_scale = 1.2f; - float right_color_scale = 0.8f; - float bottom_color_scale = 0.7f; - float top_color_scale = 1.3f; - - if (in) { - right_color_scale = 1.2f; - left_color_scale = 0.8f; - top_color_scale = 0.7f; - bottom_color_scale = 1.3f; - } - - // Clamp all colors at white, and don't scale the alpha. - Colorf cleft(min(_color[0] * left_color_scale, 1.0f), - min(_color[1] * left_color_scale, 1.0f), - min(_color[2] * left_color_scale, 1.0f), - _color[3]); - - Colorf cright(min(_color[0] * right_color_scale, 1.0f), - min(_color[1] * right_color_scale, 1.0f), - min(_color[2] * right_color_scale, 1.0f), - _color[3]); - - Colorf cbottom(min(_color[0] * bottom_color_scale, 1.0f), - min(_color[1] * bottom_color_scale, 1.0f), - min(_color[2] * bottom_color_scale, 1.0f), - _color[3]); - - Colorf ctop(min(_color[0] * top_color_scale, 1.0f), - min(_color[1] * top_color_scale, 1.0f), - min(_color[2] * top_color_scale, 1.0f), - _color[3]); - - // Now make the tristrips. - Geom *geom = new GeomTristrip; - gnode->add_geom(geom); - - PTA_int lengths; - PTA_Vertexf verts; - PTA_Colorf colors; - - // Tristrip 1. - lengths.push_back(8); - - verts.push_back(Vertexf(right, 0.0f, bottom)); - verts.push_back(Vertexf(mid_right, 0.0f, mid_bottom)); - verts.push_back(Vertexf(left, 0.0f, bottom)); - verts.push_back(Vertexf(mid_left, 0.0f, mid_bottom)); - verts.push_back(Vertexf(left, 0.0f, top)); - verts.push_back(Vertexf(mid_left, 0.0f, mid_top)); - verts.push_back(Vertexf(right, 0.0f, top)); - verts.push_back(Vertexf(mid_right, 0.0f, mid_top)); - - colors.push_back(cbottom); - colors.push_back(cbottom); - colors.push_back(cleft); - colors.push_back(cleft); - colors.push_back(ctop); - colors.push_back(ctop); - - // Tristrip 2. - lengths.push_back(8); - - verts.push_back(Vertexf(mid_right, 0.0f, mid_bottom)); - verts.push_back(Vertexf(inner_right, 0.0f, inner_bottom)); - verts.push_back(Vertexf(mid_left, 0.0f, mid_bottom)); - verts.push_back(Vertexf(inner_left, 0.0f, inner_bottom)); - verts.push_back(Vertexf(mid_left, 0.0f, mid_top)); - verts.push_back(Vertexf(inner_left, 0.0f, inner_top)); - verts.push_back(Vertexf(mid_right, 0.0f, mid_top)); - verts.push_back(Vertexf(inner_right, 0.0f, inner_top)); - - colors.push_back(ctop); - colors.push_back(ctop); - colors.push_back(cright); - colors.push_back(cright); - colors.push_back(cbottom); - colors.push_back(cbottom); - - // Tristrip 3. - lengths.push_back(8); - - verts.push_back(Vertexf(right, 0.0f, bottom)); - verts.push_back(Vertexf(right, 0.0f, top)); - verts.push_back(Vertexf(mid_right, 0.0f, mid_bottom)); - verts.push_back(Vertexf(mid_right, 0.0f, mid_top)); - verts.push_back(Vertexf(inner_right, 0.0f, inner_bottom)); - verts.push_back(Vertexf(inner_right, 0.0f, inner_top)); - verts.push_back(Vertexf(inner_left, 0.0f, inner_bottom)); - verts.push_back(Vertexf(inner_left, 0.0f, inner_top)); - - colors.push_back(cright); - colors.push_back(cright); - colors.push_back(cleft); - colors.push_back(cleft); - colors.push_back(_color); - colors.push_back(_color); - - geom->set_num_prims(3); - geom->set_lengths(lengths); - geom->set_coords(verts); - geom->set_colors(colors, G_PER_COMPONENT); - - return gnode.p(); -} - //////////////////////////////////////////////////////////////////// // Function: PGFrameStyle::qpgenerate_flat_geom // Access: Private diff --git a/panda/src/pgui/pgFrameStyle.h b/panda/src/pgui/pgFrameStyle.h index d6930a8945..977d4abba4 100644 --- a/panda/src/pgui/pgFrameStyle.h +++ b/panda/src/pgui/pgFrameStyle.h @@ -22,10 +22,7 @@ #include "pandabase.h" #include "luse.h" -#include "pt_Node.h" -class NodeRelation; -class Node; class PandaNode; class qpNodePath; @@ -65,13 +62,9 @@ PUBLISHED: public: bool xform(const LMatrix4f &mat); - NodeRelation *generate_into(Node *node, const LVecBase4f &frame); qpNodePath generate_into(const qpNodePath &parent, const LVecBase4f &frame); private: - PT_Node generate_flat_geom(const LVecBase4f &frame); - PT_Node generate_bevel_geom(const LVecBase4f &frame, bool in); - PT_Node generate_groove_geom(const LVecBase4f &frame, bool in); PT(PandaNode) qpgenerate_flat_geom(const LVecBase4f &frame); PT(PandaNode) qpgenerate_bevel_geom(const LVecBase4f &frame, bool in); PT(PandaNode) qpgenerate_groove_geom(const LVecBase4f &frame, bool in); diff --git a/panda/src/pgui/pgItem.I b/panda/src/pgui/pgItem.I deleted file mode 100644 index 37003aef79..0000000000 --- a/panda/src/pgui/pgItem.I +++ /dev/null @@ -1,468 +0,0 @@ -// Filename: pgItem.I -// Created by: drose (02Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_region -// Access: Public -// Description: Returns the MouseWatcherRegion associated with this -// item. Every PGItem has a MouseWatcherRegion -// associated with it, that is created when the PGItem -// is created; it does not change during the lifetime of -// the PGItem. Even items that do not have a frame have -// an associated MouseWatcherRegion, although it will -// not be used in this case. -//////////////////////////////////////////////////////////////////// -INLINE PGMouseWatcherRegion *PGItem:: -get_region() const { - return _region; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::set_frame -// Access: Published -// Description: Sets the bounding rectangle of the item, in local -// coordinates. This is the region on screen within -// which the mouse will be considered to be within the -// item. Normally, it should correspond to the bounding -// rectangle of the visible geometry of the item. -//////////////////////////////////////////////////////////////////// -INLINE void PGItem:: -set_frame(float left, float right, float bottom, float top) { - set_frame(LVecBase4f(left, right, bottom, top)); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::set_frame -// Access: Published -// Description: Sets the bounding rectangle of the item, in local -// coordinates. This is the region on screen within -// which the mouse will be considered to be within the -// item. Normally, it should correspond to the bounding -// rectangle of the visible geometry of the item. -//////////////////////////////////////////////////////////////////// -INLINE void PGItem:: -set_frame(const LVecBase4f &frame) { - _has_frame = true; - _frame = frame; - mark_frames_stale(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_frame -// Access: Published -// Description: Returns the bounding rectangle of the item. See -// set_frame(). It is an error to call this if -// has_frame() returns false. -//////////////////////////////////////////////////////////////////// -INLINE const LVecBase4f &PGItem:: -get_frame() const { - nassertr(has_frame(), _frame); - return _frame; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::has_frame -// Access: Published -// Description: Returns true if the item has a bounding rectangle; -// see set_frame(). -//////////////////////////////////////////////////////////////////// -INLINE bool PGItem:: -has_frame() const { - return _has_frame; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::clear_frame -// Access: Published -// Description: Removes the bounding rectangle from the item. It -// will no longer be possible to position the mouse -// within the item; see set_frame(). -//////////////////////////////////////////////////////////////////// -INLINE void PGItem:: -clear_frame() { - _has_frame = false; - mark_frames_stale(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::set_state -// Access: Published -// Description: Sets the "state" of this particular PGItem. -// -// The PGItem node will render as if it were the -// subgraph assigned to the corresponding index via -// set_state_def(). -//////////////////////////////////////////////////////////////////// -INLINE void PGItem:: -set_state(int state) { - _state = state; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_state -// Access: Published -// Description: Returns the "state" of this particular PGItem. See -// set_state(). -//////////////////////////////////////////////////////////////////// -INLINE int PGItem:: -get_state() const { - return _state; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_active -// Access: Published -// Description: Returns whether the PGItem is currently active for -// mouse events. See set_active(). -//////////////////////////////////////////////////////////////////// -INLINE bool PGItem:: -get_active() const { - return (_flags & F_active) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_focus -// Access: Published -// Description: Returns whether the PGItem currently has focus for -// keyboard events. See set_focus(). -//////////////////////////////////////////////////////////////////// -INLINE bool PGItem:: -get_focus() const { - return (_flags & F_focus) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_background_focus -// Access: Published -// Description: Returns whether background_focus is currently -// enabled. See set_background_focus(). -//////////////////////////////////////////////////////////////////// -INLINE bool PGItem:: -get_background_focus() const { - return (_flags & F_background_focus) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::set_suppress_flags -// Access: Published -// Description: This is just an interface to set the suppress flags -// on the underlying MouseWatcherRegion. See -// MouseWatcherRegion::set_suppress_flags(). -//////////////////////////////////////////////////////////////////// -INLINE void PGItem:: -set_suppress_flags(int suppress_flags) { - _region->set_suppress_flags(suppress_flags); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_suppress_flags -// Access: Published -// Description: This is just an interface to get the suppress flags -// on the underlying MouseWatcherRegion. See -// MouseWatcherRegion::get_suppress_flags(). -//////////////////////////////////////////////////////////////////// -INLINE int PGItem:: -get_suppress_flags() const { - return _region->get_suppress_flags(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_id -// Access: Published -// Description: Returns the unique ID assigned to this PGItem. This -// will be assigned to the region created with the -// MouseWatcher, and will thus be used to generate event -// names. -//////////////////////////////////////////////////////////////////// -INLINE const string &PGItem:: -get_id() const { - return _region->get_name(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::set_id -// Access: Published -// Description: Set the unique ID assigned to this PGItem. It is the -// user's responsibility to ensure that this ID is -// unique. -// -// Normally, this should not need to be called, as the -// PGItem will assign itself an ID when it is created, -// but this function allows the user to decide to -// redefine the ID to be something possibly more -// meaningful. -//////////////////////////////////////////////////////////////////// -INLINE void PGItem:: -set_id(const string &id) { - _region->set_name(id); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_enter_prefix -// Access: Published, Static -// Description: Returns the prefix that is used to define the enter -// event for all PGItems. The enter event is the -// concatenation of this string followed by get_id(). -//////////////////////////////////////////////////////////////////// -INLINE string PGItem:: -get_enter_prefix() { - return "enter-"; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_exit_prefix -// Access: Published, Static -// Description: Returns the prefix that is used to define the exit -// event for all PGItems. The exit event is the -// concatenation of this string followed by get_id(). -//////////////////////////////////////////////////////////////////// -INLINE string PGItem:: -get_exit_prefix() { - return "exit-"; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_within_prefix -// Access: Published, Static -// Description: Returns the prefix that is used to define the within -// event for all PGItems. The within event is the -// concatenation of this string followed by get_id(). -//////////////////////////////////////////////////////////////////// -INLINE string PGItem:: -get_within_prefix() { - return "within-"; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_without_prefix -// Access: Published, Static -// Description: Returns the prefix that is used to define the without -// event for all PGItems. The without event is the -// concatenation of this string followed by get_id(). -//////////////////////////////////////////////////////////////////// -INLINE string PGItem:: -get_without_prefix() { - return "without-"; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_focus_in_prefix -// Access: Published, Static -// Description: Returns the prefix that is used to define the focus_in -// event for all PGItems. The focus_in event is the -// concatenation of this string followed by get_id(). -// -// Unlike most item events, this event is thrown with no -// parameters. -//////////////////////////////////////////////////////////////////// -INLINE string PGItem:: -get_focus_in_prefix() { - return "fin-"; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_focus_out_prefix -// Access: Published, Static -// Description: Returns the prefix that is used to define the focus_out -// event for all PGItems. The focus_out event is the -// concatenation of this string followed by get_id(). -// -// Unlike most item events, this event is thrown with no -// parameters. -//////////////////////////////////////////////////////////////////// -INLINE string PGItem:: -get_focus_out_prefix() { - return "fout-"; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_press_prefix -// Access: Published, Static -// Description: Returns the prefix that is used to define the press -// event for all PGItems. The press event is the -// concatenation of this string followed by a button -// name, followed by a hyphen and get_id(). -//////////////////////////////////////////////////////////////////// -INLINE string PGItem:: -get_press_prefix() { - return "press-"; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_release_prefix -// Access: Published, Static -// Description: Returns the prefix that is used to define the release -// event for all PGItems. The release event is the -// concatenation of this string followed by a button -// name, followed by a hyphen and get_id(). -//////////////////////////////////////////////////////////////////// -INLINE string PGItem:: -get_release_prefix() { - return "release-"; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_keystroke_prefix -// Access: Published, Static -// Description: Returns the prefix that is used to define the -// keystroke event for all PGItems. The keystroke event -// is the concatenation of this string followed by a -// hyphen and get_id(). -//////////////////////////////////////////////////////////////////// -INLINE string PGItem:: -get_keystroke_prefix() { - return "keystroke-"; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_enter_event -// Access: Published -// Description: Returns the event name that will be thrown when the -// item is active and the mouse enters its frame, but -// not any nested frames. -//////////////////////////////////////////////////////////////////// -INLINE string PGItem:: -get_enter_event() const { - return get_enter_prefix() + get_id(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_exit_event -// Access: Published -// Description: Returns the event name that will be thrown when the -// item is active and the mouse exits its frame, or -// enters a nested frame. -//////////////////////////////////////////////////////////////////// -INLINE string PGItem:: -get_exit_event() const { - return get_exit_prefix() + get_id(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_within_event -// Access: Published -// Description: Returns the event name that will be thrown when the -// item is active and the mouse moves within the -// boundaries of the frame. This is different from the -// enter_event in that the mouse is considered within -// the frame even if it is also within a nested frame. -//////////////////////////////////////////////////////////////////// -INLINE string PGItem:: -get_within_event() const { - return get_within_prefix() + get_id(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_without_event -// Access: Published -// Description: Returns the event name that will be thrown when the -// item is active and the mouse moves completely outside -// the boundaries of the frame. This is different from -// the exit_event in that the mouse is considered -// within the frame even if it is also within a nested -// frame. -//////////////////////////////////////////////////////////////////// -INLINE string PGItem:: -get_without_event() const { - return get_without_prefix() + get_id(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_focus_in_event -// Access: Published -// Description: Returns the event name that will be thrown when the -// item gets the keyboard focus. -//////////////////////////////////////////////////////////////////// -INLINE string PGItem:: -get_focus_in_event() const { - return get_focus_in_prefix() + get_id(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_focus_out_event -// Access: Published -// Description: Returns the event name that will be thrown when the -// item loses the keyboard focus. -//////////////////////////////////////////////////////////////////// -INLINE string PGItem:: -get_focus_out_event() const { - return get_focus_out_prefix() + get_id(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_press_event -// Access: Published -// Description: Returns the event name that will be thrown when the -// item is active and the indicated mouse or keyboard -// button is depressed while the mouse is within the -// frame. -//////////////////////////////////////////////////////////////////// -INLINE string PGItem:: -get_press_event(const ButtonHandle &button) const { - return get_press_prefix() + button.get_name() + "-" + get_id(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_release_event -// Access: Published -// Description: Returns the event name that will be thrown when the -// item is active and the indicated mouse or keyboard -// button, formerly clicked down is within the frame, is -// released. -//////////////////////////////////////////////////////////////////// -INLINE string PGItem:: -get_release_event(const ButtonHandle &button) const { - return get_release_prefix() + button.get_name() + "-" + get_id(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_keystroke_event -// Access: Published -// Description: Returns the event name that will be thrown when the -// item is active and any key is pressed by the user. -//////////////////////////////////////////////////////////////////// -INLINE string PGItem:: -get_keystroke_event() const { - return get_keystroke_prefix() + get_id(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::set_text_node -// Access: Published, Static -// Description: Changes the TextNode object that will be used by all -// PGItems to generate default labels given a string. -// This can be loaded with the default font, etc. -//////////////////////////////////////////////////////////////////// -INLINE void PGItem:: -set_text_node(TextNode *node) { - _text_node = node; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_focus_item -// Access: Published, Static -// Description: Returns the one PGItem in the world that currently -// has keyboard focus, if any, or NULL if no item has -// keyboard focus. Use PGItem::set_focus() to activate -// or deactivate keyboard focus on a particular item. -//////////////////////////////////////////////////////////////////// -INLINE PGItem *PGItem:: -get_focus_item() { - return _focus_item; -} diff --git a/panda/src/pgui/pgItem.cxx b/panda/src/pgui/pgItem.cxx deleted file mode 100644 index 70db87cb17..0000000000 --- a/panda/src/pgui/pgItem.cxx +++ /dev/null @@ -1,826 +0,0 @@ -// Filename: pgItem.cxx -// Created by: drose (02Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "pgTop.h" -#include "pgItem.h" -#include "pgMouseWatcherParameter.h" -#include "config_pgui.h" - -#include "namedNode.h" -#include "throw_event.h" -#include "string_utils.h" -#include "arcChain.h" -#include "transformTransition.h" -#include "sceneGraphReducer.h" -#include "directRenderTraverser.h" -#include "quickRenderTraverser.h" -#include "allTransitionsWrapper.h" -#include "graphicsStateGuardian.h" - -#ifdef HAVE_AUDIO -#include "audioSound.h" -#endif - -TypeHandle PGItem::_type_handle; -PT(TextNode) PGItem::_text_node; -PGItem *PGItem::_focus_item = (PGItem *)NULL; -PGItem::BackgroundFocus PGItem::_background_focus; - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -PGItem:: -PGItem(const string &name) : NamedNode(name) -{ - _has_frame = false; - _frame.set(0, 0, 0, 0); - _region = new PGMouseWatcherRegion(this); - _state = 0; - _flags = 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -PGItem:: -~PGItem() { - nassertv(_region->_item == this); - _region->_item = (PGItem *)NULL; - - set_background_focus(false); - if (_focus_item == this) { - _focus_item = (PGItem *)NULL; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -PGItem:: -PGItem(const PGItem ©) : - NamedNode(copy), - _has_frame(copy._has_frame), - _frame(copy._frame), - _state(copy._state), - _flags(copy._flags) -{ - _region = new PGMouseWatcherRegion(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void PGItem:: -operator = (const PGItem ©) { - NamedNode::operator = (copy); - _has_frame = copy._has_frame; - _frame = copy._frame; - _state = copy._state; - _flags = copy._flags; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::make_copy -// Access: Public, Virtual -// Description: Returns a newly-allocated Node that is a shallow copy -// of this one. It will be a different Node pointer, -// but its internal data may or may not be shared with -// that of the original Node. -//////////////////////////////////////////////////////////////////// -Node *PGItem:: -make_copy() const { - return new PGItem(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::xform -// Access: Public, Virtual -// Description: Transforms the contents of this node by the indicated -// matrix, if it means anything to do so. For most -// kinds of nodes, this does nothing. -//////////////////////////////////////////////////////////////////// -void PGItem:: -xform(const LMatrix4f &mat) { - // Transform the frame. - LPoint3f ll(_frame[0], 0.0, _frame[2]); - LPoint3f ur(_frame[1], 0.0, _frame[3]); - ll = ll * mat; - ur = ur * mat; - _frame.set(ll[0], ur[0], ll[2], ur[2]); - - // Transform the individual states and their frame styles. - StateDefs::iterator di; - for (di = _state_defs.begin(); di != _state_defs.end(); ++di) { - Node *node = (*di)._node; - if (node != (Node *)NULL) { - // Apply the matrix to the previous transform on all the arcs - // here. - int num_children = node->get_num_children(RenderRelation::get_class_type()); - for (int i = 0; i < num_children; i++) { - NodeRelation *arc = node->get_child(RenderRelation::get_class_type(), i); - if (arc != (*di)._frame_arc) { - LMatrix4f arc_mat; - TransformTransition *tt; - if (!get_transition_into(tt, arc)) { - // No previous transform. - arc_mat = mat; - } else { - arc_mat = tt->get_matrix() * mat; - } - tt = new TransformTransition(arc_mat); - arc->set_transition(tt); - - // Now flatten the transform into the subgraph. - SceneGraphReducer gr; - gr.apply_transitions(arc); - } - } - } - - // Transform the frame style too. - if ((*di)._frame_style.xform(mat)) { - (*di)._frame_stale = true; - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::activate_region -// Access: Public, Virtual -// Description: Applies the indicated scene graph transform and order -// as determined by the traversal from PGTop. -//////////////////////////////////////////////////////////////////// -void PGItem:: -activate_region(PGTop *, const LMatrix4f &transform, int sort) { - // Transform all four vertices, and get the new bounding box. This - // way the region works (mostly) even if has been rotated. - LPoint3f ll(_frame[0], 0.0, _frame[2]); - LPoint3f lr(_frame[1], 0.0, _frame[2]); - LPoint3f ul(_frame[0], 0.0, _frame[3]); - LPoint3f ur(_frame[1], 0.0, _frame[3]); - ll = ll * transform; - lr = lr * transform; - ul = ul * transform; - ur = ur * transform; - _region->set_frame(min(min(ll[0], lr[0]), min(ul[0], ur[0])), - max(max(ll[0], lr[0]), max(ul[0], ur[0])), - min(min(ll[2], lr[2]), min(ul[2], ur[2])), - max(max(ll[2], lr[2]), max(ul[2], ur[2]))); - - _region->set_sort(sort); - _region->set_active(true); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::draw_item -// Access: Public, Virtual -// Description: Called by the PGTop's traversal to draw this -// particular item. -//////////////////////////////////////////////////////////////////// -void PGItem:: -draw_item(PGTop *top, GraphicsStateGuardian *gsg, - const AllTransitionsWrapper &trans) { - if (has_state_def(get_state())) { - // This item has a current state definition that we should use - // to render the item. - Node *def = get_state_def(get_state()); - - if (!pgui_quick) { - // We'll use a normal DirectRenderTraverser to do the rendering - // of the subgraph. - DirectRenderTraverser drt(gsg, RenderRelation::get_class_type()); - drt.set_view_frustum_cull(false); - drt.traverse(def, trans); - - } else { - QuickRenderTraverser qrt(gsg, RenderRelation::get_class_type()); - qrt.traverse(def, trans); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::enter -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever the -// mouse enters the region. The mouse is only -// considered to be "entered" in one region at a time; -// in the case of nested regions, it exits the outer -// region before entering the inner one. -//////////////////////////////////////////////////////////////////// -void PGItem:: -enter(const MouseWatcherParameter ¶m) { - PGMouseWatcherParameter *ep = new PGMouseWatcherParameter(param); - string event = get_enter_event(); - play_sound(event); - throw_event(event, EventParameter(ep)); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::exit -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever the -// mouse exits the region. The mouse is only considered -// to be "entered" in one region at a time; in the case -// of nested regions, it exits the outer region before -// entering the inner one. -//////////////////////////////////////////////////////////////////// -void PGItem:: -exit(const MouseWatcherParameter ¶m) { - PGMouseWatcherParameter *ep = new PGMouseWatcherParameter(param); - string event = get_exit_event(); - play_sound(event); - throw_event(event, EventParameter(ep)); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::within -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever the -// mouse moves within the boundaries of the region, even -// if it is also within the boundaries of a nested -// region. This is different from "enter", which is -// only called whenever the mouse is within only that -// region. -//////////////////////////////////////////////////////////////////// -void PGItem:: -within(const MouseWatcherParameter ¶m) { - PGMouseWatcherParameter *ep = new PGMouseWatcherParameter(param); - string event = get_within_event(); - play_sound(event); - throw_event(event, EventParameter(ep)); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::without -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever the -// mouse moves completely outside the boundaries of the -// region. See within(). -//////////////////////////////////////////////////////////////////// -void PGItem:: -without(const MouseWatcherParameter ¶m) { - PGMouseWatcherParameter *ep = new PGMouseWatcherParameter(param); - string event = get_without_event(); - play_sound(event); - throw_event(event, EventParameter(ep)); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::focus_in -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever the -// widget gets the keyboard focus. -//////////////////////////////////////////////////////////////////// -void PGItem:: -focus_in() { - string event = get_focus_in_event(); - play_sound(event); - throw_event(event); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::focus_out -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever the -// widget loses the keyboard focus. -//////////////////////////////////////////////////////////////////// -void PGItem:: -focus_out() { - string event = get_focus_out_event(); - play_sound(event); - throw_event(event); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::press -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever a -// mouse or keyboard button is depressed while the mouse -// is within the region. -//////////////////////////////////////////////////////////////////// -void PGItem:: -press(const MouseWatcherParameter ¶m, bool background) { - if (!background) { - PGMouseWatcherParameter *ep = new PGMouseWatcherParameter(param); - string event = get_press_event(param.get_button()); - play_sound(event); - throw_event(event, EventParameter(ep)); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::release -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever a -// mouse or keyboard button previously depressed with -// press() is released. -//////////////////////////////////////////////////////////////////// -void PGItem:: -release(const MouseWatcherParameter ¶m, bool background) { - if (!background) { - PGMouseWatcherParameter *ep = new PGMouseWatcherParameter(param); - string event = get_release_event(param.get_button()); - play_sound(event); - throw_event(event, EventParameter(ep)); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::keystroke -// Access: Public, Virtual -// Description: This is a callback hook function, called whenever -// the user presses a key. -//////////////////////////////////////////////////////////////////// -void PGItem:: -keystroke(const MouseWatcherParameter ¶m, bool background) { - if (!background) { - PGMouseWatcherParameter *ep = new PGMouseWatcherParameter(param); - string event = get_keystroke_event(); - play_sound(event); - throw_event(event, EventParameter(ep)); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::background_press -// Access: Public, Static -// Description: Calls press() on all the PGItems with background -// focus. -//////////////////////////////////////////////////////////////////// -void PGItem:: -background_press(const MouseWatcherParameter ¶m) { - BackgroundFocus::const_iterator fi; - for (fi = _background_focus.begin(); fi != _background_focus.end(); ++fi) { - PGItem *item = *fi; - if (!item->get_focus()) { - item->press(param, true); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::background_release -// Access: Public, Static -// Description: Calls release() on all the PGItems with background -// focus. -//////////////////////////////////////////////////////////////////// -void PGItem:: -background_release(const MouseWatcherParameter ¶m) { - BackgroundFocus::const_iterator fi; - for (fi = _background_focus.begin(); fi != _background_focus.end(); ++fi) { - PGItem *item = *fi; - if (!item->get_focus()) { - item->release(param, true); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::background_keystroke -// Access: Public, Static -// Description: Calls keystroke() on all the PGItems with background -// focus. -//////////////////////////////////////////////////////////////////// -void PGItem:: -background_keystroke(const MouseWatcherParameter ¶m) { - BackgroundFocus::const_iterator fi; - for (fi = _background_focus.begin(); fi != _background_focus.end(); ++fi) { - PGItem *item = *fi; - if (!item->get_focus()) { - item->keystroke(param, true); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::set_active -// Access: Published, Virtual -// Description: Sets whether the PGItem is active for mouse watching. -// This is not necessarily related to the -// active/inactive appearance of the item, which is -// controlled by set_state(), but it does affect whether -// it responds to mouse events. -//////////////////////////////////////////////////////////////////// -void PGItem:: -set_active(bool active) { - if (active) { - _flags |= F_active; - } else { - _flags &= ~F_active; - // Deactivating the item automatically defocuses it too. - if (get_focus()) { - set_focus(false); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::set_focus -// Access: Published, Virtual -// Description: Sets whether the PGItem currently has keyboard focus. -// This simply means that the item may respond to -// keyboard events as well as to mouse events; precisely -// what this means is up to the individual item. -// -// Only one PGItem in the world is allowed to have focus -// at any given time. Setting the focus on any other -// item automatically disables the focus from the -// previous item. -//////////////////////////////////////////////////////////////////// -void PGItem:: -set_focus(bool focus) { - if (focus) { - if (!get_active()) { - // Cannot set focus on an inactive item. - return; - } - - // Set the keyboard focus to this item. - if (_focus_item != this) { - if (_focus_item != (PGItem *)NULL) { - // Clear the focus from whatever item currently has it. - _focus_item->set_focus(false); - } - _focus_item = this; - } - if (!get_focus()) { - focus_in(); - _flags |= F_focus; - } - - } else { - if (_focus_item == this) { - // Remove this item from the focus. - _focus_item = (PGItem *)NULL; - } - - if (get_focus()) { - focus_out(); - _flags &= ~F_focus; - } - } - _region->set_keyboard(focus); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::set_background_focus -// Access: Published -// Description: Sets the background_focus flag for this item. When -// background_focus is enabled, the item will receive -// keypress events even if it is not in focus; in fact, -// even if it is not onscreen. Unlike normal focus, -// many items may have background_focus simultaneously. -//////////////////////////////////////////////////////////////////// -void PGItem:: -set_background_focus(bool focus) { - if (focus != get_background_focus()) { - if (focus) { - // Activate background focus. - _flags |= F_background_focus; - bool inserted = _background_focus.insert(this).second; - nassertv(inserted); - - } else { - // Deactivate background focus. - _flags &= ~F_background_focus; - size_t num_erased = _background_focus.erase(this); - nassertv(num_erased == 1); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_num_state_defs -// Access: Published -// Description: Returns one more than the highest-numbered state def -// that was ever assigned to the PGItem. The complete -// set of state defs assigned may then be retrieved by -// indexing from 0 to (get_num_state_defs() - 1). -// -// This is only an upper limit on the actual number of -// state defs, since there may be holes in the list. -//////////////////////////////////////////////////////////////////// -int PGItem:: -get_num_state_defs() const { - return _state_defs.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::has_state_def -// Access: Published -// Description: Returns true if get_state_def() has ever been called -// for the indicated state (thus defining a render -// subgraph for this state index), false otherwise. -//////////////////////////////////////////////////////////////////// -bool PGItem:: -has_state_def(int state) const { - if (state < 0 || state >= (int)_state_defs.size()) { - return false; - } - return (_state_defs[state]._node != (Node *)NULL); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::clear_state_def -// Access: Published -// Description: Resets the NodePath assigned to the indicated state -// to its initial default, with only a frame -// representation if appropriate. -//////////////////////////////////////////////////////////////////// -void PGItem:: -clear_state_def(int state) { - if (state < 0 || state >= (int)_state_defs.size()) { - return; - } - - remove_all_children(_state_defs[state]._node); - - _state_defs[state]._frame_arc = (NodeRelation *)NULL; - _state_defs[state]._frame_stale = true; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_state_def -// Access: Published -// Description: Returns the Node that is the root of the subgraph -// that will be drawn when the PGItem is in the -// indicated state. The first time this is called for a -// particular state index, it may create the Node. -//////////////////////////////////////////////////////////////////// -Node *PGItem:: -get_state_def(int state) { - nassertr(state >= 0 && state < 1000, (Node *)NULL); // Sanity check. - slot_state_def(state); - - if (_state_defs[state]._node == (Node *)NULL) { - // Create a new node. - _state_defs[state]._node = new NamedNode("state_" + format_string(state)); - _state_defs[state]._frame_stale = true; - } - - if (_state_defs[state]._frame_stale) { - update_frame(state); - } - - return _state_defs[state]._node; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::instance_to_state_def -// Access: Published -// Description: Parents an instance of the bottom node of the -// indicated ArcChain (normally a NodePath) to the -// indicated state index. -//////////////////////////////////////////////////////////////////// -void PGItem:: -instance_to_state_def(int state, const ArcChain &chain) { - if (chain.empty()) { - // If the chain is empty, quietly do nothing. - return; - } - - NodeRelation *new_arc = - new RenderRelation(get_state_def(state), chain.node()); - - if (chain.has_arcs()) { - // If the chain has an arc, copy the transitions from it. - new_arc->copy_transitions_from(chain.arc()); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_frame_style -// Access: Published -// Description: Returns the kind of frame that will be drawn behind -// the item when it is in the indicated state. -//////////////////////////////////////////////////////////////////// -PGFrameStyle PGItem:: -get_frame_style(int state) { - if (state < 0 || state >= (int)_state_defs.size()) { - return PGFrameStyle(); - } - return _state_defs[state]._frame_style; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::set_frame_style -// Access: Published -// Description: Changes the kind of frame that will be drawn behind -// the item when it is in the indicated state. -//////////////////////////////////////////////////////////////////// -void PGItem:: -set_frame_style(int state, const PGFrameStyle &style) { - // Get the state def node, mainly to ensure that this state is - // slotted and listed as having been defined. - Node *def = get_state_def(state); - nassertv(def != (Node *)NULL); - - _state_defs[state]._frame_style = style; - _state_defs[state]._frame_stale = true; -} - -#ifdef HAVE_AUDIO -//////////////////////////////////////////////////////////////////// -// Function: PGItem::set_sound -// Access: Published -// Description: Sets the sound that will be played whenever the -// indicated event occurs. -//////////////////////////////////////////////////////////////////// -void PGItem:: -set_sound(const string &event, AudioSound *sound) { - _sounds[event] = sound; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::clear_sound -// Access: Published -// Description: Removes the sound associated with the indicated -// event. -//////////////////////////////////////////////////////////////////// -void PGItem:: -clear_sound(const string &event) { - _sounds.erase(event); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_sound -// Access: Published -// Description: Returns the sound associated with the indicated -// event, or NULL if there is no associated sound. -//////////////////////////////////////////////////////////////////// -AudioSound *PGItem:: -get_sound(const string &event) const { - Sounds::const_iterator si = _sounds.find(event); - if (si != _sounds.end()) { - return (*si).second; - } - return (AudioSound *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::has_sound -// Access: Published -// Description: Returns true if there is a sound associated with the -// indicated event, or false otherwise. -//////////////////////////////////////////////////////////////////// -bool PGItem:: -has_sound(const string &event) const { - return (_sounds.count(event) != 0); -} -#endif // HAVE_AUDIO - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::get_text_node -// Access: Published, Static -// Description: Returns the TextNode object that will be used by all -// PGItems to generate default labels given a string. -// This can be loaded with the default font, etc. -//////////////////////////////////////////////////////////////////// -TextNode *PGItem:: -get_text_node() { - if (_text_node == (TextNode *)NULL) { - _text_node = new TextNode("pguiText"); - _text_node->freeze(); - _text_node->set_text_color(0.0, 0.0, 0.0, 1.0); - - // The default TextNode is aligned to the left, for the - // convenience of PGEntry. - _text_node->set_align(TextNode::A_left); - } - return _text_node; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::play_sound -// Access: Protected -// Description: Plays the sound associated with the indicated event, -// if there is one. -//////////////////////////////////////////////////////////////////// -void PGItem:: -play_sound(const string &event) { -#ifdef HAVE_AUDIO - Sounds::const_iterator si = _sounds.find(event); - if (si != _sounds.end()) { - AudioSound *sound = (*si).second; - sound->play(); - } -#endif // HAVE_AUDIO -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::remove_all_children -// Access: Protected, Static -// Description: An internal utility function to remove all the -// children of the indicated Node. -//////////////////////////////////////////////////////////////////// -void PGItem:: -remove_all_children(Node *node) { - if (node != (Node *)NULL) { - int num_children = - node->get_num_children(RenderRelation::get_class_type()); - while (num_children > 0) { - nassertv(num_children == node->get_num_children(RenderRelation::get_class_type())); - NodeRelation *arc = - node->get_child(RenderRelation::get_class_type(), num_children - 1); - remove_arc(arc); - num_children--; - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::slot_state_def -// Access: Private -// Description: Ensures there is a slot in the array for the given -// state definition. -//////////////////////////////////////////////////////////////////// -void PGItem:: -slot_state_def(int state) { - while (state >= (int)_state_defs.size()) { - StateDef def; - def._frame_stale = true; - _state_defs.push_back(def); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::update_frame -// Access: Private -// Description: Generates a new instance of the frame geometry for -// the indicated state. -//////////////////////////////////////////////////////////////////// -void PGItem:: -update_frame(int state) { - // First, remove the old frame geometry, if any. - if (state >= 0 && state < (int)_state_defs.size()) { - NodeRelation *old_arc = _state_defs[state]._frame_arc; - if (old_arc != (NodeRelation *)NULL) { - if (old_arc->is_attached()) { - remove_arc(old_arc); - } - _state_defs[state]._frame_arc = (NodeRelation *)NULL; - } - } - - // We must turn off the stale flag first, before we call - // get_state_def(), to prevent get_state_def() from being a - // recursive call. - _state_defs[state]._frame_stale = false; - - // Now create new frame geometry. - if (has_frame()) { - Node *node = get_state_def(state); - nassertv(node != (Node *)NULL); - - _state_defs[state]._frame_arc = - _state_defs[state]._frame_style.generate_into(node, _frame); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGItem::mark_frames_stale -// Access: Private -// Description: Marks all the frames in all states stale, so that -// they will be regenerated the next time each state is -// requested. -//////////////////////////////////////////////////////////////////// -void PGItem:: -mark_frames_stale() { - StateDefs::iterator di; - for (di = _state_defs.begin(); di != _state_defs.end(); ++di) { - // Remove the old frame, if any. - NodeRelation *old_arc = (*di)._frame_arc; - if (old_arc != (NodeRelation *)NULL) { - if (old_arc->is_attached()) { - remove_arc(old_arc); - (*di)._frame_arc = (NodeRelation *)NULL; - } - } - - (*di)._frame_stale = true; - } -} diff --git a/panda/src/pgui/pgItem.h b/panda/src/pgui/pgItem.h deleted file mode 100644 index 49361a46cb..0000000000 --- a/panda/src/pgui/pgItem.h +++ /dev/null @@ -1,218 +0,0 @@ -// Filename: pgItem.h -// Created by: drose (02Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef PGITEM_H -#define PGITEM_H - -#include "pandabase.h" - -#include "pgMouseWatcherRegion.h" -#include "pgFrameStyle.h" - -#include "namedNode.h" -#include "nodeRelation.h" -#include "luse.h" -#include "pointerTo.h" -#include "pt_Node.h" -#include "pt_NodeRelation.h" -#include "textNode.h" - -#include "pmap.h" - -class PGTop; -class GraphicsStateGuardian; -class AllTransitionsWrapper; -class MouseWatcherParameter; -class ArcChain; -class AudioSound; - -//////////////////////////////////////////////////////////////////// -// Class : PGItem -// Description : This is the base class for all the various kinds of -// gui widget objects. -// -// It is a Node which corresponds to a rectangular -// region on the screen, and it may have any number of -// "state" subgraphs, one of which is rendered at any -// given time according to its current state. -// -// The PGItem node must be parented to the scene graph -// somewhere beneath a PGTop node in order for this -// behavior to work. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA PGItem : public NamedNode { -PUBLISHED: - PGItem(const string &name = ""); - virtual ~PGItem(); - -public: - PGItem(const PGItem ©); - void operator = (const PGItem ©); - - virtual Node *make_copy() const; - virtual void xform(const LMatrix4f &mat); - - void activate_region(PGTop *top, const LMatrix4f &transform, int sort); - INLINE PGMouseWatcherRegion *get_region() const; - - virtual void draw_item(PGTop *top, GraphicsStateGuardian *gsg, - const AllTransitionsWrapper &trans); - - virtual void enter(const MouseWatcherParameter ¶m); - virtual void exit(const MouseWatcherParameter ¶m); - virtual void within(const MouseWatcherParameter ¶m); - virtual void without(const MouseWatcherParameter ¶m); - virtual void focus_in(); - virtual void focus_out(); - virtual void press(const MouseWatcherParameter ¶m, bool background); - virtual void release(const MouseWatcherParameter ¶m, bool background); - virtual void keystroke(const MouseWatcherParameter ¶m, bool background); - - static void background_press(const MouseWatcherParameter ¶m); - static void background_release(const MouseWatcherParameter ¶m); - static void background_keystroke(const MouseWatcherParameter ¶m); - -PUBLISHED: - INLINE void set_frame(float left, float right, float bottom, float top); - INLINE void set_frame(const LVecBase4f &frame); - INLINE const LVecBase4f &get_frame() const; - INLINE bool has_frame() const; - INLINE void clear_frame(); - - INLINE void set_state(int state); - INLINE int get_state() const; - - virtual void set_active(bool active); - INLINE bool get_active() const; - - virtual void set_focus(bool focus); - INLINE bool get_focus() const; - - void set_background_focus(bool focus); - INLINE bool get_background_focus() const; - - INLINE void set_suppress_flags(int suppress_flags); - INLINE int get_suppress_flags() const; - - int get_num_state_defs() const; - void clear_state_def(int state); - bool has_state_def(int state) const; - Node *get_state_def(int state); - void instance_to_state_def(int state, const ArcChain &chain); - - PGFrameStyle get_frame_style(int state); - void set_frame_style(int state, const PGFrameStyle &style); - - INLINE const string &get_id() const; - INLINE void set_id(const string &id); - - INLINE static string get_enter_prefix(); - INLINE static string get_exit_prefix(); - INLINE static string get_within_prefix(); - INLINE static string get_without_prefix(); - INLINE static string get_focus_in_prefix(); - INLINE static string get_focus_out_prefix(); - INLINE static string get_press_prefix(); - INLINE static string get_release_prefix(); - INLINE static string get_keystroke_prefix(); - - INLINE string get_enter_event() const; - INLINE string get_exit_event() const; - INLINE string get_within_event() const; - INLINE string get_without_event() const; - INLINE string get_focus_in_event() const; - INLINE string get_focus_out_event() const; - INLINE string get_press_event(const ButtonHandle &button) const; - INLINE string get_release_event(const ButtonHandle &button) const; - INLINE string get_keystroke_event() const; - -#ifdef HAVE_AUDIO - void set_sound(const string &event, AudioSound *sound); - void clear_sound(const string &event); - AudioSound *get_sound(const string &event) const; - bool has_sound(const string &event) const; -#endif - - static TextNode *get_text_node(); - INLINE static void set_text_node(TextNode *node); - - INLINE static PGItem *get_focus_item(); - -protected: - void play_sound(const string &event); - static void remove_all_children(Node *node); - -private: - void slot_state_def(int state); - void update_frame(int state); - void mark_frames_stale(); - - bool _has_frame; - LVecBase4f _frame; - int _state; - enum Flags { - F_active = 0x01, - F_focus = 0x02, - F_background_focus = 0x04, - }; - int _flags; - - PT(PGMouseWatcherRegion) _region; - - class StateDef { - public: - PT_Node _node; - PGFrameStyle _frame_style; - PT_NodeRelation _frame_arc; - bool _frame_stale; - }; - typedef pvector StateDefs; - StateDefs _state_defs; - -#ifdef HAVE_AUDIO - typedef pmap Sounds; - Sounds _sounds; -#endif - - static PT(TextNode) _text_node; - static PGItem *_focus_item; - - typedef pset BackgroundFocus; - static BackgroundFocus _background_focus; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - NamedNode::init_type(); - register_type(_type_handle, "PGItem", - NamedNode::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "pgItem.I" - -#endif diff --git a/panda/src/pgui/pgMouseWatcherBackground.cxx b/panda/src/pgui/pgMouseWatcherBackground.cxx index ce4aa5e99f..01aa6ca615 100644 --- a/panda/src/pgui/pgMouseWatcherBackground.cxx +++ b/panda/src/pgui/pgMouseWatcherBackground.cxx @@ -17,7 +17,6 @@ //////////////////////////////////////////////////////////////////// #include "pgMouseWatcherBackground.h" -#include "pgItem.h" #include "qppgItem.h" TypeHandle PGMouseWatcherBackground::_type_handle; @@ -53,7 +52,6 @@ PGMouseWatcherBackground:: //////////////////////////////////////////////////////////////////// void PGMouseWatcherBackground:: press(const MouseWatcherParameter ¶m) { - PGItem::background_press(param); qpPGItem::background_press(param); } @@ -66,7 +64,6 @@ press(const MouseWatcherParameter ¶m) { //////////////////////////////////////////////////////////////////// void PGMouseWatcherBackground:: release(const MouseWatcherParameter ¶m) { - PGItem::background_release(param); qpPGItem::background_release(param); } @@ -78,6 +75,5 @@ release(const MouseWatcherParameter ¶m) { //////////////////////////////////////////////////////////////////// void PGMouseWatcherBackground:: keystroke(const MouseWatcherParameter ¶m) { - PGItem::background_keystroke(param); qpPGItem::background_keystroke(param); } diff --git a/panda/src/pgui/pgMouseWatcherGroup.I b/panda/src/pgui/pgMouseWatcherGroup.I index fad63c5b30..c181ead307 100644 --- a/panda/src/pgui/pgMouseWatcherGroup.I +++ b/panda/src/pgui/pgMouseWatcherGroup.I @@ -17,16 +17,6 @@ //////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////// -// Function: PGMouseWatcherGroup::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE PGMouseWatcherGroup:: -PGMouseWatcherGroup(PGTop *top) : _top(top) { - _qptop = (qpPGTop *)NULL; -} - //////////////////////////////////////////////////////////////////// // Function: PGMouseWatcherGroup::Constructor // Access: Public @@ -34,20 +24,6 @@ PGMouseWatcherGroup(PGTop *top) : _top(top) { //////////////////////////////////////////////////////////////////// INLINE PGMouseWatcherGroup:: PGMouseWatcherGroup(qpPGTop *top) : _qptop(top) { - _top = (PGTop *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGMouseWatcherGroup::clear_top -// Access: Public -// Description: Called by the PGTop object to indicate that it is no -// longer keeping the pointer to the PGMouseWatcherGroup -// object. -//////////////////////////////////////////////////////////////////// -INLINE void PGMouseWatcherGroup:: -clear_top(PGTop *top) { - nassertv(_top == top); - _top = (PGTop *)NULL; } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pgui/pgMouseWatcherGroup.cxx b/panda/src/pgui/pgMouseWatcherGroup.cxx index c8d861fd7e..1c923451ec 100644 --- a/panda/src/pgui/pgMouseWatcherGroup.cxx +++ b/panda/src/pgui/pgMouseWatcherGroup.cxx @@ -17,7 +17,7 @@ //////////////////////////////////////////////////////////////////// #include "pgMouseWatcherGroup.h" -#include "pgTop.h" +#include "qppgTop.h" TypeHandle PGMouseWatcherGroup::_type_handle; @@ -28,11 +28,10 @@ TypeHandle PGMouseWatcherGroup::_type_handle; //////////////////////////////////////////////////////////////////// PGMouseWatcherGroup:: ~PGMouseWatcherGroup() { - cerr << "~PGMouseWatcherGroup()\n"; // When the MouseWatcherGroup destructs for whatever reason, the // PGTop object should lose its MouseWatcher. - if (_top != (PGTop *)NULL) { - _top->_watcher_group = (PGMouseWatcherGroup *)NULL; - _top->set_mouse_watcher((MouseWatcher *)NULL); + if (_qptop != (qpPGTop *)NULL) { + _qptop->_watcher_group = (PGMouseWatcherGroup *)NULL; + _qptop->set_mouse_watcher((qpMouseWatcher *)NULL); } } diff --git a/panda/src/pgui/pgMouseWatcherGroup.h b/panda/src/pgui/pgMouseWatcherGroup.h index 656d9d1742..7e7b918d67 100644 --- a/panda/src/pgui/pgMouseWatcherGroup.h +++ b/panda/src/pgui/pgMouseWatcherGroup.h @@ -24,7 +24,6 @@ #include "mouseWatcherGroup.h" #include "pointerTo.h" -class PGTop; class qpPGTop; //////////////////////////////////////////////////////////////////// @@ -37,15 +36,12 @@ class qpPGTop; //////////////////////////////////////////////////////////////////// class EXPCL_PANDA PGMouseWatcherGroup : public MouseWatcherGroup { public: - INLINE PGMouseWatcherGroup(PGTop *top); INLINE PGMouseWatcherGroup(qpPGTop *top); virtual ~PGMouseWatcherGroup(); - INLINE void clear_top(PGTop *top); INLINE void clear_top(qpPGTop *top); private: - PGTop *_top; qpPGTop *_qptop; public: diff --git a/panda/src/pgui/pgMouseWatcherRegion.cxx b/panda/src/pgui/pgMouseWatcherRegion.cxx index 5f1ac060e1..b747ee2f65 100644 --- a/panda/src/pgui/pgMouseWatcherRegion.cxx +++ b/panda/src/pgui/pgMouseWatcherRegion.cxx @@ -17,7 +17,6 @@ //////////////////////////////////////////////////////////////////// #include "pgMouseWatcherRegion.h" -#include "pgItem.h" #include "qppgItem.h" #include "string_utils.h" @@ -25,21 +24,6 @@ int PGMouseWatcherRegion::_next_index = 0; TypeHandle PGMouseWatcherRegion::_type_handle; -//////////////////////////////////////////////////////////////////// -// Function: PGMouseWatcherRegion::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -PGMouseWatcherRegion:: -PGMouseWatcherRegion(PGItem *item) : -#ifndef CPPPARSER - MouseWatcherRegion("pg" + format_string(_next_index++), 0, 0, 0, 0), -#endif - _item(item) -{ - _qpitem = (qpPGItem *)NULL; -} - //////////////////////////////////////////////////////////////////// // Function: PGMouseWatcherRegion::Constructor // Access: Public @@ -52,7 +36,6 @@ PGMouseWatcherRegion(qpPGItem *item) : #endif _qpitem(item) { - _item = (PGItem *)NULL; } //////////////////////////////////////////////////////////////////// @@ -76,9 +59,6 @@ PGMouseWatcherRegion:: //////////////////////////////////////////////////////////////////// void PGMouseWatcherRegion:: enter(const MouseWatcherParameter ¶m) { - if (_item != (PGItem *)NULL) { - _item->enter(param); - } if (_qpitem != (qpPGItem *)NULL) { _qpitem->enter(param); } @@ -95,9 +75,6 @@ enter(const MouseWatcherParameter ¶m) { //////////////////////////////////////////////////////////////////// void PGMouseWatcherRegion:: exit(const MouseWatcherParameter ¶m) { - if (_item != (PGItem *)NULL) { - _item->exit(param); - } if (_qpitem != (qpPGItem *)NULL) { _qpitem->exit(param); } @@ -115,9 +92,6 @@ exit(const MouseWatcherParameter ¶m) { //////////////////////////////////////////////////////////////////// void PGMouseWatcherRegion:: within(const MouseWatcherParameter ¶m) { - if (_item != (PGItem *)NULL) { - _item->within(param); - } if (_qpitem != (qpPGItem *)NULL) { _qpitem->within(param); } @@ -132,9 +106,6 @@ within(const MouseWatcherParameter ¶m) { //////////////////////////////////////////////////////////////////// void PGMouseWatcherRegion:: without(const MouseWatcherParameter ¶m) { - if (_item != (PGItem *)NULL) { - _item->without(param); - } if (_qpitem != (qpPGItem *)NULL) { _qpitem->without(param); } @@ -149,9 +120,6 @@ without(const MouseWatcherParameter ¶m) { //////////////////////////////////////////////////////////////////// void PGMouseWatcherRegion:: press(const MouseWatcherParameter ¶m) { - if (_item != (PGItem *)NULL) { - _item->press(param, false); - } if (_qpitem != (qpPGItem *)NULL) { _qpitem->press(param, false); } @@ -166,9 +134,6 @@ press(const MouseWatcherParameter ¶m) { //////////////////////////////////////////////////////////////////// void PGMouseWatcherRegion:: release(const MouseWatcherParameter ¶m) { - if (_item != (PGItem *)NULL) { - _item->release(param, false); - } if (_qpitem != (qpPGItem *)NULL) { _qpitem->release(param, false); } @@ -182,9 +147,6 @@ release(const MouseWatcherParameter ¶m) { //////////////////////////////////////////////////////////////////// void PGMouseWatcherRegion:: keystroke(const MouseWatcherParameter ¶m) { - if (_item != (PGItem *)NULL) { - _item->keystroke(param, false); - } if (_qpitem != (qpPGItem *)NULL) { _qpitem->keystroke(param, false); } diff --git a/panda/src/pgui/pgMouseWatcherRegion.h b/panda/src/pgui/pgMouseWatcherRegion.h index fa3bf21322..1d373eee1a 100644 --- a/panda/src/pgui/pgMouseWatcherRegion.h +++ b/panda/src/pgui/pgMouseWatcherRegion.h @@ -23,7 +23,6 @@ #include "mouseWatcherRegion.h" -class PGItem; class qpPGItem; //////////////////////////////////////////////////////////////////// @@ -35,7 +34,6 @@ class qpPGItem; //////////////////////////////////////////////////////////////////// class EXPCL_PANDA PGMouseWatcherRegion : public MouseWatcherRegion { public: - PGMouseWatcherRegion(PGItem *item); PGMouseWatcherRegion(qpPGItem *item); virtual ~PGMouseWatcherRegion(); @@ -48,7 +46,6 @@ public: virtual void keystroke(const MouseWatcherParameter ¶m); private: - PGItem *_item; qpPGItem *_qpitem; static int _next_index; @@ -69,7 +66,6 @@ public: private: static TypeHandle _type_handle; - friend class PGItem; friend class qpPGItem; }; diff --git a/panda/src/pgui/pgTop.I b/panda/src/pgui/pgTop.I deleted file mode 100644 index bee626dad2..0000000000 --- a/panda/src/pgui/pgTop.I +++ /dev/null @@ -1,84 +0,0 @@ -// Filename: pgTop.I -// Created by: drose (02Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: PGTop::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE PGTop:: -PGTop(const PGTop ©) : - NamedNode(copy), - _watcher(copy._watcher) -{ - _gsg = (GraphicsStateGuardian *)NULL; - _trav = (RenderTraverser *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGTop::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void PGTop:: -operator = (const PGTop ©) { - NamedNode::operator = (copy); - _watcher = copy._watcher; -} - - -//////////////////////////////////////////////////////////////////// -// Function: PGTop::get_mouse_watcher -// Access: Published -// Description: Returns the MouseWatcher pointer that the PGTop object -// registers its PG items with, or NULL if the -// MouseWatcher has not yet been set. -//////////////////////////////////////////////////////////////////// -INLINE MouseWatcher *PGTop:: -get_mouse_watcher() const { - return _watcher; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGTop::add_region -// Access: Published -// Description: Adds the indicated region to the set of regions in -// the group. Returns true if it was successfully -// added, or false if it was already on the list. -//////////////////////////////////////////////////////////////////// -INLINE bool PGTop:: -add_region(MouseWatcherRegion *region) { - if (_watcher_group == (PGMouseWatcherGroup *)NULL) { - return false; - } - return _watcher_group->add_region(region); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGTop::clear_regions -// Access: Published -// Description: Removes all the regions from the group. -//////////////////////////////////////////////////////////////////// -INLINE void PGTop:: -clear_regions() { - if (_watcher_group == (PGMouseWatcherGroup *)NULL) { - return; - } - _watcher_group->clear_regions(); -} diff --git a/panda/src/pgui/pgTop.cxx b/panda/src/pgui/pgTop.cxx deleted file mode 100644 index d9ee080599..0000000000 --- a/panda/src/pgui/pgTop.cxx +++ /dev/null @@ -1,260 +0,0 @@ -// Filename: pgTop.cxx -// Created by: drose (02Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "pgTop.h" -#include "pgItem.h" -#include "pgMouseWatcherGroup.h" - -#include "arcChain.h" -#include "graphicsStateGuardian.h" -#include "config_sgraphutil.h" -#include "renderRelation.h" -#include "geomNode.h" -#include "allTransitionsWrapper.h" -#include "allTransitionsWrapper.h" -#include "wrt.h" -#include "switchNode.h" -#include "transformTransition.h" -#include "nodeTransitionWrapper.h" -#include "omniBoundingVolume.h" -#include "pruneTransition.h" - -TypeHandle PGTop::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: PGTop::Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -PGTop:: -PGTop(const string &name) : NamedNode(name) -{ - _watcher_group = (PGMouseWatcherGroup *)NULL; - _gsg = (GraphicsStateGuardian *)NULL; - _trav = (RenderTraverser *)NULL; - - // A PGTop node normally has an infinite bounding volume. Screw - // culling. - set_bound(OmniBoundingVolume()); - set_final(true); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGTop::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -PGTop:: -~PGTop() { - set_mouse_watcher((MouseWatcher *)NULL); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGTop::make_copy -// Access: Public, Virtual -// Description: Returns a newly-allocated Node that is a shallow copy -// of this one. It will be a different Node pointer, -// but its internal data may or may not be shared with -// that of the original Node. -//////////////////////////////////////////////////////////////////// -Node *PGTop:: -make_copy() const { - return new PGTop(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGTop::sub_render -// Access: Public, Virtual -// Description: Gets called during the draw traversal to render this -// node and all nodes below it. In the case of the -// PGTop node, this uses a depth-first left-to-right -// traversal to render all of the GeomNodes and PGItems -// in the scene graph order. -//////////////////////////////////////////////////////////////////// -bool PGTop:: -sub_render(const AllTransitionsWrapper &input_trans, - AllTransitionsWrapper &, RenderTraverser *trav) { - _trans = input_trans; - _gsg = trav->get_gsg(); - const ArcChain &chain = trav->get_arc_chain(); - - // Empty our set of regions in preparation for re-adding whichever - // ones we encounter in the traversal that are current. - clear_regions(); - _sort_index = 0; - - // Start the traversal below the current node. - const DownRelationPointers &drp = - find_connection(RenderRelation::get_class_type()).get_down(); - - DownRelationPointers::const_iterator drpi; - for (drpi = drp.begin(); drpi != drp.end(); ++drpi) { - NodeRelation *arc = (*drpi); - if (!arc->has_transition(PruneTransition::get_class_type())) { - ArcChain next_chain(chain); - next_chain.push_back(arc); - r_traverse(arc->get_child(), next_chain); - } - } - - // We don't need the normal render traverser to do anything else; - // we've done it all. - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGTop::has_sub_render -// Access: Public, Virtual -// Description: Should be redefined to return true if the function -// sub_render(), above, expects to be called during -// traversal. -//////////////////////////////////////////////////////////////////// -bool PGTop:: -has_sub_render() const { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGTop::set_mouse_watcher -// Access: Published -// Description: Sets the MouseWatcher pointer that the PGTop object -// registers its PG items with. This must be set before -// the PG items are active. -//////////////////////////////////////////////////////////////////// -void PGTop:: -set_mouse_watcher(MouseWatcher *watcher) { - if (_watcher_group != (PGMouseWatcherGroup *)NULL) { - _watcher_group->clear_top(this); - } - if (_watcher != (MouseWatcher *)NULL) { - _watcher->remove_group(_watcher_group); - } - - _watcher = watcher; - _watcher_group = (PGMouseWatcherGroup *)NULL; - - if (_watcher != (MouseWatcher *)NULL) { - // We create a new PGMouseWatcherGroup, but we don't own the - // reference count; the watcher will own this for us. - _watcher_group = new PGMouseWatcherGroup(this); - _watcher->add_group(_watcher_group); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PGTop::r_traverse -// Access: Private -// Description: Handles the main recursive traversal of the scene -// graph for nodes below the PGTop node. This -// implements a depth-first traversal. -//////////////////////////////////////////////////////////////////// -void PGTop:: -r_traverse(Node *node, const ArcChain &chain) { - if (implicit_app_traversal) { - node->app_traverse(chain); - } - node->draw_traverse(chain); - _gsg->_nodes_pcollector.add_level(1); - - - if (node->is_of_type(PGItem::get_class_type())) { - PGItem *pgi = DCAST(PGItem, node); - - if (pgi->has_frame() && pgi->get_active()) { - // The item has a frame, so we want to generate a region for it - // and update the MouseWatcher. - - // Get the complete net transform to the PGItem from the top. - LMatrix4f mat; - - NodeTransitionWrapper ntw(TransformTransition::get_class_type()); - wrt(pgi, chain.begin(), chain.end(), (Node *)NULL, - ntw, RenderRelation::get_class_type()); - const TransformTransition *tt; - if (!get_transition_into(tt, ntw)) { - // No relative transform. - mat = LMatrix4f::ident_mat(); - } else { - mat = tt->get_matrix(); - } - - // Now apply this transform to the item's frame. - pgi->activate_region(this, mat, _sort_index); - _sort_index++; - - add_region(pgi->get_region()); - } - - // And draw the item, however it wishes to be drawn. - - // Get the net transitions to the PGItem. - AllTransitionsWrapper wrt_trans; - wrt(pgi, chain.begin(), chain.end(), this, - wrt_trans, RenderRelation::get_class_type()); - AllTransitionsWrapper complete_trans; - complete_trans.compose_from(_trans, wrt_trans); - pgi->draw_item(this, _gsg, complete_trans); - - } else if (node->is_of_type(GeomNode::get_class_type())) { - _gsg->_geom_nodes_pcollector.add_level(1); - GeomNode *geom = DCAST(GeomNode, node); - - // Get the complete state of the GeomNode. - AllTransitionsWrapper wrt_trans; - wrt(node, chain.begin(), chain.end(), this, - wrt_trans, RenderRelation::get_class_type()); - AllTransitionsWrapper complete_trans; - complete_trans.compose_from(_trans, wrt_trans); - _gsg->set_state(complete_trans.get_transitions()); - - // Finally, draw the Geom. - _gsg->prepare_display_region(); - geom->draw(_gsg); - } - - - // Continue the traversal. - const DownRelationPointers &drp = - node->find_connection(RenderRelation::get_class_type()).get_down(); - - if (node->is_of_type(SwitchNode::get_class_type())) { - SwitchNode *swnode = DCAST(SwitchNode, node); - swnode->compute_switch(_trav); - size_t i = 0; - for (i = 0; i < drp.size(); i++) { - if (swnode->is_child_visible(RenderRelation::get_class_type(), i)) { - NodeRelation *arc = drp[i]; - if (!arc->has_transition(PruneTransition::get_class_type())) { - ArcChain next_chain(chain); - next_chain.push_back(arc); - r_traverse(arc->get_child(), next_chain); - } - } - } - } else { - DownRelationPointers::const_iterator drpi; - for (drpi = drp.begin(); drpi != drp.end(); ++drpi) { - NodeRelation *arc = (*drpi); - if (!arc->has_transition(PruneTransition::get_class_type())) { - ArcChain next_chain(chain); - next_chain.push_back(arc); - r_traverse(arc->get_child(), next_chain); - } - } - } -} diff --git a/panda/src/pgui/pgTop.h b/panda/src/pgui/pgTop.h deleted file mode 100644 index 9178eccede..0000000000 --- a/panda/src/pgui/pgTop.h +++ /dev/null @@ -1,109 +0,0 @@ -// Filename: pgTop.h -// Created by: drose (02Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef PGTOP_H -#define PGTOP_H - -#include "pandabase.h" - -#include "pgMouseWatcherGroup.h" - -#include "namedNode.h" -#include "mouseWatcher.h" -#include "pointerTo.h" -#include "allTransitionsWrapper.h" - -class GraphicsStateGuardian; -class RenderTraverser; -class ArcChain; -class PGMouseWatcherGroup; - -//////////////////////////////////////////////////////////////////// -// Class : PGTop -// Description : The "top" node of the new Panda GUI system. This -// node must be parented to the 2-d scene graph, and all -// PG objects should be parented to this node or -// somewhere below it. PG objects not parented within -// this hierarchy will not even be visible. -// -// This node begins the special traversal of the PG -// objects that registers each node within the -// MouseWatcher and forces everything to render in a -// depth-first, left-to-right order, appropriate for 2-d -// objects. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA PGTop : public NamedNode { -PUBLISHED: - PGTop(const string &name = ""); - virtual ~PGTop(); - -public: - INLINE PGTop(const PGTop ©); - INLINE void operator = (const PGTop ©); - - virtual Node *make_copy() const; - - virtual bool sub_render(const AllTransitionsWrapper &input_trans, - AllTransitionsWrapper &modify_trans, - RenderTraverser *trav); - virtual bool has_sub_render() const; - -PUBLISHED: - void set_mouse_watcher(MouseWatcher *watcher); - INLINE MouseWatcher *get_mouse_watcher() const; - -private: - // These methods duplicate the functionality of MouseWatcherGroup. - INLINE bool add_region(MouseWatcherRegion *region); - INLINE void clear_regions(); - -private: - void r_traverse(Node *node, const ArcChain &chain); - - PT(MouseWatcher) _watcher; - PGMouseWatcherGroup *_watcher_group; - GraphicsStateGuardian *_gsg; - RenderTraverser *_trav; - AllTransitionsWrapper _trans; - int _sort_index; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - NamedNode::init_type(); - MouseWatcherGroup::init_type(); - register_type(_type_handle, "PGTop", - NamedNode::get_class_type(), - MouseWatcherGroup::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; - - friend class PGMouseWatcherGroup; -}; - -#include "pgTop.I" - -#endif diff --git a/panda/src/pgui/pgWaitBar.I b/panda/src/pgui/pgWaitBar.I deleted file mode 100644 index 6adf1b3b15..0000000000 --- a/panda/src/pgui/pgWaitBar.I +++ /dev/null @@ -1,94 +0,0 @@ -// Filename: pgWaitBar.I -// Created by: drose (12Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: PGWaitBar::set_range -// Access: Published -// Description: Sets the value at which the WaitBar indicates 100%. -//////////////////////////////////////////////////////////////////// -INLINE void PGWaitBar:: -set_range(float range) { - _range = range; - _bar_state = -1; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGWaitBar::get_range -// Access: Published -// Description: Returns the value at which the WaitBar indicates 100%. -//////////////////////////////////////////////////////////////////// -INLINE float PGWaitBar:: -get_range() const { - return _range; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGWaitBar::set_value -// Access: Published -// Description: Sets the current value of the bar. This should range -// between 0 and get_range(). -//////////////////////////////////////////////////////////////////// -INLINE void PGWaitBar:: -set_value(float value) { - _value = value; - _bar_state = -1; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGWaitBar::get_value -// Access: Published -// Description: Returns the current value of the bar. -//////////////////////////////////////////////////////////////////// -INLINE float PGWaitBar:: -get_value() const { - return _value; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGWaitBar::get_percent -// Access: Published -// Description: Returns the percentage complete. -//////////////////////////////////////////////////////////////////// -INLINE float PGWaitBar:: -get_percent() const { - return _value / _range * 100.0; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGWaitBar::set_bar_style -// Access: Published -// Description: Sets the kind of frame that is drawn on top of the -// WaitBar to represent the amount completed. -//////////////////////////////////////////////////////////////////// -INLINE void PGWaitBar:: -set_bar_style(const PGFrameStyle &style) { - _bar_style = style; - _bar_state = -1; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGWaitBar::get_bar_style -// Access: Published -// Description: Returns the kind of frame that is drawn on top of the -// WaitBar to represent the amount completed. -//////////////////////////////////////////////////////////////////// -INLINE PGFrameStyle PGWaitBar:: -get_bar_style() const { - return _bar_style; -} diff --git a/panda/src/pgui/pgWaitBar.cxx b/panda/src/pgui/pgWaitBar.cxx deleted file mode 100644 index 2f71503326..0000000000 --- a/panda/src/pgui/pgWaitBar.cxx +++ /dev/null @@ -1,178 +0,0 @@ -// Filename: pgWaitBar.cxx -// Created by: drose (12Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "pgWaitBar.h" -#include "pgMouseWatcherParameter.h" - -#include "throw_event.h" - -TypeHandle PGWaitBar::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: PGWaitBar::Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -PGWaitBar:: -PGWaitBar(const string &name) : PGItem(name) -{ - _range = 100.0; - _value = 0.0; - _bar_state = -1; - _bar_arc = (NodeRelation *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGWaitBar::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -PGWaitBar:: -~PGWaitBar() { -} - -//////////////////////////////////////////////////////////////////// -// Function: PGWaitBar::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -PGWaitBar:: -PGWaitBar(const PGWaitBar ©) : - PGItem(copy), - _range(copy._range), - _value(copy._value) -{ - _bar_state = -1; - _bar_arc = (NodeRelation *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGWaitBar::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void PGWaitBar:: -operator = (const PGWaitBar ©) { - PGItem::operator = (copy); - _range = copy._range; - _value = copy._value; - - _bar_state = -1; -} - -//////////////////////////////////////////////////////////////////// -// Function: PGWaitBar::make_copy -// Access: Public, Virtual -// Description: Returns a newly-allocated Node that is a shallow copy -// of this one. It will be a different Node pointer, -// but its internal data may or may not be shared with -// that of the original Node. -//////////////////////////////////////////////////////////////////// -Node *PGWaitBar:: -make_copy() const { - return new PGWaitBar(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGWaitBar::draw_item -// Access: Public, Virtual -// Description: Called by the PGTop's traversal to draw this -// particular item. -//////////////////////////////////////////////////////////////////// -void PGWaitBar:: -draw_item(PGTop *top, GraphicsStateGuardian *gsg, - const AllTransitionsWrapper &trans) { - update(); - PGItem::draw_item(top, gsg, trans); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGWaitBar::setup -// Access: Public -// Description: Creates a PGWaitBar with the indicated dimensions, -// with the indicated maximum range. -//////////////////////////////////////////////////////////////////// -void PGWaitBar:: -setup(float width, float height, float range) { - set_state(0); - clear_state_def(0); - - set_frame(-0.5 * width, 0.5 * width, -0.5 * height, 0.5 * height); - - PGFrameStyle style; - style.set_width(0.05, 0.05); - - style.set_color(0.6, 0.6, 0.6, 1.0); - style.set_type(PGFrameStyle::T_bevel_in); - set_frame_style(0, style); - - style.set_color(0.8, 0.8, 0.8, 1.0); - style.set_type(PGFrameStyle::T_bevel_out); - set_bar_style(style); -} - -//////////////////////////////////////////////////////////////////// -// Function: PGWaitBar::update -// Access: Private -// Description: Computes the appropriate size of the bar frame -// according to the percentage completed. -//////////////////////////////////////////////////////////////////// -void PGWaitBar:: -update() { - int state = get_state(); - - // If the bar was last drawn in this state and is still current, we - // don't have to draw it again. - if (_bar_state == state) { - return; - } - - // Remove the old bar geometry, if any. - if (_bar_arc != (NodeRelation *)NULL) { - if (_bar_arc->is_attached()) { - remove_arc(_bar_arc); - } - _bar_arc = (NodeRelation *)NULL; - } - - // Now create new bar geometry. - if (_value != 0.0 && _range != 0.0) { - Node *node = get_state_def(state); - nassertv(node != (Node *)NULL); - - PGFrameStyle style = get_frame_style(state); - const LVecBase4f &frame = get_frame(); - const LVecBase2f &width = style.get_width(); - - // Put the bar within the item's frame's border. - LVecBase4f bar_frame(frame[0] + width[0], - frame[1] - width[0], - frame[2] + width[1], - frame[3] - width[1]); - - // And scale the bar according to our value. - float frac = _value / _range; - frac = max(min(frac, 1.0f), 0.0f); - bar_frame[1] = bar_frame[0] + frac * (bar_frame[1] - bar_frame[0]); - - _bar_arc = _bar_style.generate_into(node, bar_frame); - } - - // Indicate that the bar is current for this state. - _bar_state = state; -} diff --git a/panda/src/pgui/pgWaitBar.h b/panda/src/pgui/pgWaitBar.h deleted file mode 100644 index b775fe810d..0000000000 --- a/panda/src/pgui/pgWaitBar.h +++ /dev/null @@ -1,89 +0,0 @@ -// Filename: pgWaitBar.h -// Created by: drose (12Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef PGWAITBAR_H -#define PGWAITBAR_H - -#include "pandabase.h" - -#include "pgItem.h" - -//////////////////////////////////////////////////////////////////// -// Class : PGWaitBar -// Description : This is a particular kind of PGItem that draws a -// little bar that fills from left to right to indicate -// a slow process gradually completing, like a -// traditional "wait, loading" bar. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA PGWaitBar : public PGItem { -PUBLISHED: - PGWaitBar(const string &name = ""); - virtual ~PGWaitBar(); - -public: - PGWaitBar(const PGWaitBar ©); - void operator = (const PGWaitBar ©); - - virtual Node *make_copy() const; - - virtual void draw_item(PGTop *top, GraphicsStateGuardian *gsg, - const AllTransitionsWrapper &trans); - -PUBLISHED: - void setup(float width, float height, float range); - - INLINE void set_range(float range); - INLINE float get_range() const; - - INLINE void set_value(float value); - INLINE float get_value() const; - - INLINE float get_percent() const; - - INLINE void set_bar_style(const PGFrameStyle &style); - INLINE PGFrameStyle get_bar_style() const; - -private: - void update(); - - float _range, _value; - int _bar_state; - PGFrameStyle _bar_style; - PT_NodeRelation _bar_arc; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - PGItem::init_type(); - register_type(_type_handle, "PGWaitBar", - PGItem::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "pgWaitBar.I" - -#endif diff --git a/panda/src/pgui/pgui_composite1.cxx b/panda/src/pgui/pgui_composite1.cxx index 2716b34eb5..c652d38ab9 100644 --- a/panda/src/pgui/pgui_composite1.cxx +++ b/panda/src/pgui/pgui_composite1.cxx @@ -1,9 +1,7 @@ #include "config_pgui.cxx" -#include "pgButton.cxx" #include "qppgButton.cxx" #include "pgCullTraverser.cxx" -#include "pgEntry.cxx" #include "qppgEntry.cxx" #include "pgMouseWatcherGroup.cxx" #include "pgMouseWatcherParameter.cxx" diff --git a/panda/src/pgui/pgui_composite2.cxx b/panda/src/pgui/pgui_composite2.cxx index d88ff742a2..421d15226b 100644 --- a/panda/src/pgui/pgui_composite2.cxx +++ b/panda/src/pgui/pgui_composite2.cxx @@ -1,11 +1,8 @@ #include "pgFrameStyle.cxx" -#include "pgItem.cxx" #include "qppgItem.cxx" #include "pgMouseWatcherBackground.cxx" #include "pgMouseWatcherRegion.cxx" -#include "pgTop.cxx" #include "qppgTop.cxx" -#include "pgWaitBar.cxx" #include "qppgWaitBar.cxx" diff --git a/panda/src/pgui/qppgItem.cxx b/panda/src/pgui/qppgItem.cxx index 9325d775df..ff4ca990da 100644 --- a/panda/src/pgui/qppgItem.cxx +++ b/panda/src/pgui/qppgItem.cxx @@ -17,7 +17,6 @@ //////////////////////////////////////////////////////////////////// #include "qppgItem.h" -#include "pgTop.h" #include "pgMouseWatcherParameter.h" #include "pgCullTraverser.h" #include "config_pgui.h" @@ -29,6 +28,7 @@ #include "qpnodePath.h" #include "qpcullTraverser.h" #include "cullTraverserData.h" +#include "dcast.h" #ifdef HAVE_AUDIO #include "audioSound.h" diff --git a/panda/src/pgui/qppgTop.cxx b/panda/src/pgui/qppgTop.cxx index 153f188172..bd03f80e79 100644 --- a/panda/src/pgui/qppgTop.cxx +++ b/panda/src/pgui/qppgTop.cxx @@ -17,7 +17,6 @@ //////////////////////////////////////////////////////////////////// #include "qppgTop.h" -#include "pgItem.h" #include "pgMouseWatcherGroup.h" #include "pgCullTraverser.h" #include "cullBinAttrib.h" @@ -150,33 +149,3 @@ set_mouse_watcher(qpMouseWatcher *watcher) { _watcher->add_group(_watcher_group); } } - -/* - if (node->is_of_type(PGItem::get_class_type())) { - PGItem *pgi = DCAST(PGItem, node); - - if (pgi->has_frame() && pgi->get_active()) { - // The item has a frame, so we want to generate a region for it - // and update the MouseWatcher. - - // Get the complete net transform to the PGItem from the top. - LMatrix4f mat; - - NodeTransitionWrapper ntw(TransformTransition::get_class_type()); - wrt(pgi, chain.begin(), chain.end(), (Node *)NULL, - ntw, RenderRelation::get_class_type()); - const TransformTransition *tt; - if (!get_transition_into(tt, ntw)) { - // No relative transform. - mat = LMatrix4f::ident_mat(); - } else { - mat = tt->get_matrix(); - } - - // Now apply this transform to the item's frame. - pgi->activate_region(this, mat, _sort_index); - _sort_index++; - - add_region(pgi->get_region()); - } -*/ diff --git a/panda/src/physics/Sources.pp b/panda/src/physics/Sources.pp index b3a40c3bb3..3244190308 100644 --- a/panda/src/physics/Sources.pp +++ b/panda/src/physics/Sources.pp @@ -4,7 +4,7 @@ #begin lib_target #define TARGET physics #define LOCAL_LIBS \ - linmath sgraph sgattrib sgraphutil + pgraph linmath #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx diff --git a/panda/src/physics/actorNode.I b/panda/src/physics/actorNode.I index aea9ee1933..46c95804a0 100644 --- a/panda/src/physics/actorNode.I +++ b/panda/src/physics/actorNode.I @@ -15,21 +15,3 @@ // panda3d@yahoogroups.com . // //////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function : set_parent_arc -// Access : public -//////////////////////////////////////////////////////////////////// -INLINE void ActorNode:: -set_parent_arc(RenderRelation *arc) { - _parent_arc = arc; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_parent_arc -// Access : public -//////////////////////////////////////////////////////////////////// -INLINE RenderRelation *ActorNode:: -get_parent_arc(void) const { - return _parent_arc; -} diff --git a/panda/src/physics/actorNode.cxx b/panda/src/physics/actorNode.cxx index a6e611d9a9..faefc56052 100644 --- a/panda/src/physics/actorNode.cxx +++ b/panda/src/physics/actorNode.cxx @@ -20,7 +20,7 @@ #include "config_physics.h" #include "physicsObject.h" -#include +#include "transformState.h" TypeHandle ActorNode::_type_handle; @@ -31,7 +31,7 @@ TypeHandle ActorNode::_type_handle; //////////////////////////////////////////////////////////////////// ActorNode:: ActorNode(const string &name) : - PhysicalNode(name), _parent_arc(NULL) { + PhysicalNode(name) { add_physical(new Physical(1, true)); _mass_center = get_physical(0)->get_phys_body(); _mass_center->set_active(true); @@ -41,13 +41,11 @@ ActorNode(const string &name) : //////////////////////////////////////////////////////////////////// // Function : ActorNode // Access : public -// Description : Copy Constructor. This does NOT copy the parent -// arc, but does deep copy the physical/physicsObject +// Description : Copy Constructor. //////////////////////////////////////////////////////////////////// ActorNode:: ActorNode(const ActorNode ©) : PhysicalNode(copy) { - _parent_arc = (RenderRelation *) NULL; _ok_to_callback = true; _mass_center = get_physical(0)->get_phys_body(); } @@ -62,21 +60,18 @@ ActorNode:: } //////////////////////////////////////////////////////////////////// -// Function : update_arc +// Function : update_transform // Access : public -// Description : this populates the parent arc with the transform -// generated by the contained Physical, moving the -// node and subsequent geometry. +// Description : this sets the transform generated by the contained +// Physical, moving the node and subsequent geometry. //////////////////////////////////////////////////////////////////// void ActorNode:: -update_arc(void) { - nassertv(_parent_arc != (RenderRelation *) NULL); - +update_transform(void) { LMatrix4f lcs = _mass_center->get_lcs(); // lock the callback so that this doesn't call transform_changed. _ok_to_callback = false; - _parent_arc->set_transition(new TransformTransition(lcs)); + set_transform(TransformState::make_mat(lcs)); _ok_to_callback = true; } @@ -88,26 +83,22 @@ update_arc(void) { // and updates the internal representation of the node. //////////////////////////////////////////////////////////////////// void ActorNode:: -transform_changed(NodeRelation *arc) { - // this callback could be triggered by update_arc, BAD. +transform_changed() { + // this callback could be triggered by update_transform, BAD. if (_ok_to_callback == false) return; - TransformTransition *tt; - - // get the transition - tt = (TransformTransition *) - arc->get_transition(TransformTransition::get_class_type()); + // get the transform + CPT(TransformState) transform = get_transform(); // extract the position LPoint3f pos; - - tt->get_matrix().get_row3(pos,3); + transform->get_mat().get_row3(pos,3); // extract the orientation if (_mass_center->get_oriented() == true) { - LOrientationf orientation(tt->get_matrix()); + LOrientationf orientation(transform->get_mat()); _mass_center->set_orientation(orientation); } diff --git a/panda/src/physics/actorNode.h b/panda/src/physics/actorNode.h index a8008c9c73..5276b8ab05 100644 --- a/panda/src/physics/actorNode.h +++ b/panda/src/physics/actorNode.h @@ -19,26 +19,23 @@ #ifndef ACTORNODE_H #define ACTORNODE_H -#include +#include "pandabase.h" #include "physicalNode.h" -#include - //////////////////////////////////////////////////////////////////// // Class : ActorNode // Description : Like a physical node, but with a little more. The -// actornode assumes responsibility for its parent arc, -// and changes in its own PhysicsObject will be -// reflected as transforms in the arc. This relation -// goes both ways; changes in the arc will update the +// actornode assumes responsibility for its own +// transform, and changes in its own PhysicsObject will +// be reflected as transforms. This relation goes both +// ways; changes in the transform will update the // object's position (shoves). //////////////////////////////////////////////////////////////////// class EXPCL_PANDAPHYSICS ActorNode : public PhysicalNode { private: - // node hook if the client changes the parent arc. - virtual void transform_changed(NodeRelation *arc); + // node hook if the client changes the node's transform. + virtual void transform_changed(); - RenderRelation *_parent_arc; PhysicsObject *_mass_center; bool _ok_to_callback; @@ -49,10 +46,7 @@ public: virtual ~ActorNode(void); // update the parent arc with PhysicsObject information - void update_arc(void); - - INLINE void set_parent_arc(RenderRelation *arc); - INLINE RenderRelation *get_parent_arc(void) const; + void update_transform(void); public: static TypeHandle get_class_type(void) { diff --git a/panda/src/physics/physicsManager.cxx b/panda/src/physics/physicsManager.cxx index 167001e685..801cc88905 100644 --- a/panda/src/physics/physicsManager.cxx +++ b/panda/src/physics/physicsManager.cxx @@ -126,7 +126,7 @@ do_physics(float dt) { PhysicalNode *pn = physical->get_physical_node(); if (pn->is_of_type(ActorNode::get_class_type())) { ActorNode *an = (ActorNode *) pn; - an->update_arc(); + an->update_transform(); } } } diff --git a/panda/src/ps2gsg/Sources.pp b/panda/src/ps2gsg/Sources.pp index 4e59e60aa0..93a0bdf2c1 100644 --- a/panda/src/ps2gsg/Sources.pp +++ b/panda/src/ps2gsg/Sources.pp @@ -6,8 +6,8 @@ #begin lib_target #define TARGET ps2gsg #define LOCAL_LIBS \ - cull gsgmisc gsgbase gobj sgattrib sgraphutil graph display \ - putil linmath sgraph mathutil pnmimage + gsgmisc gsgbase gobj display \ + putil linmath mathutil pnmimage #define SOURCES \ config_ps2gsg.cxx ps2GraphicsStateGuardian.cxx \ diff --git a/panda/src/putil/factoryParams.h b/panda/src/putil/factoryParams.h index 360fc35069..20e4fe39a3 100644 --- a/panda/src/putil/factoryParams.h +++ b/panda/src/putil/factoryParams.h @@ -25,6 +25,7 @@ #include "typedReferenceCount.h" #include "pointerTo.h" #include "factoryParam.h" +#include "dcast.h" #include "pvector.h" diff --git a/panda/src/ribdisplay/Sources.pp b/panda/src/ribdisplay/Sources.pp index 741d91fcd6..289f82dadb 100644 --- a/panda/src/ribdisplay/Sources.pp +++ b/panda/src/ribdisplay/Sources.pp @@ -6,7 +6,7 @@ #begin lib_target #define TARGET ribdisplay #define LOCAL_LIBS \ - display ribgsg sgraph + display ribgsg #define SOURCES \ config_ribdisplay.cxx config_ribdisplay.h ribGraphicsPipe.I \ diff --git a/panda/src/ribgsg/Sources.pp b/panda/src/ribgsg/Sources.pp index 18268549f8..5789722ef7 100644 --- a/panda/src/ribgsg/Sources.pp +++ b/panda/src/ribgsg/Sources.pp @@ -6,7 +6,7 @@ #begin lib_target #define TARGET ribgsg #define LOCAL_LIBS \ - gsgmisc display gobj sgattrib sgraph sgraphutil + pgraph gsgmisc display gobj #define SOURCES \ config_ribgsg.cxx config_ribgsg.h ribGraphicsStateGuardian.I \ diff --git a/panda/src/sgattrib/Sources.pp b/panda/src/sgattrib/Sources.pp deleted file mode 100644 index 40343e5849..0000000000 --- a/panda/src/sgattrib/Sources.pp +++ /dev/null @@ -1,139 +0,0 @@ -#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \ - dtoolutil:c dtoolbase:c dtool:m - -#begin lib_target - #define TARGET sgattrib - #define LOCAL_LIBS \ - sgraph gobj graph putil pnmimage display mathutil gsgbase linmath - - #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx $[TARGET]_composite3.cxx - - #define SOURCES \ - alphaTransformProperty.I alphaTransformProperty.h \ - alphaTransformTransition.I alphaTransformTransition.h \ - attribTraverser.h billboardTransition.I \ - billboardTransition.h clipPlaneTransition.I \ - clipPlaneTransition.h \ - colorBlendProperty.I colorBlendProperty.h \ - colorBlendTransition.I colorBlendTransition.h \ - colorMaskProperty.I colorMaskProperty.h \ - colorMaskTransition.I colorMaskTransition.h \ - colorMatrixTransition.I colorMatrixTransition.h \ - colorProperty.I colorProperty.h colorTransition.I \ - colorTransition.h config_sgattrib.h \ - cullFaceProperty.I cullFaceProperty.h \ - cullFaceTransition.I cullFaceTransition.h \ - decalTransition.I decalTransition.h \ - depthTestProperty.I depthTestProperty.h \ - depthTestTransition.I depthTestTransition.h \ - depthWriteTransition.I depthWriteTransition.h \ - drawBoundsTransition.I drawBoundsTransition.h \ - fog.I fog.h fogTransition.I fogTransition.h \ - linesmoothTransition.I linesmoothTransition.h \ - materialTransition.I \ - materialTransition.h pointShapeProperty.I \ - pointShapeProperty.h pointShapeTransition.I \ - pointShapeTransition.h polygonOffsetProperty.I \ - polygonOffsetProperty.h polygonOffsetTransition.I \ - polygonOffsetTransition.h pruneTransition.I \ - pruneTransition.h renderModeProperty.I \ - renderModeProperty.h renderModeTransition.I \ - renderModeTransition.h renderRelation.I renderRelation.N \ - renderRelation.h stencilProperty.I stencilProperty.h \ - stencilTransition.I stencilTransition.h \ - texGenProperty.I texGenProperty.h \ - texGenTransition.I texGenTransition.h texMatrixTransition.I \ - texMatrixTransition.h textureApplyProperty.I \ - textureApplyProperty.h textureApplyTransition.I \ - textureApplyTransition.h textureTransition.I textureTransition.h \ - transformTransition.I transformTransition.h \ - transparencyProperty.I transparencyProperty.h \ - transparencyTransition.I transparencyTransition.h - - #define INCLUDED_SOURCES \ - alphaTransformProperty.cxx \ - alphaTransformTransition.cxx attribTraverser.cxx billboardTransition.cxx \ - clipPlaneTransition.cxx \ - colorBlendProperty.cxx colorBlendTransition.cxx \ - colorMaskProperty.cxx colorMaskTransition.cxx \ - colorMatrixTransition.cxx colorProperty.cxx \ - colorTransition.cxx config_sgattrib.cxx \ - cullFaceProperty.cxx cullFaceTransition.cxx \ - decalTransition.cxx depthTestProperty.cxx \ - depthTestTransition.cxx depthWriteTransition.cxx \ - drawBoundsTransition.cxx fog.cxx fogTransition.cxx \ - linesmoothTransition.cxx \ - materialTransition.cxx pointShapeProperty.cxx \ - pointShapeTransition.cxx \ - polygonOffsetProperty.cxx polygonOffsetTransition.cxx pruneTransition.cxx \ - renderModeProperty.cxx renderModeTransition.cxx \ - renderRelation.cxx \ - stencilProperty.cxx stencilTransition.cxx \ - texGenProperty.cxx texGenTransition.cxx \ - texMatrixTransition.cxx \ - textureApplyProperty.cxx textureApplyTransition.cxx \ - textureTransition.cxx transformTransition.cxx \ - transparencyProperty.cxx \ - transparencyTransition.cxx - - #define INSTALL_HEADERS \ - alphaTransformProperty.I alphaTransformProperty.h \ - alphaTransformTransition.I alphaTransformTransition.h \ - attribTraverser.h billboardTransition.I billboardTransition.h \ - clipPlaneTransition.I \ - clipPlaneTransition.h \ - colorBlendProperty.I \ - colorBlendProperty.h colorBlendTransition.I colorBlendTransition.h \ - colorMaskProperty.I \ - colorMaskProperty.h colorMaskTransition.I colorMaskTransition.h \ - colorMatrixTransition.I colorMatrixTransition.h colorProperty.I \ - colorProperty.h colorTransition.I colorTransition.h \ - config_sgattrib.h \ - cullFaceProperty.I cullFaceProperty.h cullFaceTransition.I \ - cullFaceTransition.h \ - decalTransition.I decalTransition.h \ - depthTestProperty.I depthTestProperty.h \ - depthTestTransition.I depthTestTransition.h \ - depthWriteTransition.I depthWriteTransition.h \ - drawBoundsTransition.I drawBoundsTransition.h \ - fog.I fog.h fogTransition.I fogTransition.h \ - linesmoothTransition.I \ - linesmoothTransition.h \ - materialTransition.I materialTransition.h \ - pointShapeProperty.I pointShapeProperty.h \ - pointShapeTransition.I pointShapeTransition.h \ - polygonOffsetProperty.I polygonOffsetProperty.h \ - polygonOffsetTransition.I polygonOffsetTransition.h \ - pruneTransition.I pruneTransition.h \ - renderModeProperty.I renderModeProperty.h \ - renderModeTransition.I renderModeTransition.h renderRelation.I \ - renderRelation.h \ - stencilProperty.I \ - stencilProperty.h stencilTransition.I stencilTransition.h \ - texGenProperty.I \ - texGenProperty.h texGenTransition.I texGenTransition.h \ - texMatrixTransition.I \ - texMatrixTransition.h \ - textureApplyProperty.I \ - textureApplyProperty.h textureApplyTransition.I \ - textureApplyTransition.h \ - textureTransition.I textureTransition.h \ - transformTransition.I transformTransition.h \ - transparencyProperty.I transparencyProperty.h \ - transparencyTransition.I transparencyTransition.h - - #define IGATESCAN all - -#end lib_target - -#begin test_bin_target - #define TARGET test_attrib - #define LOCAL_LIBS \ - sgraph gobj graph putil sgattrib pnmimage display mathutil gsgbase \ - linmath - - #define SOURCES \ - test_attrib.cxx - -#end test_bin_target - diff --git a/panda/src/sgattrib/alphaTransformProperty.I b/panda/src/sgattrib/alphaTransformProperty.I deleted file mode 100644 index 52fd6f967e..0000000000 --- a/panda/src/sgattrib/alphaTransformProperty.I +++ /dev/null @@ -1,79 +0,0 @@ -// Filename: alphaTransformProperty.I -// Created by: jason (01Aug00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformProperty::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE AlphaTransformProperty:: -AlphaTransformProperty() : - _offset(0), _scale(1) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformProperty::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE AlphaTransformProperty:: -AlphaTransformProperty(float offset, float scale) : - _offset(offset), _scale(scale) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformProperty::set_offset -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void AlphaTransformProperty:: -set_offset(float offset) { - _offset = offset; -} - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformProperty::get_offset -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE float AlphaTransformProperty:: -get_offset() const { - return _offset; -} - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformProperty::set_scale -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void AlphaTransformProperty:: -set_scale(float scale) { - _scale = scale; -} - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformProperty::get_scale -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE float AlphaTransformProperty:: -get_scale() const { - return _scale; -} diff --git a/panda/src/sgattrib/alphaTransformProperty.cxx b/panda/src/sgattrib/alphaTransformProperty.cxx deleted file mode 100644 index 02a9bd0275..0000000000 --- a/panda/src/sgattrib/alphaTransformProperty.cxx +++ /dev/null @@ -1,47 +0,0 @@ -// Filename: alphaTransformProperty.cxx -// Created by: jason (01Aug00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "alphaTransformProperty.h" - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformProperty::compare_to -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -int AlphaTransformProperty:: -compare_to(const AlphaTransformProperty &other) const { - if (_offset < other._offset) - return -1; - else if (_offset > other._offset) - return 1; - if (_scale < other._scale) - return -1; - else if (_scale > other._scale) - return 1; - return 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformProperty::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void AlphaTransformProperty:: -output(ostream &out) const { - out << "Offset " << _offset << " Scale " << _scale << endl; -} diff --git a/panda/src/sgattrib/alphaTransformProperty.h b/panda/src/sgattrib/alphaTransformProperty.h deleted file mode 100644 index 8a6c9e30cb..0000000000 --- a/panda/src/sgattrib/alphaTransformProperty.h +++ /dev/null @@ -1,55 +0,0 @@ -// Filename: alphaTransformProperty.h -// Created by: jason (01Aug00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef ALPHA_TRANSFORM_PROPERTY_H -#define ALPHA_TRANSFORM_PROPERTY_H - -#include - -#include - -//////////////////////////////////////////////////////////////////// -// Class : AlphaTransformProperty -// Description : This class defines the set state for polygon offseting -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA AlphaTransformProperty { -public: - INLINE AlphaTransformProperty(); - INLINE AlphaTransformProperty(float offset, float scale); - - INLINE void set_offset(float offset); - INLINE float get_offset() const; - INLINE void set_scale(float scale); - INLINE float get_scale() const; - - int compare_to(const AlphaTransformProperty &other) const; - void output(ostream &out) const; - -private: - float _offset; - float _scale; -}; - -INLINE ostream &operator << (ostream &out, const AlphaTransformProperty &prop) { - prop.output(out); - return out; -} - -#include "alphaTransformProperty.I" - -#endif diff --git a/panda/src/sgattrib/alphaTransformTransition.I b/panda/src/sgattrib/alphaTransformTransition.I deleted file mode 100644 index ce30f2c53b..0000000000 --- a/panda/src/sgattrib/alphaTransformTransition.I +++ /dev/null @@ -1,68 +0,0 @@ -// Filename: alphaTransformTransition.I -// Created by: jason (01Aug00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE AlphaTransformTransition:: -AlphaTransformTransition(float offset, float scale) : - _state(offset, scale) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformTransition::set_offset -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void AlphaTransformTransition:: -set_offset(float offset) { - _state.set_offset(offset); -} - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformTransition::get_offset -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE float AlphaTransformTransition:: -get_offset() const { - return _state.get_offset(); -} - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformTransition::set_scale -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void AlphaTransformTransition:: -set_scale(float scale) { - _state.set_scale(scale); -} - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformTransition::get_scale -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE float AlphaTransformTransition:: -get_scale() const { - return _state.get_scale(); -} diff --git a/panda/src/sgattrib/alphaTransformTransition.cxx b/panda/src/sgattrib/alphaTransformTransition.cxx deleted file mode 100644 index ad03b66c32..0000000000 --- a/panda/src/sgattrib/alphaTransformTransition.cxx +++ /dev/null @@ -1,110 +0,0 @@ -// Filename: alphaTransformTransition.cxx -// Created by: jason (01Aug00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "alphaTransformTransition.h" - -#include "graphicsStateGuardianBase.h" -#include "indent.h" -#include "dcast.h" - -PT(NodeTransition) AlphaTransformTransition::_initial; -TypeHandle AlphaTransformTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated AlphaTransformTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *AlphaTransformTransition:: -make_copy() const { - return new AlphaTransformTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated AlphaTransformTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *AlphaTransformTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new AlphaTransformTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void AlphaTransformTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_alpha_transform(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformTransition::set_value_from -// Access: Protected, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another AlphaTransformTransition. -//////////////////////////////////////////////////////////////////// -void AlphaTransformTransition:: -set_value_from(const OnTransition *other) { - const AlphaTransformTransition *ot; - DCAST_INTO_V(ot, other); - _state = ot->_state; -} - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformTransition::compare_values -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int AlphaTransformTransition:: -compare_values(const OnTransition *other) const { - const AlphaTransformTransition *ot; - DCAST_INTO_R(ot, other, false); - return _state.compare_to(ot->_state); -} - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -void AlphaTransformTransition:: -output_value(ostream &out) const { - out << _state; -} - -//////////////////////////////////////////////////////////////////// -// Function: AlphaTransformTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -void AlphaTransformTransition:: -write_value(ostream &out, int indent_level) const { - indent(out, indent_level) << _state << "\n"; -} diff --git a/panda/src/sgattrib/alphaTransformTransition.h b/panda/src/sgattrib/alphaTransformTransition.h deleted file mode 100644 index 52982e0293..0000000000 --- a/panda/src/sgattrib/alphaTransformTransition.h +++ /dev/null @@ -1,78 +0,0 @@ -// Filename: alphaTransformTransition.h -// Created by: jason (01Aug00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef ALPHA_TRANSFORM_TRANSTION_H -#define ALPHA_TRANSFORM_TRANSTION_H - -#include - -#include "alphaTransformProperty.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : AlphaTransformTransition -// Description : This allows for scaling and offseting of current -// alpha values -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA AlphaTransformTransition : public OnTransition { -public: - INLINE AlphaTransformTransition(float offset = 0, float scale = 1); - - INLINE void set_offset(float offset); - INLINE float get_offset() const; - INLINE void set_scale(float scale); - INLINE float get_scale() const; - - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual void set_value_from(const OnTransition *other); - virtual int compare_values(const OnTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - AlphaTransformProperty _state; - static PT(NodeTransition) _initial; - -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() { - OnTransition::init_type(); - register_type(_type_handle, "AlphaTransformTransition", - OnTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - - -#include "alphaTransformTransition.I" - -#endif diff --git a/panda/src/sgattrib/attribTraverser.cxx b/panda/src/sgattrib/attribTraverser.cxx deleted file mode 100644 index f86412edc8..0000000000 --- a/panda/src/sgattrib/attribTraverser.cxx +++ /dev/null @@ -1,201 +0,0 @@ -// Filename: attribTraverser.cxx -// Created by: mike (16Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "attribTraverser.h" -#include "renderRelation.h" -#include -#include -#include - -#include "textureTransition.h" -#include "textureTransition.h" - -#include -#include -#include -#include - -//////////////////////////////////////////////////////////////////// -// Function: AttribTraverser::constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -AttribTraverser:: -AttribTraverser() - : _has_attrib(false), _has_transition(false) -{ - _attrib_type = TypeHandle::none(); - _transition_type = TypeHandle::none(); -} - -//////////////////////////////////////////////////////////////////// -// Function: AttribTraverser::reached_node -// Access: Public -// Description: Called for each node of the scene graph -//////////////////////////////////////////////////////////////////// -bool AttribTraverser:: -reached_node(Node *node, NodeTransitionWrapper &state, NullLevelState &) { - - //Short circuit if we aren't looking for an attribute - if (_attrib_type == TypeHandle::none()) - { - return true; - } - - if (node->is_of_type(GeomNode::get_class_type())) - { - NodeTransition *attrib = state.get_trans(); - if (attrib != (NodeTransition *)NULL) - { - nassertr(attrib->is_of_type(_attrib_type), false); - - if (attrib->is_of_type(OnOffTransition::get_class_type())) - { - if(DCAST(OnOffTransition, attrib)->is_on()) - { - _has_attrib = true; - } - } - else - { - _has_attrib = true; - } - - } - } - - // Prune the search if we've discovered that we have the attribute - // being searched for anywhere. - return !_has_attrib; -} - -//////////////////////////////////////////////////////////////////// -// Function: AttribTraverser::forward_arc -// Access: Public -// Description: Called for each forward arc of the scene graph -//////////////////////////////////////////////////////////////////// -bool AttribTraverser:: -forward_arc(NodeRelation *, TransitionWrapper &trans, - NodeTransitionWrapper &, NodeTransitionWrapper &, - NullLevelState &) -{ - //Short circuit if we aren't looking for a transition - if (_transition_type == TypeHandle::none()) - { - return true; - } - - NodeTransition *transition = trans.get_trans(); - - if (transition != (NodeTransition *)NULL) - { - nassertr(transition->is_of_type(_transition_type), false); - _has_transition = true; - } - // Prune the search if we've discovered that we have the transition - // being searched for anywhere. - return !_has_transition; -} -//////////////////////////////////////////////////////////////////// -// Function: AttribTraverser::set_attrib_type -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void AttribTraverser:: -set_attrib_type(TypeHandle type) -{ - _attrib_type = type; -} - -//////////////////////////////////////////////////////////////////// -// Function: AttribTraverser::set_transition_type -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void AttribTraverser:: -set_transition_type(TypeHandle type) -{ - _transition_type = type; - nassertv(_transition_type.is_derived_from(ImmediateTransition::get_class_type())); -} - -//////////////////////////////////////////////////////////////////// -// Function: is_textured -// Description: Recursively checks the tree of nodes from root to -// see if any geometry is textured -//////////////////////////////////////////////////////////////////// -bool -is_textured(Node* root) { - AttribTraverser trav; - - trav.set_attrib_type(TextureTransition::get_class_type()); - - df_traverse(root, trav, - NodeTransitionWrapper(TextureTransition::get_class_type()), - NullLevelState(), RenderRelation::get_class_type()); - - return trav._has_attrib; -} - -//////////////////////////////////////////////////////////////////// -// Function: is_textured -// Description: Recursively checks the tree of nodes from root to -// see if any geometry is textured -//////////////////////////////////////////////////////////////////// -bool -is_textured(Node* root, const AllTransitionsWrapper &init_state) -{ - AttribTraverser trav; - - trav.set_attrib_type(TextureTransition::get_class_type()); - - NodeTransitionWrapper state(TextureTransition::get_class_type()); - state.set_trans(init_state.get_transition(TextureTransition::get_class_type())); - - df_traverse(root, trav, state, NullLevelState(), RenderRelation::get_class_type()); - - return trav._has_attrib; -} - -//////////////////////////////////////////////////////////////////// -// Function: is_shaded -// Description: Recursively checks the tree of nodes from root to -// see if any geometry is shaded -//////////////////////////////////////////////////////////////////// -bool -is_shaded(Node* root) { - AttribTraverser trav; - - //We use the TypeRegistry here because attribTraverser is defined in - //the package sgattrib. And this package knows nothing about - //Shaders. So we can just include shaderTransition.h, as it may not - //have been compiled yet. So use this workaround to get the type - //handle of a ShaderTransition - trav.set_transition_type(TypeRegistry::ptr()->find_type("ShaderTransition")); - - df_traverse(root, trav, - NodeTransitionWrapper(TypeRegistry::ptr()->find_type("ShaderTransition")), - NullLevelState(), RenderRelation::get_class_type()); - - return trav._has_attrib; -} - - - - - diff --git a/panda/src/sgattrib/attribTraverser.h b/panda/src/sgattrib/attribTraverser.h deleted file mode 100644 index 2529f762b4..0000000000 --- a/panda/src/sgattrib/attribTraverser.h +++ /dev/null @@ -1,60 +0,0 @@ -// Filename: attribTraverser.h -// Created by: mike (16Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef ATTRIBTRAVERSER_H -#define ATTRIBTRAVERSER_H - -#include - -#include -#include -#include - -class AllTransitionsWrapper; - -//////////////////////////////////////////////////////////////////// -// Class : AttribTraverser -// Description : -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA AttribTraverser : - public TraverserVisitor { -public: - AttribTraverser(); - bool reached_node(Node *node, NodeTransitionWrapper &state, NullLevelState &); - bool forward_arc(NodeRelation *arc, TransitionWrapper &trans, - NodeTransitionWrapper &, NodeTransitionWrapper &, - NullLevelState &); - - - void set_attrib_type(TypeHandle type); - void set_transition_type(TypeHandle type); -public: - bool _has_attrib; - bool _has_transition; -private: - TypeHandle _attrib_type; - TypeHandle _transition_type; -}; - -EXPCL_PANDA bool is_textured(Node* root); -EXPCL_PANDA bool is_textured(Node* root, const AllTransitionsWrapper &init_state); - -EXPCL_PANDA bool is_shaded(Node* root); - -#endif - diff --git a/panda/src/sgattrib/billboardTransition.I b/panda/src/sgattrib/billboardTransition.I deleted file mode 100644 index e956f979e9..0000000000 --- a/panda/src/sgattrib/billboardTransition.I +++ /dev/null @@ -1,196 +0,0 @@ -// Filename: billboardTransition.I -// Created by: drose (24Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE BillboardTransition:: -BillboardTransition() { - _up_vector = LVector3f::up(); - _eye_relative = false; - _axial_rotate = true; - _offset = 0.0; -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::axis -// Access: Public, Static -// Description: This named constructor returns a BillboardTransition -// set up to rotate about whatever up axis is -// appropriate to the given coordinate system. -//////////////////////////////////////////////////////////////////// -INLINE BillboardTransition BillboardTransition:: -axis(float offset, CoordinateSystem cs) { - BillboardTransition t; - t.set_up_vector(LVector3f::up(cs)); - t.set_eye_relative(false); - t.set_axial_rotate(true); - t.set_offset(offset); - return t; -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::point_eye -// Access: Public, Static -// Description: This named constructor returns a BillboardTransition -// set up to rotate about the indicated point in eye -// (camera) coordinates. -//////////////////////////////////////////////////////////////////// -INLINE BillboardTransition BillboardTransition:: -point_eye(float offset, CoordinateSystem cs) { - BillboardTransition t; - t.set_up_vector(LVector3f::up(cs)); - t.set_eye_relative(true); - t.set_axial_rotate(false); - t.set_offset(offset); - return t; -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::point_world -// Access: Public, Static -// Description: This named constructor returns a BillboardTransition -// set up to rotate about the indicated point in world -// coordinates. -//////////////////////////////////////////////////////////////////// -INLINE BillboardTransition BillboardTransition:: -point_world(float offset, CoordinateSystem cs) { - BillboardTransition t; - t.set_up_vector(LVector3f::up(cs)); - t.set_eye_relative(false); - t.set_axial_rotate(false); - t.set_offset(offset); - return t; -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::set_up_vector -// Access: Public -// Description: Sets the vector that determines the "up" direction -// for the billboard. In axial_rotate mode, this is the -// vector around which the billboard is constrained to -// rotate. When axial_rotate mode is off (i.e. in point -// rotate mode), this vector describes the direction -// that the billboard tries to keep facing upward as it -// rotates around the point. -// -// This vector may be either world-relative or -// camera-relative, according to the eye_relative flag. -//////////////////////////////////////////////////////////////////// -INLINE void BillboardTransition:: -set_up_vector(const LVector3f &up_vector) { - nassertv(!up_vector.almost_equal(LVector3f(0.0, 0.0, 0.0))); - _up_vector = up_vector; - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::get_up_vector -// Access: Public -// Description: See set_up_vector. -//////////////////////////////////////////////////////////////////// -INLINE LVector3f BillboardTransition:: -get_up_vector() const { - return _up_vector; -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::set_eye_relative -// Access: Public -// Description: Sets the flag indicating whether the billboard's up -// vector should be considered to be in camera space -// (true) or world space (false). -//////////////////////////////////////////////////////////////////// -INLINE void BillboardTransition:: -set_eye_relative(bool eye_relative) { - _eye_relative = eye_relative; - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::get_eye_relative -// Access: Public -// Description: See set_eye_relative. -//////////////////////////////////////////////////////////////////// -INLINE bool BillboardTransition:: -get_eye_relative() const { - return _eye_relative; -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::set_axial_rotate -// Access: Public -// Description: When this flag is true, the billboard will be -// constrained to rotate in two dimensions about its up -// vector only. When false, the billboard will rotate -// in all three dimensions as necessary to keep itself -// facing the camera directly. -//////////////////////////////////////////////////////////////////// -INLINE void BillboardTransition:: -set_axial_rotate(bool axial_rotate) { - _axial_rotate = axial_rotate; - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::get_axial_rotate -// Access: Public -// Description: See set_axial_rotate. -//////////////////////////////////////////////////////////////////// -INLINE bool BillboardTransition:: -get_axial_rotate() const { - return _axial_rotate; -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::set_offset -// Access: Public -// Description: Sets a linear offset in the billboard. This is -// particularly useful when eye_relative is true (which -// means the billboard rotates towards the camera plane, -// instead of towards the camera point). -// -// The billboard geometry is first rotated -// appropriately, and then translated along the linear -// offset directly towards the camera. -// -// This can be used to allow billboarding geometry to -// appear to float in front of an object, while not -// drifting away from the object as the object goes -// off-axis. Another way to achieve the same effect is -// to simply translate the billboarding geometry by some -// linear distance along the z axis before making it a -// billboard, but this does not work in eye_relative -// mode. -//////////////////////////////////////////////////////////////////// -INLINE void BillboardTransition:: -set_offset(float offset) { - _offset = offset; -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::get_axial_rotate -// Access: Public -// Description: See set_offset(). -//////////////////////////////////////////////////////////////////// -INLINE float BillboardTransition:: -get_offset() const { - return _offset; -} diff --git a/panda/src/sgattrib/billboardTransition.cxx b/panda/src/sgattrib/billboardTransition.cxx deleted file mode 100644 index 0e8b4dfdc4..0000000000 --- a/panda/src/sgattrib/billboardTransition.cxx +++ /dev/null @@ -1,280 +0,0 @@ -// Filename: billboardTransition.cxx -// Created by: mike (06Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "billboardTransition.h" -#include "transformTransition.h" -#include "renderRelation.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -PT(NodeTransition) BillboardTransition::_initial; -TypeHandle BillboardTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::make_copy -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -NodeTransition *BillboardTransition:: -make_copy() const { - return new BillboardTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated BillboardTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *BillboardTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new BillboardTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::sub_render -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -bool BillboardTransition:: -sub_render(NodeRelation *arc, const AllTransitionsWrapper &, - AllTransitionsWrapper &modify_trans, RenderTraverser *trav) { - Node *node = arc->get_child(); - GraphicsStateGuardian *gsg = trav->get_gsg(); - - // First, we have to get the current viewing frustum. This is - // normally the same thing as the current camera, but the - // DisplayRegion may have some override in effect, so we ask the - // DisplayRegion instead of the GSG. - const DisplayRegion *dr = gsg->get_current_display_region(); - LensNode *camera = dr->get_cull_frustum(); - if (camera == (LensNode *)NULL) { - // Never mind; ask the gsg. - camera = gsg->get_current_camera(); - } - - nassertr(camera != (LensNode *)NULL, true); - - // And the relative coordinate space. - LMatrix4f rel_mat; - NodeTransitionWrapper ntw(TransformTransition::get_class_type()); - wrt(camera, node, trav->begin(), trav->end(), - ntw, RenderRelation::get_class_type()); - TransformTransition *tt; - if (!get_transition_into(tt, ntw)) { - // No relative transform. - rel_mat = LMatrix4f::ident_mat(); - } else { - rel_mat = tt->get_matrix(); - } - - LVector3f camera_pos, up; - - CoordinateSystem coordsys = gsg->get_coordinate_system(); - - // If this is an eye-relative Billboard, then (a) the up vector is - // relative to the camera, not to the world, and (b) the look - // direction is towards the plane that contains the camera, - // perpendicular to the forward direction, not directly to the - // camera. - - if (_eye_relative) { - up = _up_vector * rel_mat; - camera_pos = LVector3f::forward(coordsys) * rel_mat; - - } else { -// camera_pos= -rel_mat.get_row3(3); - - camera_pos[0] = -rel_mat(3,0); - camera_pos[1] = -rel_mat(3,1); - camera_pos[2] = -rel_mat(3,2); - - up = _up_vector; - } - - // Now determine the rotation matrix for the Billboard. - LMatrix4f rotate; - if (_axial_rotate) { - heads_up(rotate, camera_pos, up, coordsys); - } else { - look_at(rotate, camera_pos, up, coordsys); - } - - // Also slide the billboard geometry towards the camera according to - // the offset factor. - if (_offset != 0.0f) { - LVector3f translate(rel_mat(3, 0), rel_mat(3, 1), rel_mat(3, 2)); - translate.normalize(); - translate *= _offset; - rotate.set_row(3, translate); - } - - // And finally, apply the rotation transform to the set of - // transitions we've accumulated for this node. - modify_trans.set_transition(new TransformTransition(rotate)); - - // Continue the render pass - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::has_sub_render -// Access: Public, Virtual -// Description: Should be redefined to return true if the function -// sub_render(), above, expects to be called during -// traversal. -//////////////////////////////////////////////////////////////////// -bool BillboardTransition:: -has_sub_render() const { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void BillboardTransition:: -output(ostream &out) const { - if (_axial_rotate) { - out << "axial"; - } else { - out << "point"; - } - if (_eye_relative) { - out << " eye"; - } - out << " Billboard"; -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::write -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void BillboardTransition:: -write(ostream &out, int indent_level) const { - indent(out, indent_level); - if (_axial_rotate) { - out << "axial"; - } else { - out << "point"; - } - if (_eye_relative) { - out << " eye"; - } - out << " Billboard:\n"; - - indent(out, indent_level + 2) - << "up vector: " << _up_vector << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::internal_compare_to -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int BillboardTransition:: -internal_compare_to(const NodeTransition *other) const { - const BillboardTransition *ot; - DCAST_INTO_R(ot, other, false); - - if (_eye_relative != ot->_eye_relative) { - return (int)_eye_relative - (int)ot->_eye_relative; - } - if (_axial_rotate != ot->_axial_rotate) { - return (int)_axial_rotate - (int)ot->_axial_rotate; - } - return _up_vector.compare_to(ot->_up_vector); -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void BillboardTransition:: -write_datagram(BamWriter *manager, Datagram &me) -{ - ImmediateTransition::write_datagram(manager, me); - _up_vector.write_datagram(me); - me.add_uint8(_eye_relative); - me.add_uint8(_axial_rotate); -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void BillboardTransition:: -fillin(DatagramIterator& scan, BamReader* manager) -{ - ImmediateTransition::fillin(scan, manager); - _up_vector.read_datagram(scan); - _eye_relative = (scan.get_uint8() !=0); - _axial_rotate = (scan.get_uint8() !=0); -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::make_BillboardTransition -// Access: Protected -// Description: Factory method to generate a BillboardTransition object -//////////////////////////////////////////////////////////////////// -TypedWritable* BillboardTransition:: -make_BillboardTransition(const FactoryParams ¶ms) -{ - BillboardTransition *me = new BillboardTransition; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: BillboardTransition::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a BillboardTransition object -//////////////////////////////////////////////////////////////////// -void BillboardTransition:: -register_with_read_factory(void) -{ - BamReader::get_factory()->register_factory(get_class_type(), make_BillboardTransition); -} - diff --git a/panda/src/sgattrib/billboardTransition.h b/panda/src/sgattrib/billboardTransition.h deleted file mode 100644 index fbeb678893..0000000000 --- a/panda/src/sgattrib/billboardTransition.h +++ /dev/null @@ -1,110 +0,0 @@ -// Filename: billboardTransition.h -// Created by: mike (19Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef BILLBOARDTRANSITION_H -#define BILLBOARDTRANSITION_H - -#include - -#include -#include - -//////////////////////////////////////////////////////////////////// -// Class : BillboardTransition -// Description : This transition, when applied to an arc, causes that -// arc and everything below it to be rendered so that it -// always faces the camera. There are all kinds of ways -// that billboards can be set to rotate. -// -// A BillboardTransition is neither on nor off, and it -// does not compose with nested BillboardTransitions. -// Instead, it has an immediate effect. Once a -// billboard transition is in place, it affects -// everything below it. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA BillboardTransition : public ImmediateTransition { -public: - INLINE BillboardTransition(); - INLINE static BillboardTransition axis(float offset = 0.0, CoordinateSystem cs = CS_default); - INLINE static BillboardTransition point_eye(float offset = 0.0, CoordinateSystem cs = CS_default); - INLINE static BillboardTransition point_world(float offset = 0.0, CoordinateSystem cs = CS_default); - - INLINE void set_up_vector(const LVector3f &up_vector); - INLINE LVector3f get_up_vector() const; - - INLINE void set_eye_relative(bool eye_relative); - INLINE bool get_eye_relative() const; - - INLINE void set_axial_rotate(bool axial_rotate); - INLINE bool get_axial_rotate() const; - - INLINE void set_offset(float offset); - INLINE float get_offset() const; - - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual bool sub_render(NodeRelation *arc, - const AllTransitionsWrapper &input_trans, - AllTransitionsWrapper &modify_trans, - RenderTraverser *trav); - virtual bool has_sub_render() const; - - virtual void output(ostream &out) const; - virtual void write(ostream &out, int indent_level = 0) const; - -protected: - virtual int internal_compare_to(const NodeTransition *other) const; - -private: - LVector3f _up_vector; - bool _eye_relative; - bool _axial_rotate; - float _offset; - static PT(NodeTransition) _initial; - -public: - static void register_with_read_factory(void); - virtual void write_datagram(BamWriter* manager, Datagram &me); - - static TypedWritable *make_BillboardTransition(const FactoryParams ¶ms); - -protected: - 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() { - ImmediateTransition::init_type(); - register_type(_type_handle, "BillboardTransition", - ImmediateTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "billboardTransition.I" - -#endif diff --git a/panda/src/sgattrib/clipPlaneTransition.I b/panda/src/sgattrib/clipPlaneTransition.I deleted file mode 100644 index 896cc14a20..0000000000 --- a/panda/src/sgattrib/clipPlaneTransition.I +++ /dev/null @@ -1,99 +0,0 @@ -// Filename: clipPlaneTransition.I -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: ClipPlaneTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ClipPlaneTransition:: -ClipPlaneTransition() { -} - -//////////////////////////////////////////////////////////////////// -// Function: ClipPlaneTransition::all_off -// Access: Public -// Description: This named constructor returns a ClipPlaneTransition -// that's preconfigured to turn off all planes below it. -//////////////////////////////////////////////////////////////////// -INLINE ClipPlaneTransition ClipPlaneTransition:: -all_off() { - ClipPlaneTransition t; - t.set_default_dir(TD_off); - return t; -} - -//////////////////////////////////////////////////////////////////// -// Function: ClipPlaneTransition::set_identity -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void ClipPlaneTransition:: -set_identity(const PT(PlaneNode) &property) { - MultiNodeTransition::set_identity(property.p()); -} - -//////////////////////////////////////////////////////////////////// -// Function: ClipPlaneTransition::set_on -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void ClipPlaneTransition:: -set_on(const PT(PlaneNode) &property) { - MultiNodeTransition::set_on(property.p()); -} - -//////////////////////////////////////////////////////////////////// -// Function: ClipPlaneTransition::set_off -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void ClipPlaneTransition:: -set_off(const PT(PlaneNode) &property) { - MultiNodeTransition::set_off(property.p()); -} - -//////////////////////////////////////////////////////////////////// -// Function: ClipPlaneTransition::is_identity -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool ClipPlaneTransition:: -is_identity(const PT(PlaneNode) &property) const { - return MultiNodeTransition::is_identity(property.p()); -} - -//////////////////////////////////////////////////////////////////// -// Function: ClipPlaneTransition::is_on -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool ClipPlaneTransition:: -is_on(const PT(PlaneNode) &property) const { - return MultiNodeTransition::is_on(property.p()); -} - -//////////////////////////////////////////////////////////////////// -// Function: ClipPlaneTransition::is_off -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool ClipPlaneTransition:: -is_off(const PT(PlaneNode) &property) const { - return MultiNodeTransition::is_off(property.p()); -} diff --git a/panda/src/sgattrib/clipPlaneTransition.cxx b/panda/src/sgattrib/clipPlaneTransition.cxx deleted file mode 100644 index c808cf0c0b..0000000000 --- a/panda/src/sgattrib/clipPlaneTransition.cxx +++ /dev/null @@ -1,100 +0,0 @@ -// Filename: clipPlaneTransition.cxx -// Created by: mike (06Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "clipPlaneTransition.h" - -#include - -PT(NodeTransition) ClipPlaneTransition::_initial; -TypeHandle ClipPlaneTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: ClipPlaneTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated ClipPlaneTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *ClipPlaneTransition:: -make_copy() const { - return new ClipPlaneTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: ClipPlaneTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated ClipPlaneTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *ClipPlaneTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new ClipPlaneTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: ClipPlaneTransition::make_identity -// Access: Public, Virtual -// Description: Returns a newly allocated ClipPlaneTransition -// corresponding to identity state. -//////////////////////////////////////////////////////////////////// -NodeTransition *ClipPlaneTransition:: -make_identity() const { - return new ClipPlaneTransition; -} - -//////////////////////////////////////////////////////////////////// -// Function: ClipPlaneTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void ClipPlaneTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_clip_plane(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: ClipPlaneTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -void ClipPlaneTransition:: -output_property(ostream &out, const PT_Node &prop) const { - const PlaneNode *node; - DCAST_INTO_V(node, prop.p()); - out << node->get_name() << "=" << node->get_plane(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ClipPlaneTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -void ClipPlaneTransition:: -write_property(ostream &out, const PT_Node &prop, - int indent_level) const { - const PlaneNode *node; - DCAST_INTO_V(node, prop); - indent(out, indent_level) - << node->get_name() << "=" << node->get_plane() << "\n"; -} diff --git a/panda/src/sgattrib/clipPlaneTransition.h b/panda/src/sgattrib/clipPlaneTransition.h deleted file mode 100644 index 1f1de222aa..0000000000 --- a/panda/src/sgattrib/clipPlaneTransition.h +++ /dev/null @@ -1,83 +0,0 @@ -// Filename: clipPlaneTransition.h -// Created by: mike (19Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CLIPPLANETRANSITION_H -#define CLIPPLANETRANSITION_H - -#include - -#include - -#include -#include - -//////////////////////////////////////////////////////////////////// -// Class : ClipPlaneTransition -// Description : This allows the definition of zero or more arbitrary -// clipping planes. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ClipPlaneTransition : public MultiNodeTransition { -public: - INLINE ClipPlaneTransition(); - INLINE static ClipPlaneTransition all_off(); - - INLINE void set_identity(const PT(PlaneNode) &prop); - INLINE void set_on(const PT(PlaneNode) &prop); - INLINE void set_off(const PT(PlaneNode) &prop); - - INLINE bool is_identity(const PT(PlaneNode) &prop) const; - INLINE bool is_on(const PT(PlaneNode) &prop) const; - INLINE bool is_off(const PT(PlaneNode) &prop) const; - - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - virtual NodeTransition *make_identity() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual void output_property(ostream &out, const PT_Node &prop) const; - virtual void write_property(ostream &out, const PT_Node &prop, - int indent_level) const; - -private: - static PT(NodeTransition) _initial; - -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() { - MultiNodeTransition::init_type(); - register_type(_type_handle, "ClipPlaneTransition", - MultiNodeTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "clipPlaneTransition.I" - -#endif - - diff --git a/panda/src/sgattrib/colorBlendProperty.I b/panda/src/sgattrib/colorBlendProperty.I deleted file mode 100644 index 05f8fb7002..0000000000 --- a/panda/src/sgattrib/colorBlendProperty.I +++ /dev/null @@ -1,58 +0,0 @@ -// Filename: colorBlendProperty.I -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: ColorBlendProperty::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ColorBlendProperty:: -ColorBlendProperty(ColorBlendProperty::Mode mode) : - _mode(mode) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorBlendProperty::set_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void ColorBlendProperty:: -set_mode(ColorBlendProperty::Mode mode) { - _mode = mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorBlendProperty::get_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ColorBlendProperty::Mode ColorBlendProperty:: -get_mode() const { - return _mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorBlendProperty::compare_to -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int ColorBlendProperty:: -compare_to(const ColorBlendProperty &other) const { - return (int)_mode - (int)other._mode; -} diff --git a/panda/src/sgattrib/colorBlendProperty.cxx b/panda/src/sgattrib/colorBlendProperty.cxx deleted file mode 100644 index 1a65ea6434..0000000000 --- a/panda/src/sgattrib/colorBlendProperty.cxx +++ /dev/null @@ -1,51 +0,0 @@ -// Filename: colorBlendProperty.cxx -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "colorBlendProperty.h" - -ostream & -operator << (ostream &out, ColorBlendProperty::Mode mode) { - switch (mode) { - case ColorBlendProperty::M_none: - return out << "none"; - - case ColorBlendProperty::M_multiply: - return out << "multiply"; - - case ColorBlendProperty::M_add: - return out << "add"; - - case ColorBlendProperty::M_multiply_add: - return out << "multiply_add"; - - case ColorBlendProperty::M_alpha: - return out << "alpha"; - } - - return out << "**invalid**(" << (int)mode << ")"; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorBlendProperty::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void ColorBlendProperty:: -output(ostream &out) const { - out << _mode; -} diff --git a/panda/src/sgattrib/colorBlendProperty.h b/panda/src/sgattrib/colorBlendProperty.h deleted file mode 100644 index 98c43fe839..0000000000 --- a/panda/src/sgattrib/colorBlendProperty.h +++ /dev/null @@ -1,62 +0,0 @@ -// Filename: colorBlendProperty.h -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef COLORBLENDPROPERTY_H -#define COLORBLENDPROPERTY_H - -#include - -//////////////////////////////////////////////////////////////////// -// Class : ColorBlendProperty -// Description : This defines the types of color blending we can -// perform. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ColorBlendProperty { -public: - enum Mode { - M_none, // Blending is disabled - M_multiply, // color already in fbuffer * incoming color - M_add, // color already in fbuffer + incoming color - M_multiply_add, // color already in fbuffer * incoming color + - // color already in fbuffer - M_alpha, // ???? - }; - -public: - INLINE ColorBlendProperty(Mode mode); - - INLINE void set_mode(Mode mode); - INLINE Mode get_mode() const; - - INLINE int compare_to(const ColorBlendProperty &other) const; - void output(ostream &out) const; - -private: - Mode _mode; -}; - -ostream &operator << (ostream &out, ColorBlendProperty::Mode mode); - -INLINE ostream &operator << (ostream &out, const ColorBlendProperty &prop) { - prop.output(out); - return out; -} - -#include "colorBlendProperty.I" - -#endif diff --git a/panda/src/sgattrib/colorBlendTransition.I b/panda/src/sgattrib/colorBlendTransition.I deleted file mode 100644 index 3bb464391a..0000000000 --- a/panda/src/sgattrib/colorBlendTransition.I +++ /dev/null @@ -1,49 +0,0 @@ -// Filename: colorBlendTransition.I -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: ColorBlendTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ColorBlendTransition:: -ColorBlendTransition(ColorBlendProperty::Mode mode) : - _value(mode) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorBlendTransition::set_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void ColorBlendTransition:: -set_mode(ColorBlendProperty::Mode mode) { - _value.set_mode(mode); - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorBlendTransition::get_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ColorBlendProperty::Mode ColorBlendTransition:: -get_mode() const { - return _value.get_mode(); -} diff --git a/panda/src/sgattrib/colorBlendTransition.cxx b/panda/src/sgattrib/colorBlendTransition.cxx deleted file mode 100644 index 8709e21dc1..0000000000 --- a/panda/src/sgattrib/colorBlendTransition.cxx +++ /dev/null @@ -1,108 +0,0 @@ -// Filename: colorBlendTransition.cxx -// Created by: mike (28Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "colorBlendTransition.h" - -#include - -PT(NodeTransition) ColorBlendTransition::_initial; -TypeHandle ColorBlendTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: ColorBlendTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated ColorBlendTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *ColorBlendTransition:: -make_copy() const { - return new ColorBlendTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorBlendTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated ColorBlendTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *ColorBlendTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new ColorBlendTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorBlendTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void ColorBlendTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_color_blend(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorBlendTransition::set_value_from -// Access: Protected, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another ColorBlendTransition. -//////////////////////////////////////////////////////////////////// -void ColorBlendTransition:: -set_value_from(const OnTransition *other) { - const ColorBlendTransition *ot; - DCAST_INTO_V(ot, other); - _value = ot->_value; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorBlendTransition::compare_values -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int ColorBlendTransition:: -compare_values(const OnTransition *other) const { - const ColorBlendTransition *ot; - DCAST_INTO_R(ot, other, false); - return _value.compare_to(ot->_value); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorBlendTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -void ColorBlendTransition:: -output_value(ostream &out) const { - out << _value; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorBlendTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -void ColorBlendTransition:: -write_value(ostream &out, int indent_level) const { - indent(out, indent_level) << _value << "\n"; -} diff --git a/panda/src/sgattrib/colorBlendTransition.h b/panda/src/sgattrib/colorBlendTransition.h deleted file mode 100644 index d678e138d0..0000000000 --- a/panda/src/sgattrib/colorBlendTransition.h +++ /dev/null @@ -1,75 +0,0 @@ -// Filename: colorBlendTransition.h -// Created by: mike (18Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef COLORBLENDTRANSITION_H -#define COLORBLENDTRANSITION_H - -#include - -#include "colorBlendProperty.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : ColorBlendTransition -// Description : This controls the kinds of blending between colors -// being rendered and the existing frame buffer. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ColorBlendTransition : public OnTransition { -public: - INLINE ColorBlendTransition(ColorBlendProperty::Mode mode = ColorBlendProperty::M_none); - - INLINE void set_mode(ColorBlendProperty::Mode mode); - INLINE ColorBlendProperty::Mode get_mode() const; - - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual void set_value_from(const OnTransition *other); - virtual int compare_values(const OnTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - ColorBlendProperty _value; - static PT(NodeTransition) _initial; - -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() { - OnTransition::init_type(); - register_type(_type_handle, "ColorBlendTransition", - OnTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "colorBlendTransition.I" - -#endif diff --git a/panda/src/sgattrib/colorMaskProperty.I b/panda/src/sgattrib/colorMaskProperty.I deleted file mode 100644 index 4d9bcd209b..0000000000 --- a/panda/src/sgattrib/colorMaskProperty.I +++ /dev/null @@ -1,72 +0,0 @@ -// Filename: colorMaskProperty.I -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskProperty::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ColorMaskProperty:: -ColorMaskProperty(int mask) : - _mask(mask) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskProperty::all_on -// Access: Public, Static -// Description: This named constructor returns a ColorMaskProperty -// whose bits are all on: that property that writes to -// all the color planes at once (the normal case). -//////////////////////////////////////////////////////////////////// -INLINE ColorMaskProperty ColorMaskProperty:: -all_on() { - return ColorMaskProperty(M_r | M_g | M_b | M_a); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskProperty::set_mask -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void ColorMaskProperty:: -set_mask(int mask) { - _mask = mask; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskProperty::get_mask -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int ColorMaskProperty:: -get_mask() const { - return _mask; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskProperty::compare_to -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int ColorMaskProperty:: -compare_to(const ColorMaskProperty &other) const { - return (int)_mask - (int)other._mask; -} diff --git a/panda/src/sgattrib/colorMaskProperty.cxx b/panda/src/sgattrib/colorMaskProperty.cxx deleted file mode 100644 index a70c215944..0000000000 --- a/panda/src/sgattrib/colorMaskProperty.cxx +++ /dev/null @@ -1,48 +0,0 @@ -// Filename: colorMaskProperty.cxx -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "colorMaskProperty.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskProperty::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void ColorMaskProperty:: -output(ostream &out) const { - char hex[20]; - sprintf(hex, "%02x", _mask); - nassertv(strlen(hex) < 20); - - out << "0x" << hex << "("; - if ((_mask & M_r) != 0) { - out << "r"; - } - if ((_mask & M_g) != 0) { - out << "g"; - } - if ((_mask & M_b) != 0) { - out << "b"; - } - if ((_mask & M_a) != 0) { - out << "a"; - } - out << ")"; -} diff --git a/panda/src/sgattrib/colorMaskProperty.h b/panda/src/sgattrib/colorMaskProperty.h deleted file mode 100644 index 37f7e3089c..0000000000 --- a/panda/src/sgattrib/colorMaskProperty.h +++ /dev/null @@ -1,58 +0,0 @@ -// Filename: colorMaskProperty.h -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef COLORMASKPROPERTY_H -#define COLORMASKPROPERTY_H - -#include - -//////////////////////////////////////////////////////////////////// -// Class : ColorMaskProperty -// Description : This defines the set of color planes that may be -// active for writing to the color buffer. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ColorMaskProperty { -public: - enum Mask { - M_r = 0x001, - M_g = 0x002, - M_b = 0x004, - M_a = 0x008 - }; - - INLINE ColorMaskProperty(int mask); - INLINE static ColorMaskProperty all_on(); - - INLINE void set_mask(int mask); - INLINE int get_mask() const; - - INLINE int compare_to(const ColorMaskProperty &other) const; - void output(ostream &out) const; - -private: - int _mask; -}; - -INLINE ostream &operator << (ostream &out, const ColorMaskProperty &prop) { - prop.output(out); - return out; -} - -#include "colorMaskProperty.I" - -#endif diff --git a/panda/src/sgattrib/colorMaskTransition.I b/panda/src/sgattrib/colorMaskTransition.I deleted file mode 100644 index 6504f65209..0000000000 --- a/panda/src/sgattrib/colorMaskTransition.I +++ /dev/null @@ -1,104 +0,0 @@ -// Filename: colorMaskTransition.I -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ColorMaskTransition:: -ColorMaskTransition() : - _value(ColorMaskProperty::all_on()) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ColorMaskTransition:: -ColorMaskTransition(int mask) : - _value(mask) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskTransition::set_mask -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void ColorMaskTransition:: -set_mask(int mask) { - _value.set_mask(mask); - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskTransition::get_mask -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int ColorMaskTransition:: -get_mask() const { - return _value.get_mask(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskTransition::is_write_r -// Access: Public -// Description: Returns true if the red component is enabled for -// writing. -//////////////////////////////////////////////////////////////////// -INLINE bool ColorMaskTransition:: -is_write_r() const { - return (_value.get_mask() & ColorMaskProperty::M_r) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskTransition::is_write_g -// Access: Public -// Description: Returns true if the green component is enabled for -// writing. -//////////////////////////////////////////////////////////////////// -INLINE bool ColorMaskTransition:: -is_write_g() const { - return (_value.get_mask() & ColorMaskProperty::M_g) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskTransition::is_write_b -// Access: Public -// Description: Returns true if the blue component is enabled for -// writing. -//////////////////////////////////////////////////////////////////// -INLINE bool ColorMaskTransition:: -is_write_b() const { - return (_value.get_mask() & ColorMaskProperty::M_b) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskTransition::is_write_a -// Access: Public -// Description: Returns true if the alpha component is enabled for -// writing. -//////////////////////////////////////////////////////////////////// -INLINE bool ColorMaskTransition:: -is_write_a() const { - return (_value.get_mask() & ColorMaskProperty::M_a) != 0; -} diff --git a/panda/src/sgattrib/colorMaskTransition.cxx b/panda/src/sgattrib/colorMaskTransition.cxx deleted file mode 100644 index 4cdf46a8ff..0000000000 --- a/panda/src/sgattrib/colorMaskTransition.cxx +++ /dev/null @@ -1,108 +0,0 @@ -// Filename: colorMaskTransition.cxx -// Created by: mike (08Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "colorMaskTransition.h" - -#include - -PT(NodeTransition) ColorMaskTransition::_initial; -TypeHandle ColorMaskTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated ColorMaskTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *ColorMaskTransition:: -make_copy() const { - return new ColorMaskTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated ColorMaskTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *ColorMaskTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new ColorMaskTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void ColorMaskTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_color_mask(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskTransition::set_value_from -// Access: Protected, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another ColorMaskTransition. -//////////////////////////////////////////////////////////////////// -void ColorMaskTransition:: -set_value_from(const OnTransition *other) { - const ColorMaskTransition *ot; - DCAST_INTO_V(ot, other); - _value = ot->_value; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskTransition::compare_values -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int ColorMaskTransition:: -compare_values(const OnTransition *other) const { - const ColorMaskTransition *ot; - DCAST_INTO_R(ot, other, false); - return _value.compare_to(ot->_value); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -void ColorMaskTransition:: -output_value(ostream &out) const { - out << _value; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMaskTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -void ColorMaskTransition:: -write_value(ostream &out, int indent_level) const { - indent(out, indent_level) << _value << "\n"; -} diff --git a/panda/src/sgattrib/colorMaskTransition.h b/panda/src/sgattrib/colorMaskTransition.h deleted file mode 100644 index 0f27a568c7..0000000000 --- a/panda/src/sgattrib/colorMaskTransition.h +++ /dev/null @@ -1,86 +0,0 @@ -// Filename: colorMaskTransition.h -// Created by: mike (08Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef COLORMASKTRANSITION_H -#define COLORMASKTRANSITION_H - -#include - -#include "colorMaskProperty.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : ColorMaskTransition -// Description : This is scene graph colorMask (which is not to be -// confused with geometry colorMask). By setting a -// ColorMaskTransition on the scene graph, you can override -// the colorMask at the object level, but not at the -// individual primitive or vertex level. If a scene -// graph colorMask is set, it overrides the primitive colorMask; -// otherwise, the primitive colorMask shows through. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ColorMaskTransition : public OnTransition { -public: - INLINE ColorMaskTransition(); - INLINE ColorMaskTransition(int mask); - - INLINE void set_mask(int mask); - INLINE int get_mask() const; - - INLINE bool is_write_r() const; - INLINE bool is_write_g() const; - INLINE bool is_write_b() const; - INLINE bool is_write_a() const; - - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual void set_value_from(const OnTransition *other); - virtual int compare_values(const OnTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - ColorMaskProperty _value; - static PT(NodeTransition) _initial; - -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() { - OnTransition::init_type(); - register_type(_type_handle, "ColorMaskTransition", - OnTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "colorMaskTransition.I" - -#endif diff --git a/panda/src/sgattrib/colorMatrixTransition.I b/panda/src/sgattrib/colorMatrixTransition.I deleted file mode 100644 index 65c1313764..0000000000 --- a/panda/src/sgattrib/colorMatrixTransition.I +++ /dev/null @@ -1,37 +0,0 @@ -// Filename: colorMatrixTransition.I -// Created by: jason (01Aug00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: ColorMatrixTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ColorMatrixTransition:: -ColorMatrixTransition() { -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMatrixTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ColorMatrixTransition:: -ColorMatrixTransition(const LMatrix4f &matrix) : - LMatrix4fTransition(matrix) -{ -} diff --git a/panda/src/sgattrib/colorMatrixTransition.cxx b/panda/src/sgattrib/colorMatrixTransition.cxx deleted file mode 100644 index d2a9e9c68f..0000000000 --- a/panda/src/sgattrib/colorMatrixTransition.cxx +++ /dev/null @@ -1,104 +0,0 @@ -// Filename: colorMatrixTransition.cxx -// Created by: jason (01Aug00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "colorMatrixTransition.h" - -#include -#include -#include -#include -#include - -PT(NodeTransition) ColorMatrixTransition::_initial; -TypeHandle ColorMatrixTransition::_type_handle; - -////////////////////////////////////////////////////////////////////s -// Function: ColorMatrixTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated ColorMatrixTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *ColorMatrixTransition:: -make_copy() const { - return new ColorMatrixTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMatrixTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated ColorMatrixTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *ColorMatrixTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new ColorMatrixTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMatrixTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void ColorMatrixTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_color_transform(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMatrixTransition::make_with_matrix -// Access: Protected, Virtual -// Description: Returns a new transition with the indicated matrix. -//////////////////////////////////////////////////////////////////// -MatrixTransition *ColorMatrixTransition:: -make_with_matrix(const LMatrix4f &matrix) const { - return new ColorMatrixTransition(matrix); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMatrixTransition::make_ColorMatrixTransition -// Access: Protected -// Description: Factory method to generate a ColorMatrixTransition object -//////////////////////////////////////////////////////////////////// -TypedWritable* ColorMatrixTransition:: -make_ColorMatrixTransition(const FactoryParams ¶ms) -{ - ColorMatrixTransition *me = new ColorMatrixTransition; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorMatrixTransition::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a ColorMatrixTransition object -//////////////////////////////////////////////////////////////////// -void ColorMatrixTransition:: -register_with_read_factory(void) -{ - BamReader::get_factory()->register_factory(get_class_type(), make_ColorMatrixTransition); -} diff --git a/panda/src/sgattrib/colorMatrixTransition.h b/panda/src/sgattrib/colorMatrixTransition.h deleted file mode 100644 index b8e2ee14d2..0000000000 --- a/panda/src/sgattrib/colorMatrixTransition.h +++ /dev/null @@ -1,74 +0,0 @@ -// Filename: colorMatrixTransition.h -// Created by: jason (01Aug00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef COLOR_MATRIX_TRANSITION_H -#define COLOR_MATRIX_TRANSITION_H - -#include - -#include -#include - -//////////////////////////////////////////////////////////////////// -// Class : ColorMatrixTransition -// Description : This defines a transformation for color. I.E. to -// make something blue, or rotate the colors, or whatever -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ColorMatrixTransition : public LMatrix4fTransition { -public: - INLINE ColorMatrixTransition(); - INLINE ColorMatrixTransition(const LMatrix4f &matrix); - - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual MatrixTransition * - make_with_matrix(const LMatrix4f &matrix) const; - -private: - static PT(NodeTransition) _initial; - -public: - static void register_with_read_factory(void); - - static TypedWritable *make_ColorMatrixTransition(const FactoryParams ¶ms); - -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() { - LMatrix4fTransition::init_type(); - register_type(_type_handle, "ColorMatrixTransition", - LMatrix4fTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "colorMatrixTransition.I" - -#endif diff --git a/panda/src/sgattrib/colorProperty.I b/panda/src/sgattrib/colorProperty.I deleted file mode 100644 index b3bca899ba..0000000000 --- a/panda/src/sgattrib/colorProperty.I +++ /dev/null @@ -1,81 +0,0 @@ -// Filename: colorProperty.I -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include - -//////////////////////////////////////////////////////////////////// -// Function: ColorProperty::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ColorProperty:: -ColorProperty() : - _real(false) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorProperty::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ColorProperty:: -ColorProperty(const Colorf &color) : - _color(color), - _real(true) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorProperty::is_real -// Access: Public -// Description: Returns true if the color is a real color, false if -// it is the uncolor. -//////////////////////////////////////////////////////////////////// -INLINE bool ColorProperty:: -is_real() const { - return _real; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorProperty::get_color -// Access: Public -// Description: Returns the four-component color. It is only valid -// to call this method if is_real() returns true. -//////////////////////////////////////////////////////////////////// -INLINE Colorf ColorProperty:: -get_color() const { - nassertr(is_real(), Colorf(0.0, 0.0, 0.0, 0.0)); - return _color; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorProperty::compare_to -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int ColorProperty:: -compare_to(const ColorProperty &other) const { - if (_real != other._real) { - return (int)_real - (int)other._real; - } - if (_real) { - return _color.compare_to(other._color); - } - return 0; -} diff --git a/panda/src/sgattrib/colorProperty.cxx b/panda/src/sgattrib/colorProperty.cxx deleted file mode 100644 index c86f303e82..0000000000 --- a/panda/src/sgattrib/colorProperty.cxx +++ /dev/null @@ -1,59 +0,0 @@ -// Filename: colorProperty.cxx -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "colorProperty.h" -#include -#include - -//////////////////////////////////////////////////////////////////// -// Function: ColorProperty::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void ColorProperty:: -output(ostream &out) const { - if (is_real()) { - out << "rgba(" << get_color() << ")"; - } else { - out << "uncolor"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorProperty::write_datagram -// Access: Public -// Description: Function to write the important information in -// this object to a Datagram -//////////////////////////////////////////////////////////////////// -void ColorProperty:: -write_datagram(Datagram &destination) { - _color.write_datagram(destination); - destination.add_bool(_real); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorProperty::read_datagram -// Access: Public -// Description: Function to write the important information into -// this object out of a Datagram -//////////////////////////////////////////////////////////////////// -void ColorProperty:: -read_datagram(DatagramIterator &source) { - _color.read_datagram(source); - _real = source.get_bool(); -} diff --git a/panda/src/sgattrib/colorProperty.h b/panda/src/sgattrib/colorProperty.h deleted file mode 100644 index cf93110fa1..0000000000 --- a/panda/src/sgattrib/colorProperty.h +++ /dev/null @@ -1,68 +0,0 @@ -// Filename: colorProperty.h -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef COLORPROPERTY_H -#define COLORPROPERTY_H - -#include - -#include - -class Datagram; -class DatagramIterator; - -//////////////////////////////////////////////////////////////////// -// Class : ColorProperty -// Description : This class defines the scene graph color property -// that we may set on a transition. It makes a -// distinction between a real color and the uncolor. -// When a "real" color is set, it specifies the RGBA -// that will be sent in lieu of vertex color. When a -// "non-real" color (i.e. the uncolor) is set, it -// disables the sending of any color information at all. -// When no color is set (e.g. the transition is "off" or -// absent), the vertex color is sent. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ColorProperty { -public: - INLINE ColorProperty(); - INLINE ColorProperty(const Colorf &color); - - INLINE bool is_real() const; - INLINE Colorf get_color() const; - - INLINE int compare_to(const ColorProperty &other) const; - void output(ostream &out) const; - -public: - void write_datagram(Datagram &destination); - void read_datagram(DatagramIterator &source); - -private: - Colorf _color; - bool _real; -}; - -INLINE ostream &operator << (ostream &out, const ColorProperty &prop) { - prop.output(out); - return out; -} - -#include "colorProperty.I" - -#endif diff --git a/panda/src/sgattrib/colorTransition.I b/panda/src/sgattrib/colorTransition.I deleted file mode 100644 index b55eb2a5d2..0000000000 --- a/panda/src/sgattrib/colorTransition.I +++ /dev/null @@ -1,139 +0,0 @@ -// Filename: colorTransition.I -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ColorTransition:: -ColorTransition() { -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ColorTransition:: -ColorTransition(const Colorf &color) : - OnOffTransition(TD_on), - _value(color) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ColorTransition:: -ColorTransition(float r, float g, float b, float a) : - OnOffTransition(TD_on), - _value(Colorf(r, g, b, a)) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::uncolor -// Access: Public -// Description: This named constructor returns a ColorTransition that -// turns on the "uncolor", i.e. turns off all sending of -// color commands down the pipe. -//////////////////////////////////////////////////////////////////// -INLINE ColorTransition ColorTransition:: -uncolor() { - ColorTransition result; - result.set_uncolor(); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::off -// Access: Public -// Description: This named constructor returns a ColorTransition that -// turns off scene graph color, thus allowing the -// geometry's natural polygon or vertex color to show -// through. -//////////////////////////////////////////////////////////////////// -INLINE ColorTransition ColorTransition:: -off() { - ColorTransition result; - result.set_off(); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::set_on -// Access: Public -// Description: Changes the ColorTransition to turn on the particular -// color. -//////////////////////////////////////////////////////////////////// -INLINE void ColorTransition:: -set_on(const Colorf &color) { - _value = ColorProperty(color); - OnOffTransition::set_on(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::set_on -// Access: Public -// Description: Changes the ColorTransition to turn on the particular -// color. -//////////////////////////////////////////////////////////////////// -INLINE void ColorTransition:: -set_on(float r, float g, float b, float a) { - set_on(Colorf(r, g, b, a)); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::set_uncolor -// Access: Public -// Description: Changes the ColorTransition to turn on uncolor. -//////////////////////////////////////////////////////////////////// -INLINE void ColorTransition:: -set_uncolor() { - _value = ColorProperty(); - OnOffTransition::set_on(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::is_real -// Access: Public -// Description: Returns true if the ColorTransition represents a real -// color, false if it represents the uncolor. It is -// only valid to call this if is_on() has returned true. -//////////////////////////////////////////////////////////////////// -INLINE bool ColorTransition:: -is_real() const { - nassertr(is_on(), false); - return _value.is_real(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::get_color -// Access: Public -// Description: Returns the color that the ColorTransition -// represents. It is only valid to call this if is_on() -// and is_real() have both returned true. -//////////////////////////////////////////////////////////////////// -INLINE Colorf ColorTransition:: -get_color() const { - nassertr(is_on() && is_real(), Colorf(0.0, 0.0, 0.0, 0.0)); - return _value.get_color(); -} diff --git a/panda/src/sgattrib/colorTransition.cxx b/panda/src/sgattrib/colorTransition.cxx deleted file mode 100644 index 540ab9c8e9..0000000000 --- a/panda/src/sgattrib/colorTransition.cxx +++ /dev/null @@ -1,166 +0,0 @@ -// Filename: colorTransition.cxx -// Created by: drose (28Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "colorTransition.h" - -#include -#include -#include -#include -#include - -PT(NodeTransition) ColorTransition::_initial; -TypeHandle ColorTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated ColorTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *ColorTransition:: -make_copy() const { - return new ColorTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated ColorTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *ColorTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new ColorTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void ColorTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_color(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::set_value_from -// Access: Protected, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another ColorTransition. -//////////////////////////////////////////////////////////////////// -void ColorTransition:: -set_value_from(const OnOffTransition *other) { - const ColorTransition *ot; - DCAST_INTO_V(ot, other); - _value = ot->_value; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::compare_values -// Access: Protected, Virtual -// Description: Returns true if the two transitions have the same -// value. It is guaranteed that the other transition is -// another ColorTransition, and that both are "on". -//////////////////////////////////////////////////////////////////// -int ColorTransition:: -compare_values(const OnOffTransition *other) const { - const ColorTransition *ot; - DCAST_INTO_R(ot, other, false); - return _value.compare_to(ot->_value); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -void ColorTransition:: -output_value(ostream &out) const { - out << _value; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -void ColorTransition:: -write_value(ostream &out, int indent_level) const { - indent(out, indent_level) << _value << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::register_with_read_factory -// Access: Public, Static -// Description: Factory method to generate a ColorTransition object -//////////////////////////////////////////////////////////////////// -void ColorTransition:: -register_with_read_factory() { - BamReader::get_factory()->register_factory(get_class_type(), make_ColorTransition); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void ColorTransition:: -write_datagram(BamWriter *manager, Datagram &me) { - OnOffTransition::write_datagram(manager, me); - _value.write_datagram(me); -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::make_ColorTransition -// Access: Protected -// Description: Factory method to generate a ColorTransition object -//////////////////////////////////////////////////////////////////// -TypedWritable *ColorTransition:: -make_ColorTransition(const FactoryParams ¶ms) { - ColorTransition *me = new ColorTransition; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: ColorTransition::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void ColorTransition:: -fillin(DatagramIterator& scan, BamReader* manager) { - OnOffTransition::fillin(scan, manager); - _value.read_datagram(scan); -} diff --git a/panda/src/sgattrib/colorTransition.h b/panda/src/sgattrib/colorTransition.h deleted file mode 100644 index ae614499a3..0000000000 --- a/panda/src/sgattrib/colorTransition.h +++ /dev/null @@ -1,97 +0,0 @@ -// Filename: colorTransition.h -// Created by: drose (18Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef COLORTRANSITION_H -#define COLORTRANSITION_H - -#include - -#include "colorProperty.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : ColorTransition -// Description : This is scene graph color (which is not to be -// confused with geometry color). By setting a -// ColorTransition on the scene graph, you can override -// the color at the object level, but not at the -// individual primitive or vertex level. If a scene -// graph color is set, it overrides the primitive color; -// otherwise, the primitive color shows through. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ColorTransition : public OnOffTransition { -PUBLISHED: - INLINE ColorTransition(); - INLINE ColorTransition(const Colorf &color); - INLINE ColorTransition(float r, float g, float b, float a); - INLINE static ColorTransition uncolor(); - INLINE static ColorTransition off(); - - INLINE void set_on(const Colorf &color); - INLINE void set_on(float r, float g, float b, float a); - INLINE void set_uncolor(); - - INLINE bool is_real() const; - INLINE Colorf get_color() const; - -public: - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual void set_value_from(const OnOffTransition *other); - virtual int compare_values(const OnOffTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - ColorProperty _value; - static PT(NodeTransition) _initial; - -public: - static void register_with_read_factory(); - virtual void write_datagram(BamWriter *manager, Datagram &me); - -protected: - static TypedWritable *make_ColorTransition(const FactoryParams ¶ms); - 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() { - OnOffTransition::init_type(); - register_type(_type_handle, "ColorTransition", - OnOffTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "colorTransition.I" - -#endif diff --git a/panda/src/sgattrib/config_sgattrib.cxx b/panda/src/sgattrib/config_sgattrib.cxx deleted file mode 100644 index e552bced15..0000000000 --- a/panda/src/sgattrib/config_sgattrib.cxx +++ /dev/null @@ -1,169 +0,0 @@ -// Filename: config_sgattrib.cxx -// Created by: drose (10Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "config_sgattrib.h" -#include "renderRelation.h" -#include "colorTransition.h" -#include "textureTransition.h" -#include "decalTransition.h" -#include "depthTestTransition.h" -#include "depthWriteTransition.h" -#include "colorBlendTransition.h" -#include "renderModeTransition.h" -#include "materialTransition.h" -#include "texGenTransition.h" -#include "cullFaceTransition.h" -#include "colorMaskTransition.h" -#include "stencilTransition.h" -#include "textureApplyTransition.h" -#include "clipPlaneTransition.h" -#include "transparencyTransition.h" -#include "fog.h" -#include "fogTransition.h" -#include "linesmoothTransition.h" -#include "transformTransition.h" -#include "texMatrixTransition.h" -#include "billboardTransition.h" -#include "polygonOffsetTransition.h" -#include "pruneTransition.h" -#include "drawBoundsTransition.h" -#include "pointShapeTransition.h" -#include "colorMatrixTransition.h" -#include "alphaTransformTransition.h" - - -#include - -Configure(config_sgattrib); -NotifyCategoryDef(sgattrib, ""); - - -// For performance testing reasons, it may be useful to support -// certain rendering special effects that require a special-case -// direct render traversal to varying less-than-complete degrees. The -// variables support-decals, support-subrender, or support-direct may -// be set to change these. support-decals specifically controls the -// rendering of decal geometry (polygons against a coplanar -// background), while support-subrender controls other effects such as -// LOD's and billboards. support-direct controls any effect which -// requires switching to DirectRenderTraverser from a CullTraverser, -// including decals and things specifically flagged with a -// DirectRenderTransition. -// -// The legal values for each variable are: -// -// on - This is the default, and causes the effect to be rendered -// properly (if supported by the gsg backend). This could have -// performance implications in fill, transform, and -// state-sorting. This is equivalent to #t. -// -// off - The special effect is ignored, and the geometry is rendered -// as if the effect were not set at all. The result will -// generally be horrible looking, for instance with decals -// Z-fighting with the base geometry. This is equivalent to -// #f. -// -// hide - The nested geometry--the decals, or the billboards, or -// whatever--is not drawn at all. -// -// If compiled in NDEBUG mode, this variable is ignored and decals -// etc. are always on. -// -SupportDirect support_decals = SD_on; -SupportDirect support_subrender = SD_on; -SupportDirect support_direct = SD_on; - -static SupportDirect -get_support_direct(const string &varname) { - string type = config_sgattrib.GetString(varname, ""); - if (type == "on") { - return SD_on; - } else if (type == "off") { - return SD_off; - } else if (type == "hide") { - return SD_hide; - } - - // None of the above, so use #t/#f. - if (config_sgattrib.GetBool(varname, true)) { - return SD_on; - } else { - return SD_off; - } -} - -ConfigureFn(config_sgattrib) { - support_decals = get_support_direct("support-decals"); - support_subrender = get_support_direct("support-subrender"); - support_direct = get_support_direct("support-direct"); - - // MPG - we want to ensure that texture transitions are applied - // before texgen transitions, so the texture transition must be - // initialized first. - - RenderRelation::init_type(); - TextureTransition::init_type(); - TransformTransition::init_type(); - TexMatrixTransition::init_type(); - DecalTransition::init_type(); - DepthTestTransition::init_type(); - DepthWriteTransition::init_type(); - ColorBlendTransition::init_type(); - RenderModeTransition::init_type(); - MaterialTransition::init_type(); - TexGenTransition::init_type(); - CullFaceTransition::init_type(); - ColorMaskTransition::init_type(); - StencilTransition::init_type(); - TextureApplyTransition::init_type(); - ClipPlaneTransition::init_type(); - TransparencyTransition::init_type(); - Fog::init_type(); - FogTransition::init_type(); - LinesmoothTransition::init_type(); - PruneTransition::init_type(); - ColorTransition::init_type(); - BillboardTransition::init_type(); - DrawBoundsTransition::init_type(); - PointShapeTransition::init_type(); - PolygonOffsetTransition::init_type(); - ColorMatrixTransition::init_type(); - AlphaTransformTransition::init_type(); - - // Register the RenderRelation class for the - // NodeRelation::create_typed_arc() function. - RenderRelation::register_with_factory(); - - //Registration of writeable object's creation - //functions with BamReader's factory - BillboardTransition::register_with_read_factory(); - ColorMatrixTransition::register_with_read_factory(); - ColorTransition::register_with_read_factory(); - CullFaceTransition::register_with_read_factory(); - DecalTransition::register_with_read_factory(); - DepthTestTransition::register_with_read_factory(); - DepthWriteTransition::register_with_read_factory(); - MaterialTransition::register_with_read_factory(); - PruneTransition::register_with_read_factory(); - RenderRelation::register_with_read_factory(); - TextureApplyTransition::register_with_read_factory(); - TextureTransition::register_with_read_factory(); - TransformTransition::register_with_read_factory(); - TransparencyTransition::register_with_read_factory(); -} - diff --git a/panda/src/sgattrib/config_sgattrib.h b/panda/src/sgattrib/config_sgattrib.h deleted file mode 100644 index be22717131..0000000000 --- a/panda/src/sgattrib/config_sgattrib.h +++ /dev/null @@ -1,38 +0,0 @@ -// Filename: config_sgattrib.h -// Created by: drose (10Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CONFIG_SGATTRIB_H -#define CONFIG_SGATTRIB_H - -#include -#include - -NotifyCategoryDecl(sgattrib, EXPCL_PANDA, EXPTP_PANDA); - -// Configure variables for sgattrib package. -enum SupportDirect { - SD_on, - SD_off, - SD_hide -}; - -extern EXPCL_PANDA SupportDirect support_decals; -extern EXPCL_PANDA SupportDirect support_subrender; -extern EXPCL_PANDA SupportDirect support_direct; - -#endif diff --git a/panda/src/sgattrib/cullFaceProperty.I b/panda/src/sgattrib/cullFaceProperty.I deleted file mode 100644 index e5cec58598..0000000000 --- a/panda/src/sgattrib/cullFaceProperty.I +++ /dev/null @@ -1,59 +0,0 @@ -// Filename: cullFaceProperty.I -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceProperty::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CullFaceProperty:: -CullFaceProperty(Mode mode) : - _mode(mode) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceProperty::set_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void CullFaceProperty:: -set_mode(CullFaceProperty::Mode mode) { - _mode = mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceProperty::get_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CullFaceProperty::Mode CullFaceProperty:: -get_mode() const { - return _mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceProperty::compare_to -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int CullFaceProperty:: -compare_to(const CullFaceProperty &other) const { - return (int)_mode - (int)other._mode; -} - diff --git a/panda/src/sgattrib/cullFaceProperty.cxx b/panda/src/sgattrib/cullFaceProperty.cxx deleted file mode 100644 index 6e46b02486..0000000000 --- a/panda/src/sgattrib/cullFaceProperty.cxx +++ /dev/null @@ -1,74 +0,0 @@ -// Filename: cullFaceProperty.cxx -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "cullFaceProperty.h" -#include -#include - -ostream & -operator << (ostream &out, CullFaceProperty::Mode mode) { - switch (mode) { - case CullFaceProperty::M_cull_none: - return out << "cull_none"; - - case CullFaceProperty::M_cull_clockwise: - return out << "cull_clockwise"; - - case CullFaceProperty::M_cull_counter_clockwise: - return out << "cull_counter_clockwise"; - - case CullFaceProperty::M_cull_all: - return out << "cull_all"; - } - - return out << "**invalid**(" << (int)mode << ")"; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceProperty::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void CullFaceProperty:: -output(ostream &out) const { - out << _mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceProperty::write_datagram -// Access: Public -// Description: Function to write the important information in -// this object to a Datagram -//////////////////////////////////////////////////////////////////// -void CullFaceProperty:: -write_datagram(Datagram &destination) -{ - destination.add_uint8(_mode); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceProperty::read_datagram -// Access: Public -// Description: Function to write the important information into -// this object out of a Datagram -//////////////////////////////////////////////////////////////////// -void CullFaceProperty:: -read_datagram(DatagramIterator &source) -{ - _mode = (enum Mode) source.get_uint8(); -} diff --git a/panda/src/sgattrib/cullFaceProperty.h b/panda/src/sgattrib/cullFaceProperty.h deleted file mode 100644 index b810c6fa01..0000000000 --- a/panda/src/sgattrib/cullFaceProperty.h +++ /dev/null @@ -1,68 +0,0 @@ -// Filename: cullFaceProperty.h -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CULLFACEPROPERTY_H -#define CULLFACEPROPERTY_H - -#include - -class Datagram; -class DatagramIterator; - -//////////////////////////////////////////////////////////////////// -// Class : CullFaceProperty -// Description : This defines the ways we can cull faces according to -// their vertex ordering (and hence orientation relative -// to the camera). -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA CullFaceProperty { -public: - enum Mode { - M_cull_none, // Cull no polygons - M_cull_clockwise, // Cull clockwise-oriented polygons - M_cull_counter_clockwise, // Cull counter-clockwise-oriented polygons - M_cull_all, // Cull all polygons (other primitives are still drawn) - }; - -public: - INLINE CullFaceProperty(Mode mode = M_cull_none); - - INLINE void set_mode(Mode mode); - INLINE Mode get_mode() const; - - INLINE int compare_to(const CullFaceProperty &other) const; - void output(ostream &out) const; - -public: - void write_datagram(Datagram &destination); - void read_datagram(DatagramIterator &source); - -private: - Mode _mode; -}; - -ostream &operator << (ostream &out, CullFaceProperty::Mode mode); - -INLINE ostream &operator << (ostream &out, const CullFaceProperty &prop) { - prop.output(out); - return out; -} - -#include "cullFaceProperty.I" - -#endif diff --git a/panda/src/sgattrib/cullFaceTransition.I b/panda/src/sgattrib/cullFaceTransition.I deleted file mode 100644 index d188cb94b7..0000000000 --- a/panda/src/sgattrib/cullFaceTransition.I +++ /dev/null @@ -1,49 +0,0 @@ -// Filename: cullFaceTransition.I -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CullFaceTransition:: -CullFaceTransition(CullFaceProperty::Mode mode) : - _value(mode) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceTransition::set_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void CullFaceTransition:: -set_mode(CullFaceProperty::Mode mode) { - _value.set_mode(mode); - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceTransition::get_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CullFaceProperty::Mode CullFaceTransition:: -get_mode() const { - return _value.get_mode(); -} diff --git a/panda/src/sgattrib/cullFaceTransition.cxx b/panda/src/sgattrib/cullFaceTransition.cxx deleted file mode 100644 index db838064b8..0000000000 --- a/panda/src/sgattrib/cullFaceTransition.cxx +++ /dev/null @@ -1,173 +0,0 @@ -// Filename: cullFaceTransition.cxx -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "cullFaceTransition.h" - -#include -#include -#include -#include -#include - -PT(NodeTransition) CullFaceTransition::_initial; -TypeHandle CullFaceTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated CullFaceTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *CullFaceTransition:: -make_copy() const { - return new CullFaceTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated CullFaceTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *CullFaceTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new CullFaceTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void CullFaceTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_cull_face(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceTransition::set_value_from -// Access: Protected, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another CullFaceTransition. -//////////////////////////////////////////////////////////////////// -void CullFaceTransition:: -set_value_from(const OnTransition *other) { - const CullFaceTransition *ot; - DCAST_INTO_V(ot, other); - _value = ot->_value; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceTransition::compare_values -// Access: Protected, Virtual -// Description: Returns true if the two transitions have the same -// value. It is guaranteed that the other transition is -// another CullFaceTransition, and that both are "on". -//////////////////////////////////////////////////////////////////// -int CullFaceTransition:: -compare_values(const OnTransition *other) const { - const CullFaceTransition *ot; - DCAST_INTO_R(ot, other, false); - return _value.compare_to(ot->_value); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -void CullFaceTransition:: -output_value(ostream &out) const { - out << _value; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -void CullFaceTransition:: -write_value(ostream &out, int indent_level) const { - indent(out, indent_level) << _value << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceTransition::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void CullFaceTransition:: -write_datagram(BamWriter *manager, Datagram &me) -{ - OnTransition::write_datagram(manager, me); - _value.write_datagram(me); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceTransition::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void CullFaceTransition:: -fillin(DatagramIterator& scan, BamReader* manager) -{ - OnTransition::fillin(scan, manager); - _value.read_datagram(scan); -} - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceTransition::make_CullFaceTransition -// Access: Protected -// Description: Factory method to generate a CullFaceTransition object -//////////////////////////////////////////////////////////////////// -TypedWritable* CullFaceTransition:: -make_CullFaceTransition(const FactoryParams ¶ms) -{ - CullFaceTransition *me = new CullFaceTransition; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: CullFaceTransition::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a CullFaceTransition object -//////////////////////////////////////////////////////////////////// -void CullFaceTransition:: -register_with_read_factory(void) -{ - BamReader::get_factory()->register_factory(get_class_type(), make_CullFaceTransition); -} - - - diff --git a/panda/src/sgattrib/cullFaceTransition.h b/panda/src/sgattrib/cullFaceTransition.h deleted file mode 100644 index 62de63455c..0000000000 --- a/panda/src/sgattrib/cullFaceTransition.h +++ /dev/null @@ -1,88 +0,0 @@ -// Filename: cullFaceTransition.h -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CULLFACETRANSITION_H -#define CULLFACETRANSITION_H - -#include - -#include "cullFaceProperty.h" - -#include "nodeTransition.h" -#include "pointerTo.h" -#include "onTransition.h" - -//////////////////////////////////////////////////////////////////// -// Class : CullFaceTransition -// Description : This controls how polygons are culled according to -// the ordering of their vertices after projection (and, -// hence, according to their facing relative to the -// camera). -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA CullFaceTransition : public OnTransition { -public: - INLINE CullFaceTransition(CullFaceProperty::Mode mode = CullFaceProperty::M_cull_none); - - INLINE void set_mode(CullFaceProperty::Mode mode); - INLINE CullFaceProperty::Mode get_mode() const; - - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual void set_value_from(const OnTransition *other); - virtual int compare_values(const OnTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - CullFaceProperty _value; - static PT(NodeTransition) _initial; - -public: - static void register_with_read_factory(void); - virtual void write_datagram(BamWriter* manager, Datagram &me); - - static TypedWritable *make_CullFaceTransition(const FactoryParams ¶ms); - -protected: - 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() { - OnTransition::init_type(); - register_type(_type_handle, "CullFaceTransition", - OnTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "cullFaceTransition.I" - -#endif diff --git a/panda/src/sgattrib/decalTransition.I b/panda/src/sgattrib/decalTransition.I deleted file mode 100644 index 825ece6358..0000000000 --- a/panda/src/sgattrib/decalTransition.I +++ /dev/null @@ -1,39 +0,0 @@ -// Filename: decalTransition.I -// Created by: drose (17Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: DecalTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE DecalTransition:: -DecalTransition() { - set_on(); -} - -//////////////////////////////////////////////////////////////////// -// Function: DecalTransition::off -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE DecalTransition DecalTransition:: -off() { - DecalTransition result; - result.set_off(); - return result; -} diff --git a/panda/src/sgattrib/decalTransition.cxx b/panda/src/sgattrib/decalTransition.cxx deleted file mode 100644 index e68b6c5573..0000000000 --- a/panda/src/sgattrib/decalTransition.cxx +++ /dev/null @@ -1,92 +0,0 @@ -// Filename: decalTransition.cxx -// Created by: drose (17Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "decalTransition.h" -#include -#include -#include -#include - -PT(NodeTransition) DecalTransition::_initial; -TypeHandle DecalTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: DecalTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated DecalTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *DecalTransition:: -make_copy() const { - return new DecalTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: DecalTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated DecalTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *DecalTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new DecalTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: DecalTransition::has_sub_render -// Access: Public, Virtual -// Description: DecalTransition doesn't actually have a sub_render() -// function, but it might as well, because it's treated -// as a special case. We set this function to return -// true so GraphReducer will behave correctly. -//////////////////////////////////////////////////////////////////// -bool DecalTransition:: -has_sub_render() const { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: DecalTransition::make_DecalTransition -// Access: Protected -// Description: Factory method to generate a DecalTransition object -//////////////////////////////////////////////////////////////////// -TypedWritable* DecalTransition:: -make_DecalTransition(const FactoryParams ¶ms) -{ - DecalTransition *me = new DecalTransition; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: DecalTransition::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a DecalTransition object -//////////////////////////////////////////////////////////////////// -void DecalTransition:: -register_with_read_factory(void) -{ - BamReader::get_factory()->register_factory(get_class_type(), make_DecalTransition); -} diff --git a/panda/src/sgattrib/decalTransition.h b/panda/src/sgattrib/decalTransition.h deleted file mode 100644 index 47c901782c..0000000000 --- a/panda/src/sgattrib/decalTransition.h +++ /dev/null @@ -1,81 +0,0 @@ -// Filename: decalTransition.h -// Created by: drose (17Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DECALTRANSITION_H -#define DECALTRANSITION_H - -#include - -#include - -//////////////////////////////////////////////////////////////////// -// Class : DecalTransition -// Description : When this transition is in effect, the first GeomNode -// encountered is rendered in a special mode, such that -// all of its *children* (indeed, the whole subtree -// beginning at the top GeomNode under the transition) -// are rendered as decals of the GeomNode. -// -// This means that the decal geometry (i.e. all geometry -// in GeomNodes parented somewhere below the top -// GeomNode) is assumed to be coplanar with the base -// geometry, and will be rendered so that no z-fighting -// will occur between it and the base geometry. -// -// The render behavior is undefined if the decal -// geometry is *not* coplanar with the base geometry. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA DecalTransition : public OnOffTransition { -PUBLISHED: - INLINE DecalTransition(); - INLINE static DecalTransition off(); - -public: - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual bool has_sub_render() const; - -private: - static PT(NodeTransition) _initial; - -public: - static void register_with_read_factory(void); - static TypedWritable *make_DecalTransition(const FactoryParams ¶ms); - -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() { - OnOffTransition::init_type(); - register_type(_type_handle, "DecalTransition", - OnOffTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "decalTransition.I" - -#endif diff --git a/panda/src/sgattrib/depthTestProperty.I b/panda/src/sgattrib/depthTestProperty.I deleted file mode 100644 index fe64b823d4..0000000000 --- a/panda/src/sgattrib/depthTestProperty.I +++ /dev/null @@ -1,58 +0,0 @@ -// Filename: depthTestProperty.I -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestProperty::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE DepthTestProperty:: -DepthTestProperty(DepthTestProperty::Mode mode) : - _mode(mode) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestProperty::set_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void DepthTestProperty:: -set_mode(DepthTestProperty::Mode mode) { - _mode = mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestProperty::get_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE DepthTestProperty::Mode DepthTestProperty:: -get_mode() const { - return _mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestProperty::compare_to -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int DepthTestProperty:: -compare_to(const DepthTestProperty &other) const { - return (int)_mode - (int)other._mode; -} diff --git a/panda/src/sgattrib/depthTestProperty.cxx b/panda/src/sgattrib/depthTestProperty.cxx deleted file mode 100644 index e973c7c517..0000000000 --- a/panda/src/sgattrib/depthTestProperty.cxx +++ /dev/null @@ -1,87 +0,0 @@ -// Filename: depthTestProperty.cxx -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "depthTestProperty.h" -#include -#include - -ostream & -operator << (ostream &out, DepthTestProperty::Mode mode) { - switch (mode) { - case DepthTestProperty::M_none: - return out << "none"; - - case DepthTestProperty::M_never: - return out << "never"; - - case DepthTestProperty::M_less: - return out << "less"; - - case DepthTestProperty::M_equal: - return out << "equal"; - - case DepthTestProperty::M_less_equal: - return out << "less_equal"; - - case DepthTestProperty::M_greater: - return out << "greater"; - - case DepthTestProperty::M_not_equal: - return out << "not_equal"; - - case DepthTestProperty::M_greater_equal: - return out << "greater_equal"; - - case DepthTestProperty::M_always: - return out << "always"; - } - - return out << "**invalid**(" << (int)mode << ")"; -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestProperty::write_datagram -// Access: Public -// Description: Function to write the important information in -// this object to a Datagram -//////////////////////////////////////////////////////////////////// -void DepthTestProperty:: -write_datagram(Datagram &destination) { - destination.add_uint8(_mode); -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestProperty::read_datagram -// Access: Public -// Description: Function to write the important information into -// this object out of a Datagram -//////////////////////////////////////////////////////////////////// -void DepthTestProperty:: -read_datagram(DatagramIterator &source) { - _mode = (Mode)source.get_uint8(); -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestProperty::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void DepthTestProperty:: -output(ostream &out) const { - out << _mode; -} diff --git a/panda/src/sgattrib/depthTestProperty.h b/panda/src/sgattrib/depthTestProperty.h deleted file mode 100644 index 838a9a08e7..0000000000 --- a/panda/src/sgattrib/depthTestProperty.h +++ /dev/null @@ -1,73 +0,0 @@ -// Filename: depthTestProperty.h -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DEPTHTESTPROPERTY_H -#define DEPTHTESTPROPERTY_H - -#include - -class Datagram; -class DatagramIterator; - -//////////////////////////////////////////////////////////////////// -// Class : DepthTestProperty -// Description : This defines the types of depth testing we can -// enable. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA DepthTestProperty { -PUBLISHED: - enum Mode { - M_none, // No depth test; may still write to depth buffer. - M_never, // Never draw. - M_less, // incoming < stored - M_equal, // incoming == stored - M_less_equal, // incoming <= stored - M_greater, // incoming > stored - M_not_equal, // incoming != stored - M_greater_equal, // incoming >= stored - M_always // Always draw. Same effect as none, more expensive. - }; - -public: - INLINE DepthTestProperty(Mode mode = M_none); - - INLINE void set_mode(Mode mode); - INLINE Mode get_mode() const; - - INLINE int compare_to(const DepthTestProperty &other) const; - - void output(ostream &out) const; - -public: - void write_datagram(Datagram &destination); - void read_datagram(DatagramIterator &source); - -private: - Mode _mode; -}; - -ostream &operator << (ostream &out, DepthTestProperty::Mode mode); - -INLINE ostream &operator << (ostream &out, const DepthTestProperty &prop) { - prop.output(out); - return out; -} - -#include "depthTestProperty.I" - -#endif diff --git a/panda/src/sgattrib/depthTestTransition.I b/panda/src/sgattrib/depthTestTransition.I deleted file mode 100644 index bb33ad8590..0000000000 --- a/panda/src/sgattrib/depthTestTransition.I +++ /dev/null @@ -1,49 +0,0 @@ -// Filename: depthTestTransition.I -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE DepthTestTransition:: -DepthTestTransition(DepthTestProperty::Mode mode) : - _value(mode) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestTransition::set_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void DepthTestTransition:: -set_mode(DepthTestProperty::Mode mode) { - _value.set_mode(mode); - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestTransition::get_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE DepthTestProperty::Mode DepthTestTransition:: -get_mode() const { - return _value.get_mode(); -} diff --git a/panda/src/sgattrib/depthTestTransition.cxx b/panda/src/sgattrib/depthTestTransition.cxx deleted file mode 100644 index 0809d94a98..0000000000 --- a/panda/src/sgattrib/depthTestTransition.cxx +++ /dev/null @@ -1,164 +0,0 @@ -// Filename: depthTestTransition.cxx -// Created by: mike (28Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "depthTestTransition.h" - -#include -#include -#include -#include -#include - -PT(NodeTransition) DepthTestTransition::_initial; -TypeHandle DepthTestTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated DepthTestTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *DepthTestTransition:: -make_copy() const { - return new DepthTestTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated DepthTestTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *DepthTestTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new DepthTestTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void DepthTestTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_depth_test(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestTransition::set_value_from -// Access: Protected, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another DepthTestTransition. -//////////////////////////////////////////////////////////////////// -void DepthTestTransition:: -set_value_from(const OnTransition *other) { - const DepthTestTransition *ot; - DCAST_INTO_V(ot, other); - _value = ot->_value; -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestTransition::compare_values -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int DepthTestTransition:: -compare_values(const OnTransition *other) const { - const DepthTestTransition *ot; - DCAST_INTO_R(ot, other, false); - return _value.compare_to(ot->_value); -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -void DepthTestTransition:: -output_value(ostream &out) const { - out << _value; -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -void DepthTestTransition:: -write_value(ostream &out, int indent_level) const { - indent(out, indent_level) << _value << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestTransition::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a DepthTestTransition object -//////////////////////////////////////////////////////////////////// -void DepthTestTransition:: -register_with_read_factory() { - BamReader::get_factory()->register_factory(get_class_type(), make_DepthTestTransition); -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestTransition::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void DepthTestTransition:: -write_datagram(BamWriter *manager, Datagram &me) { - OnTransition::write_datagram(manager, me); - _value.write_datagram(me); -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestTransition::make_DepthTestTransition -// Access: Protected -// Description: Factory method to generate a DepthTestTransition object -//////////////////////////////////////////////////////////////////// -TypedWritable* DepthTestTransition:: -make_DepthTestTransition(const FactoryParams ¶ms) { - DepthTestTransition *me = new DepthTestTransition; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthTestTransition::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void DepthTestTransition:: -fillin(DatagramIterator& scan, BamReader* manager) { - OnTransition::fillin(scan, manager); - _value.read_datagram(scan); -} diff --git a/panda/src/sgattrib/depthTestTransition.h b/panda/src/sgattrib/depthTestTransition.h deleted file mode 100644 index 899cb1dab6..0000000000 --- a/panda/src/sgattrib/depthTestTransition.h +++ /dev/null @@ -1,90 +0,0 @@ -// Filename: depthTestTransition.h -// Created by: drose (18Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DEPTHTESTTRANSITION_H -#define DEPTHTESTTRANSITION_H - -#include - -#include "depthTestProperty.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : DepthTestTransition -// Description : This transition controls the nature of the test -// against the depth buffer. It does not affect whether -// the depth buffer will be written to or not; that is -// handled by a separate transition, -// DepthWriteTransition. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA DepthTestTransition : public OnTransition { -PUBLISHED: - INLINE DepthTestTransition(DepthTestProperty::Mode mode = DepthTestProperty::M_less); - - INLINE void set_mode(DepthTestProperty::Mode mode); - INLINE DepthTestProperty::Mode get_mode() const; - -public: - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual void set_value_from(const OnTransition *other); - virtual int compare_values(const OnTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - DepthTestProperty _value; - static PT(NodeTransition) _initial; - -public: - static void register_with_read_factory(); - virtual void write_datagram(BamWriter *manager, Datagram &me); - - static TypedWritable *make_DepthTestTransition(const FactoryParams ¶ms); - -protected: - 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() { - OnTransition::init_type(); - register_type(_type_handle, "DepthTestTransition", - OnTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "depthTestTransition.I" - -#endif - - diff --git a/panda/src/sgattrib/depthWriteTransition.I b/panda/src/sgattrib/depthWriteTransition.I deleted file mode 100644 index 76c243b598..0000000000 --- a/panda/src/sgattrib/depthWriteTransition.I +++ /dev/null @@ -1,39 +0,0 @@ -// Filename: depthWriteTransition.I -// Created by: drose (31Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: DepthWriteTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE DepthWriteTransition:: -DepthWriteTransition() { - set_on(); -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthWriteTransition::off -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE DepthWriteTransition DepthWriteTransition:: -off() { - DepthWriteTransition result; - result.set_off(); - return result; -} diff --git a/panda/src/sgattrib/depthWriteTransition.cxx b/panda/src/sgattrib/depthWriteTransition.cxx deleted file mode 100644 index f3583ca95d..0000000000 --- a/panda/src/sgattrib/depthWriteTransition.cxx +++ /dev/null @@ -1,115 +0,0 @@ -// Filename: depthWriteTransition.cxx -// Created by: drose (31Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "depthWriteTransition.h" - -#include -#include -#include -#include - -PT(NodeTransition) DepthWriteTransition::_initial; -TypeHandle DepthWriteTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: DepthWriteTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated DepthWriteTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *DepthWriteTransition:: -make_copy() const { - return new DepthWriteTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthWriteTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated DepthWriteTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *DepthWriteTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new DepthWriteTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthWriteTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void DepthWriteTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_depth_write(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthWriteTransition::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a DepthWriteTransition object -//////////////////////////////////////////////////////////////////// -void DepthWriteTransition:: -register_with_read_factory() { - BamReader::get_factory()->register_factory(get_class_type(), make_DepthWriteTransition); -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthWriteTransition::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void DepthWriteTransition:: -write_datagram(BamWriter *manager, Datagram &me) { - OnOffTransition::write_datagram(manager, me); -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthWriteTransition::make_DepthWriteTransition -// Access: Public -// Description: Factory method to generate a DepthWriteTransition object -//////////////////////////////////////////////////////////////////// -TypedWritable *DepthWriteTransition:: -make_DepthWriteTransition(const FactoryParams ¶ms) { - DepthWriteTransition *me = new DepthWriteTransition; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: DepthWriteTransition::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void DepthWriteTransition:: -fillin(DatagramIterator &scan, BamReader *manager) { - OnOffTransition::fillin(scan, manager); -} diff --git a/panda/src/sgattrib/depthWriteTransition.h b/panda/src/sgattrib/depthWriteTransition.h deleted file mode 100644 index ee49f11396..0000000000 --- a/panda/src/sgattrib/depthWriteTransition.h +++ /dev/null @@ -1,74 +0,0 @@ -// Filename: depthWriteTransition.h -// Created by: drose (31Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DEPTHWRITETRANSITION_H -#define DEPTHWRITETRANSITION_H - -#include - -#include - -//////////////////////////////////////////////////////////////////// -// Class : DepthWriteTransition -// Description : This enables or disables the writing to the depth -// buffer. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA DepthWriteTransition : public OnOffTransition { -PUBLISHED: - INLINE DepthWriteTransition(); - INLINE static DepthWriteTransition off(); - -public: - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -private: - static PT(NodeTransition) _initial; - -public: - static void register_with_read_factory(); - virtual void write_datagram(BamWriter* manager, Datagram &me); - - static TypedWritable *make_DepthWriteTransition(const FactoryParams ¶ms); - -protected: - 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() { - OnOffTransition::init_type(); - register_type(_type_handle, "DepthWriteTransition", - OnOffTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "depthWriteTransition.I" - -#endif diff --git a/panda/src/sgattrib/drawBoundsTransition.I b/panda/src/sgattrib/drawBoundsTransition.I deleted file mode 100644 index fad9b112ec..0000000000 --- a/panda/src/sgattrib/drawBoundsTransition.I +++ /dev/null @@ -1,18 +0,0 @@ -// Filename: drawBoundsTransition.I -// Created by: drose (26Jun00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - diff --git a/panda/src/sgattrib/drawBoundsTransition.cxx b/panda/src/sgattrib/drawBoundsTransition.cxx deleted file mode 100644 index df894e3e9a..0000000000 --- a/panda/src/sgattrib/drawBoundsTransition.cxx +++ /dev/null @@ -1,156 +0,0 @@ -// Filename: drawBoundsTransition.cxx -// Created by: drose (26Jun00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "config_sgattrib.h" -#include "drawBoundsTransition.h" -#include "renderModeTransition.h" -#include "cullFaceTransition.h" -#include "colorTransition.h" -#include "transformTransition.h" - -#include -#include -#include -#include -#include -#include -#include - -PT(NodeTransition) DrawBoundsTransition::_initial; -TypeHandle DrawBoundsTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: DrawBoundsTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -DrawBoundsTransition:: -DrawBoundsTransition() { - RenderModeTransition *rma = new RenderModeTransition(RenderModeProperty::M_wireframe); - CullFaceTransition *cfao = new CullFaceTransition(CullFaceProperty::M_cull_clockwise); - ColorTransition *cao = new ColorTransition(0.3f, 1.0f, 0.5f, 1.0f); - - CullFaceTransition *cfai = new CullFaceTransition(CullFaceProperty::M_cull_counter_clockwise); - ColorTransition *cai = new ColorTransition(0.15f, 0.5f, 0.25f, 1.0f); - - _outside_attrib.set_transition(rma); - _outside_attrib.set_transition(cfao); - _outside_attrib.set_transition(cao); - - _inside_attrib.set_transition(cfai); - _inside_attrib.set_transition(cai); -} - -//////////////////////////////////////////////////////////////////// -// Function: DrawBoundsTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated DrawBoundsTransition just -// like this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *DrawBoundsTransition:: -make_copy() const { - return new DrawBoundsTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: DrawBoundsTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated DrawBoundsTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *DrawBoundsTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new DrawBoundsTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: DrawBoundsTransition::sub_render -// Access: Public, Virtual -// Description: This is called by the RenderTraverser to tell the -// drawBounds to do its thing. -//////////////////////////////////////////////////////////////////// -bool DrawBoundsTransition:: -sub_render(NodeRelation *arc, const AllTransitionsWrapper &input_trans, - AllTransitionsWrapper &, RenderTraverser *trav) { - GraphicsStateGuardian *gsg = trav->get_gsg(); - - const BoundingVolume &vol = arc->get_bound(); - if (!vol.is_empty() && !vol.is_infinite()) { - // This is a bit of work, because the bounding volume has already - // been transformed by this arc's transform. - - LMatrix4f mat; - TransformTransition *ta; - if (get_transition_into(ta, input_trans)) { - mat = ta->get_matrix(); - } else { - mat = LMatrix4f::ident_mat(); - } - - TransformTransition *tt; - if (get_transition_into(tt, arc)) { - // Undo the application of the arc's transform. Yuck. - mat = ::invert(tt->get_matrix()) * mat; - } - - TransformTransition *new_ta = new TransformTransition; - new_ta->set_matrix(mat); - _outside_attrib.set_transition(new_ta); - - gsg->set_state(_outside_attrib); - - if (vol.is_of_type(BoundingSphere::get_class_type())) { - const BoundingSphere *sphere = DCAST(BoundingSphere, &vol); - - GeomSphere geom; - PTA_Vertexf verts; - LPoint3f center = sphere->get_center(); - verts.push_back(center); - center[0] += sphere->get_radius(); - verts.push_back(center); - geom.set_coords(verts); - geom.set_num_prims(1); - - gsg->draw_sphere(&geom, NULL); - gsg->modify_state(_inside_attrib); - gsg->draw_sphere(&geom, NULL); - - } else { - sgattrib_cat.warning() - << "Don't know how to draw a representation of " - << vol.get_class_type() << "\n"; - } - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: DrawBoundsTransition::has_sub_render -// Access: Public, Virtual -// Description: Should be redefined to return true if the function -// sub_render(), above, expects to be called during -// traversal. -//////////////////////////////////////////////////////////////////// -bool DrawBoundsTransition:: -has_sub_render() const { - return true; -} diff --git a/panda/src/sgattrib/drawBoundsTransition.h b/panda/src/sgattrib/drawBoundsTransition.h deleted file mode 100644 index e27a21b40c..0000000000 --- a/panda/src/sgattrib/drawBoundsTransition.h +++ /dev/null @@ -1,78 +0,0 @@ -// Filename: drawBoundsTransition.h -// Created by: drose (26Jun00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DRAWBOUNDSTRANSITION_H -#define DRAWBOUNDSTRANSITION_H - -#include "pandabase.h" - -#include "immediateTransition.h" -#include "nodeTransitions.h" -#include "allTransitionsWrapper.h" - -//////////////////////////////////////////////////////////////////// -// Class : DrawBoundsTransition -// Description : This is a special transition that does not change -// rendering state, but instead causes a representation -// of the arc's bounding volume to be rendered -// immediately. It's intended primarily for debugging -// purposes; it's not designed to be terribly efficient. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA DrawBoundsTransition : public ImmediateTransition { -public: - DrawBoundsTransition(); - -public: - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual bool sub_render(NodeRelation *arc, - const AllTransitionsWrapper &input_trans, - AllTransitionsWrapper &modify_trans, - RenderTraverser *trav); - virtual bool has_sub_render() const; - -private: - AllTransitionsWrapper _outside_attrib; - NodeTransitions _inside_attrib; - - static PT(NodeTransition) _initial; - -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() { - ImmediateTransition::init_type(); - register_type(_type_handle, "DrawBoundsTransition", - ImmediateTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "drawBoundsTransition.I" - -#endif - - diff --git a/panda/src/sgattrib/fog.I b/panda/src/sgattrib/fog.I deleted file mode 100644 index b842c56c8c..0000000000 --- a/panda/src/sgattrib/fog.I +++ /dev/null @@ -1,283 +0,0 @@ -// Filename: fog.I -// Created by: krisg (05Feb01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: Fog::get_mode -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE Fog::Mode Fog:: -get_mode() const { - return _mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::set_mode -// Access: Published -// Description: Specifies the computation that is used to determine -// the fog effect. If this is M_linear, then the fog -// will range from linearly from the onset point to the -// opaque point (or for the distances specified in -// set_linear_range), and the fog object should be -// parented into the scene graph, or to the camera. -// -// If this is anything else, the onset point and opaque -// point are not used, and the fog effect is based on -// the value specified to set_exp_density(), and it -// doesn't matter to which node the fog object is -// parented, or if it is parented anywhere at all. -//////////////////////////////////////////////////////////////////// -INLINE void Fog:: -set_mode(Mode mode) { - _mode = mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::get_bits_per_color_channel -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int Fog:: -get_bits_per_color_channel() const { - return _bits_per_color_channel; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::set_bits_per_color_channel -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void Fog:: -set_bits_per_color_channel(int bits_per_color_channel) { - _bits_per_color_channel = bits_per_color_channel; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::get_color -// Access: Published -// Description: Returns the color of the fog. -//////////////////////////////////////////////////////////////////// -INLINE const Colorf &Fog:: -get_color() const { - return _color; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::set_color -// Access: Published -// Description: Sets the color of the fog. -//////////////////////////////////////////////////////////////////// -INLINE void Fog:: -set_color(float r, float g, float b) { - _color[0] = r; - _color[1] = g; - _color[2] = b; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::set_color -// Access: Published -// Description: Sets the color of the fog. The alpha component is -// not used. -//////////////////////////////////////////////////////////////////// -INLINE void Fog:: -set_color(const Colorf &color) { - _color = color; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::set_linear_range -// Access: Published -// Description: Specifies the effects of the fog in linear distance -// units. This is only used if the mode is M_linear. -// -// This specifies a fog that begins at distance onset -// units from the origin, and becomes totally opaque at -// distance opaque units from the origin, along the -// forward axis (usually Y). -// -// This function also implicitly sets the mode the -// M_linear, if it is not already set. -//////////////////////////////////////////////////////////////////// -INLINE void Fog:: -set_linear_range(float onset, float opaque, CoordinateSystem cs) { - LVector3f forward = LVector3f::forward(cs); - _linear_onset_point = onset * forward; - _linear_opaque_point = opaque * forward; - _mode = M_linear; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::get_linear_onset_point -// Access: Published -// Description: Returns the point in space at which the fog begins. -// This is only used if the mode is M_linear. -//////////////////////////////////////////////////////////////////// -INLINE const LPoint3f &Fog:: -get_linear_onset_point() const { - return _linear_onset_point; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::set_linear_onset_point -// Access: Published -// Description: Specifies the point in space at which the fog begins. -// This is only used if the mode is M_linear. -//////////////////////////////////////////////////////////////////// -INLINE void Fog:: -set_linear_onset_point(float x, float y, float z) { - _linear_onset_point.set(x, y, z); -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::set_linear_onset_point -// Access: Published -// Description: Specifies the point in space at which the fog begins. -// This is only used if the mode is M_linear. -//////////////////////////////////////////////////////////////////// -INLINE void Fog:: -set_linear_onset_point(const LPoint3f &linear_onset_point) { - _linear_onset_point = linear_onset_point; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::get_linear_opaque_point -// Access: Published -// Description: Returns the point in space at which the fog -// completely obscures geometry. This is only used if -// the mode is M_linear. -//////////////////////////////////////////////////////////////////// -INLINE const LPoint3f &Fog:: -get_linear_opaque_point() const { - return _linear_opaque_point; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::set_linear_opaque_point -// Access: Published -// Description: Specifies the point in space at which the fog -// completely obscures geometry. This is only used if -// the mode is M_linear. -//////////////////////////////////////////////////////////////////// -INLINE void Fog:: -set_linear_opaque_point(float x, float y, float z) { - _linear_opaque_point.set(x, y, z); -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::set_linear_opaque_point -// Access: Published -// Description: Specifies the point in space at which the fog -// completely obscures geometry. This is only used if -// the mode is M_linear. -//////////////////////////////////////////////////////////////////// -INLINE void Fog:: -set_linear_opaque_point(const LPoint3f &linear_opaque_point) { - _linear_opaque_point = linear_opaque_point; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::set_linear_fallback -// Access: Published -// Description: Fog effects are traditionally defined in -// camera-relative space, but the Panda Fog node has a -// special mode in which it can define a linear fog -// effect in an arbitrary coordinate space. -// -// This is done by specifying 3-d onset and opaque -// points, and parenting the Fog object somewhere within -// the scene graph. In this mode, the fog will be -// rendered as if it extended along the vector from the -// onset point to the opaque point, in 3-d space. -// -// However, the underlying fog effect supported by -// hardware is generally only one-dimensional, and must -// be rendered based on linear distance from the camera -// plane. Thus, this in-the-world effect is most -// effective when the fog vector from onset point to -// opaque point is most nearly parallel to the camera's -// eye vector. -// -// As the angle between the fog vector and the eye -// vector increases, the accuracy of the effect -// diminishes, up to a complete breakdown of the effect -// at a 90 degree angle. -// -// This function exists to define the workaround to this -// problem. The linear fallback parameters given here -// specify how the fog should be rendered when the -// parameters are exceeded in this way. -// -// The angle parameter is the minimum angle, in degrees, -// of the fog vector to the eye vector, at which the -// fallback effect should be employed. The onset and -// opaque parameters specify the camera-relative onset -// and opaque distances to pass to the rendering -// hardware when employing the fallback effect. This -// supercedes the 3-d onset point and opaque points. -//////////////////////////////////////////////////////////////////// -INLINE void Fog:: -set_linear_fallback(float angle, float onset, float opaque) { - _linear_fallback_cosa = ccos(deg_2_rad(angle)); - _linear_fallback_onset = onset; - _linear_fallback_opaque = opaque; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::get_exp_density -// Access: Published -// Description: Returns the density of the fog for exponential -// calculations. This is only used if the mode is not -// M_linear. -//////////////////////////////////////////////////////////////////// -INLINE float Fog:: -get_exp_density() const { - return _exp_density; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::set_exp_density -// Access: Published -// Description: Sets the density of the fog for exponential -// calculations. This is only used if the mode is not -// M_linear. -// -// If the mode is currently set to M_linear, this -// function implicitly sets it to M_exponential. -//////////////////////////////////////////////////////////////////// -INLINE void Fog:: -set_exp_density(float exp_density) { - nassertv((exp_density >= 0.0) && (exp_density <= 1.0)); - _exp_density = exp_density; - - if (_mode == M_linear) { - _mode = M_exponential; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::apply -// Access: Public -// Description: Called during rendering to enable fogging with the -// GSG. -//////////////////////////////////////////////////////////////////// -INLINE void Fog:: -apply(GraphicsStateGuardianBase *gsg) { - gsg->apply_fog(this); -} diff --git a/panda/src/sgattrib/fog.cxx b/panda/src/sgattrib/fog.cxx deleted file mode 100644 index b9319787b8..0000000000 --- a/panda/src/sgattrib/fog.cxx +++ /dev/null @@ -1,258 +0,0 @@ -// Filename: fog.cxx -// Created by: mike (09Jan97) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// -#include "pandabase.h" - -#include "fog.h" - -#include "mathNumbers.h" -#include "renderRelation.h" -#include "transformTransition.h" -#include "wrt.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Static variables -//////////////////////////////////////////////////////////////////// -TypeHandle Fog::_type_handle; - -ostream & -operator << (ostream &out, Fog::Mode mode) { - switch (mode) { - case Fog::M_linear: - return out << "linear"; - - case Fog::M_exponential: - return out << "exponential"; - - case Fog::M_exponential_squared: - return out << "exponential-squared"; - } - - return out << "**invalid**(" << (int)mode << ")"; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -Fog:: -Fog(const string &name) : NamedNode(name) { - _mode = M_linear; - _bits_per_color_channel = 8; - _color.set(1.0f, 1.0f, 1.0f, 1.0f); - _linear_onset_point.set(0.0f, 0.0f, 0.0f); - _linear_opaque_point.set(0.0f, 100.0f, 0.0f); - _exp_density = 0.5f; - _linear_fallback_cosa = -1.0f; - _linear_fallback_onset = 0.0f; - _linear_fallback_opaque = 0.0f; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -Fog:: -Fog(const Fog ©) : - NamedNode(copy) -{ - _mode = copy._mode; - _bits_per_color_channel = copy._bits_per_color_channel; - _color = copy._color; - _linear_onset_point = copy._linear_onset_point; - _linear_opaque_point = copy._linear_opaque_point; - _exp_density = copy._exp_density; - _linear_fallback_cosa = copy._linear_fallback_cosa; - _linear_fallback_onset = copy._linear_fallback_onset; - _linear_fallback_opaque = copy._linear_fallback_opaque; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void Fog:: -operator = (const Fog ©) { - NamedNode::operator = (copy); - _mode = copy._mode; - _bits_per_color_channel = copy._bits_per_color_channel; - _color = copy._color; - _linear_onset_point = copy._linear_onset_point; - _linear_opaque_point = copy._linear_opaque_point; - _exp_density = copy._exp_density; - _linear_fallback_cosa = copy._linear_fallback_cosa; - _linear_fallback_onset = copy._linear_fallback_onset; - _linear_fallback_opaque = copy._linear_fallback_opaque; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -Fog:: -~Fog() { -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::make_copy -// Access: Public, Virtual -// Description: Returns a newly-allocated Node that is a shallow copy -// of this one. It will be a different Node pointer, -// but its internal data may or may not be shared with -// that of the original Node. -//////////////////////////////////////////////////////////////////// -Node *Fog:: -make_copy() const { - return new Fog(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::xform -// Access: Public, Virtual -// Description: Transforms the contents of this node by the indicated -// matrix, if it means anything to do so. For most -// kinds of nodes, this does nothing. -//////////////////////////////////////////////////////////////////// -void Fog:: -xform(const LMatrix4f &mat) { - _linear_onset_point = _linear_onset_point * mat; - _linear_opaque_point = _linear_opaque_point * mat; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void Fog:: -output(ostream &out) const { - out << "fog: " << _mode; - switch (_mode) { - case M_linear: - out << "(" << _linear_onset_point << ") -> (" - << _linear_opaque_point << ")"; - break; - - case M_exponential: - case M_exponential_squared: - out << "(" << _bits_per_color_channel << ", " << _exp_density - << ")"; - break; - }; -} - -//////////////////////////////////////////////////////////////////// -// Function: Fog::compute_linear_range -// Access: Public -// Description: This function is intended to be called by GSG's to -// compute the appropriate camera-relative onset and -// opaque distances, based on the fog node's position -// within the scene graph (if linear fog is in effect). -//////////////////////////////////////////////////////////////////// -void Fog:: -compute_linear_range(float &onset, float &opaque, - Node *camera_node, CoordinateSystem cs) { - LVector3f forward = LVector3f::forward(cs); - - LPoint3f onset_point, opaque_point; - if (get_num_parents(RenderRelation::get_class_type()) != 0) { - // Linear fog is relative to the fog's net transform in the scene - // graph. - LMatrix4f mat; - - NodeTransitionWrapper ntw(TransformTransition::get_class_type()); - wrt(this, camera_node, ntw, RenderRelation::get_class_type()); - const TransformTransition *tt; - if (!get_transition_into(tt, ntw)) { - // No relative transform. - mat = LMatrix4f::ident_mat(); - } else { - mat = tt->get_matrix(); - } - - // How far out of whack are we? - LVector3f fog_vector = (_linear_opaque_point - _linear_onset_point) * mat; - fog_vector.normalize(); - float cosa = fog_vector.dot(forward); - if (cabs(cosa) < _linear_fallback_cosa) { - // The fog vector is too far from the eye vector; use the - // fallback mode. - onset = _linear_fallback_onset; - opaque = _linear_fallback_opaque; - //cerr << "fallback! " << cosa << " vs. " << _linear_fallback_cosa << "\n"; - return; - } - - onset_point = _linear_onset_point * mat; - opaque_point = _linear_opaque_point * mat; - - } else { - // If the fog object has no parents, we assume the user meant - // camera-relative fog. - onset_point = _linear_onset_point; - opaque_point = _linear_opaque_point; - } - - onset = onset_point.dot(forward); - opaque = opaque_point.dot(forward); -} - -#if 0 -// this fn tries to 'match' exponential to linear fog by computing an -// exponential density factor such that exponential fog matches linear -// fog at the linear fog's 'fog-end' distance. usefulness of this is -// debatable since the exponential fog that matches will be very very -// close to observer, and it's harder to guess a good end fog distance -// than it is to manipulate the [0.0,1.0f] density range directly, so -// taking this out - -//////////////////////////////////////////////////////////////////// -// Function: Fog::compute_density -// Access: Protected -// Description: -//////////////////////////////////////////////////////////////////// -void Fog::compute_density(void) { - _density = 1.0f; - float opaque_multiplier; - switch (_mode) { - - case M_linear: - break; - - case M_exponential: - // Multiplier = ln(2^bits) - // attempt to compute density based on full - opaque_multiplier = MathNumbers::ln2 * _bits_per_color_channel; - _density = opaque_multiplier / _opaque_distance; - break; - - case M_exponential_squared: - // Multiplier = ln(sqrt(2^bits)) - opaque_multiplier = 0.5f * MathNumbers::ln2 * _bits_per_color_channel; - opaque_multiplier *= opaque_multiplier; - _density = opaque_multiplier / _opaque_distance; - break; - } -} - -#endif diff --git a/panda/src/sgattrib/fog.h b/panda/src/sgattrib/fog.h deleted file mode 100644 index 32afb4f65f..0000000000 --- a/panda/src/sgattrib/fog.h +++ /dev/null @@ -1,144 +0,0 @@ -// Filename: fog.h -// Created by: mike (09Jan97) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// -#ifndef FOG_H -#define FOG_H - -#include "pandabase.h" - -#include "graphicsStateGuardianBase.h" -#include "luse.h" -#include "pointerToArray.h" -#include "namedNode.h" -#include "cmath.h" -#include "deg_2_rad.h" - -class ArcChain; - -//////////////////////////////////////////////////////////////////// -// Class : Fog -// Description : Specifies how atmospheric fog effects are applied to -// geometry. The Fog object is now a Node, which means -// it can be used similar to a Light to define effects -// relative to a particular coordinate system within the -// scene graph. -// -// In exponential mode, the fog effects are always -// camera-relative, and it does not matter where the Fog -// node is parented. However, in linear mode, the onset -// and opaque distances are defined as offsets along the -// local forward axis (e.g. the Y axis). This allows -// the fog effect to be localized to a particular region -// in space, rather than always camera-relative. If the -// fog object is not parented to any node, it is treated -// as if it were parented to the camera. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA Fog : public NamedNode { -PUBLISHED: - Fog(const string &name = ""); - -public: - Fog(const Fog ©); - void operator = (const Fog ©); - virtual ~Fog(); - - virtual Node *make_copy() const; - virtual void xform(const LMatrix4f &mat); - -PUBLISHED: - enum Mode { - M_linear, // f = (end - z) / (end - start) - M_exponential, // f = e^(-density * z) - M_exponential_squared // f = e^((-density * z)^2) - }; - - INLINE Mode get_mode() const; - INLINE void set_mode(Mode mode); - - INLINE int get_bits_per_color_channel() const; - INLINE void set_bits_per_color_channel(int bits_per_color_channel); - - INLINE const Colorf &get_color() const; - INLINE void set_color(float r, float g, float b); - INLINE void set_color(const Colorf &color); - - INLINE void set_linear_range(float onset, float opaque, - CoordinateSystem cs = CS_default); - - INLINE const LPoint3f &get_linear_onset_point() const; - INLINE void set_linear_onset_point(float x, float y, float z); - INLINE void set_linear_onset_point(const LPoint3f &linear_onset_point); - - INLINE const LPoint3f &get_linear_opaque_point() const; - INLINE void set_linear_opaque_point(const LPoint3f &linear_opaque_point); - INLINE void set_linear_opaque_point(float x, float y, float z); - - INLINE void set_linear_fallback(float angle, float onset, float opaque); - - INLINE float get_exp_density() const; - INLINE void set_exp_density(float exp_density); - - void output(ostream &out) const; - -public: - INLINE void apply(GraphicsStateGuardianBase *gsg); - - void compute_linear_range(float &onset, float &opaque, - Node *camera_node, CoordinateSystem cs); - -protected: - void compute_density(); - -protected: - Mode _mode; - int _bits_per_color_channel; - Colorf _color; - LPoint3f _linear_onset_point; - LPoint3f _linear_opaque_point; - float _exp_density; - - float _linear_fallback_cosa; - float _linear_fallback_onset, _linear_fallback_opaque; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - TypedReferenceCount::init_type(); - register_type(_type_handle, "Fog", - TypedReferenceCount::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -ostream &operator << (ostream &out, Fog::Mode mode); - -INLINE ostream &operator << (ostream &out, const Fog &fog) { - fog.output(out); - return out; -} - -#include "fog.I" - -#endif diff --git a/panda/src/sgattrib/fogTransition.I b/panda/src/sgattrib/fogTransition.I deleted file mode 100644 index 25361c10a8..0000000000 --- a/panda/src/sgattrib/fogTransition.I +++ /dev/null @@ -1,77 +0,0 @@ -// Filename: fogTransition.I -// Created by: drose (24Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: FogTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE FogTransition:: -FogTransition() { -} - -//////////////////////////////////////////////////////////////////// -// Function: FogTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE FogTransition:: -FogTransition(Fog *fog) : - OnOffTransition(TD_on), - _value(fog) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: FogTransition::off -// Access: Public -// Description: This named constructor returns a FogTransition that -// turns off fog. -//////////////////////////////////////////////////////////////////// -INLINE FogTransition FogTransition:: -off() { - FogTransition result; - result.set_off(); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: FogTransition::set_on -// Access: Public -// Description: Changes the FogTransition to render the particular -// fog. -//////////////////////////////////////////////////////////////////// -INLINE void FogTransition:: -set_on(Fog *fog) { - nassertv(fog != (Fog *)NULL); - _value = fog; - OnOffTransition::set_on(); -} - -//////////////////////////////////////////////////////////////////// -// Function: FogTransition::get_fog -// Access: Public -// Description: Returns the fog that the FogTransition represents. -// It is only valid to call this if is_on() has returned -// true. -//////////////////////////////////////////////////////////////////// -INLINE Fog *FogTransition:: -get_fog() const { - nassertr(is_on(), NULL); - return _value; -} diff --git a/panda/src/sgattrib/fogTransition.cxx b/panda/src/sgattrib/fogTransition.cxx deleted file mode 100644 index e1ada03ee2..0000000000 --- a/panda/src/sgattrib/fogTransition.cxx +++ /dev/null @@ -1,112 +0,0 @@ -// Filename: fogTransition.cxx -// Created by: mike (06Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "fogTransition.h" - -#include "dcast.h" -#include "indent.h" - -PT(NodeTransition) FogTransition::_initial; -TypeHandle FogTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: FogTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated FogTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *FogTransition:: -make_copy() const { - return new FogTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: FogTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated FogTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *FogTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new FogTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: FogTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void FogTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_fog(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: FogTransition::set_value_from -// Access: Protected, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another FogTransition. -//////////////////////////////////////////////////////////////////// -void FogTransition:: -set_value_from(const OnOffTransition *other) { - const FogTransition *ot; - DCAST_INTO_V(ot, other); - _value = ot->_value; - nassertv(_value != (Fog *)NULL); -} - -//////////////////////////////////////////////////////////////////// -// Function: FogTransition::compare_values -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int FogTransition:: -compare_values(const OnOffTransition *other) const { - const FogTransition *ot; - DCAST_INTO_R(ot, other, false); - return (int)(_value.p() - ot->_value.p()); -} - -//////////////////////////////////////////////////////////////////// -// Function: FogTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -void FogTransition:: -output_value(ostream &out) const { - nassertv(_value != (Fog *)NULL); - out << *_value; -} - -//////////////////////////////////////////////////////////////////// -// Function: FogTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -void FogTransition:: -write_value(ostream &out, int indent_level) const { - nassertv(_value != (Fog *)NULL); - indent(out, indent_level) << *_value << "\n"; -} diff --git a/panda/src/sgattrib/fogTransition.h b/panda/src/sgattrib/fogTransition.h deleted file mode 100644 index 6019408710..0000000000 --- a/panda/src/sgattrib/fogTransition.h +++ /dev/null @@ -1,78 +0,0 @@ -// Filename: fogTransition.h -// Created by: mike (19Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef FOGTRANSITION_H -#define FOGTRANSITION_H - -#include "pandabase.h" - -#include "onOffTransition.h" -#include "fog.h" - -//////////////////////////////////////////////////////////////////// -// Class : FogTransition -// Description : This controls the enabling of fog. This typically -// attenuates the colors based on the distance from the -// observer (e.g. the z depth). -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA FogTransition : public OnOffTransition { -public: - INLINE FogTransition(); - INLINE FogTransition(Fog *fog); - INLINE static FogTransition off(); - - INLINE void set_on(Fog *fog); - INLINE Fog *get_fog() const; - -public: - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual void set_value_from(const OnOffTransition *other); - virtual int compare_values(const OnOffTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - PT(Fog) _value; - static PT(NodeTransition) _initial; - -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() { - OnOffTransition::init_type(); - register_type(_type_handle, "FogTransition", - OnOffTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "fogTransition.I" - -#endif diff --git a/panda/src/sgattrib/linesmoothTransition.I b/panda/src/sgattrib/linesmoothTransition.I deleted file mode 100644 index def7014f82..0000000000 --- a/panda/src/sgattrib/linesmoothTransition.I +++ /dev/null @@ -1,39 +0,0 @@ -// Filename: linesmoothTransition.I -// Created by: drose (24Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: LinesmoothTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE LinesmoothTransition:: -LinesmoothTransition() { - set_on(); -} - -//////////////////////////////////////////////////////////////////// -// Function: LinesmoothTransition::off -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE LinesmoothTransition LinesmoothTransition:: -off() { - LinesmoothTransition result; - result.set_off(); - return result; -} diff --git a/panda/src/sgattrib/linesmoothTransition.cxx b/panda/src/sgattrib/linesmoothTransition.cxx deleted file mode 100644 index 6170decfd8..0000000000 --- a/panda/src/sgattrib/linesmoothTransition.cxx +++ /dev/null @@ -1,60 +0,0 @@ -// Filename: linesmoothTransition.cxx -// Created by: mike (08Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "linesmoothTransition.h" - -PT(NodeTransition) LinesmoothTransition::_initial; -TypeHandle LinesmoothTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: LinesmoothTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated LinesmoothTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *LinesmoothTransition:: -make_copy() const { - return new LinesmoothTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: LinesmoothTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated LinesmoothTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *LinesmoothTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new LinesmoothTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: LinesmoothTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void LinesmoothTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_linesmooth(this); -} diff --git a/panda/src/sgattrib/linesmoothTransition.h b/panda/src/sgattrib/linesmoothTransition.h deleted file mode 100644 index 88fda1ffb8..0000000000 --- a/panda/src/sgattrib/linesmoothTransition.h +++ /dev/null @@ -1,65 +0,0 @@ -// Filename: linesmoothTransition.h -// Created by: mike (08Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef LINESMOOTHTRANSITION_H -#define LINESMOOTHTRANSITION_H - -#include - -#include - -//////////////////////////////////////////////////////////////////// -// Class : LinesmoothTransition -// Description : This enables or disables the antialiasing of lines. -// It has no additional properties; it's simply an -// on-or-off thing. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA LinesmoothTransition : public OnOffTransition { -public: - INLINE LinesmoothTransition(); - INLINE static LinesmoothTransition off(); - - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -private: - static PT(NodeTransition) _initial; - -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() { - OnOffTransition::init_type(); - register_type(_type_handle, "LinesmoothTransition", - OnOffTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "linesmoothTransition.I" - -#endif diff --git a/panda/src/sgattrib/materialTransition.I b/panda/src/sgattrib/materialTransition.I deleted file mode 100644 index 7fcaa29f32..0000000000 --- a/panda/src/sgattrib/materialTransition.I +++ /dev/null @@ -1,76 +0,0 @@ -// Filename: materialTransition.I -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: MaterialTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE MaterialTransition:: -MaterialTransition() { -} - -//////////////////////////////////////////////////////////////////// -// Function: MaterialTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE MaterialTransition:: -MaterialTransition(const Material *material) : - OnOffTransition(TD_on), - _value(material) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: MaterialTransition::off -// Access: Public -// Description: This named constructor returns a MaterialTransition -// that disables materials. -//////////////////////////////////////////////////////////////////// -INLINE MaterialTransition MaterialTransition:: -off() { - MaterialTransition result; - result.set_off(); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: MaterialTransition::set_on -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void MaterialTransition:: -set_on(const Material *material) { - nassertv(material != (const Material *)NULL); - _value = material; - OnOffTransition::set_on(); -} - -//////////////////////////////////////////////////////////////////// -// Function: MaterialTransition::get_material -// Access: Public -// Description: Returns the material that the MaterialTransition -// represents. It is only valid to call this if is_on() -// has returned true. -//////////////////////////////////////////////////////////////////// -INLINE const Material *MaterialTransition:: -get_material() const { - nassertr(is_on(), NULL); - return _value; -} diff --git a/panda/src/sgattrib/materialTransition.cxx b/panda/src/sgattrib/materialTransition.cxx deleted file mode 100644 index 36ed539617..0000000000 --- a/panda/src/sgattrib/materialTransition.cxx +++ /dev/null @@ -1,193 +0,0 @@ -// Filename: materialTransition.cxx -// Created by: mike (06Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "materialTransition.h" -#include "config_sgattrib.h" - -#include -#include -#include -#include -#include - -PT(NodeTransition) MaterialTransition::_initial; -TypeHandle MaterialTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: MaterialTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated MaterialTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *MaterialTransition:: -make_copy() const { - return new MaterialTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: MaterialTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated MaterialTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *MaterialTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new MaterialTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: MaterialTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void MaterialTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_material(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: MaterialTransition::set_value_from -// Access: Protected, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another MaterialTransition. -//////////////////////////////////////////////////////////////////// -void MaterialTransition:: -set_value_from(const OnOffTransition *other) { - const MaterialTransition *ot; - DCAST_INTO_V(ot, other); - _value = ot->_value; - nassertv(_value != (const Material *)NULL); -} - -//////////////////////////////////////////////////////////////////// -// Function: MaterialTransition::compare_values -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int MaterialTransition:: -compare_values(const OnOffTransition *other) const { - const MaterialTransition *ot; - DCAST_INTO_R(ot, other, false); - return (int)(_value.p() - ot->_value.p()); -} - -//////////////////////////////////////////////////////////////////// -// Function: MaterialTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -void MaterialTransition:: -output_value(ostream &out) const { - nassertv(_value != (const Material *)NULL); - out << *_value; -} - -//////////////////////////////////////////////////////////////////// -// Function: MaterialTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -void MaterialTransition:: -write_value(ostream &out, int indent_level) const { - nassertv(_value != (const Material *)NULL); - indent(out, indent_level) << *_value << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: MaterialTransition::register_with_read_factory -// Access: Public, Static -// Description: Factory method to generate a MaterialTransition object -//////////////////////////////////////////////////////////////////// -void MaterialTransition:: -register_with_read_factory() { - BamReader::get_factory()->register_factory(get_class_type(), make_MaterialTransition); -} - -//////////////////////////////////////////////////////////////////// -// Function: MaterialTransition::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void MaterialTransition:: -write_datagram(BamWriter *manager, Datagram &me) { - OnOffTransition::write_datagram(manager, me); - manager->write_pointer(me, (Material *)_value.p()); -} - -//////////////////////////////////////////////////////////////////// -// Function: MaterialTransition::complete_pointers -// Access: Public -// Description: Takes in a vector of pointes to TypedWritable -// objects that correspond to all the requests for -// pointers that this object made to BamReader. -//////////////////////////////////////////////////////////////////// -int MaterialTransition:: -complete_pointers(TypedWritable **p_list, BamReader *) { - if (p_list[0] == TypedWritable::Null) { - if (sgattrib_cat.is_debug()) { - sgattrib_cat->debug() - << get_type().get_name() << " received null Material," - << " turning off" << endl; - } - _value = (const Material *)NULL; - set_off(); - - } else { - _value = DCAST(Material, p_list[0]); - } - - return 1; -} - -//////////////////////////////////////////////////////////////////// -// Function: MaterialTransition::make_MaterialTransition -// Access: Protected -// Description: Factory method to generate a MaterialTransition object -//////////////////////////////////////////////////////////////////// -TypedWritable* MaterialTransition:: -make_MaterialTransition(const FactoryParams ¶ms) { - MaterialTransition *me = new MaterialTransition; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: MaterialTransition::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void MaterialTransition:: -fillin(DatagramIterator& scan, BamReader* manager) { - OnOffTransition::fillin(scan, manager); - manager->read_pointer(scan); -} diff --git a/panda/src/sgattrib/materialTransition.h b/panda/src/sgattrib/materialTransition.h deleted file mode 100644 index cc74e8f82a..0000000000 --- a/panda/src/sgattrib/materialTransition.h +++ /dev/null @@ -1,88 +0,0 @@ -// Filename: materialTransition.h -// Created by: mike (19Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef MATERIALTRANSITION_H -#define MATERIALTRANSITION_H - -#include - -#include -#include -#include - -//////////////////////////////////////////////////////////////////// -// Class : MaterialTransition -// Description : Applies a material, controlling subtle lighting -// parameters, to geometry. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA MaterialTransition : public OnOffTransition { -public: - INLINE MaterialTransition(); - INLINE MaterialTransition(const Material *material); - INLINE static MaterialTransition off(); - - INLINE void set_on(const Material *material); - INLINE const Material *get_material() const; - -public: - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual void set_value_from(const OnOffTransition *other); - virtual int compare_values(const OnOffTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - CPT(Material) _value; - static PT(NodeTransition) _initial; - -public: - static void register_with_read_factory(); - virtual void write_datagram(BamWriter *manager, Datagram &me); - virtual int complete_pointers(TypedWritable **plist, - BamReader *manager); - -protected: - static TypedWritable *make_MaterialTransition(const FactoryParams ¶ms); - 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() { - OnOffTransition::init_type(); - register_type(_type_handle, "MaterialTransition", - OnOffTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "materialTransition.I" - -#endif diff --git a/panda/src/sgattrib/pointShapeProperty.I b/panda/src/sgattrib/pointShapeProperty.I deleted file mode 100644 index 09c8301465..0000000000 --- a/panda/src/sgattrib/pointShapeProperty.I +++ /dev/null @@ -1,58 +0,0 @@ -// Filename: pointShapeProperty.I -// Created by: charles (10Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function : PointShapeProperty -// Access : public -//////////////////////////////////////////////////////////////////// - -INLINE PointShapeProperty:: -PointShapeProperty(PointShapeProperty::Mode mode) : - _mode(mode) { -} - -//////////////////////////////////////////////////////////////////// -// Function : set_mode -// Access : public -//////////////////////////////////////////////////////////////////// -INLINE void PointShapeProperty:: -set_mode(PointShapeProperty::Mode mode) { - _mode = mode; -} - -//////////////////////////////////////////////////////////////////// -// Function : get_mode -// Access : public -//////////////////////////////////////////////////////////////////// -INLINE PointShapeProperty::Mode PointShapeProperty:: -get_mode(void) const { - return _mode; -} - -//////////////////////////////////////////////////////////////////// -// Function : compare_to -// Access : public -//////////////////////////////////////////////////////////////////// -INLINE int PointShapeProperty:: -compare_to(const PointShapeProperty& other) const { - if (_mode != other._mode) { - return (int) _mode - (int) other._mode; - } - - return 0; -} diff --git a/panda/src/sgattrib/pointShapeProperty.cxx b/panda/src/sgattrib/pointShapeProperty.cxx deleted file mode 100644 index 4010ff9f57..0000000000 --- a/panda/src/sgattrib/pointShapeProperty.cxx +++ /dev/null @@ -1,41 +0,0 @@ -// Filename: pointShapeProperty.cxx -// Created by: charles (10Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "pointShapeProperty.h" - -ostream & -operator << (ostream &out, PointShapeProperty::Mode mode) { - switch (mode) { - case PointShapeProperty::M_square: - return out << "square"; - - case PointShapeProperty::M_circle: - return out << "circle"; - } - - return out << "**invalid**(" << (int)mode << ")"; -} - -//////////////////////////////////////////////////////////////////// -// Function : output -// Access : public -//////////////////////////////////////////////////////////////////// -void PointShapeProperty:: -output(ostream &out) const { - out << _mode; -} diff --git a/panda/src/sgattrib/pointShapeProperty.h b/panda/src/sgattrib/pointShapeProperty.h deleted file mode 100644 index 85a8baeed5..0000000000 --- a/panda/src/sgattrib/pointShapeProperty.h +++ /dev/null @@ -1,60 +0,0 @@ -// Filename: pointShapeProperty.h -// Created by: charles (10Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef POINTSHAPEPROPERTY_H -#define POINTSHAPEPROPERTY_H - -#include - -//////////////////////////////////////////////////////////////////// -// Class : PointShapeProperty -// Description : Affects the shapes of point primitives -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA PointShapeProperty { -public: - - enum Mode { - M_square, - M_circle - }; - -public: - - INLINE PointShapeProperty(Mode mode); - - INLINE void set_mode(Mode mode); - INLINE Mode get_mode(void) const; - - INLINE int compare_to(const PointShapeProperty& other) const; - void output(ostream &out) const; - -private: - - Mode _mode; -}; - -ostream &operator << (ostream &out, PointShapeProperty::Mode mode); - -INLINE ostream &operator << (ostream &out, const PointShapeProperty &prop) { - prop.output(out); - return out; -} - -#include "pointShapeProperty.I" - -#endif // POINTSHAPEPROPERTY_H diff --git a/panda/src/sgattrib/pointShapeTransition.I b/panda/src/sgattrib/pointShapeTransition.I deleted file mode 100644 index 785598a6c5..0000000000 --- a/panda/src/sgattrib/pointShapeTransition.I +++ /dev/null @@ -1,48 +0,0 @@ -// Filename: pointShapeTransition.I -// Created by: charles (11Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: PointShapeTransition -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE PointShapeTransition:: -PointShapeTransition(PointShapeProperty::Mode mode) : - _value(mode) { -} - -//////////////////////////////////////////////////////////////////// -// Function: set_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void PointShapeTransition:: -set_mode(PointShapeProperty::Mode mode) { - _value.set_mode(mode); - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: get_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE PointShapeProperty::Mode PointShapeTransition:: -get_mode(void) const { - return _value.get_mode(); -} diff --git a/panda/src/sgattrib/pointShapeTransition.cxx b/panda/src/sgattrib/pointShapeTransition.cxx deleted file mode 100644 index b213350d14..0000000000 --- a/panda/src/sgattrib/pointShapeTransition.cxx +++ /dev/null @@ -1,108 +0,0 @@ -// Filename: pointShapeTransition.cxx -// Created by: charles (11Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "pointShapeTransition.h" - -#include - -PT(NodeTransition) PointShapeTransition::_initial; -TypeHandle PointShapeTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: Pointshapetransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated Pointshapetransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *PointShapeTransition:: -make_copy() const { - return new PointShapeTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: PointShapeTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated PointShapeTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *PointShapeTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new PointShapeTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: PointShapeTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void PointShapeTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_point_shape(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: PointShapeTransition -// Access: Protected, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another PointShapeTransition. -//////////////////////////////////////////////////////////////////// -void PointShapeTransition:: -set_value_from(const OnTransition *other) { - const PointShapeTransition *ot; - DCAST_INTO_V(ot, other); - _value = ot->_value; -} - -//////////////////////////////////////////////////////////////////// -// Function: PointShapeTransition::compare_values -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int PointShapeTransition:: -compare_values(const OnTransition *other) const { - const PointShapeTransition *ot; - DCAST_INTO_R(ot, other, false); - return _value.compare_to(ot->_value); -} - -//////////////////////////////////////////////////////////////////// -// Function: PointShapeTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -void PointShapeTransition:: -output_value(ostream &out) const { - out << _value; -} - -//////////////////////////////////////////////////////////////////// -// Function: PointShapeTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -void PointShapeTransition:: -write_value(ostream &out, int indent_level) const { - indent(out, indent_level) << _value << "\n"; -} diff --git a/panda/src/sgattrib/pointShapeTransition.h b/panda/src/sgattrib/pointShapeTransition.h deleted file mode 100644 index c924938f7e..0000000000 --- a/panda/src/sgattrib/pointShapeTransition.h +++ /dev/null @@ -1,75 +0,0 @@ -// Filename: pointShapeTransition.h -// Created by: charles (10Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef POINTSHAPETRANSITION_H -#define POINTSHAPETRANSITION_H - -#include - -#include "pointShapeProperty.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : PointShapeTransition -// Description : An arc that determines the shape of point primitives -// drawn beneath. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA PointShapeTransition : public OnTransition { -public: - INLINE PointShapeTransition(PointShapeProperty::Mode mode = PointShapeProperty::M_square); - - INLINE void set_mode(PointShapeProperty::Mode mode); - INLINE PointShapeProperty::Mode get_mode() const; - - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual void set_value_from(const OnTransition *other); - virtual int compare_values(const OnTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - PointShapeProperty _value; - static PT(NodeTransition) _initial; - -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() { - OnTransition::init_type(); - register_type(_type_handle, "PointShapeTransition", - OnTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "pointShapeTransition.I" - -#endif // POINTSHAPETRANSITION_H diff --git a/panda/src/sgattrib/polygonOffsetProperty.I b/panda/src/sgattrib/polygonOffsetProperty.I deleted file mode 100644 index b0ce2763cf..0000000000 --- a/panda/src/sgattrib/polygonOffsetProperty.I +++ /dev/null @@ -1,94 +0,0 @@ -// Filename: polygonOffsetProperty.I -// Created by: jason (12Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetProperty::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE PolygonOffsetProperty:: -PolygonOffsetProperty() : - _units(0), _factor(0) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetProperty::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE PolygonOffsetProperty:: -PolygonOffsetProperty(int units, int factor) : - _units(units), _factor(factor) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetProperty::set_units -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void PolygonOffsetProperty:: -set_units(int units) { - _units = units; -} - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetProperty::get_units -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int PolygonOffsetProperty:: -get_units() const { - return _units; -} - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetProperty::set_factor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void PolygonOffsetProperty:: -set_factor(int factor) { - _factor = factor; -} - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetProperty::get_factor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int PolygonOffsetProperty:: -get_factor() const { - return _factor; -} - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetProperty::compare_to -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int PolygonOffsetProperty:: -compare_to(const PolygonOffsetProperty &other) const { - if (_units != other._units) - { - return (other._units - _units); - } - - return (other._factor - _factor); -} diff --git a/panda/src/sgattrib/polygonOffsetProperty.cxx b/panda/src/sgattrib/polygonOffsetProperty.cxx deleted file mode 100644 index 20d70d0e2d..0000000000 --- a/panda/src/sgattrib/polygonOffsetProperty.cxx +++ /dev/null @@ -1,29 +0,0 @@ -// Filename: polygonOffsetProperty.cxx -// Created by: jason (12Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "polygonOffsetProperty.h" - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetProperty::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void PolygonOffsetProperty:: -output(ostream &out) const { - out << "Units " << _units << " Factor " << _factor << endl; -} diff --git a/panda/src/sgattrib/polygonOffsetProperty.h b/panda/src/sgattrib/polygonOffsetProperty.h deleted file mode 100644 index b24d25d440..0000000000 --- a/panda/src/sgattrib/polygonOffsetProperty.h +++ /dev/null @@ -1,55 +0,0 @@ -// Filename: polygonOffsetProperty.h -// Created by: jason (12Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef POLYGONOFFSETPROPERTY_H -#define POLYGONOFFSETPROPERTY_H - -#include - -#include - -//////////////////////////////////////////////////////////////////// -// Class : PolygonOffsetProperty -// Description : This class defines the set state for polygon offseting -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA PolygonOffsetProperty { -public: - INLINE PolygonOffsetProperty(); - INLINE PolygonOffsetProperty(int units, int factor); - - INLINE void set_units(int units); - INLINE int get_units() const; - INLINE void set_factor(int factor); - INLINE int get_factor() const; - - INLINE int compare_to(const PolygonOffsetProperty &other) const; - void output(ostream &out) const; - -private: - int _units; - int _factor; -}; - -INLINE ostream &operator << (ostream &out, const PolygonOffsetProperty &prop) { - prop.output(out); - return out; -} - -#include "polygonOffsetProperty.I" - -#endif diff --git a/panda/src/sgattrib/polygonOffsetTransition.I b/panda/src/sgattrib/polygonOffsetTransition.I deleted file mode 100644 index 9a7d044acc..0000000000 --- a/panda/src/sgattrib/polygonOffsetTransition.I +++ /dev/null @@ -1,68 +0,0 @@ -// Filename: polygonOffsetTransition.I -// Created by: jason (12Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE PolygonOffsetTransition:: -PolygonOffsetTransition(int units, int factor) : - _state(units, factor) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetTransition::set_units -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void PolygonOffsetTransition:: -set_units(int units) { - _state.set_units(units); -} - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetTransition::get_units -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int PolygonOffsetTransition:: -get_units() const { - return _state.get_units(); -} - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetTransition::set_factor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void PolygonOffsetTransition:: -set_factor(int factor) { - _state.set_factor(factor); -} - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetTransition::get_factor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int PolygonOffsetTransition:: -get_factor() const { - return _state.get_factor(); -} diff --git a/panda/src/sgattrib/polygonOffsetTransition.cxx b/panda/src/sgattrib/polygonOffsetTransition.cxx deleted file mode 100644 index 3e8a0848f2..0000000000 --- a/panda/src/sgattrib/polygonOffsetTransition.cxx +++ /dev/null @@ -1,115 +0,0 @@ -// Filename: polygonOffsetTransition.cxx -// Created by: jason (12Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "polygonOffsetTransition.h" - -#include - -PT(NodeTransition) PolygonOffsetTransition::_initial; -TypeHandle PolygonOffsetTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated PolygonOffsetTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *PolygonOffsetTransition:: -make_copy() const { - return new PolygonOffsetTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated PolygonOffsetTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *PolygonOffsetTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new PolygonOffsetTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void PolygonOffsetTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_polygon_offset(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetTransition::set_value_from -// Access: Protected, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another PolygonOffsetTransition. -//////////////////////////////////////////////////////////////////// -void PolygonOffsetTransition:: -set_value_from(const OnTransition *other) { - const PolygonOffsetTransition *ot; - DCAST_INTO_V(ot, other); - _state = ot->_state; -} - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetTransition::compare_values -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int PolygonOffsetTransition:: -compare_values(const OnTransition *other) const { - const PolygonOffsetTransition *ot; - DCAST_INTO_R(ot, other, false); - return _state.compare_to(ot->_state); -} - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -void PolygonOffsetTransition:: -output_value(ostream &out) const { - out << _state; -} - -//////////////////////////////////////////////////////////////////// -// Function: PolygonOffsetTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -void PolygonOffsetTransition:: -write_value(ostream &out, int indent_level) const { - indent(out, indent_level) << _state << "\n"; -} - - - - - - - diff --git a/panda/src/sgattrib/polygonOffsetTransition.h b/panda/src/sgattrib/polygonOffsetTransition.h deleted file mode 100644 index 11bb6e2edf..0000000000 --- a/panda/src/sgattrib/polygonOffsetTransition.h +++ /dev/null @@ -1,81 +0,0 @@ -// Filename: polygonOffsetTransition.h -// Created by: jason (12Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef POLYGONOFFSETTRANSITION_H -#define POLYGONOFFSETTRANSITION_H - -#include - -#include "polygonOffsetProperty.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : PolygonOffsetTransition -// Description : This controls the amount of offseting done for depth -// tests. The first value is the units, this is the -// fixed offseting to be used, and the second value -// allows for variable offsetting per polygon based on -// the ratio of depth relative to screen area of the polygon -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA PolygonOffsetTransition : public OnTransition { -public: - INLINE PolygonOffsetTransition(int amount = 0, int factor = 0); - - INLINE void set_units(int units); - INLINE int get_units() const; - INLINE void set_factor(int factor); - INLINE int get_factor() const; - - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual void set_value_from(const OnTransition *other); - virtual int compare_values(const OnTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - PolygonOffsetProperty _state; - static PT(NodeTransition) _initial; - -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() { - OnTransition::init_type(); - register_type(_type_handle, "PolygonOffsetTransition", - OnTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - - -#include "polygonOffsetTransition.I" - -#endif diff --git a/panda/src/sgattrib/pruneTransition.I b/panda/src/sgattrib/pruneTransition.I deleted file mode 100644 index cd61cd7572..0000000000 --- a/panda/src/sgattrib/pruneTransition.I +++ /dev/null @@ -1,26 +0,0 @@ -// Filename: pruneTransition.I -// Created by: drose (26Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: PruneTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE PruneTransition:: -PruneTransition() { -} diff --git a/panda/src/sgattrib/pruneTransition.cxx b/panda/src/sgattrib/pruneTransition.cxx deleted file mode 100644 index 6541c32fe3..0000000000 --- a/panda/src/sgattrib/pruneTransition.cxx +++ /dev/null @@ -1,87 +0,0 @@ -// Filename: pruneTransition.cxx -// Created by: drose (26Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "pruneTransition.h" -#include -#include -#include -#include - -TypeHandle PruneTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: PruneTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated PruneTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *PruneTransition:: -make_copy() const { - return new PruneTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: PruneTransition::sub_render -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -bool PruneTransition:: -sub_render(NodeRelation *, const AllTransitionsWrapper &, - AllTransitionsWrapper &, RenderTraverser *) { - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: PruneTransition::has_sub_render -// Access: Public, Virtual -// Description: Should be redefined to return true if the function -// sub_render(), above, expects to be called during -// traversal. -//////////////////////////////////////////////////////////////////// -bool PruneTransition:: -has_sub_render() const { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: PruneTransition::make_PruneTransition -// Access: Protected -// Description: Factory method to generate a PruneTransition object -//////////////////////////////////////////////////////////////////// -TypedWritable* PruneTransition:: -make_PruneTransition(const FactoryParams ¶ms) -{ - PruneTransition *me = new PruneTransition; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: PruneTransition::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a PruneTransition object -//////////////////////////////////////////////////////////////////// -void PruneTransition:: -register_with_read_factory(void) -{ - BamReader::get_factory()->register_factory(get_class_type(), make_PruneTransition); -} diff --git a/panda/src/sgattrib/pruneTransition.h b/panda/src/sgattrib/pruneTransition.h deleted file mode 100644 index c8570e81db..0000000000 --- a/panda/src/sgattrib/pruneTransition.h +++ /dev/null @@ -1,72 +0,0 @@ -// Filename: pruneTransition.h -// Created by: drose (26Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef PRUNETRANSITION_H -#define PRUNETRANSITION_H - -#include - -#include -#include - -//////////////////////////////////////////////////////////////////// -// Class : PruneTransition -// Description : This transition, when encountered in the scene graph, -// causes rendering to stop at this point and not -// traverse anything below. In effect, it causes all -// the geometry at this level and below to become -// invisible. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA PruneTransition : public ImmediateTransition { -PUBLISHED: - INLINE PruneTransition(); - -public: - virtual NodeTransition *make_copy() const; - - virtual bool sub_render(NodeRelation *arc, - const AllTransitionsWrapper &input_trans, - AllTransitionsWrapper &modify_trans, - RenderTraverser *trav); - virtual bool has_sub_render() const; - -public: - static void register_with_read_factory(void); - static TypedWritable *make_PruneTransition(const FactoryParams ¶ms); - -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() { - ImmediateTransition::init_type(); - register_type(_type_handle, "PruneTransition", - ImmediateTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "pruneTransition.I" - -#endif diff --git a/panda/src/sgattrib/renderModeProperty.I b/panda/src/sgattrib/renderModeProperty.I deleted file mode 100644 index 0dfef38e1c..0000000000 --- a/panda/src/sgattrib/renderModeProperty.I +++ /dev/null @@ -1,86 +0,0 @@ -// Filename: renderModeProperty.I -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeProperty::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE RenderModeProperty:: -RenderModeProperty(Mode mode, double line_width) : - _mode(mode), - _line_width(line_width) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeProperty::set_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void RenderModeProperty:: -set_mode(RenderModeProperty::Mode mode) { - _mode = mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeProperty::get_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE RenderModeProperty::Mode RenderModeProperty:: -get_mode() const { - return _mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeProperty::set_line_width -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void RenderModeProperty:: -set_line_width(double line_width) { - _line_width = line_width; -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeProperty::get_line_width -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE double RenderModeProperty:: -get_line_width() const { - return _line_width; -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeProperty::compare_to -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int RenderModeProperty:: -compare_to(const RenderModeProperty &other) const { - if (_mode != other._mode) { - return (int)_mode - (int)other._mode; - } - if (_line_width != other._line_width) { - return _line_width < other._line_width ? -1 : 1; - } - return 0; -} - diff --git a/panda/src/sgattrib/renderModeProperty.cxx b/panda/src/sgattrib/renderModeProperty.cxx deleted file mode 100644 index e1eaa80194..0000000000 --- a/panda/src/sgattrib/renderModeProperty.cxx +++ /dev/null @@ -1,42 +0,0 @@ -// Filename: renderModeProperty.cxx -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "renderModeProperty.h" - -ostream & -operator << (ostream &out, RenderModeProperty::Mode mode) { - switch (mode) { - case RenderModeProperty::M_filled: - return out << "filled"; - - case RenderModeProperty::M_wireframe: - return out << "wireframe"; - } - - return out << "**invalid**(" << (int)mode << ")"; -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeProperty::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void RenderModeProperty:: -output(ostream &out) const { - out << _mode << ":" << _line_width; -} diff --git a/panda/src/sgattrib/renderModeProperty.h b/panda/src/sgattrib/renderModeProperty.h deleted file mode 100644 index d844945eb9..0000000000 --- a/panda/src/sgattrib/renderModeProperty.h +++ /dev/null @@ -1,65 +0,0 @@ -// Filename: renderModeProperty.h -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef RENDERMODEPROPERTY_H -#define RENDERMODEPROPERTY_H - -#include - -//////////////////////////////////////////////////////////////////// -// Class : RenderModeProperty -// Description : This defines the types of renderMode testing we can -// enable. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA RenderModeProperty { -public: - enum Mode { - M_filled, - M_wireframe, - // M_point - - // Perhaps others to be added later. - }; - -public: - INLINE RenderModeProperty(Mode mode, double line_width); - - INLINE void set_mode(Mode mode); - INLINE Mode get_mode() const; - - INLINE void set_line_width(double line_width); - INLINE double get_line_width() const; - - INLINE int compare_to(const RenderModeProperty &other) const; - void output(ostream &out) const; - -private: - Mode _mode; - double _line_width; -}; - -ostream &operator << (ostream &out, RenderModeProperty::Mode mode); - -INLINE ostream &operator << (ostream &out, const RenderModeProperty &prop) { - prop.output(out); - return out; -} - -#include "renderModeProperty.I" - -#endif diff --git a/panda/src/sgattrib/renderModeTransition.I b/panda/src/sgattrib/renderModeTransition.I deleted file mode 100644 index 0f5401b78c..0000000000 --- a/panda/src/sgattrib/renderModeTransition.I +++ /dev/null @@ -1,70 +0,0 @@ -// Filename: renderModeTransition.I -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE RenderModeTransition:: -RenderModeTransition(RenderModeProperty::Mode mode, double line_width) : - _value(mode, line_width) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeTransition::set_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void RenderModeTransition:: -set_mode(RenderModeProperty::Mode mode) { - _value.set_mode(mode); - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeTransition::get_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE RenderModeProperty::Mode RenderModeTransition:: -get_mode() const { - return _value.get_mode(); -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeTransition::set_line_width -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void RenderModeTransition:: -set_line_width(double line_width) { - _value.set_line_width(line_width); - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeTransition::get_line_width -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE double RenderModeTransition:: -get_line_width() const { - return _value.get_line_width(); -} diff --git a/panda/src/sgattrib/renderModeTransition.cxx b/panda/src/sgattrib/renderModeTransition.cxx deleted file mode 100644 index 169cb49e5f..0000000000 --- a/panda/src/sgattrib/renderModeTransition.cxx +++ /dev/null @@ -1,108 +0,0 @@ -// Filename: renderModeTransition.cxx -// Created by: drose (08Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "renderModeTransition.h" - -#include - -PT(NodeTransition) RenderModeTransition::_initial; -TypeHandle RenderModeTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated RenderModeTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *RenderModeTransition:: -make_copy() const { - return new RenderModeTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated RenderModeTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *RenderModeTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new RenderModeTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void RenderModeTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_render_mode(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeTransition::set_value_from -// Access: Protected, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another RenderModeTransition. -//////////////////////////////////////////////////////////////////// -void RenderModeTransition:: -set_value_from(const OnTransition *other) { - const RenderModeTransition *ot; - DCAST_INTO_V(ot, other); - _value = ot->_value; -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeTransition::compare_values -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int RenderModeTransition:: -compare_values(const OnTransition *other) const { - const RenderModeTransition *ot; - DCAST_INTO_R(ot, other, false); - return _value.compare_to(ot->_value); -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -void RenderModeTransition:: -output_value(ostream &out) const { - out << _value; -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderModeTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -void RenderModeTransition:: -write_value(ostream &out, int indent_level) const { - indent(out, indent_level) << _value << "\n"; -} diff --git a/panda/src/sgattrib/renderModeTransition.h b/panda/src/sgattrib/renderModeTransition.h deleted file mode 100644 index 44bfd4ac95..0000000000 --- a/panda/src/sgattrib/renderModeTransition.h +++ /dev/null @@ -1,78 +0,0 @@ -// Filename: renderModeTransition.h -// Created by: drose (08Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef RENDERMODETRANSITION_H -#define RENDERMODETRANSITION_H - -#include - -#include "renderModeProperty.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : RenderModeTransition -// Description : -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA RenderModeTransition : public OnTransition { -public: - INLINE RenderModeTransition(RenderModeProperty::Mode mode = RenderModeProperty::M_filled, - double line_width = 1.0); - - INLINE void set_mode(RenderModeProperty::Mode mode); - INLINE RenderModeProperty::Mode get_mode() const; - - INLINE void set_line_width(double line_width); - INLINE double get_line_width() const; - - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual void set_value_from(const OnTransition *other); - virtual int compare_values(const OnTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - RenderModeProperty _value; - static PT(NodeTransition) _initial; - -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() { - OnTransition::init_type(); - register_type(_type_handle, "RenderModeTransition", - OnTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "renderModeTransition.I" - -#endif diff --git a/panda/src/sgattrib/renderRelation.I b/panda/src/sgattrib/renderRelation.I deleted file mode 100644 index 6529e1baf8..0000000000 --- a/panda/src/sgattrib/renderRelation.I +++ /dev/null @@ -1,65 +0,0 @@ -// Filename: renderRelation.I -// Created by: mike (24Sep99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: RenderRelation::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE RenderRelation:: -RenderRelation(Node *from, Node *to, int sort) : - NodeRelation(from, to, sort, get_class_type()) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderRelation::Constructor -// Access: Protected -// Description: Creates a new, unattached arc. This constructor is -// only intended for passing through the factory to -// create an arc based on a particular type using -// create_typed_arc(), below. You shouldn't, in -// general, attempt to create an unattached arc. -//////////////////////////////////////////////////////////////////// -INLINE RenderRelation:: -RenderRelation() : - NodeRelation(get_class_type()) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderRelation::register_with_factory -// Access: Public, Static -// Description: Registers the type RenderRelation with the factory. -// This is only intended to be called at initialization -// time; don't call it directly. -//////////////////////////////////////////////////////////////////// -INLINE void RenderRelation:: -register_with_factory() { - get_factory().register_factory(get_class_type(), make_arc); -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderRelation::get_class_type -// Access: Public, Static -// Description: Returns the TypeHandle associated with this type. -//////////////////////////////////////////////////////////////////// -INLINE TypeHandle RenderRelation:: -get_class_type() { - return _type_handle; -} diff --git a/panda/src/sgattrib/renderRelation.N b/panda/src/sgattrib/renderRelation.N deleted file mode 100644 index 4899282a65..0000000000 --- a/panda/src/sgattrib/renderRelation.N +++ /dev/null @@ -1 +0,0 @@ -ignoremember register_with_factory diff --git a/panda/src/sgattrib/renderRelation.cxx b/panda/src/sgattrib/renderRelation.cxx deleted file mode 100644 index 0d534d1b57..0000000000 --- a/panda/src/sgattrib/renderRelation.cxx +++ /dev/null @@ -1,154 +0,0 @@ -// Filename: renderRelation.cxx -// Created by: drose (26Oct98) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "renderRelation.h" -#include "transformTransition.h" - -#include - -TypeHandle RenderRelation::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: RenderRelation::changed_transition -// Access: Public, Virtual -// Description: This is called by set_transition() or -// clear_transition() whenever a transition is added, -// updated, or removed from the arc. It is just a -// callback to the arc so it can decide whether -// it needs to update any internal data as a response to -// this adjustment (for instance, by marking the -// bounding sphere stale). -//////////////////////////////////////////////////////////////////// -void RenderRelation:: -changed_transition(TypeHandle trans_type) { - if (trans_type == TransformTransition::get_class_type()) { - // Changing the transform means changing our bounding volume. - mark_bound_stale(); - - // And we also might want to tell our node below that the - // transform has changed. - nassertv(get_child() != (Node *)NULL); - get_child()->transform_changed(this); - } - NodeRelation::changed_transition(trans_type); -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderRelation::recompute_bound -// Access: Protected, Virtual -// Description: Recomputes the dynamic bounding volume for this arc -// (and all of its descendants). -//////////////////////////////////////////////////////////////////// -BoundingVolume *RenderRelation:: -recompute_bound() { - // First, compute the bounding volume around all of our children. - BoundingVolume *bound = NodeRelation::recompute_bound(); - nassertr(bound != (BoundingVolume *)NULL, bound); - - // Now, if we have a transform transition on the arc, apply it to - // the bounding volume. - GeometricBoundingVolume *gbv; - DCAST_INTO_R(gbv, bound, bound); - - const TransformTransition *tt; - if (get_transition_into(tt, this)) { - gbv->xform(tt->get_matrix()); - } - - return bound; -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderRelation::make_arc -// Access: Public, Static -// Description: This function is passed to the Factory to make a new -// RenderRelation by type. Don't try to call this -// function directly. -//////////////////////////////////////////////////////////////////// -NodeRelation *RenderRelation:: -make_arc(const FactoryParams &) { - return new RenderRelation; -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderRelation::make_RenderRelation -// Access: Protected -// Description: Factory method to generate a RenderRelation object -//////////////////////////////////////////////////////////////////// -TypedWritable* RenderRelation:: -make_RenderRelation(const FactoryParams ¶ms) -{ - RenderRelation *me = new RenderRelation; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderRelation::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a RenderRelation object -//////////////////////////////////////////////////////////////////// -void RenderRelation:: -register_with_read_factory(void) -{ - BamReader::get_factory()->register_factory(get_class_type(), make_RenderRelation); -} - - -//////////////////////////////////////////////////////////////////// -// Function: RenderRelation::init_type -// Access: Public, Static -// Description: Initializes the TypeHandles associated with this -// class. -//////////////////////////////////////////////////////////////////// -void RenderRelation:: -init_type() { - NodeRelation::init_type(); - register_type(_type_handle, "RenderRelation", - NodeRelation::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderRelation::get_type -// Access: Public, Virtual -// Description: Returns the particular type represented by this -// instance of the class. -//////////////////////////////////////////////////////////////////// -TypeHandle RenderRelation:: -get_type() const { - return get_class_type(); -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderRelation::force_init_type -// Access: Public, Virtual -// Description: Called by the TypeHandle system when it is detected -// that init_type() was not called for some reason. -// This is only called in an error situation, and it -// attempts to remedy the problem so we can recover and -// continue. -//////////////////////////////////////////////////////////////////// -TypeHandle RenderRelation:: -force_init_type() { - init_type(); - return get_class_type(); -} diff --git a/panda/src/sgattrib/renderRelation.h b/panda/src/sgattrib/renderRelation.h deleted file mode 100644 index 37c72bae31..0000000000 --- a/panda/src/sgattrib/renderRelation.h +++ /dev/null @@ -1,73 +0,0 @@ -// Filename: renderRelation.h -// Created by: drose (26Oct98) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef RENDERRELATION_H -#define RENDERRELATION_H - -#include - -#include -#include - -/////////////////////////////////////////////////////////////////// -// Class : RenderRelation -// Description : The arc type specific to renderable scene graphs. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA RenderRelation : public NodeRelation { -public: - INLINE RenderRelation(Node *from, Node *to, int sort = 0); - -protected: - // Normally, this should only be used for passing to the factory. - // Don't attempt to create an unattached arc directly. - INLINE RenderRelation(); - -public: - virtual void changed_transition(TypeHandle transition_type); - -protected: - virtual BoundingVolume *recompute_bound(); - -public: - // This is just to be called at initialization time; don't try to - // call this directly. - INLINE static void register_with_factory(); - -private: - static NodeRelation *make_arc(const FactoryParams ¶ms); - -public: - static void register_with_read_factory(void); - - static TypedWritable *make_RenderRelation(const FactoryParams ¶ms); - -PUBLISHED: - INLINE static TypeHandle get_class_type(); - -public: - static void init_type(); - virtual TypeHandle get_type() const; - virtual TypeHandle force_init_type(); - -private: - static TypeHandle _type_handle; -}; - -#include "renderRelation.I" - -#endif diff --git a/panda/src/sgattrib/sgattrib_composite1.cxx b/panda/src/sgattrib/sgattrib_composite1.cxx deleted file mode 100644 index 659afd3ab6..0000000000 --- a/panda/src/sgattrib/sgattrib_composite1.cxx +++ /dev/null @@ -1,14 +0,0 @@ - -#include "alphaTransformTransition.cxx" -#include "billboardTransition.cxx" -#include "clipPlaneTransition.cxx" -#include "colorBlendTransition.cxx" -#include "colorMaskTransition.cxx" -#include "colorMatrixTransition.cxx" -#include "colorTransition.cxx" -#include "cullFaceTransition.cxx" -#include "decalTransition.cxx" -#include "depthTestTransition.cxx" -#include "depthWriteTransition.cxx" -#include "drawBoundsTransition.cxx" -#include "fog.cxx" diff --git a/panda/src/sgattrib/sgattrib_composite2.cxx b/panda/src/sgattrib/sgattrib_composite2.cxx deleted file mode 100644 index cd3ebe45af..0000000000 --- a/panda/src/sgattrib/sgattrib_composite2.cxx +++ /dev/null @@ -1,15 +0,0 @@ - -#include "fogTransition.cxx" -#include "linesmoothTransition.cxx" -#include "materialTransition.cxx" -#include "pointShapeTransition.cxx" -#include "polygonOffsetTransition.cxx" -#include "pruneTransition.cxx" -#include "renderModeTransition.cxx" -#include "stencilTransition.cxx" -#include "texGenTransition.cxx" -#include "texMatrixTransition.cxx" -#include "textureApplyTransition.cxx" -#include "textureTransition.cxx" -#include "transformTransition.cxx" -#include "transparencyTransition.cxx" diff --git a/panda/src/sgattrib/sgattrib_composite3.cxx b/panda/src/sgattrib/sgattrib_composite3.cxx deleted file mode 100644 index 7eb0d8eb63..0000000000 --- a/panda/src/sgattrib/sgattrib_composite3.cxx +++ /dev/null @@ -1,18 +0,0 @@ - -#include "config_sgattrib.cxx" -#include "alphaTransformProperty.cxx" -#include "attribTraverser.cxx" -#include "colorBlendProperty.cxx" -#include "colorMaskProperty.cxx" -#include "colorProperty.cxx" -#include "cullFaceProperty.cxx" -#include "depthTestProperty.cxx" -#include "pointShapeProperty.cxx" -#include "polygonOffsetProperty.cxx" -#include "renderModeProperty.cxx" -#include "renderRelation.cxx" -#include "stencilProperty.cxx" -#include "texGenProperty.cxx" -#include "textureApplyProperty.cxx" -#include "transparencyProperty.cxx" - diff --git a/panda/src/sgattrib/stencilProperty.I b/panda/src/sgattrib/stencilProperty.I deleted file mode 100644 index 6d12edd142..0000000000 --- a/panda/src/sgattrib/stencilProperty.I +++ /dev/null @@ -1,58 +0,0 @@ -// Filename: stencilProperty.I -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: StencilProperty::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE StencilProperty:: -StencilProperty(StencilProperty::Mode mode, StencilProperty::Action pass_action, - StencilProperty::Action fail_action, StencilProperty::Action zfail_action, - unsigned long refval, unsigned long funcmask, unsigned long writemask) : - _mode(mode), - _pass_action(pass_action), - _fail_action(fail_action), - _zfail_action(zfail_action), - _refval(refval), - _funcmask(funcmask), - _writemask(writemask) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: StencilProperty::compare_to -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int StencilProperty:: -compare_to(const StencilProperty &other) const { - - #define CMPVAL(VAL) \ - if (VAL != other.VAL) {return (int)VAL - (int)other.VAL;} - - CMPVAL(_mode); - CMPVAL(_pass_action); - CMPVAL(_fail_action); - CMPVAL(_zfail_action); - CMPVAL(_refval); - CMPVAL(_funcmask); - CMPVAL(_writemask); - - return 0; -} diff --git a/panda/src/sgattrib/stencilProperty.cxx b/panda/src/sgattrib/stencilProperty.cxx deleted file mode 100644 index 91323bd1b7..0000000000 --- a/panda/src/sgattrib/stencilProperty.cxx +++ /dev/null @@ -1,98 +0,0 @@ -// Filename: stencilProperty.cxx -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "stencilProperty.h" - -ostream & -operator << (ostream &out, StencilProperty::Mode mode) { - switch (mode) { - case StencilProperty::M_none: - return out << "none"; - - case StencilProperty::M_never: - return out << "never"; - - case StencilProperty::M_less: - return out << "less"; - - case StencilProperty::M_equal: - return out << "equal"; - - case StencilProperty::M_less_equal: - return out << "less_equal"; - - case StencilProperty::M_greater: - return out << "greater"; - - case StencilProperty::M_not_equal: - return out << "not_equal"; - - case StencilProperty::M_greater_equal: - return out << "greater_equal"; - - case StencilProperty::M_always: - return out << "always"; - } - - return out << "**invalid**(" << (int)mode << ")"; -} - -ostream & -operator << (ostream &out, StencilProperty::Action action) { - switch (action) { - case StencilProperty::A_keep: - return out << "keep"; - - case StencilProperty::A_zero: - return out << "zero"; - - case StencilProperty::A_replace: - return out << "replace"; - - case StencilProperty::A_increment: - return out << "increment"; - - case StencilProperty::A_increment_clamp: - return out << "increment_clamp"; - - case StencilProperty::A_decrement: - return out << "decrement"; - - case StencilProperty::A_decrement_clamp: - return out << "decrement_clamp"; - - case StencilProperty::A_invert: - return out << "invert"; - } - - return out << "**invalid**(" << (int)action << ")"; -} - -//////////////////////////////////////////////////////////////////// -// Function: StencilProperty::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void StencilProperty:: -output(ostream &out) const { - out << _mode; - if (_mode != M_none) { - out << ":" << _pass_action << ":" << _fail_action << ":" << _zfail_action - << ":" << _refval << ": 0x" << (void*)_funcmask << ": 0x" << (void*)_writemask; - } -} diff --git a/panda/src/sgattrib/stencilProperty.h b/panda/src/sgattrib/stencilProperty.h deleted file mode 100644 index b3d925cade..0000000000 --- a/panda/src/sgattrib/stencilProperty.h +++ /dev/null @@ -1,109 +0,0 @@ -// Filename: stencilProperty.h -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef STENCILPROPERTY_H -#define STENCILPROPERTY_H - -#include - -//////////////////////////////////////////////////////////////////// -// Class : StencilProperty -// Description : Defines how we can write to and stencil via the -// stencil buffer. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA StencilProperty { -public: - enum Mode { - M_none, // No stencil test, and no write to stencil buffer. - M_never, // Never draw. - M_less, // incoming < stored - M_equal, // incoming == stored - M_less_equal, // incoming <= stored - M_greater, // incoming > stored - M_not_equal, // incoming != stored - M_greater_equal, // incoming >= stored - M_always // Always draw. - }; - - enum Action { - A_keep, - A_zero, - A_replace, - A_increment, // incr maxval will wrap around to 0 - A_decrement, // decr 0 will wrap around to all 1's - A_increment_clamp, // cap value to max stencil val - A_decrement_clamp, // cap value at zero - A_invert - }; - -public: - INLINE StencilProperty(Mode mode,Action pass_action,Action fail_action,Action zfail_action, - unsigned long refval, unsigned long funcmask, unsigned long writemask); - - INLINE void set_mode(Mode mode) { _mode = mode; }; - INLINE Mode get_mode() const { return _mode; }; - - INLINE void set_pass_action(Action action) { _pass_action = action; }; - INLINE Action get_pass_action() const { return _pass_action; }; - - INLINE void set_fail_action(Action action) { _fail_action = action; }; - INLINE Action get_fail_action() const { return _fail_action; }; - - INLINE void set_zfail_action(Action action) { _zfail_action = action; }; - INLINE Action get_zfail_action() const { return _zfail_action; }; - - INLINE void set_reference_value(unsigned long v) { _refval = v; }; - INLINE unsigned long get_reference_value() const { return _refval; }; - - INLINE void set_func_mask(unsigned long m) { _funcmask = m; }; - INLINE unsigned long get_func_mask() const { return _funcmask; }; - - INLINE void set_write_mask(unsigned long m) { _writemask = m; }; - INLINE unsigned long get_write_mask() const { return _writemask; }; - - INLINE void set_stencil_state(Mode mode, Action pass_action, Action fail_action, Action zfail_action, - unsigned long refval, unsigned long funcmask, unsigned long writemask) { - _mode = mode; - _pass_action = pass_action; - _fail_action = fail_action; - _zfail_action = zfail_action; - _refval = refval; - _funcmask = funcmask; - _writemask = writemask; - }; - - INLINE int compare_to(const StencilProperty &other) const; - void output(ostream &out) const; - -private: - Mode _mode; - Action _pass_action,_fail_action,_zfail_action; - unsigned long _refval,_funcmask,_writemask; -}; - -ostream &operator << (ostream &out, StencilProperty::Mode mode); -ostream &operator << (ostream &out, StencilProperty::Action action); - -INLINE ostream &operator << (ostream &out, const StencilProperty &prop) { - prop.output(out); - return out; -} - -#include "stencilProperty.I" - -#endif diff --git a/panda/src/sgattrib/stencilTransition.I b/panda/src/sgattrib/stencilTransition.I deleted file mode 100644 index 3ec10db1da..0000000000 --- a/panda/src/sgattrib/stencilTransition.I +++ /dev/null @@ -1,141 +0,0 @@ -// Filename: stencilTransition.I -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: StencilTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE StencilTransition:: -StencilTransition(StencilProperty::Mode mode, StencilProperty::Action pass_action, - StencilProperty::Action fail_action, StencilProperty::Action zfail_action, - unsigned long refval, unsigned long funcmask, unsigned long writemask) : - _value(mode,pass_action,fail_action,zfail_action,refval,funcmask,writemask) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: StencilTransition::set_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void StencilTransition:: -set_mode(StencilProperty::Mode mode) { - _value.set_mode(mode); - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: StencilTransition::get_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE StencilProperty::Mode StencilTransition:: -get_mode() const { - return _value.get_mode(); -} - -//////////////////////////////////////////////////////////////////// -// Function: StencilTransition::set_action -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void StencilTransition:: -set_pass_action(StencilProperty::Action action) { - _value.set_pass_action(action); - state_changed(); -} - -INLINE void StencilTransition:: -set_fail_action(StencilProperty::Action action) { - _value.set_fail_action(action); - state_changed(); -} - -INLINE void StencilTransition:: -set_zfail_action(StencilProperty::Action action) { - _value.set_zfail_action(action); - state_changed(); -} - -INLINE void StencilTransition:: -set_reference_value(unsigned long v) { - _value.set_reference_value(v); - state_changed(); -} - -INLINE void StencilTransition:: -set_func_mask(unsigned long m) { - _value.set_func_mask(m); - state_changed(); -} - -INLINE void StencilTransition:: -set_write_mask(unsigned long m) { - _value.set_write_mask(m); - state_changed(); -} - -INLINE void StencilTransition:: -set_stencil_state(StencilProperty::Mode mode, StencilProperty::Action pass_action, - StencilProperty::Action fail_action, StencilProperty::Action zfail_action, - unsigned long refval, unsigned long refmask, unsigned long writemask) { - _value.set_stencil_state(mode,pass_action,fail_action,zfail_action, - refval,refmask,writemask); - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: StencilTransition::get_action -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE StencilProperty::Action StencilTransition:: -get_pass_action() const { - return _value.get_pass_action(); -} - -INLINE StencilProperty::Action StencilTransition:: -get_fail_action() const { - return _value.get_fail_action(); -} - -INLINE StencilProperty::Action StencilTransition:: -get_zfail_action() const { - return _value.get_zfail_action(); -} - -INLINE unsigned long StencilTransition:: -get_reference_value() const { - return _value.get_reference_value(); -} - -INLINE unsigned long StencilTransition:: -get_func_mask() const { - return _value.get_func_mask(); -} - -INLINE unsigned long StencilTransition:: -get_write_mask() const { - return _value.get_write_mask(); -} - - - - - diff --git a/panda/src/sgattrib/stencilTransition.cxx b/panda/src/sgattrib/stencilTransition.cxx deleted file mode 100644 index 9eebbbc064..0000000000 --- a/panda/src/sgattrib/stencilTransition.cxx +++ /dev/null @@ -1,108 +0,0 @@ -// Filename: stencilTransition.cxx -// Created by: mike (28Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "stencilTransition.h" - -#include - -PT(NodeTransition) StencilTransition::_initial; -TypeHandle StencilTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: StencilTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated StencilTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *StencilTransition:: -make_copy() const { - return new StencilTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: StencilTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated StencilTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *StencilTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new StencilTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: StencilTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void StencilTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_stencil(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: StencilTransition::set_value_from -// Access: Protected, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another StencilTransition. -//////////////////////////////////////////////////////////////////// -void StencilTransition:: -set_value_from(const OnTransition *other) { - const StencilTransition *ot; - DCAST_INTO_V(ot, other); - _value = ot->_value; -} - -//////////////////////////////////////////////////////////////////// -// Function: StencilTransition::compare_values -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int StencilTransition:: -compare_values(const OnTransition *other) const { - const StencilTransition *ot; - DCAST_INTO_R(ot, other, false); - return _value.compare_to(ot->_value); -} - -//////////////////////////////////////////////////////////////////// -// Function: StencilTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -void StencilTransition:: -output_value(ostream &out) const { - out << _value; -} - -//////////////////////////////////////////////////////////////////// -// Function: StencilTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -void StencilTransition:: -write_value(ostream &out, int indent_level) const { - indent(out, indent_level) << _value << "\n"; -} diff --git a/panda/src/sgattrib/stencilTransition.h b/panda/src/sgattrib/stencilTransition.h deleted file mode 100644 index 86d7dbc40e..0000000000 --- a/panda/src/sgattrib/stencilTransition.h +++ /dev/null @@ -1,108 +0,0 @@ -// Filename: stencilTransition.h -// Created by: mike (18Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef STENCILTRANSITION_H -#define STENCILTRANSITION_H - -#include - -#include "stencilProperty.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : StencilTransition -// Description : This is scene graph stencil (which is not to be -// confused with geometry stencil). By setting a -// StencilTransition on the scene graph, you can override -// the stencil at the object level, but not at the -// individual primitive or vertex level. If a scene -// graph stencil is set, it overrides the primitive stencil; -// otherwise, the primitive stencil shows through. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA StencilTransition : public OnTransition { -public: - INLINE StencilTransition(StencilProperty::Mode mode = StencilProperty::M_none, - StencilProperty::Action pass_action = StencilProperty::A_replace, - StencilProperty::Action fail_action = StencilProperty::A_keep, - StencilProperty::Action zfail_action = StencilProperty::A_keep, - unsigned long refval = 0, - unsigned long funcmask = 0xFFFFFFFF, - unsigned long writemask = 0xFFFFFFFF); - - INLINE void set_mode(StencilProperty::Mode mode); - INLINE StencilProperty::Mode get_mode() const; - - INLINE void set_pass_action(StencilProperty::Action action); - INLINE StencilProperty::Action get_pass_action() const; - - INLINE void set_fail_action(StencilProperty::Action action); - INLINE StencilProperty::Action get_fail_action() const; - - INLINE void set_zfail_action(StencilProperty::Action action); - INLINE StencilProperty::Action get_zfail_action() const; - - INLINE void set_reference_value(unsigned long v); - INLINE unsigned long get_reference_value() const; - - INLINE void set_func_mask(unsigned long m); - INLINE unsigned long get_func_mask() const; - - INLINE void set_write_mask(unsigned long m); - INLINE unsigned long get_write_mask() const; - - INLINE void set_stencil_state(StencilProperty::Mode mode, StencilProperty::Action pass_action, - StencilProperty::Action fail_action, StencilProperty::Action zfail_action, - unsigned long refval, unsigned long funcmask, unsigned long writemask); - - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual void set_value_from(const OnTransition *other); - virtual int compare_values(const OnTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - StencilProperty _value; - static PT(NodeTransition) _initial; - -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() { - OnTransition::init_type(); - register_type(_type_handle, "StencilTransition", - OnTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "stencilTransition.I" - -#endif diff --git a/panda/src/sgattrib/test_attrib.cxx b/panda/src/sgattrib/test_attrib.cxx deleted file mode 100644 index 26516ab2dc..0000000000 --- a/panda/src/sgattrib/test_attrib.cxx +++ /dev/null @@ -1,165 +0,0 @@ -// Filename: test_attrib.cxx -// Created by: drose (18Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "colorTransition.h" -#include "textureTransition.h" - -#include -#include -#include -#include -#include -#include -#include - - -class PrintNodes : - public TraverserVisitor { -public: - PrintNodes() { - _indent_level = 0; - } - bool reached_node(Node *node, TransitionWrapper &state, - NullLevelState &) { - indent(cerr, _indent_level) - << "\nReached " << *node << ", state is:\n"; - state.write(cerr, _indent_level); - return true; - } - bool forward_arc(NodeRelation *arc, TransitionWrapper &trans, - TransitionWrapper &pre, TransitionWrapper &post, - NullLevelState &) { - _indent_level += 2; - return true; - } - void backward_arc(NodeRelation *arc, TransitionWrapper &trans, - TransitionWrapper &pre, TransitionWrapper &post, - const NullLevelState &) { - _indent_level -= 2; - } - int _indent_level; -}; - - -int -main(int argc, char *argv[]) { - PT_NamedNode r = new NamedNode("r"); - - PT_NamedNode a = new NamedNode("a"); - PT_NamedNode b = new NamedNode("b"); - - PT_NamedNode aa = new NamedNode("aa"); - PT_NamedNode ab = new NamedNode("ab"); - PT_NamedNode ba = new NamedNode("ba"); - - NodeRelation *r_a = - new NodeRelation(r, a, 0, NodeRelation::get_class_type()); - NodeRelation *r_b = - new NodeRelation(r, b, 0, NodeRelation::get_class_type()); - - NodeRelation *a_aa = - new NodeRelation(a, aa, 0, NodeRelation::get_class_type()); - NodeRelation *a_ab = - new NodeRelation(a, ab, 0, NodeRelation::get_class_type()); - NodeRelation *b_ba = - new NodeRelation(b, ba, 0, NodeRelation::get_class_type()); - - PT(Texture) alpha = new Texture; - alpha->set_name("alpha"); - PT(Texture) beta = new Texture; - beta->set_name("beta"); - - r_a->set_transition(new ColorTransition(1.0f, 1.0f, 1.0f, 1.0f)); - r_a->set_transition(new TextureTransition(alpha)); - a_aa->set_transition(new ColorTransition(0.5f, 1.0f, 0.5f, 0.2f)); - a_ab->set_transition(new TextureTransition(beta)); - - cerr << "\nr to a has:\n"; - r_a->write_transitions(cerr, 2); - cerr << "\nr to b has:\n"; - r_b->write_transitions(cerr, 2); - cerr << "\na to aa has:\n"; - a_aa->write_transitions(cerr, 2); - cerr << "\na to ab has:\n"; - a_ab->write_transitions(cerr, 2); - cerr << "\nb to ba has:\n"; - b_ba->write_transitions(cerr, 2); - cerr << "\n"; - - { - cerr << "\n"; - PrintNodes pn; - df_traverse(r, pn, - AllTransitionsWrapper(), - NullLevelState(), - NodeRelation::get_class_type()); - cerr << "\n"; - - AllTransitionsWrapper result; - wrt(r, aa, result, NodeRelation::get_class_type()); - cerr << "\nwrt of r to aa is:\n"; - result.write(cerr, 2); - - wrt(aa, r, result, NodeRelation::get_class_type()); - cerr << "\nwrt of aa to r is:\n"; - result.write(cerr, 2); - - wrt(r, ab, result, NodeRelation::get_class_type()); - cerr << "\nwrt of r to ab is:\n"; - result.write(cerr, 2); - - wrt(ab, r, result, NodeRelation::get_class_type()); - cerr << "\nwrt of ab to r is:\n"; - result.write(cerr, 2); - - wrt(ab, aa, result, NodeRelation::get_class_type()); - cerr << "\nwrt of ab to aa is:\n"; - result.write(cerr, 2); - - wrt(aa, ab, result, NodeRelation::get_class_type()); - cerr << "\nwrt of aa to ab is:\n"; - result.write(cerr, 2); - - wrt(r, ba, result, NodeRelation::get_class_type()); - cerr << "\nwrt of r to ba is:\n"; - result.write(cerr, 2); - - wrt(ba, r, result, NodeRelation::get_class_type()); - cerr << "\nwrt of ba to r is:\n"; - result.write(cerr, 2); - - wrt(aa, ba, result, NodeRelation::get_class_type()); - cerr << "\nwrt of aa to ba is:\n"; - result.write(cerr, 2); - - wrt(ba, aa, result, NodeRelation::get_class_type()); - cerr << "\nwrt of ba to aa is:\n"; - result.write(cerr, 2); - - wrt(ab, ba, result, NodeRelation::get_class_type()); - cerr << "\nwrt of ab to ba is:\n"; - result.write(cerr, 2); - - wrt(ba, ab, result, NodeRelation::get_class_type()); - cerr << "\nwrt of ba to ab is:\n"; - result.write(cerr, 2); - } - - return (0); -} - diff --git a/panda/src/sgattrib/texGenProperty.I b/panda/src/sgattrib/texGenProperty.I deleted file mode 100644 index 64f3104960..0000000000 --- a/panda/src/sgattrib/texGenProperty.I +++ /dev/null @@ -1,87 +0,0 @@ -// Filename: texGenProperty.I -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: TexGenProperty::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TexGenProperty:: -TexGenProperty() : - _mode(M_none) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenProperty::texture_projector -// Access: Public -// Description: This named constructor creates a TexGenProperty -// suitable for projecting textures through a -// perspective frustum. -//////////////////////////////////////////////////////////////////// -INLINE TexGenProperty TexGenProperty:: -texture_projector() { - TexGenProperty p; - p._mode = M_texture_projector; - p._plane = LMatrix4f::ident_mat(); - return p; -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenProperty::sphere_map -// Access: Public -// Description: This named constructor creates a TexGenProperty -// suitable for applying textures as a sphere map. -//////////////////////////////////////////////////////////////////// -INLINE TexGenProperty TexGenProperty:: -sphere_map() { - TexGenProperty p; - p._mode = M_sphere_map; - return p; -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenProperty::get_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TexGenProperty::Mode TexGenProperty:: -get_mode() const { - return _mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenProperty::get_plane -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE const LMatrix4f &TexGenProperty:: -get_plane() const { - return _plane; -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenProperty::Equality Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int TexGenProperty:: -compare_to(const TexGenProperty &other) const { - return (int)_mode - (int)other._mode; - // Should we compare planes also? -} diff --git a/panda/src/sgattrib/texGenProperty.cxx b/panda/src/sgattrib/texGenProperty.cxx deleted file mode 100644 index 1eedf1289c..0000000000 --- a/panda/src/sgattrib/texGenProperty.cxx +++ /dev/null @@ -1,48 +0,0 @@ -// Filename: texGenProperty.cxx -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "texGenProperty.h" - -ostream & -operator << (ostream &out, TexGenProperty::Mode mode) { - switch (mode) { - case TexGenProperty::M_none: - return out << "none"; - - case TexGenProperty::M_eye_linear: - return out << "eye_linear"; - - case TexGenProperty::M_texture_projector: - return out << "texture_projector"; - - case TexGenProperty::M_sphere_map: - return out << "sphere_map"; - } - - return out << "**invalid**(" << (int)mode << ")"; -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenProperty::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void TexGenProperty:: -output(ostream &out) const { - out << _mode; -} diff --git a/panda/src/sgattrib/texGenProperty.h b/panda/src/sgattrib/texGenProperty.h deleted file mode 100644 index ecc8a6649d..0000000000 --- a/panda/src/sgattrib/texGenProperty.h +++ /dev/null @@ -1,66 +0,0 @@ -// Filename: texGenProperty.h -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef TEXGENPROPERTY_H -#define TEXGENPROPERTY_H - -#include - -#include - -//////////////////////////////////////////////////////////////////// -// Class : TexGenProperty -// Description : This defines the kinds of texture coordinates that -// may be automatically generated at render time. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA TexGenProperty { -public: - enum Mode { - M_none, - M_eye_linear, - M_texture_projector, - M_sphere_map, - }; - -public: - INLINE TexGenProperty(); - INLINE static TexGenProperty texture_projector(); - INLINE static TexGenProperty sphere_map(); - - INLINE Mode get_mode() const; - INLINE const LMatrix4f &get_plane() const; - - INLINE int compare_to(const TexGenProperty &other) const; - - void output(ostream &out) const; - -private: - Mode _mode; - LMatrix4f _plane; -}; - -ostream &operator << (ostream &out, TexGenProperty::Mode mode); - -INLINE ostream &operator << (ostream &out, const TexGenProperty &prop) { - prop.output(out); - return out; -} - -#include "texGenProperty.I" - -#endif diff --git a/panda/src/sgattrib/texGenTransition.I b/panda/src/sgattrib/texGenTransition.I deleted file mode 100644 index b57a3cab56..0000000000 --- a/panda/src/sgattrib/texGenTransition.I +++ /dev/null @@ -1,108 +0,0 @@ -// Filename: texGenTransition.I -// Created by: drose (24Sep99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: TexGenTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TexGenTransition:: -TexGenTransition() { -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenTransition::texture_projector -// Access: Public -// Description: This named constructor creates a transition to -// project textures through a perpective frustum. -//////////////////////////////////////////////////////////////////// -INLINE TexGenTransition TexGenTransition:: -texture_projector() { - TexGenTransition result; - result.set_texture_projector(); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenTransition::sphere_map -// Access: Public -// Description: This named constructor creates a transition to -// project textures as sphere maps. -//////////////////////////////////////////////////////////////////// -INLINE TexGenTransition TexGenTransition:: -sphere_map() { - TexGenTransition result; - result.set_sphere_map(); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenTransition::set_none -// Access: Public -// Description: Sets the transition to disable texture coordinate -// generation. -//////////////////////////////////////////////////////////////////// -INLINE void TexGenTransition:: -set_none() { - _value = TexGenProperty(); - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenTransition::set_texture_projector -// Access: Public -// Description: Sets the transition to project textures through a -// perpective frustum. -//////////////////////////////////////////////////////////////////// -INLINE void TexGenTransition:: -set_texture_projector() { - _value = TexGenProperty::texture_projector(); - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenTransition::set_sphere_map -// Access: Public -// Description: Sets the transition to project textures as sphere -// maps. -//////////////////////////////////////////////////////////////////// -INLINE void TexGenTransition:: -set_sphere_map() { - _value = TexGenProperty::sphere_map(); - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenTransition::get_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TexGenProperty::Mode TexGenTransition:: -get_mode() const { - return _value.get_mode(); -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenTransition::get_plane -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE LMatrix4f TexGenTransition:: -get_plane() const { - return _value.get_plane(); -} diff --git a/panda/src/sgattrib/texGenTransition.cxx b/panda/src/sgattrib/texGenTransition.cxx deleted file mode 100644 index 2cc0d74871..0000000000 --- a/panda/src/sgattrib/texGenTransition.cxx +++ /dev/null @@ -1,108 +0,0 @@ -// Filename: texGenTransition.cxx -// Created by: mike (28Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "texGenTransition.h" - -#include - -PT(NodeTransition) TexGenTransition::_initial; -TypeHandle TexGenTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: TexGenTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated TexGenTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *TexGenTransition:: -make_copy() const { - return new TexGenTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated TexGenTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *TexGenTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new TexGenTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void TexGenTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_tex_gen(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenTransition::set_value_from -// Access: Protected, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another TexGenTransition. -//////////////////////////////////////////////////////////////////// -void TexGenTransition:: -set_value_from(const OnTransition *other) { - const TexGenTransition *ot; - DCAST_INTO_V(ot, other); - _value = ot->_value; -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenTransition::compare_values -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int TexGenTransition:: -compare_values(const OnTransition *other) const { - const TexGenTransition *ot; - DCAST_INTO_R(ot, other, false); - return _value.compare_to(ot->_value); -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -void TexGenTransition:: -output_value(ostream &out) const { - out << _value; -} - -//////////////////////////////////////////////////////////////////// -// Function: TexGenTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -void TexGenTransition:: -write_value(ostream &out, int indent_level) const { - indent(out, indent_level) << _value << "\n"; -} diff --git a/panda/src/sgattrib/texGenTransition.h b/panda/src/sgattrib/texGenTransition.h deleted file mode 100644 index e2b8da56e6..0000000000 --- a/panda/src/sgattrib/texGenTransition.h +++ /dev/null @@ -1,82 +0,0 @@ -// Filename: texGenTransition.h -// Created by: mike (18Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef TEXGENTRANSITION_H -#define TEXGENTRANSITION_H - -#include - -#include "texGenProperty.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : TexGenTransition -// Description : This controls generation of texture coordinates in -// the graphics HW, for instance for projected -// textures. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA TexGenTransition : public OnTransition { -public: - INLINE TexGenTransition(); - INLINE static TexGenTransition texture_projector(); - INLINE static TexGenTransition sphere_map(); - - INLINE void set_none(); - INLINE void set_texture_projector(); - INLINE void set_sphere_map(); - - INLINE TexGenProperty::Mode get_mode() const; - INLINE LMatrix4f get_plane() const; - - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual void set_value_from(const OnTransition *other); - virtual int compare_values(const OnTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - TexGenProperty _value; - static PT(NodeTransition) _initial; - -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() { - OnTransition::init_type(); - register_type(_type_handle, "TexGenTransition", - OnTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "texGenTransition.I" - -#endif diff --git a/panda/src/sgattrib/texMatrixTransition.I b/panda/src/sgattrib/texMatrixTransition.I deleted file mode 100644 index 1b5bdd917d..0000000000 --- a/panda/src/sgattrib/texMatrixTransition.I +++ /dev/null @@ -1,37 +0,0 @@ -// Filename: texMatrixTransition.I -// Created by: drose (24Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: TexMatrixTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TexMatrixTransition:: -TexMatrixTransition() { -} - -//////////////////////////////////////////////////////////////////// -// Function: TexMatrixTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TexMatrixTransition:: -TexMatrixTransition(const LMatrix4f &matrix) : - LMatrix4fTransition(matrix) -{ -} diff --git a/panda/src/sgattrib/texMatrixTransition.cxx b/panda/src/sgattrib/texMatrixTransition.cxx deleted file mode 100644 index e84de824f9..0000000000 --- a/panda/src/sgattrib/texMatrixTransition.cxx +++ /dev/null @@ -1,72 +0,0 @@ -// Filename: texMatrixTransition.cxx -// Created by: mike (19Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "texMatrixTransition.h" - -#include - -PT(NodeTransition) TexMatrixTransition::_initial; -TypeHandle TexMatrixTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: TexMatrixTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated TexMatrixTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *TexMatrixTransition:: -make_copy() const { - return new TexMatrixTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: TexMatrixTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated TexMatrixTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *TexMatrixTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new TexMatrixTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: TexMatrixTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void TexMatrixTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_tex_matrix(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: TexMatrixTransition::make_with_matrix -// Access: Protected, Virtual -// Description: Returns a new transition with the indicated matrix. -//////////////////////////////////////////////////////////////////// -MatrixTransition *TexMatrixTransition:: -make_with_matrix(const LMatrix4f &matrix) const { - return new TexMatrixTransition(matrix); -} diff --git a/panda/src/sgattrib/texMatrixTransition.h b/panda/src/sgattrib/texMatrixTransition.h deleted file mode 100644 index 0715afa8db..0000000000 --- a/panda/src/sgattrib/texMatrixTransition.h +++ /dev/null @@ -1,71 +0,0 @@ -// Filename: texMatrixTransition.h -// Created by: mike (19Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef TEXMATRIXTRANSITION_H -#define TEXMATRIXTRANSITION_H - -#include - -#include -#include - -//////////////////////////////////////////////////////////////////// -// Class : TexMatrixTransition -// Description : If present, this modifies the texture coordinates on -// geometry as it is rendered. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA TexMatrixTransition : public LMatrix4fTransition { -public: - INLINE TexMatrixTransition(); - INLINE TexMatrixTransition(const LMatrix4f &matrix); - - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual MatrixTransition * - make_with_matrix(const LMatrix4f &matrix) const; - -private: - static PT(NodeTransition) _initial; - -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() { - LMatrix4fTransition::init_type(); - register_type(_type_handle, "TexMatrixTransition", - LMatrix4fTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "texMatrixTransition.I" - -#endif - - diff --git a/panda/src/sgattrib/textureApplyProperty.I b/panda/src/sgattrib/textureApplyProperty.I deleted file mode 100644 index 0db292bfa7..0000000000 --- a/panda/src/sgattrib/textureApplyProperty.I +++ /dev/null @@ -1,73 +0,0 @@ -// Filename: textureApplyProperty.I -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyProperty::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TextureApplyProperty:: -TextureApplyProperty(TextureApplyProperty::Mode mode) : - _mode(mode) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyProperty::Constructor -// Access: Public -// Description: This should only be called in the Protected -// constructor of TextureApplyTransition. It is made -// public, only for that to access, and is necessary -// for creating an object in make_TextureApplyTransition -// before any information has been read -//////////////////////////////////////////////////////////////////// -INLINE TextureApplyProperty:: -TextureApplyProperty(void) -{ -} - - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyProperty::set_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TextureApplyProperty:: -set_mode(TextureApplyProperty::Mode mode) { - _mode = mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyProperty::get_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TextureApplyProperty::Mode TextureApplyProperty:: -get_mode() const { - return _mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyProperty::compare_to -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int TextureApplyProperty:: -compare_to(const TextureApplyProperty &other) const { - return (int)_mode - (int)other._mode; -} diff --git a/panda/src/sgattrib/textureApplyProperty.cxx b/panda/src/sgattrib/textureApplyProperty.cxx deleted file mode 100644 index 616471b0dc..0000000000 --- a/panda/src/sgattrib/textureApplyProperty.cxx +++ /dev/null @@ -1,80 +0,0 @@ -// Filename: textureApplyProperty.cxx -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "textureApplyProperty.h" -#include -#include - -ostream & -operator << (ostream &out, TextureApplyProperty::Mode mode) { - switch (mode) { - case TextureApplyProperty::M_modulate: - return out << "modulate"; - - case TextureApplyProperty::M_decal: - return out << "decal"; - - case TextureApplyProperty::M_blend: - return out << "blend"; - - case TextureApplyProperty::M_replace: - return out << "replace"; - - case TextureApplyProperty::M_add: - return out << "add"; - } - - return out << "**invalid**(" << (int)mode << ")"; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyProperty::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void TextureApplyProperty:: -output(ostream &out) const { - out << _mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyProperty::write_datagram -// Access: Public -// Description: Function to write the important information in -// this object to a Datagram -//////////////////////////////////////////////////////////////////// -void TextureApplyProperty:: -write_datagram(Datagram &destination) -{ - destination.add_uint8(_mode); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyProperty::read_datagram -// Access: Public -// Description: Function to write the important information into -// this object out of a Datagram -//////////////////////////////////////////////////////////////////// -void TextureApplyProperty:: -read_datagram(DatagramIterator &source) -{ - _mode = (enum Mode) source.get_uint8(); -} - - - diff --git a/panda/src/sgattrib/textureApplyProperty.h b/panda/src/sgattrib/textureApplyProperty.h deleted file mode 100644 index c1cff07f1a..0000000000 --- a/panda/src/sgattrib/textureApplyProperty.h +++ /dev/null @@ -1,70 +0,0 @@ -// Filename: textureApplyProperty.h -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef TEXTUREAPPLYPROPERTY_H -#define TEXTUREAPPLYPROPERTY_H - -#include - -class Datagram; -class DatagramIterator; - -//////////////////////////////////////////////////////////////////// -// Class : TextureApplyProperty -// Description : Defines the way texture colors modify existing -// geometry colors. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA TextureApplyProperty { -public: - enum Mode { - M_modulate, - M_decal, - M_blend, - M_replace, - M_add - }; - -public: - INLINE TextureApplyProperty(Mode mode); - INLINE TextureApplyProperty(void); - - INLINE void set_mode(Mode mode); - INLINE Mode get_mode() const; - - INLINE int compare_to(const TextureApplyProperty &other) const; - - void output(ostream &out) const; - -public: - void write_datagram(Datagram &destination); - void read_datagram(DatagramIterator &source); - -private: - Mode _mode; -}; - -ostream &operator << (ostream &out, TextureApplyProperty::Mode mode); - -INLINE ostream &operator << (ostream &out, const TextureApplyProperty &prop) { - prop.output(out); - return out; -} - -#include "textureApplyProperty.I" - -#endif diff --git a/panda/src/sgattrib/textureApplyTransition.I b/panda/src/sgattrib/textureApplyTransition.I deleted file mode 100644 index 8d738d91ff..0000000000 --- a/panda/src/sgattrib/textureApplyTransition.I +++ /dev/null @@ -1,49 +0,0 @@ -// Filename: textureApplyTransition.I -// Created by: drose (23Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TextureApplyTransition:: -TextureApplyTransition(TextureApplyProperty::Mode mode) : - _value(mode) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyTransition::set_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TextureApplyTransition:: -set_mode(TextureApplyProperty::Mode mode) { - _value.set_mode(mode); - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyTransition::get_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TextureApplyProperty::Mode TextureApplyTransition:: -get_mode() const { - return _value.get_mode(); -} diff --git a/panda/src/sgattrib/textureApplyTransition.cxx b/panda/src/sgattrib/textureApplyTransition.cxx deleted file mode 100644 index 939f44acba..0000000000 --- a/panda/src/sgattrib/textureApplyTransition.cxx +++ /dev/null @@ -1,171 +0,0 @@ -// Filename: textureApplyTransition.cxx -// Created by: drose (06Oct99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "textureApplyTransition.h" - -#include -#include -#include -#include -#include - -PT(NodeTransition) TextureApplyTransition::_initial; -TypeHandle TextureApplyTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated TextureApplyTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *TextureApplyTransition:: -make_copy() const { - return new TextureApplyTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated TextureApplyTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *TextureApplyTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new TextureApplyTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void TextureApplyTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_texture_apply(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyTransition::set_value_from -// Access: Protected, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another TextureApplyTransition. -//////////////////////////////////////////////////////////////////// -void TextureApplyTransition:: -set_value_from(const OnTransition *other) { - const TextureApplyTransition *ot; - DCAST_INTO_V(ot, other); - _value = ot->_value; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyTransition::compare_values -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int TextureApplyTransition:: -compare_values(const OnTransition *other) const { - const TextureApplyTransition *ot; - DCAST_INTO_R(ot, other, false); - return _value.compare_to(ot->_value); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -void TextureApplyTransition:: -output_value(ostream &out) const { - out << _value; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -void TextureApplyTransition:: -write_value(ostream &out, int indent_level) const { - indent(out, indent_level) << _value << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyTransition::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void TextureApplyTransition:: -write_datagram(BamWriter *manager, Datagram &me) -{ - OnTransition::write_datagram(manager, me); - _value.write_datagram(me); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyTransition::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void TextureApplyTransition:: -fillin(DatagramIterator& scan, BamReader* manager) -{ - OnTransition::fillin(scan, manager); - _value.read_datagram(scan); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyTransition::make_TextureApplyTransition -// Access: Protected -// Description: Factory method to generate a TextureApplyTransition object -//////////////////////////////////////////////////////////////////// -TypedWritable* TextureApplyTransition:: -make_TextureApplyTransition(const FactoryParams ¶ms) -{ - TextureApplyTransition *me = new TextureApplyTransition; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureApplyTransition::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a TextureApplyTransition object -//////////////////////////////////////////////////////////////////// -void TextureApplyTransition:: -register_with_read_factory(void) -{ - BamReader::get_factory()->register_factory(get_class_type(), make_TextureApplyTransition); -} - - - diff --git a/panda/src/sgattrib/textureApplyTransition.h b/panda/src/sgattrib/textureApplyTransition.h deleted file mode 100644 index 974912532a..0000000000 --- a/panda/src/sgattrib/textureApplyTransition.h +++ /dev/null @@ -1,87 +0,0 @@ -// Filename: textureApplyTransition.h -// Created by: drose (06Oct99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef TEXTUREAPPLYTRANSITION_H -#define TEXTUREAPPLYTRANSITION_H - -#include - -#include "textureApplyProperty.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : TextureApplyTransition -// Description : This controls the way textures modify the colors -// assigned to geometry. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA TextureApplyTransition : public OnTransition { -public: - INLINE TextureApplyTransition(TextureApplyProperty::Mode mode = TextureApplyProperty::M_modulate); - - INLINE void set_mode(TextureApplyProperty::Mode mode); - INLINE TextureApplyProperty::Mode get_mode() const; - - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual void set_value_from(const OnTransition *other); - virtual int compare_values(const OnTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - TextureApplyProperty _value; - static PT(NodeTransition) _initial; - -public: - static void register_with_read_factory(void); - virtual void write_datagram(BamWriter* manager, Datagram &me); - - static TypedWritable *make_TextureApplyTransition(const FactoryParams ¶ms); - -protected: - 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() { - OnTransition::init_type(); - register_type(_type_handle, "TextureApplyTransition", - OnTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "textureApplyTransition.I" - -#endif - - - diff --git a/panda/src/sgattrib/textureTransition.I b/panda/src/sgattrib/textureTransition.I deleted file mode 100644 index 682296ca43..0000000000 --- a/panda/src/sgattrib/textureTransition.I +++ /dev/null @@ -1,78 +0,0 @@ -// Filename: textureTransition.I -// Created by: drose (22Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: TextureTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TextureTransition:: -TextureTransition() { -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TextureTransition:: -TextureTransition(Texture *texture) : - OnOffTransition(TD_on), - _value(texture) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureTransition::off -// Access: Public -// Description: This named constructor returns a TextureTransition that -// turns off texturing, thus rendering geometry -// untextured. -//////////////////////////////////////////////////////////////////// -INLINE TextureTransition TextureTransition:: -off() { - TextureTransition result; - result.set_off(); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureTransition::set_on -// Access: Public -// Description: Changes the TextureTransition to render the particular -// texture. -//////////////////////////////////////////////////////////////////// -INLINE void TextureTransition:: -set_on(Texture *texture) { - nassertv(texture != (Texture *)NULL); - _value = texture; - OnOffTransition::set_on(); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureTransition::get_texture -// Access: Public -// Description: Returns the texture that the TextureTransition -// represents. It is only valid to call this if is_on() -// has returned true. -//////////////////////////////////////////////////////////////////// -INLINE PT(Texture) TextureTransition:: -get_texture() const { - nassertr(is_on(), NULL); - return _value; -} diff --git a/panda/src/sgattrib/textureTransition.cxx b/panda/src/sgattrib/textureTransition.cxx deleted file mode 100644 index 7d7bca50f2..0000000000 --- a/panda/src/sgattrib/textureTransition.cxx +++ /dev/null @@ -1,194 +0,0 @@ -// Filename: textureTransition.cxx -// Created by: drose (06Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "config_sgattrib.h" - -#include "textureTransition.h" - -#include -#include -#include -#include -#include - -PT(NodeTransition) TextureTransition::_initial; -TypeHandle TextureTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: TextureTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated TextureTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *TextureTransition:: -make_copy() const { - return new TextureTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated TextureTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *TextureTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new TextureTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void TextureTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_texture(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureTransition::set_value_from -// Access: Protected, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another TextureTransition. -//////////////////////////////////////////////////////////////////// -void TextureTransition:: -set_value_from(const OnOffTransition *other) { - const TextureTransition *ot; - DCAST_INTO_V(ot, other); - _value = ot->_value; - nassertv(_value != (Texture *)NULL); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureTransition::compare_values -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int TextureTransition:: -compare_values(const OnOffTransition *other) const { - const TextureTransition *ot; - DCAST_INTO_R(ot, other, false); - return (int)(_value - ot->_value); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -void TextureTransition:: -output_value(ostream &out) const { - nassertv(_value != (Texture *)NULL); - out << *_value; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -void TextureTransition:: -write_value(ostream &out, int indent_level) const { - nassertv(_value != (Texture *)NULL); - indent(out, indent_level) << *_value << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureTransition::register_with_read_factory -// Access: Public, Static -// Description: Factory method to generate a TextureTransition object -//////////////////////////////////////////////////////////////////// -void TextureTransition:: -register_with_read_factory() { - BamReader::get_factory()->register_factory(get_class_type(), make_TextureTransition); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureTransition::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void TextureTransition:: -write_datagram(BamWriter *manager, Datagram &me) { - OnOffTransition::write_datagram(manager, me); - manager->write_pointer(me, _value); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureTransition::complete_pointers -// Access: Public -// Description: Takes in a vector of pointes to TypedWritable -// objects that correspond to all the requests for -// pointers that this object made to BamReader. -//////////////////////////////////////////////////////////////////// -int TextureTransition:: -complete_pointers(TypedWritable **p_list, BamReader *) { - if (p_list[0] == TypedWritable::Null) { - if (sgattrib_cat.is_debug()) { - sgattrib_cat->debug() - << get_type().get_name() << " received null Texture," - << " turning off" << endl; - } - _value = (Texture *)NULL; - set_off(); - - } else { - _value = DCAST(Texture, p_list[0]); - } - - return 1; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureTransition::make_TextureTransition -// Access: Protected -// Description: Factory method to generate a TextureTransition object -//////////////////////////////////////////////////////////////////// -TypedWritable* TextureTransition:: -make_TextureTransition(const FactoryParams ¶ms) { - TextureTransition *me = new TextureTransition; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextureTransition::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void TextureTransition:: -fillin(DatagramIterator& scan, BamReader* manager) { - OnOffTransition::fillin(scan, manager); - manager->read_pointer(scan); -} diff --git a/panda/src/sgattrib/textureTransition.h b/panda/src/sgattrib/textureTransition.h deleted file mode 100644 index 26a53c163e..0000000000 --- a/panda/src/sgattrib/textureTransition.h +++ /dev/null @@ -1,100 +0,0 @@ -// Filename: textureTransition.h -// Created by: drose (18Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef TEXTURETRANSITION_H -#define TEXTURETRANSITION_H - -#include - -#include -#include - -//////////////////////////////////////////////////////////////////// -// Class : TextureTransition -// Description : This controls the assignment of the primary texture -// to a piece of geometry. If there is no -// TextureTransition or the transition is off, the -// geometry is rendered untextured; if there is an 'on' -// TextureTransition affecting a piece of geometry it -// will be rendered with the indicated texture. -// -// At one time this was a MultiTransition because we -// were thinking of using this interface to support -// multitexturing. But on reflection that is a flawed -// idea because MultiTransitions don't support any -// ordering, and we don't yet have an interface for -// specifying multiple layers of UV coordinates anyway. -// Until this is fully worked out, this will be a simple -// OnOffTransition: either there is a texture or there -// isn't. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA TextureTransition : public OnOffTransition { -public: - INLINE TextureTransition(); - INLINE TextureTransition(Texture *texture); - INLINE static TextureTransition off(); - - INLINE void set_on(Texture *texture); - INLINE PT(Texture) get_texture() const; - - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual void set_value_from(const OnOffTransition *other); - virtual int compare_values(const OnOffTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - PT(Texture) _value; - static PT(NodeTransition) _initial; - -public: - static void register_with_read_factory(); - virtual void write_datagram(BamWriter *manager, Datagram &me); - virtual int complete_pointers(TypedWritable **plist, - BamReader *manager); - -protected: - static TypedWritable *make_TextureTransition(const FactoryParams ¶ms); - 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() { - OnOffTransition::init_type(); - register_type(_type_handle, "TextureTransition", - OnOffTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "textureTransition.I" - -#endif diff --git a/panda/src/sgattrib/transformTransition.I b/panda/src/sgattrib/transformTransition.I deleted file mode 100644 index 131d997f1e..0000000000 --- a/panda/src/sgattrib/transformTransition.I +++ /dev/null @@ -1,38 +0,0 @@ -// Filename: transformTransition.I -// Created by: drose (24Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: TransformTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TransformTransition:: -TransformTransition() { -} - -//////////////////////////////////////////////////////////////////// -// Function: TransformTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TransformTransition:: -TransformTransition(const LMatrix4f &matrix) : - LMatrix4fTransition(matrix) -{ -} - diff --git a/panda/src/sgattrib/transformTransition.cxx b/panda/src/sgattrib/transformTransition.cxx deleted file mode 100644 index efd38dede6..0000000000 --- a/panda/src/sgattrib/transformTransition.cxx +++ /dev/null @@ -1,104 +0,0 @@ -// Filename: transformTransition.cxx -// Created by: drose (24Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "transformTransition.h" - -#include -#include -#include -#include -#include - -PT(NodeTransition) TransformTransition::_initial; -TypeHandle TransformTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: TransformTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated TransformTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *TransformTransition:: -make_copy() const { - return new TransformTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: TransformTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated TransformTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *TransformTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new TransformTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: TransformTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void TransformTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_transform(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: TransformTransition::make_with_matrix -// Access: Protected, Virtual -// Description: Returns a new transition with the indicated matrix. -//////////////////////////////////////////////////////////////////// -MatrixTransition *TransformTransition:: -make_with_matrix(const LMatrix4f &matrix) const { - return new TransformTransition(matrix); -} - -//////////////////////////////////////////////////////////////////// -// Function: TransformTransition::make_TransformTransition -// Access: Protected -// Description: Factory method to generate a TransformTransition object -//////////////////////////////////////////////////////////////////// -TypedWritable* TransformTransition:: -make_TransformTransition(const FactoryParams ¶ms) -{ - TransformTransition *me = new TransformTransition; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: TransformTransition::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a TransformTransition object -//////////////////////////////////////////////////////////////////// -void TransformTransition:: -register_with_read_factory(void) -{ - BamReader::get_factory()->register_factory(get_class_type(), make_TransformTransition); -} diff --git a/panda/src/sgattrib/transformTransition.h b/panda/src/sgattrib/transformTransition.h deleted file mode 100644 index dea1adaa21..0000000000 --- a/panda/src/sgattrib/transformTransition.h +++ /dev/null @@ -1,75 +0,0 @@ -// Filename: transformTransition.h -// Created by: drose (24Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef TRANSFORMTRANSITION_H -#define TRANSFORMTRANSITION_H - -#include - -#include -#include - -//////////////////////////////////////////////////////////////////// -// Class : TransformTransition -// Description : This defines a new coordinate system. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA TransformTransition : public LMatrix4fTransition { -public: - INLINE TransformTransition(); - INLINE TransformTransition(const LMatrix4f &matrix); - - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual MatrixTransition * - make_with_matrix(const LMatrix4f &matrix) const; - -private: - static PT(NodeTransition) _initial; - -public: - static void register_with_read_factory(void); - - static TypedWritable *make_TransformTransition(const FactoryParams ¶ms); - -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() { - LMatrix4fTransition::init_type(); - register_type(_type_handle, "TransformTransition", - LMatrix4fTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "transformTransition.I" - -#endif - - diff --git a/panda/src/sgattrib/transparencyProperty.I b/panda/src/sgattrib/transparencyProperty.I deleted file mode 100644 index f818ce6f53..0000000000 --- a/panda/src/sgattrib/transparencyProperty.I +++ /dev/null @@ -1,72 +0,0 @@ -// Filename: transparencyProperty.I -// Created by: drose (24Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyProperty::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TransparencyProperty:: -TransparencyProperty(TransparencyProperty::Mode mode) : - _mode(mode) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyProperty::Constructor -// Access: Public -// Description: This should only be called in the Protected -// constructor of TransparencyTransition. It is made -// public, only for that to access, and is necessary -// for creating an object in make_TransparencyTransition -// before any information has been read -//////////////////////////////////////////////////////////////////// -INLINE TransparencyProperty:: -TransparencyProperty(void) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyProperty::set_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TransparencyProperty:: -set_mode(TransparencyProperty::Mode mode) { - _mode = mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyProperty::get_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TransparencyProperty::Mode TransparencyProperty:: -get_mode() const { - return _mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyProperty::compare_to -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE int TransparencyProperty:: -compare_to(const TransparencyProperty &other) const { - return (int)_mode - (int)other._mode; -} diff --git a/panda/src/sgattrib/transparencyProperty.cxx b/panda/src/sgattrib/transparencyProperty.cxx deleted file mode 100644 index e06a29e794..0000000000 --- a/panda/src/sgattrib/transparencyProperty.cxx +++ /dev/null @@ -1,81 +0,0 @@ -// Filename: transparencyProperty.cxx -// Created by: drose (24Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "transparencyProperty.h" -#include -#include - -ostream & -operator << (ostream &out, TransparencyProperty::Mode mode) { - switch (mode) { - case TransparencyProperty::M_none: - return out << "none"; - - case TransparencyProperty::M_alpha: - return out << "alpha"; - - case TransparencyProperty::M_alpha_sorted: - return out << "alpha sorted"; - - case TransparencyProperty::M_multisample: - return out << "multisample"; - - case TransparencyProperty::M_multisample_mask: - return out << "multisample mask"; - - case TransparencyProperty::M_binary: - return out << "binary"; - } - - return out << "**invalid**(" << (int)mode << ")"; -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyProperty::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void TransparencyProperty:: -output(ostream &out) const { - out << _mode; -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyProperty::write_datagram -// Access: Public -// Description: Function to write the important information in -// this object to a Datagram -//////////////////////////////////////////////////////////////////// -void TransparencyProperty:: -write_datagram(Datagram &destination) -{ - destination.add_uint8(_mode); -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyProperty::read_datagram -// Access: Public -// Description: Function to write the important information into -// this object out of a Datagram -//////////////////////////////////////////////////////////////////// -void TransparencyProperty:: -read_datagram(DatagramIterator &source) -{ - _mode = (enum Mode) source.get_uint8(); -} - diff --git a/panda/src/sgattrib/transparencyProperty.h b/panda/src/sgattrib/transparencyProperty.h deleted file mode 100644 index ceadc5e81b..0000000000 --- a/panda/src/sgattrib/transparencyProperty.h +++ /dev/null @@ -1,70 +0,0 @@ -// Filename: transparencyProperty.h -// Created by: drose (24Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef TRANSPARENCYPROPERTY_H -#define TRANSPARENCYPROPERTY_H - -#include - -class Datagram; -class DatagramIterator; - -//////////////////////////////////////////////////////////////////// -// Class : TransparencyProperty -// Description : This defines the types of transparency that can be -// enabled. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA TransparencyProperty { -public: - enum Mode { - M_none, // No transparency in effect. - M_alpha, // Writes to depth buffer of transp objects disabled - M_alpha_sorted, // Assumes transp objects are depth sorted - M_multisample, // Source alpha values modified to 1.0 before writing - M_multisample_mask, // Source alpha values not modified - M_binary, // Only writes pixels with alpha = 1.0 - }; - -public: - INLINE TransparencyProperty(Mode mode); - INLINE TransparencyProperty(void); - - INLINE void set_mode(Mode mode); - INLINE Mode get_mode() const; - - INLINE int compare_to(const TransparencyProperty &other) const; - void output(ostream &out) const; - -public: - void write_datagram(Datagram &destination); - void read_datagram(DatagramIterator &source); - -private: - Mode _mode; -}; - -ostream &operator << (ostream &out, TransparencyProperty::Mode mode); - -INLINE ostream &operator << (ostream &out, const TransparencyProperty &prop) { - prop.output(out); - return out; -} - -#include "transparencyProperty.I" - -#endif diff --git a/panda/src/sgattrib/transparencyTransition.I b/panda/src/sgattrib/transparencyTransition.I deleted file mode 100644 index 6dd36d245b..0000000000 --- a/panda/src/sgattrib/transparencyTransition.I +++ /dev/null @@ -1,49 +0,0 @@ -// Filename: transparencyTransition.I -// Created by: drose (24Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyTransition::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TransparencyTransition:: -TransparencyTransition(TransparencyProperty::Mode mode) : - _value(mode) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyTransition::set_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TransparencyTransition:: -set_mode(TransparencyProperty::Mode mode) { - _value.set_mode(mode); - state_changed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyTransition::get_mode -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TransparencyProperty::Mode TransparencyTransition:: -get_mode() const { - return _value.get_mode(); -} diff --git a/panda/src/sgattrib/transparencyTransition.cxx b/panda/src/sgattrib/transparencyTransition.cxx deleted file mode 100644 index b65a0b0599..0000000000 --- a/panda/src/sgattrib/transparencyTransition.cxx +++ /dev/null @@ -1,170 +0,0 @@ -// Filename: transparencyTransition.cxx -// Created by: mike (28Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "transparencyTransition.h" - -#include -#include -#include -#include -#include - -PT(NodeTransition) TransparencyTransition::_initial; -TypeHandle TransparencyTransition::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyTransition::make_copy -// Access: Public, Virtual -// Description: Returns a newly allocated TransparencyTransition just like -// this one. -//////////////////////////////////////////////////////////////////// -NodeTransition *TransparencyTransition:: -make_copy() const { - return new TransparencyTransition(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyTransition::make_initial -// Access: Public, Virtual -// Description: Returns a newly allocated TransparencyTransition -// corresponding to the default initial state. -//////////////////////////////////////////////////////////////////// -NodeTransition *TransparencyTransition:: -make_initial() const { - if (_initial.is_null()) { - _initial = new TransparencyTransition; - } - return _initial; -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyTransition::issue -// Access: Public, Virtual -// Description: This is called on scene graph rendering attributes -// when it is time to issue the particular attribute to -// the graphics engine. It should call the appropriate -// method on GraphicsStateGuardianBase. -//////////////////////////////////////////////////////////////////// -void TransparencyTransition:: -issue(GraphicsStateGuardianBase *gsgbase) { - gsgbase->issue_transparency(this); -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyTransition::set_value_from -// Access: Protected, Virtual -// Description: Copies the value from the other transition pointer, -// which is guaranteed to be another TransparencyTransition. -//////////////////////////////////////////////////////////////////// -void TransparencyTransition:: -set_value_from(const OnTransition *other) { - const TransparencyTransition *ot; - DCAST_INTO_V(ot, other); - _value = ot->_value; -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyTransition::compare_values -// Access: Protected, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -int TransparencyTransition:: -compare_values(const OnTransition *other) const { - const TransparencyTransition *ot; - DCAST_INTO_R(ot, other, false); - return _value.compare_to(ot->_value); -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyTransition::output_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on one line. -//////////////////////////////////////////////////////////////////// -void TransparencyTransition:: -output_value(ostream &out) const { - out << _value; -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyTransition::write_value -// Access: Protected, Virtual -// Description: Formats the value for human consumption on multiple -// lines if necessary. -//////////////////////////////////////////////////////////////////// -void TransparencyTransition:: -write_value(ostream &out, int indent_level) const { - indent(out, indent_level) << _value << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyTransition::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void TransparencyTransition:: -write_datagram(BamWriter *manager, Datagram &me) -{ - OnTransition::write_datagram(manager, me); - _value.write_datagram(me); -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyTransition::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void TransparencyTransition:: -fillin(DatagramIterator& scan, BamReader* manager) -{ - OnTransition::fillin(scan, manager); - _value.read_datagram(scan); -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyTransition::make_TransparencyTransition -// Access: Protected -// Description: Factory method to generate a TransparencyTransition object -//////////////////////////////////////////////////////////////////// -TypedWritable* TransparencyTransition:: -make_TransparencyTransition(const FactoryParams ¶ms) -{ - TransparencyTransition *me = new TransparencyTransition; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: TransparencyTransition::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a TransparencyTransition object -//////////////////////////////////////////////////////////////////// -void TransparencyTransition:: -register_with_read_factory(void) -{ - BamReader::get_factory()->register_factory(get_class_type(), make_TransparencyTransition); -} - - diff --git a/panda/src/sgattrib/transparencyTransition.h b/panda/src/sgattrib/transparencyTransition.h deleted file mode 100644 index c688f79f60..0000000000 --- a/panda/src/sgattrib/transparencyTransition.h +++ /dev/null @@ -1,92 +0,0 @@ -// Filename: transparencyTransition.h -// Created by: mike (18Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef TRANSPARENCYTRANSITION_H -#define TRANSPARENCYTRANSITION_H - -#include - -#include "transparencyProperty.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : TransparencyTransition -// Description : This controls the enabling of transparency. Simply -// setting an alpha component to non-1 does not in -// itself make an object transparent; you must also -// enable transparency mode with a suitable -// TransparencyTransition. Similarly, it is wasteful to -// render an object with a TransparencyTransition in -// effect unless you actually want it to be at least -// partially transparent (and it has alpha components -// less than 1). -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA TransparencyTransition : public OnTransition { -PUBLISHED: - INLINE TransparencyTransition(TransparencyProperty::Mode mode = TransparencyProperty::M_none); - - INLINE void set_mode(TransparencyProperty::Mode mode); - INLINE TransparencyProperty::Mode get_mode() const; - -public: - virtual NodeTransition *make_copy() const; - virtual NodeTransition *make_initial() const; - - virtual void issue(GraphicsStateGuardianBase *gsgbase); - -protected: - virtual void set_value_from(const OnTransition *other); - virtual int compare_values(const OnTransition *other) const; - virtual void output_value(ostream &out) const; - virtual void write_value(ostream &out, int indent_level) const; - -private: - TransparencyProperty _value; - static PT(NodeTransition) _initial; - -public: - static void register_with_read_factory(void); - virtual void write_datagram(BamWriter* manager, Datagram &me); - - static TypedWritable *make_TransparencyTransition(const FactoryParams ¶ms); - -protected: - 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() { - OnTransition::init_type(); - register_type(_type_handle, "TransparencyTransition", - OnTransition::get_class_type()); - } - -private: - static TypeHandle _type_handle; -}; - -#include "transparencyTransition.I" - -#endif diff --git a/panda/src/sgmanip/Sources.pp b/panda/src/sgmanip/Sources.pp deleted file mode 100644 index 407a0c2534..0000000000 --- a/panda/src/sgmanip/Sources.pp +++ /dev/null @@ -1,38 +0,0 @@ -#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \ - dtoolutil:c dtoolbase:c dtool:m - -#begin lib_target - #define TARGET sgmanip - #define LOCAL_LIBS \ - cull dgraph loader sgraphutil sgattrib sgraph linmath lerp - - #define COMBINED_SOURCES $[TARGET]_composite1.cxx - - #define SOURCES \ - config_sgmanip.h findApproxLevel.I findApproxLevel.h \ - findApproxPath.I findApproxPath.h nodePath.I nodePath.h \ - nodePathCollection.I \ - nodePathCollection.h nodePathLerps.h nodePath.cxx - - #define INCLUDED_SOURCES \ - config_sgmanip.cxx findApproxLevel.cxx findApproxPath.cxx \ - nodePathCollection.cxx nodePathLerps.cxx - - #define INSTALL_HEADERS \ - nodePath.I nodePath.h \ - nodePathCollection.I nodePathCollection.h - - #define IGATESCAN all - -#end lib_target - -#begin test_bin_target - #define TARGET test_sgmanip - #define LOCAL_LIBS \ - sgmanip - - #define SOURCES \ - test_sgmanip.cxx - -#end test_bin_target - diff --git a/panda/src/sgmanip/config_sgmanip.cxx b/panda/src/sgmanip/config_sgmanip.cxx deleted file mode 100644 index bd2f8967ee..0000000000 --- a/panda/src/sgmanip/config_sgmanip.cxx +++ /dev/null @@ -1,46 +0,0 @@ -// Filename: config_sgmanip.cxx -// Created by: drose (05Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "config_sgmanip.h" - -#include - -#include "nodePath.h" -#include "nodePathLerps.h" - -Configure(config_sgmanip); -NotifyCategoryDef(sgmanip, ""); - -// Set this to true to generate an assertion failure whenever you -// first attempt to apply a singular transform matrix to the scene -// graph, or false to ignore this. The default is true, which makes -// it much easier to track down singular matrix errors. In NDEBUG -// mode, this is ignored and is effectively always false. -const bool check_singular_transform = config_sgmanip.GetBool("check-singular-transform", true); - -ConfigureFn(config_sgmanip) { - NodePath::init_type(); - PosLerpFunctor::init_type(); - HprLerpFunctor::init_type(); - ScaleLerpFunctor::init_type(); - PosHprLerpFunctor::init_type(); - HprScaleLerpFunctor::init_type(); - PosHprScaleLerpFunctor::init_type(); - ColorLerpFunctor::init_type(); - ColorScaleLerpFunctor::init_type(); -} diff --git a/panda/src/sgmanip/config_sgmanip.h b/panda/src/sgmanip/config_sgmanip.h deleted file mode 100644 index ee5c79c305..0000000000 --- a/panda/src/sgmanip/config_sgmanip.h +++ /dev/null @@ -1,31 +0,0 @@ -// Filename: config_sgmanip.h -// Created by: drose (05Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CONFIG_SGMANIP_H -#define CONFIG_SGMANIP_H - -#include - -#include - -NotifyCategoryDecl(sgmanip, EXPCL_PANDA, EXPTP_PANDA); - -// Configure variables for sgmanip package. -extern const bool EXPCL_PANDA check_singular_transform; - -#endif diff --git a/panda/src/sgmanip/findApproxLevel.I b/panda/src/sgmanip/findApproxLevel.I deleted file mode 100644 index 827b8ddfb0..0000000000 --- a/panda/src/sgmanip/findApproxLevel.I +++ /dev/null @@ -1,92 +0,0 @@ -// Filename: findApproxLevel.I -// Created by: drose (18Feb00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxLevelEntry::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE FindApproxLevelEntry:: -FindApproxLevelEntry(const NodePath &node_path, FindApproxPath &approx_path) : - _node_path(node_path), - _approx_path(approx_path) -{ - _i = 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxLevelEntry::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE FindApproxLevelEntry:: -FindApproxLevelEntry(const FindApproxLevelEntry ©) : - _node_path(copy._node_path), - _i(copy._i), - _approx_path(copy._approx_path) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxLevelEntry::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void FindApproxLevelEntry:: -operator = (const FindApproxLevelEntry ©) { - _node_path = copy._node_path; - _i = copy._i; - nassertv(&_approx_path == ©._approx_path); -} - - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxLevelEntry::next_is_stashed -// Access: Public -// Description: Returns true if the next node matched by this entry -// must be a stashed node, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool FindApproxLevelEntry:: -next_is_stashed() const { - return _approx_path.matches_stashed(_i); -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxLevelEntry::is_solution -// Access: Public -// Description: Returns true if this entry represents a solution to -// the search; i.e. all the components of the path have -// been successfully matched. -//////////////////////////////////////////////////////////////////// -INLINE bool FindApproxLevelEntry:: -is_solution() const { - return (_i >= _approx_path.get_num_components()); -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxLevel::add_entry -// Access: Public -// Description: Adds a new entry to the level. -//////////////////////////////////////////////////////////////////// -INLINE void FindApproxLevel:: -add_entry(const FindApproxLevelEntry &entry) { - _v.push_back(entry); -} - diff --git a/panda/src/sgmanip/findApproxLevel.cxx b/panda/src/sgmanip/findApproxLevel.cxx deleted file mode 100644 index 074f4a1b32..0000000000 --- a/panda/src/sgmanip/findApproxLevel.cxx +++ /dev/null @@ -1,173 +0,0 @@ -// Filename: findApproxLevel.cxx -// Created by: drose (18Feb00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "findApproxLevel.h" -#include "nodePathCollection.h" - -#include -#include -#include -#include - - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxLevelEntry::output -// Access: Public -// Description: Formats the entry for meaningful output. For -// debugging only. -//////////////////////////////////////////////////////////////////// -void FindApproxLevelEntry:: -output(ostream &out) const { - out << "(" << _node_path << "):"; - if (is_solution()) { - out << " solution!"; - } else { - out << "("; - _approx_path.output_component(out, _i); - out << ")," << _i; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxLevelEntry::consider_node -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void FindApproxLevelEntry:: -consider_node(NodePathCollection &result, FindApproxLevel &next_level, - int max_matches, TypeHandle graph_type) const { - nassertv(_i < _approx_path.get_num_components()); - - if (_approx_path.is_component_match_many(_i)) { - // Match any number, zero or more, levels of nodes. This is the - // tricky case that requires this whole nutty breadth-first thing. - - // This means we must reconsider our own entry with the next path - // entry, before we consider the next entry--this supports - // matching zero levels of nodes. - FindApproxLevelEntry reconsider(*this); - ++reconsider._i; - - if (reconsider.is_solution()) { - // Does this now represent a solution? - result.add_path(reconsider._node_path); - if (max_matches > 0 && result.get_num_paths() >= max_matches) { - return; - } - } else { - reconsider.consider_node(result, next_level, max_matches, graph_type); - } - } - - Node *bottom_node = _node_path.node(); - nassertv(bottom_node != (Node *)NULL); - - TypeHandle next_graph_type = graph_type; - if (next_is_stashed()) { - next_graph_type = NodeRelation::get_stashed_type(); - } - - int num_children = bottom_node->get_num_children(next_graph_type); - for (int i = 0; i < num_children; i++) { - NodeRelation *child_arc = bottom_node->get_child(next_graph_type, i); - - consider_next_step(result, child_arc, next_level, max_matches, graph_type); - if (max_matches > 0 && result.get_num_paths() >= max_matches) { - return; - } - } - - if (_approx_path.return_stashed() && - next_graph_type != NodeRelation::get_stashed_type()) { - // If the approx path allows us to return stashed nodes, and we - // didn't just traverse the list of stashed nodes, then traverse - // them now. - next_graph_type = NodeRelation::get_stashed_type(); - - int num_children = bottom_node->get_num_children(next_graph_type); - for (int i = 0; i < num_children; i++) { - NodeRelation *child_arc = bottom_node->get_child(next_graph_type, i); - - consider_next_step(result, child_arc, next_level, max_matches, graph_type); - if (max_matches > 0 && result.get_num_paths() >= max_matches) { - return; - } - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxLevelEntry::consider_next_step -// Access: Public -// Description: Compares the indicated child node (which is assumed -// to be a child of _node, or a parent of _node if we -// happen to be searching upwards) with the next -// component of the path. If it matches, generates -// whatever additional entries are appropriate and -// stores them in next_level. -// -// If a complete solution is found, stores it in result. -//////////////////////////////////////////////////////////////////// -void FindApproxLevelEntry:: -consider_next_step(NodePathCollection &result, - NodeRelation *arc, FindApproxLevel &next_level, - int max_matches, TypeHandle graph_type) const { - if (!_approx_path.return_hidden() && - arc->has_transition(PruneTransition::get_class_type())) { - // If the approx path does not allow us to return hidden nodes, - // and this arc has indeed been hidden, then stop here. - return; - } - - nassertv(_i < _approx_path.get_num_components()); - - FindApproxLevelEntry next(*this); - bool eb = next._node_path.extend_by(arc); - nassertv(eb); - - if (_approx_path.is_component_match_many(_i)) { - // Match any number, zero or more, levels of nodes. This is the - // tricky case that requires this whole nutty breadth-first thing. - - // And now we just add the next entry without incrementing its - // path entry. - next_level.add_entry(next); - - } else { - if (_approx_path.matches_component(_i, arc)) { - // That matched, and it consumes one path entry. - ++next._i; - next_level.add_entry(next); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxLevel::write -// Access: Public -// Description: Shows the entire contents of the level, one entry per -// line. For debugging only. -//////////////////////////////////////////////////////////////////// -void FindApproxLevel:: -write(ostream &out) const { - Vec::const_iterator vi; - for (vi = _v.begin(); vi != _v.end(); ++vi) { - (*vi).output(out); - out << "\n"; - } -} diff --git a/panda/src/sgmanip/findApproxLevel.h b/panda/src/sgmanip/findApproxLevel.h deleted file mode 100644 index 99b856c08c..0000000000 --- a/panda/src/sgmanip/findApproxLevel.h +++ /dev/null @@ -1,96 +0,0 @@ -// Filename: findApproxLevel.h -// Created by: drose (18Feb00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef FINDAPPROXLEVEL_H -#define FINDAPPROXLEVEL_H - -#include - -#include "findApproxPath.h" -#include "nodePath.h" - -#include - -class Node; -class FindApproxLevel; -class NodeFinder; -class NodePathCollection; - -//////////////////////////////////////////////////////////////////// -// Class : FindApproxLevelEntry -// Description : This class is local to this package only; it doesn't -// get exported. It represents a single node under -// consideration for matching at a single point in the -// breadth-first search. -//////////////////////////////////////////////////////////////////// -class FindApproxLevelEntry { -public: - INLINE FindApproxLevelEntry(const NodePath &node_path, - FindApproxPath &approx_path); - INLINE FindApproxLevelEntry(const FindApproxLevelEntry ©); - INLINE void operator = (const FindApproxLevelEntry ©); - - INLINE bool next_is_stashed() const; - - void consider_node(NodePathCollection &result, FindApproxLevel &next_level, - int max_matches, TypeHandle graph_type) const; - void consider_next_step(NodePathCollection &result, - NodeRelation *arc, FindApproxLevel &next_level, - int max_matches, TypeHandle graph_type) const; - INLINE bool is_solution() const; - - void output(ostream &out) const; - - // _node_path represents the most recent node that we have - // previously accepted as being a partial solution. - NodePath _node_path; - - // _i represents the next component in the approx_path that must be - // matched against all of the children of _node_path, above. If _i - // refers to the end of the approx_path, then _node_path is a - // solution. - int _i; - FindApproxPath &_approx_path; -}; - -INLINE ostream & -operator << (ostream &out, const FindApproxLevelEntry &entry) { - entry.output(out); - return out; -} - -//////////////////////////////////////////////////////////////////// -// Class : FindApproxLevel -// Description : This class is local to this package only; it doesn't -// get exported. It maintains the list of nodes -// find_approx() considers for each level of the scene -// graph it visits, in its breadth-first search. -//////////////////////////////////////////////////////////////////// -class FindApproxLevel { -public: - INLINE void add_entry(const FindApproxLevelEntry &entry); - - void write(ostream &out) const; - - typedef pvector Vec; - Vec _v; -}; - -#include "findApproxLevel.I" - -#endif diff --git a/panda/src/sgmanip/findApproxPath.I b/panda/src/sgmanip/findApproxPath.I deleted file mode 100644 index f1745a5338..0000000000 --- a/panda/src/sgmanip/findApproxPath.I +++ /dev/null @@ -1,216 +0,0 @@ -// Filename: findApproxPath.I -// Created by: drose (06Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE FindApproxPath:: -FindApproxPath() { - _return_hidden = true; - _return_stashed = false; -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::add_match_name -// Access: Public -// Description: Adds a component that must match the name of a node -// exactly. -//////////////////////////////////////////////////////////////////// -INLINE void FindApproxPath:: -add_match_name(const string &name, int flags) { - Component comp; - comp._type = CT_match_name; - comp._name = name; - comp._flags = flags; - _path.push_back(comp); -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::add_match_name_glob -// Access: Public -// Description: Adds a component that must match the name of a node -// using standard shell globbing rules, with wildcard -// characters accepted. -//////////////////////////////////////////////////////////////////// -INLINE void FindApproxPath:: -add_match_name_glob(const string &name, int flags) { - Component comp; - comp._type = CT_match_name_glob; - comp._name = name; - comp._flags = flags; - _path.push_back(comp); -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::add_match_exact_type -// Access: Public -// Description: Adds a component that must match the type of a node -// exactly, with no derived types matching. -//////////////////////////////////////////////////////////////////// -INLINE void FindApproxPath:: -add_match_exact_type(TypeHandle type, int flags) { - Component comp; - comp._type = CT_match_exact_type; - comp._type_handle = type; - comp._flags = flags; - _path.push_back(comp); -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::add_match_inexact_type -// Access: Public -// Description: Adds a component that must match the type of a node -// or be a base class of the node's type. -//////////////////////////////////////////////////////////////////// -INLINE void FindApproxPath:: -add_match_inexact_type(TypeHandle type, int flags) { - Component comp; - comp._type = CT_match_inexact_type; - comp._type_handle = type; - comp._flags = flags; - _path.push_back(comp); -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::add_match_one -// Access: Public -// Description: Adds a component that will match any node (but not a -// chain of many nodes). -//////////////////////////////////////////////////////////////////// -INLINE void FindApproxPath:: -add_match_one(int flags) { - Component comp; - comp._type = CT_match_one; - comp._flags = flags; - _path.push_back(comp); -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::add_match_many -// Access: Public -// Description: Adds a component that will match a chain of zero or -// more consecutive nodes. -//////////////////////////////////////////////////////////////////// -INLINE void FindApproxPath:: -add_match_many(int flags) { - Component comp; - comp._type = CT_match_many; - comp._flags = flags; - _path.push_back(comp); -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::add_match_pointer -// Access: Public -// Description: Adds a component that must match a particular node -// exactly, by pointer. -//////////////////////////////////////////////////////////////////// -INLINE void FindApproxPath:: -add_match_pointer(Node *pointer, int flags) { - Component comp; - comp._type = CT_match_pointer; - comp._pointer = pointer; - comp._flags = flags; - _path.push_back(comp); -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::get_num_components -// Access: Public -// Description: Returns the number of components in the path. -//////////////////////////////////////////////////////////////////// -INLINE int FindApproxPath:: -get_num_components() const { - return _path.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::is_component_match_many -// Access: Public -// Description: Returns true if the nth component is of type -// match_many, which will require special handling. -//////////////////////////////////////////////////////////////////// -INLINE bool FindApproxPath:: -is_component_match_many(int index) const { - nassertr(index >= 0 && index < (int)_path.size(), false); - return (_path[index]._type == CT_match_many); -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::matches_component -// Access: Public -// Description: Returns true if the nth component of the path matches -// the indicated node, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool FindApproxPath:: -matches_component(int index, NodeRelation *arc) const { - nassertr(index >= 0 && index < (int)_path.size(), false); - return (_path[index].matches(arc)); -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::matches_stashed -// Access: Public -// Description: Returns true if the nth component of the path matches -// a stashed node only, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool FindApproxPath:: -matches_stashed(int index) const { - if (index >= 0 && index < (int)_path.size()) { - return ((_path[index]._flags & CF_stashed) != 0); - } else { - return false; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::return_hidden -// Access: Public -// Description: Returns true if this path allows returning of hidden -// nodes, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool FindApproxPath:: -return_hidden() const { - return _return_hidden; -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::return_stashed -// Access: Public -// Description: Returns true if this path allows returning of stashed -// nodes, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool FindApproxPath:: -return_stashed() const { - return _return_stashed; -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::output_component -// Access: Public -// Description: Formats the nth component of the path to the -// indicated output stream. -//////////////////////////////////////////////////////////////////// -INLINE void FindApproxPath:: -output_component(ostream &out, int index) const { - nassertv(index >= 0 && index < (int)_path.size()); - out << _path[index]; -} diff --git a/panda/src/sgmanip/findApproxPath.cxx b/panda/src/sgmanip/findApproxPath.cxx deleted file mode 100644 index 667d540095..0000000000 --- a/panda/src/sgmanip/findApproxPath.cxx +++ /dev/null @@ -1,303 +0,0 @@ -// Filename: findApproxPath.cxx -// Created by: drose (18Feb00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "findApproxPath.h" -#include "config_sgmanip.h" - -#include -#include -#include -#include - - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::Component::matches -// Access: Public -// Description: Returns true if the indicated node matches this -// component, false otherwise. -//////////////////////////////////////////////////////////////////// -bool FindApproxPath::Component:: -matches(NodeRelation *arc) const { - Node *node = arc->get_child(); - string node_name; - - switch (_type) { - case CT_match_name: - // Match the node's name exactly. - if (node->is_of_type(NamedNode::get_class_type())) { - node_name = DCAST(NamedNode, node)->get_name(); - } - return (_name == node_name); - - case CT_match_name_glob: - // Match the node's name according to filename globbing rules. - if (node->is_of_type(NamedNode::get_class_type())) { - node_name = DCAST(NamedNode, node)->get_name(); - } - { - GlobPattern pattern(_name); - return (pattern.matches(node_name)); - } - - case CT_match_exact_type: - // Match the node's type exactly. - return (node->is_exact_type(_type_handle)); - - case CT_match_inexact_type: - // Match the node's type inexactly: it's a match if the node - // is the type, or is derived from the type. - return (node->is_of_type(_type_handle)); - - case CT_match_one: - case CT_match_many: - // Match any node. - return true; - - case CT_match_pointer: - // Match only this one particular node. - return (_pointer == node); - } - - sgmanip_cat.error() - << "Invalid component in FindApproxPath\n"; - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::Component::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void FindApproxPath::Component:: -output(ostream &out) const { - out << _type; - if (_type == CT_match_name || _type == CT_match_name_glob) { - out << " \"" << _name << "\""; - - } else if (_type == CT_match_exact_type || _type == CT_match_inexact_type) { - out << " " << _type_handle; - - } else if (_type == CT_match_pointer) { - out << " (" << *_pointer << ")"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::add_string -// Access: Public -// Description: Adds a sequence of components separated by slashes, -// followed optionally by a semicolon and a sequence of -// control flags, to the path sequence. Returns true if -// successful, false if the string contained an error. -//////////////////////////////////////////////////////////////////// -bool FindApproxPath:: -add_string(const string &str_path) { - size_t start = 0; - size_t slash = str_path.find('/'); - while (slash != string::npos) { - if (!add_component(str_path.substr(start, slash - start))) { - return false; - } - start = slash + 1; - slash = str_path.find('/', start); - } - - size_t semicolon = str_path.rfind(';'); - - // We want to find the *last* semicolon at start or later, if there - // happens to be more than one. rfind will find the rightmost - // semicolon in the entire string; if this is less than start, there - // is no semicolon right of start. - if (semicolon < start) { - semicolon = string::npos; - } - - if (!add_component(str_path.substr(start, semicolon - start))) { - return false; - } - - if (semicolon != string::npos) { - return add_flags(str_path.substr(semicolon + 1)); - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::add_flags -// Access: Public -// Description: Adds a sequence of control flags. This will be a -// sequence of letters preceded by either '+' or '-', -// with no intervening punctuation. Returns true if -// successful, false otherwise. -//////////////////////////////////////////////////////////////////// -bool FindApproxPath:: -add_flags(const string &str_flags) { - string::const_iterator pi = str_flags.begin(); - while (pi != str_flags.end()) { - bool on; - switch (*pi) { - case '+': - on = true; - break; - case '-': - on = false; - break; - default: - sgmanip_cat.error() - << "Invalid control flag string: " << str_flags << "\n"; - return false; - } - - ++pi; - if (pi == str_flags.end()) { - sgmanip_cat.error() - << "Invalid control flag string: " << str_flags << "\n"; - return false; - } - - switch (*pi) { - case 'h': - _return_hidden = on; - break; - - case 's': - _return_stashed = on; - break; - - default: - sgmanip_cat.error() - << "Invalid control flag string: " << str_flags << "\n"; - return false; - } - - ++pi; - } - - return true; -} - - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::add_component -// Access: Public -// Description: Adds a single component to the path sequence, defined -// by a string as might appear between slashes in the -// path string. Returns true if successful, false if -// the string component was in some way invalid. -//////////////////////////////////////////////////////////////////// -bool FindApproxPath:: -add_component(string str_component) { - int flags = 0; - if (str_component.size() >= 2 && str_component.substr(0, 2) == "@@") { - flags |= CF_stashed; - str_component = str_component.substr(2); - } - - if (str_component == "*") { - add_match_one(flags); - - } else if (str_component == "**") { - if ((flags & CF_stashed) != 0) { - sgmanip_cat.error() - << "@@** is undefined; use @@*/** or **/@@* instead.\n"; - return false; - } - add_match_many(flags); - - } else if (!str_component.empty() && str_component[0] == '-') { - string type_name = str_component.substr(1); - TypeHandle handle = TypeRegistry::ptr()->find_type(type_name); - - if (handle == TypeHandle::none()) { - sgmanip_cat.error() - << "Invalid type name: " + type_name; - return false; - - } else { - add_match_exact_type(handle, flags); - } - - } else if (!str_component.empty() && str_component[0] == '+') { - string type_name = str_component.substr(1); - TypeHandle handle = TypeRegistry::ptr()->find_type(type_name); - - if (handle == TypeHandle::none()) { - sgmanip_cat.error() - << "Invalid type name: " + type_name; - return false; - - } else { - add_match_inexact_type(handle, flags); - } - - } else { - add_match_name_glob(str_component, flags); - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: FindApproxPath::output -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void FindApproxPath:: -output(ostream &out) const { - out << "("; - if (!_path.empty()) { - Path::const_iterator pi = _path.begin(); - out << *pi; - ++pi; - while (pi != _path.end()) { - out << " / " << *pi; - ++pi; - } - } - out << ")"; -} - -ostream & -operator << (ostream &out, FindApproxPath::ComponentType type) { - switch (type) { - case FindApproxPath::CT_match_name: - return out << "match_name"; - - case FindApproxPath::CT_match_name_glob: - return out << "match_name_glob"; - - case FindApproxPath::CT_match_exact_type: - return out << "match_exact_type"; - - case FindApproxPath::CT_match_inexact_type: - return out << "match_inexact_type"; - - case FindApproxPath::CT_match_one: - return out << "match_one"; - - case FindApproxPath::CT_match_many: - return out << "match_many"; - - case FindApproxPath::CT_match_pointer: - return out << "match_pointer"; - }; - - return out << "**invalid**"; -}; - diff --git a/panda/src/sgmanip/findApproxPath.h b/panda/src/sgmanip/findApproxPath.h deleted file mode 100644 index 333335518b..0000000000 --- a/panda/src/sgmanip/findApproxPath.h +++ /dev/null @@ -1,123 +0,0 @@ -// Filename: findApproxPath.h -// Created by: drose (18Feb00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef FINDAPPROXPATH_H -#define FINDAPPROXPATH_H - -#include - -#include - -#include -#include "pvector.h" - -class Node; -class NodeRelation; - -//////////////////////////////////////////////////////////////////// -// Class : FindApproxPath -// Description : This class is local to this package only; it doesn't -// get exported. It chops a string path, as supplied to -// find_up() or find_down(), and breaks it up into its -// component pieces. -//////////////////////////////////////////////////////////////////// -class FindApproxPath { -public: - INLINE FindApproxPath(); - - bool add_string(const string &str_path); - bool add_flags(const string &str_flags); - bool add_component(string str_component); - - INLINE void add_match_name(const string &name, int flags); - INLINE void add_match_name_glob(const string &glob, int flags); - INLINE void add_match_exact_type(TypeHandle type, int flags); - INLINE void add_match_inexact_type(TypeHandle type, int flags); - INLINE void add_match_one(int flags); - INLINE void add_match_many(int flags); - INLINE void add_match_pointer(Node *pointer, int flags); - - INLINE int get_num_components() const; - INLINE bool is_component_match_many(int index) const; - INLINE bool matches_component(int index, NodeRelation *arc) const; - INLINE bool matches_stashed(int index) const; - - INLINE bool return_hidden() const; - INLINE bool return_stashed() const; - - void output(ostream &out) const; - INLINE void output_component(ostream &out, int index) const; - -#ifndef WIN32_VC -// Visual C++ won't let us define the ostream operator functions for -// these guys if they're private--even though we declare them friends. -private: -#endif - enum ComponentType { - CT_match_name, - CT_match_name_glob, - CT_match_exact_type, - CT_match_inexact_type, - CT_match_one, - CT_match_many, - CT_match_pointer - }; - enum ComponentFlags { - CF_stashed = 0x001, - }; - - class Component { - public: - bool matches(NodeRelation *arc) const; - void output(ostream &out) const; - - ComponentType _type; - string _name; - TypeHandle _type_handle; - Node *_pointer; - int _flags; - }; - - typedef pvector Path; - Path _path; - - bool _return_hidden; - bool _return_stashed; - -friend ostream &operator << (ostream &, FindApproxPath::ComponentType); -friend INLINE ostream &operator << (ostream &, const FindApproxPath::Component &); -}; - -ostream & -operator << (ostream &out, FindApproxPath::ComponentType type); - -INLINE ostream & -operator << (ostream &out, const FindApproxPath::Component &component) { - component.output(out); - return out; -} - -INLINE ostream & -operator << (ostream &out, const FindApproxPath &path) { - path.output(out); - return out; -} - -#include "findApproxPath.I" - -#endif diff --git a/panda/src/sgmanip/nodePath.I b/panda/src/sgmanip/nodePath.I deleted file mode 100644 index bd1c981985..0000000000 --- a/panda/src/sgmanip/nodePath.I +++ /dev/null @@ -1,1557 +0,0 @@ -// Filename: nodePath.I -// Created by: drose (06Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::Default Constructor -// Access: Published -// Description: Creates an empty NodePath. This does not refer to -// any nodes, and is equivalent to a NULL Node pointer; -// it's an error to attempt to do any node operations on -// this object. -//////////////////////////////////////////////////////////////////// -INLINE NodePath:: -NodePath(TypeHandle graph_type) : - _graph_type(graph_type), - _error_type(ET_ok) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::Constructor -// Access: Published -// Description: Creates a NodePath that contains just one node: the -// top node. It's not yet much of a path, but it does -// reference at least the one node and can be used as an -// ordinary node pointer. -// -// If the Node pointer is NULL, this quietly creates an -// empty NodePath. -//////////////////////////////////////////////////////////////////// -INLINE NodePath:: -NodePath(Node *top_node, TypeHandle graph_type) : - ArcChain(top_node), - _graph_type(graph_type), - _error_type(ET_ok) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::Constructor -// Access: Published -// Description: Creates a NodePath that contains one arc, and the two -// Nodes connected to that arc. -// -// If the NodeRelation pointer is NULL, this quietly -// creates an empty NodePath. -//////////////////////////////////////////////////////////////////// -INLINE NodePath:: -NodePath(NodeRelation *arc) : - _graph_type(RenderRelation::get_class_type()), - _error_type(ET_ok) -{ - if (arc != (NodeRelation *)NULL) { - _graph_type = arc->get_type(); - extend_by(arc); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::Constructor -// Access: Published -// Description: This constructor creates a new NodePath given an -// ArcChain, which is a more primitive version of a -// NodePath. Some graph-traversal operations generate -// ArcChains, so it's useful to be able to use one of -// these to create a NodePath. -//////////////////////////////////////////////////////////////////// -INLINE NodePath:: -NodePath(const ArcChain &chain, TypeHandle graph_type) : - ArcChain(chain), - _graph_type(graph_type), - _error_type(ET_ok) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::Copy Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE NodePath:: -NodePath(const NodePath ©) : - ArcChain(copy), - _graph_type(copy._graph_type), - _error_type(copy._error_type) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::Copy Assignment Operator -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -operator = (const NodePath ©) { - ArcChain::operator = (copy); - _graph_type = copy._graph_type; - _error_type = copy._error_type; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::Destructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE NodePath:: -~NodePath() { -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::not_found named constructor -// Access: Published, Static -// Description: Creates a NodePath with the ET_not_found error type -// set. -//////////////////////////////////////////////////////////////////// -INLINE NodePath NodePath:: -not_found() { - NodePath result; - result._error_type = ET_not_found; - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::removed named constructor -// Access: Published, Static -// Description: Creates a NodePath with the ET_removed error type -// set. -//////////////////////////////////////////////////////////////////// -INLINE NodePath NodePath:: -removed() { - NodePath result; - result._error_type = ET_removed; - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::fail named constructor -// Access: Published, Static -// Description: Creates a NodePath with the ET_fail error type -// set. -//////////////////////////////////////////////////////////////////// -INLINE NodePath NodePath:: -fail() { - NodePath result; - result._error_type = ET_fail; - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::Equality Operator -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool NodePath:: -operator == (const NodePath &other) const { - return compare_to(other) == 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::Inequality Operator -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool NodePath:: -operator != (const NodePath &other) const { - return !operator == (other); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::compare_to -// Access: Published -// Description: Returns a number less than zero if this NodePath -// sorts before the indicated NodePath in an arbitrary -// lexicographical comparision, greater than zero if -// this one sorts after the other one, or zero if the -// two NodePaths are equivalent. -//////////////////////////////////////////////////////////////////// -INLINE int NodePath:: -compare_to(const NodePath &other) const { - if (is_empty() && other.is_empty()) { - return (int)get_error_type() - (int)other.get_error_type(); - } - return ArcChain::compare_to(other); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_graph_type -// Access: Published -// Description: Changes the type of graph that the NodePath will -// search for. By default, this is RenderRelation. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_graph_type(TypeHandle graph_type) { - _graph_type = graph_type; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_graph_type -// Access: Published -// Description: Returns the type of graph that the NodePath is -// currently set to. -//////////////////////////////////////////////////////////////////// -INLINE TypeHandle NodePath:: -get_graph_type() const { - return _graph_type; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_max_search_depth -// Access: Published, Static -// Description: Certain operations, such as extend_down_to() or -// find_all_matches(), require a traversal of the scene -// graph to search for the target node or nodes. This -// traversal does not attempt to detect cycles, so an -// arbitrary cap is set on the depth of the traversal as -// a poor man's cycle detection, in the event that a -// cycle has inadvertently been introduced into the -// scene graph. -// -// There may be other reasons you'd want to truncate a -// search before the bottom of the scene graph has been -// reached. In any event, this function sets the limit -// on the number of levels that a traversal will -// continue, and hence the maximum length of a path that -// may be returned by a traversal. -// -// This is a static method, and so changing this -// parameter affects all of the NodePaths in the -// universe. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_max_search_depth(int max_search_depth) { - _max_search_depth = max_search_depth; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_max_search_depth -// Access: Published, Static -// Description: Returns the current setting of the search depth -// limit. See set_max_search_depth. -//////////////////////////////////////////////////////////////////// -INLINE int NodePath:: -get_max_search_depth() { - return _max_search_depth; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_error_type -// Access: Published -// Description: If is_empty() is true, this returns a code that -// represents the reason why the NodePath is empty. -//////////////////////////////////////////////////////////////////// -INLINE NodePath::ErrorType NodePath:: -get_error_type() const { - return _error_type; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_num_children -// Access: Published -// Description: Returns the number of children of the bottom node of -// the NodePath. This will be the same as the number of -// paths in the collection returned by get_children(). -//////////////////////////////////////////////////////////////////// -INLINE int NodePath:: -get_num_children() const { - nassertr(verify_connectivity(), 0); - nassertr(!is_empty(), 0); - - return node()->get_num_children(_graph_type); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_child -// Access: Published -// Description: Returns the nth of child of the bottom node of -// the NodePath. This will be the same as nth path in -// the collection returned by get_children(). -//////////////////////////////////////////////////////////////////// -INLINE NodePath NodePath:: -get_child(int n) const { - nassertr(verify_connectivity(), NodePath::fail()); - nassertr(!is_empty(), NodePath::fail()); - nassertr(n >= 0 && n < get_num_children(), NodePath::fail()); - - NodePath result(*this); - result.extend_by(node()->get_child(_graph_type, n)); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::has_parent -// Access: Published -// Description: Returns true if the node at the bottom of the -// NodePath has a parent; i.e. the NodePath contains at -// least two nodes. -//////////////////////////////////////////////////////////////////// -INLINE bool NodePath:: -has_parent() const { - return has_arcs(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_parent -// Access: Published -// Description: Returns the NodePath to the parent node of the bottom -// arc: that is, this NodePath, shortened by one node. -//////////////////////////////////////////////////////////////////// -INLINE NodePath NodePath:: -get_parent() const { - nassertr(has_parent(), NodePath::fail()); - NodePath parent(*this); - parent.shorten(); - return parent; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::find_path_down_to -// Access: Published -// Description: Returns a NodePath that represents the extension of -// this NodePath down to the indicated node along the -// shortest possible path, if any, or an empty NodePath -// if there is no connection to the indicated node. -//////////////////////////////////////////////////////////////////// -INLINE NodePath NodePath:: -find_path_down_to(Node *dnode) const { - nassertr(_error_type == ET_ok, *this); - NodePath result(*this); - if (result.extend_down_to(dnode)) { - return result; - } - return NodePath::not_found(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::find -// Access: Published -// Description: Searches for a node below this NodePath's bottom node -// that matches the indicated string. Returns the -// shortest match found, if any, or an empty NodePath if -// no match can be found. -//////////////////////////////////////////////////////////////////// -INLINE NodePath NodePath:: -find(const string &path) const { - nassertr(_error_type == ET_ok, *this); - NodePath result(*this); - if (result.extend_by(path)) { - return result; - } - return NodePath::not_found(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::attach_new_node -// Access: Published -// Description: Creates a new NamedNode and attaches it below the -// current NodePath, returning a new NodePath that -// references it. -//////////////////////////////////////////////////////////////////// -INLINE NodePath NodePath:: -attach_new_node(const string &name, int sort) const { - nassertr(verify_connectivity(), NodePath::fail()); - nassertr(!is_empty(), *this); - - return attach_new_node(new NamedNode(name), sort); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::output -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -output(ostream &out) const { - if (_error_type == ET_ok && is_empty()) { - out << "**empty**"; - } else { - out << as_string(0); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::ls -// Access: Published -// Description: Lists all the nodes at and below the current path -// hierarchically. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -ls() const { - ls(nout); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::ls -// Access: Published -// Description: Lists all the nodes at and below the current path -// hierarchically. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -ls(ostream &out, int indent_level) const { - nassertv(verify_connectivity()); - nassertv(!is_empty()); - - r_list_descendants(out, indent_level); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::ls_transitions -// Access: Published -// Description: Lists all the nodes at and below the current path -// hierarchically, along with all the transitions on the -// arcs between them. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -ls_transitions() const { - nassertv(verify_connectivity()); - nassertv(!is_empty()); - - r_list_transitions(nout, 0); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::ls_transforms -// Access: Published -// Description: Lists only the nodes at and below this path that have -// transform matrices set, and the matrices they have. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -ls_transforms() const { - nassertv(verify_connectivity()); - nassertv(!is_empty()); - - r_list_transforms(nout, 0); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_pos -// Access: Published -// Description: Sets the translation component of the transform, -// leaving rotation and scale untouched. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_pos(float x, float y, float z) { - set_pos(LPoint3f(x, y, z)); -} - -INLINE float NodePath:: -get_x() const { - return get_pos()[0]; -} - -INLINE float NodePath:: -get_y() const { - return get_pos()[1]; -} - -INLINE float NodePath:: -get_z() const { - return get_pos()[2]; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_hpr -// Access: Published -// Description: Sets the rotation component of the transform, -// leaving translation and scale untouched. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_hpr(float h, float p, float r) { - set_hpr(LVecBase3f(h, p, r)); -} - -INLINE float NodePath:: -get_h() const { - return get_hpr()[0]; -} - -INLINE float NodePath:: -get_p() const { - return get_hpr()[1]; -} - -INLINE float NodePath:: -get_r() const { - return get_hpr()[2]; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_scale -// Access: Published -// Description: Sets the scale component of the transform, -// leaving translation and rotation untouched. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_scale(float scale) { - set_scale(LVecBase3f(scale, scale, scale)); -} - -INLINE void NodePath:: -set_scale(float sx, float sy, float sz) { - set_scale(LVecBase3f(sx, sy, sz)); -} - -INLINE float NodePath:: -get_sx() const { - return get_scale()[0]; -} - -INLINE float NodePath:: -get_sy() const { - return get_scale()[1]; -} - -INLINE float NodePath:: -get_sz() const { - return get_scale()[2]; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_color_scale -// Access: Published -// Description: Sets the color scale component of the transform -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_color_scale(float sr, float sg, float sb, float sa) { - set_color_scale(LVecBase4f(sr, sg, sb, sa)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_sr -// Access: Published -// Description: Sets the red scale component of the transform -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_sr(float sr) { - LVecBase4f new_scale = get_color_scale(); - new_scale[0] = sr; - - set_color_scale(new_scale); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_sg -// Access: Published -// Description: Sets the alpha scale component of the transform -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_sg(float sg) { - LVecBase4f new_scale = get_color_scale(); - new_scale[1] = sg; - - set_color_scale(new_scale); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_sb -// Access: Published -// Description: Sets the blue scale component of the transform -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_sb(float sb) { - LVecBase4f new_scale = get_color_scale(); - new_scale[2] = sb; - - set_color_scale(new_scale); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_sa -// Access: Published -// Description: Sets the alpha scale component of the transform -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_sa(float sa) { - LVecBase4f new_scale = get_color_scale(); - new_scale[3] = sa; - - set_color_scale(new_scale); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_sr -// Access: Published -// Description: Gets the red scale component of the transform -//////////////////////////////////////////////////////////////////// -INLINE float NodePath:: -get_sr() const { - return get_color_scale()[0]; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_sg -// Access: Published -// Description: Gets the green scale component of the transform -//////////////////////////////////////////////////////////////////// -INLINE float NodePath:: -get_sg() const { - return get_color_scale()[1]; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_sb -// Access: Published -// Description: Gets the blue scale component of the transform -//////////////////////////////////////////////////////////////////// -INLINE float NodePath:: -get_sb() const { - return get_color_scale()[2]; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_sa -// Access: Published -// Description: Gets the alpha scale component of the transform -//////////////////////////////////////////////////////////////////// -INLINE float NodePath:: -get_sa() const { - return get_color_scale()[3]; -} - - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::clear_color_scale -// Access: Published -// Description: Completely removes any color scale from the bottom arc. -// This is preferable to simply setting the color scale to -// identity, as it also removes the overhead associated -// with having a color scale at all. -// -// This method is not strictly accurate as it clears -// both a color matrix and alpha transform, and either of -// those could have only offset components -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -clear_color_scale() { - nassertv(has_arcs()); - NodeRelation *darc = arc(); - darc->clear_transition(ColorMatrixTransition::get_class_type()); - darc->clear_transition(AlphaTransformTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::has_color_scale -// Access: Published -// Description: Returns true if a color scale has been applied -// to the bottom arc, false otherwise. -// -// This method is not strictly accurate as it checks -// for a color matrix or alpha transform, and either of -// those could have only offset components -//////////////////////////////////////////////////////////////////// -INLINE bool NodePath:: -has_color_scale() const { - nassertr(has_arcs(), false); - NodeRelation *darc = arc(); - return darc->has_transition(ColorMatrixTransition::get_class_type()) || - darc->has_transition(AlphaTransformTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_pos_hpr -// Access: Published -// Description: Sets the translation and rotation component of the -// transform, leaving scale untouched. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_pos_hpr(float x, float y, float z, float h, float p, float r) { - set_pos_hpr(LVecBase3f(x, y, z), LVecBase3f(h, p, r)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_hpr_scale -// Access: Published -// Description: Sets the rotation and scale components of the -// transform, leaving translation untouched. This, or -// set_pos_hpr_scale, is the preferred way to update a -// transform when both hpr and scale are to be changed. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_hpr_scale(float h, float p, float r, float sx, float sy, float sz) { - set_hpr_scale(LVecBase3f(h, p, r), LVecBase3f(sx, sy, sz)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_pos_hpr_scale -// Access: Published -// Description: Completely replaces the transform with new -// translation, rotation, and scale components. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_pos_hpr_scale(float x, float y, float z, float h, float p, float r, - float sx, float sy, float sz) { - set_pos_hpr_scale(LVecBase3f(x, y, z), LVecBase3f(h, p, r), - LVecBase3f(sx, sy, sz)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::clear_mat -// Access: Published -// Description: Completely removes any transform from the bottom arc. -// This is preferable to simply setting the matrix to -// identity, as it also removes the overhead associated -// with having a matrix at all. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -clear_mat() { - nassertv(has_arcs()); - arc()->clear_transition(TransformTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::has_mat -// Access: Published -// Description: Returns true if a transform matrix has been applied -// to the bottom arc, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool NodePath:: -has_mat() const { - nassertr(has_arcs(), false); - return arc()->has_transition(TransformTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_mat -// Access: Published -// Description: Returns the complete transform matrix that has been -// applied to the bottom arc, or the identity matrix if -// no matrix has been applied. -//////////////////////////////////////////////////////////////////// -INLINE LMatrix4f NodePath:: -get_mat() const { - nassertr(has_arcs(), LMatrix4f::ident_mat()); - - const TransformTransition *tt; - if (!get_transition_into(tt, arc())) { - // No relative transform. - return LMatrix4f::ident_mat(); - } - - return tt->get_matrix(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::look_at -// Access: Published -// Description: Sets the transform on this NodePath so that it -// rotates to face the indicated point in space. This -// will overwrite any previously existing scale on the -// node, although it will preserve any translation. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -look_at(float x, float y, float z) { - look_at(LPoint3f(x, y, z)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::heads_up -// Access: Published -// Description: Behaves like look_at(), but with a strong preference -// to keeping the up vector oriented in the indicated -// "up" direction. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -heads_up(float x, float y, float z) { - heads_up(LPoint3f(x, y, z)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::look_at_preserve_scale -// Access: Published -// Description: Functions like look_at(), but preforms additional -// work to preserve any scales that may already be -// present on the node. Normally, look_at() blows away -// the scale because scale and rotation are represented -// in the same part of the matrix. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -look_at_preserve_scale(float x, float y, float z) { - look_at_preserve_scale(LPoint3f(x, y, z)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::heads_up_preserve_scale -// Access: Published -// Description: Functions like heads_up(), but preforms additional -// work to preserve any scales that may already be -// present on the node. Normally, heads_up() blows away -// the scale because scale and rotation are represented -// in the same part of the matrix. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -heads_up_preserve_scale(float x, float y, float z) { - heads_up_preserve_scale(LPoint3f(x, y, z)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::print_pos -// Access: Published -// Description: Displays the translation component. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -print_pos() const { - nout << get_pos() << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::print_hpr -// Access: Published -// Description: Displays the rotation component. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -print_hpr() const { - nout << get_hpr() << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::print_scale -// Access: Published -// Description: Displays the scale component. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -print_scale() const { - nout << get_scale() << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::print_pos_hpr -// Access: Published -// Description: Displays the translation and rotation component. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -print_pos_hpr() const { - nout << get_pos() << "\n" - << get_hpr() << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::print_pos_hpr_scale -// Access: Published -// Description: Displays the translation, rotation, and scale -// components. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -print_pos_hpr_scale() const { - nout << get_pos() << "\n" - << get_hpr() << "\n" - << get_scale() << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::print_mat -// Access: Published -// Description: Displays the complete transform matrix. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -print_mat() const { - nout << get_mat() << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::print_color_scale -// Access: Published -// Description: Displays the scale component. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -print_color_scale() const { - nout << get_color_scale() << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_pos -// Access: Published -// Description: Sets the translation component of the transform, -// relative to the other node. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_pos(const NodePath &other, float x, float y, float z) { - set_pos(other, LPoint3f(x, y, z)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_pos -// Access: Published -// Description: Returns the relative position of the bottom node as -// seen from the other node. -//////////////////////////////////////////////////////////////////// -INLINE LPoint3f NodePath:: -get_pos(const NodePath &other) const { - LMatrix4f mat = get_mat(other); - return mat.get_row3(3); -} - -INLINE float NodePath:: -get_x(const NodePath &other) const { - return get_pos(other)[0]; -} - -INLINE float NodePath:: -get_y(const NodePath &other) const { - return get_pos(other)[1]; -} - -INLINE float NodePath:: -get_z(const NodePath &other) const { - return get_pos(other)[2]; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_hpr -// Access: Published -// Description: Sets the rotation component of the transform, -// relative to the other node. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_hpr(const NodePath &other, float h, float p, float r) { - set_hpr(other, LPoint3f(h, p, r)); -} - -INLINE float NodePath:: -get_h(const NodePath &other) const { - return get_hpr(other)[0]; -} - -INLINE float NodePath:: -get_p(const NodePath &other) const { - return get_hpr(other)[1]; -} - -INLINE float NodePath:: -get_r(const NodePath &other) const { - return get_hpr(other)[2]; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_scale -// Access: Published -// Description: Sets the scale component of the transform, -// relative to the other node. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_scale(const NodePath &other, float sx, float sy, float sz) { - set_scale(other, LPoint3f(sx, sy, sz)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_scale -// Access: Published -// Description: Returns the relative scale of the bottom node -// as seen from the other node. -//////////////////////////////////////////////////////////////////// -INLINE float NodePath:: -get_sx(const NodePath &other) const { - return get_scale(other)[0]; -} - -INLINE float NodePath:: -get_sy(const NodePath &other) const { - return get_scale(other)[1]; -} - -INLINE float NodePath:: -get_sz(const NodePath &other) const { - return get_scale(other)[2]; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_pos_hpr -// Access: Published -// Description: Sets the translation and rotation component of the -// transform, relative to the other node. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_pos_hpr(const NodePath &other, - float x, float y, float z, - float h, float p, float r) { - set_pos_hpr(other, LVecBase3f(x, y, z), LVecBase3f(h, p, r)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_hpr_scale -// Access: Published -// Description: Sets the rotation and scale components of the -// transform, leaving translation untouched. This, or -// set_pos_hpr_scale, is the preferred way to update a -// transform when both hpr and scale are to be changed. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_hpr_scale(const NodePath &other, - float h, float p, float r, float sx, float sy, float sz) { - set_hpr_scale(other, LVecBase3f(h, p, r), LVecBase3f(sx, sy, sz)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_pos_hpr_scale -// Access: Published -// Description: Completely replaces the transform with new -// translation, rotation, and scale components, relative -// to the other node. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_pos_hpr_scale(const NodePath &other, - float x, float y, float z, - float h, float p, float r, - float sx, float sy, float sz) { - set_pos_hpr_scale(other, LVecBase3f(x, y, z), LVecBase3f(h, p, r), - LVecBase3f(sx, sy, sz)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::look_at -// Access: Published -// Description: Sets the transform on this NodePath so that it -// rotates to face the indicated point in space, which -// is relative to the other NodePath. This -// will overwrite any previously existing scale on the -// node, although it will preserve any translation. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -look_at(const NodePath &other, float x, float y, float z) { - look_at(other, LPoint3f(x, y, z)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::heads_up -// Access: Published -// Description: Behaves like look_at(), but with a strong preference -// to keeping the up vector oriented in the indicated -// "up" direction. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -heads_up(const NodePath &other, float x, float y, float z) { - heads_up(other, LPoint3f(x, y, z)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::look_at_preserve_scale -// Access: Published -// Description: Functions like look_at(), but preforms additional -// work to preserve any scales that may already be -// present on the node. Normally, look_at() blows away -// the scale because scale and rotation are represented -// in the same part of the matrix. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -look_at_preserve_scale(const NodePath &other, float x, float y, float z) { - look_at_preserve_scale(other, LPoint3f(x, y, z)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::heads_up_preserve_scale -// Access: Published -// Description: Functions like heads_up(), but preforms additional -// work to preserve any scales that may already be -// present on the node. Normally, heads_up() blows away -// the scale because scale and rotation are represented -// in the same part of the matrix. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -heads_up_preserve_scale(const NodePath &other, float x, float y, float z) { - heads_up_preserve_scale(other, LPoint3f(x, y, z)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::print_pos -// Access: Published -// Description: Displays the translation component. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -print_pos(const NodePath &other) const { - nout << get_pos(other) << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::print_hpr -// Access: Published -// Description: Displays the rotation component. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -print_hpr(const NodePath &other) const { - nout << get_hpr(other) << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::print_scale -// Access: Published -// Description: Displays the scale component. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -print_scale(const NodePath &other) const { - nout << get_scale(other) << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::print_pos_hpr -// Access: Published -// Description: Displays the translation and rotation component. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -print_pos_hpr(const NodePath &other) const { - nout << get_pos(other) << "\n" - << get_hpr(other) << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::print_pos_hpr_scale -// Access: Published -// Description: Displays the translation, rotation, and scale -// components. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -print_pos_hpr_scale(const NodePath &other) const { - nout << get_pos(other) << "\n" - << get_hpr(other) << "\n" - << get_scale(other) << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::print_mat -// Access: Published -// Description: Displays the complete transform matrix. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -print_mat(const NodePath &other) const { - nout << get_mat(other) << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_distance -// Access: Published -// Description: Returns the straight-line distance between this -// bottom node's coordinate frame's origin, and that of -// the other node's origin. -//////////////////////////////////////////////////////////////////// -INLINE float NodePath:: -get_distance(const NodePath &other) const { - LPoint3f pos = get_pos(other); - return length(LVector3f(pos)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_color -// Access: Published -// Description: Sets the color transition for a render relation -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_color(float r, float g, float b, float a, - int priority) { - set_color(Colorf(r, g, b, a), priority); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::clear_color -// Access: Published -// Description: Completely removes any color adjustment from the arc. -// This allows the natural color of the geometry, or -// whatever color transitions might be otherwise -// affecting the geometry, to show instead. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -clear_color() { - nassertv(has_arcs()); - arc()->clear_transition(ColorTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::has_color -// Access: Published -// Description: Returns true if a color has been applied to the given -// arc, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool NodePath:: -has_color() const { - nassertr(has_arcs(), false); - return arc()->has_transition(ColorTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::clear_bin -// Access: Published -// Description: Completely removes any bin adjustment that may have -// been set via set_bin() from this particular arc. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -clear_bin() { - nassertv(has_arcs()); - arc()->clear_transition(GeomBinTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::has_bin -// Access: Published -// Description: Returns true if the arc has been assigned to the a -// particular rendering bin via set_bin(), false -// otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool NodePath:: -has_bin() const { - nassertr(has_arcs(), false); - return arc()->has_transition(GeomBinTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::clear_texture -// Access: Published -// Description: Completely removes any texture adjustment that may -// have been set via set_texture() or set_texture_off() -// from this particular arc. This allows whatever -// textures might be otherwise affecting the geometry to -// show instead. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -clear_texture() { - nassertv(has_arcs()); - arc()->clear_transition(TextureTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::clear_material -// Access: Published -// Description: Completely removes any material adjustment that may -// have been set via set_material() from this particular -// arc. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -clear_material() { - nassertv(has_arcs()); - arc()->clear_transition(MaterialTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::clear_fog -// Access: Published -// Description: Completely removes any fog adjustment that may -// have been set via set_fog() or set_fog_off() -// from this particular arc. This allows whatever -// fogs might be otherwise affecting the geometry to -// show instead. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -clear_fog() { - nassertv(has_arcs()); - arc()->clear_transition(FogTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::clear_render_mode -// Access: Published -// Description: Completely removes any render mode adjustment that -// may have been set on this arc via -// set_render_mode_wireframe() or -// set_render_mode_filled(). -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -clear_render_mode() { - nassertv(has_arcs()); - arc()->clear_transition(RenderModeTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::has_render_mode -// Access: Published -// Description: Returns true if a render mode has been explicitly set -// on this particular arc via -// set_render_mode_wireframe() or -// set_render_mode_filled(), false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool NodePath:: -has_render_mode() const { - nassertr(has_arcs(), false); - return arc()->has_transition(RenderModeTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::clear_two_sided -// Access: Published -// Description: Completely removes any two-sided adjustment that -// may have been set on this arc via set_two_sided(). -// The geometry at this level and below will -// subsequently be rendered either two-sided or -// one-sided, according to whatever other arcs may have -// had set_two_sided() on it, or according to the -// initial state otherwise. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -clear_two_sided() { - nassertv(has_arcs()); - arc()->clear_transition(CullFaceTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::has_two_sided -// Access: Published -// Description: Returns true if a two-sided adjustment has been -// explicitly set on this particular arc via -// set_two_sided(). If this returns true, then -// get_two_sided() may be called to determine which has -// been set. -//////////////////////////////////////////////////////////////////// -INLINE bool NodePath:: -has_two_sided() const { - nassertr(has_arcs(), false); - return arc()->has_transition(CullFaceTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_billboard_axis -// Access: Published -// Description: Puts a billboard transition on the arc such that it -// will rotate in two dimensions around the up axis. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_billboard_axis(float offset) { - nassertv(has_arcs()); - arc()->set_transition(new BillboardTransition(BillboardTransition::axis(offset))); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_billboard_point_eye -// Access: Published -// Description: Puts a billboard transition on the arc such that it -// will rotate in three dimensions about the origin, -// keeping its up vector oriented to the top of the -// camera. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_billboard_point_eye(float offset) { - nassertv(has_arcs()); - arc()->set_transition(new BillboardTransition(BillboardTransition::point_eye(offset))); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_billboard_point_world -// Access: Published -// Description: Puts a billboard transition on the arc such that it -// will rotate in three dimensions about the origin, -// keeping its up vector oriented to the sky. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -set_billboard_point_world(float offset) { - nassertv(has_arcs()); - arc()->set_transition(new BillboardTransition(BillboardTransition::point_world(offset))); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::clear_billboard -// Access: Published -// Description: Removes any billboard transition from the arc. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -clear_billboard() { - nassertv(has_arcs()); - arc()->clear_transition(BillboardTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::has_billboard -// Access: Published -// Description: Returns true if there is any billboard transition on -// the arc. -//////////////////////////////////////////////////////////////////// -INLINE bool NodePath:: -has_billboard() const { - nassertr(has_arcs(), false); - return arc()->has_transition(BillboardTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::clear_transparency -// Access: Published -// Description: Completely removes any transparency adjustment that -// may have been set on this arc via set_transparency(). -// The geometry at this level and below will -// subsequently be rendered either transparent or not, -// to whatever other arcs may have had -// set_transparency() on them, or according to the -// initial state otherwise. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -clear_transparency() { - nassertv(has_arcs()); - arc()->clear_transition(TransparencyTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::has_transparency -// Access: Published -// Description: Returns true if a transparent-rendering adjustment -// has been explicitly set on this particular arc via -// set_transparency(). If this returns true, then -// get_transparency() may be called to determine whether -// transparency has been explicitly enabled or -// explicitly disabled for this arc. -//////////////////////////////////////////////////////////////////// -INLINE bool NodePath:: -has_transparency() const { - nassertr(has_arcs(), false); - return arc()->has_transition(TransparencyTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::adjust_all_priorities -// Access: Published -// Description: Adds the indicated adjustment amount (which may be -// negative) to the priority for all transitions on the -// bottom arc, and for all arcs in the subgraph below. -// This can be used to force these nodes not to be -// overridden by a high-level state change above. If -// the priority would drop below zero, it is set to -// zero. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -adjust_all_priorities(int adjustment) { - nassertv(has_arcs()); - r_adjust_all_priorities(arc(), adjustment); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::show -// Access: Published -// Description: Removes any PruneTransition on this bottom arc so -// that the geometry at this level and below will once -// again be visible--assuming no ancestor arc has a -// PruneTransition. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -show() { - nassertv(has_arcs()); - arc()->clear_transition(PruneTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::hide -// Access: Published -// Description: Puts a PruneTransition on this bottom arc so that the -// geometry at this level and below will be invisible. -// -// However, it will remain part of the scene graph, and -// will still be counted in its parent's bounding -// volume; furthermore, traversals like the collision -// traversal will still visit the node. -// -// See stash() for a more thorough way to hide the node. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -hide() { - nassertv(has_arcs()); - arc()->set_transition(new PruneTransition); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::show_collision_solids -// Access: Published -// Description: Reveals all the collision solids at or below this -// node. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -show_collision_solids() { - find_all_matches("**/+CollisionNode").show(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::hide_collision_solids -// Access: Published -// Description: Hides all the collision solids at or below this -// node. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -hide_collision_solids() { - find_all_matches("**/+CollisionNode").hide(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::is_hidden -// Access: Published -// Description: Returns true if the bottom arc has been hidden, -// false otherwise. The bottom node may still be -// invisible due to a higher ancestor having been -// hidden; use get_hidden_ancestor() to check this. -//////////////////////////////////////////////////////////////////// -INLINE bool NodePath:: -is_hidden() const { - return (arc()->has_transition(PruneTransition::get_class_type())); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::stash -// Access: Published -// Description: A more thorough version of hide(), this effectively -// removes the bottom node from the scene graph--it does -// not appear in any traversals, rendering or otherwise, -// and cannot be located again via NodePath::find(). -// The node is also removed from its parents' bounding -// volume. -// -// However, the node is still associated with its -// parent, and will be removed if the parent is removed, -// and it can be revealed again by a future call to -// unstash(). -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -stash() { - nassertv(has_arcs()); - arc()->set_graph_type(NodeRelation::get_stashed_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::unstash -// Access: Published -// Description: Reveals a node that was previously hidden via stash(). -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -unstash() { - nassertv(has_arcs()); - arc()->set_graph_type(arc()->get_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::is_stashed -// Access: Published -// Description: Returns true if the bottom arc has been 'stashed', -// false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool NodePath:: -is_stashed() const { - return (arc()->get_graph_type() == NodeRelation::get_stashed_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::clear_wrt_cache -// Access: Published -// Description: Recursively calls clear_wrt_cache() on every arc -// beginning at the bottom arc and below. This wipes -// out the cached wrt information, which will make the -// next call to wrt() more expensive, but may reclaim -// some memory and free up some otherwise unused -// pointers. -//////////////////////////////////////////////////////////////////// -INLINE void NodePath:: -clear_wrt_cache() { - nassertv_always(!is_empty()); - r_clear_wrt_cache(arc()); -} diff --git a/panda/src/sgmanip/nodePath.cxx b/panda/src/sgmanip/nodePath.cxx deleted file mode 100644 index b62a47d638..0000000000 --- a/panda/src/sgmanip/nodePath.cxx +++ /dev/null @@ -1,3349 +0,0 @@ -// Filename: nodePath.cxx -// Created by: drose (05Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "nodePath.h" -#include "config_sgmanip.h" -#include "findApproxLevel.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "plist.h" - -// stack seems to overflow on Intel C++ at 7000. If we need more than -// 7000, need to increase stack size. -int NodePath::_max_search_depth = 7000; -TypeHandle NodePath::_type_handle; - -// This class is used in prepare_scene() to traverse the scene graph -// and register textures and geoms with the gsg. -class ScenePrepareVisitor : public TraverserVisitor { -public: - bool forward_arc(NodeRelation *, NodeTransitionWrapper &trans, - NodeTransitionWrapper &, NodeTransitionWrapper &, - NullLevelState &) { - TextureTransition *tt; - if (get_transition_into(tt, trans)) { - if (tt->is_on()) { - tt->get_texture()->prepare(_gsg); - } - } - return true; - } - - bool reached_node(Node *node, NodeTransitionWrapper &, - NullLevelState &) { - if (_retained_mode && node->is_of_type(GeomNode::get_class_type())) { - GeomNode *gnode = DCAST(GeomNode, node); - gnode->prepare(_gsg); - } - return true; - } - - GraphicsStateGuardianBase *_gsg; - bool _retained_mode; -}; - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::extend_by -// Access: Published -// Description: Appends a new child node onto the bottom end of the -// path. This will search for an existing arc between -// the current bottom node and the indicated node; -// returns true if the arc is found and appended, false -// if no such arc exists. -// -// This operation may be ambiguous if there are multiple -// arcs connecting the bottom node of the path with the -// indicated node. In such case, the first arc found -// will be quietly chosen. Use append_arc() when -// unambiguous behavior is required. -//////////////////////////////////////////////////////////////////// -bool NodePath:: -extend_by(Node *dnode) { - nassertr(_error_type == ET_ok, false); - nassertr(verify_connectivity(), false); - nassertr(dnode != (Node *)NULL, false); - - if (is_empty()) { - // Extending an empty NodePath by a single node is the same thing - // as creating a new NodePath with just the single node. - (*this) = NodePath(dnode, _graph_type); - return true; - } - - Node *bottom_node = node(); - NodeRelation *arc = find_arc(bottom_node, dnode, _graph_type); - if (arc == (NodeRelation *)NULL) { - if (sgmanip_cat.is_debug()) { - sgmanip_cat.debug() - << "Cannot extend " << *this << " by " - << *dnode << "; no connection.\n"; - } - return false; - } - - _head = new ArcComponent(arc, _head); - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::extend_by -// Access: Published -// Description: Adds the indicated arc to the end of the path. The -// arc must connect the bottom node of the path to some -// other node. Returns true if this is so, false -// otherwise. -//////////////////////////////////////////////////////////////////// -bool NodePath:: -extend_by(NodeRelation *darc) { - nassertr(_error_type == ET_ok, false); - nassertr(verify_connectivity(), false); - nassertr(darc != (NodeRelation *)NULL, false); - - if (is_empty()) { - // If the NodePath is initially empty, we must start with its top - // node. - (*this) = NodePath(darc->get_parent(), darc->get_type()); - } - - if (darc->get_parent() != node()) { - if (sgmanip_cat.is_debug()) { - sgmanip_cat.debug() - << "Cannot extend " << *this << " by arc " << *darc - << "; no connection.\n"; - } - return false; - } - - _head = new ArcComponent(darc, _head); - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::extend_by -// Access: Published -// Description: Adds the indicated NodePath to the end of this path. -// The top node of the other NodePath must be the same -// node as the bottom node of this path. Returns true -// if this is so, false otherwise or if the other path -// is no longer accurately connected. -//////////////////////////////////////////////////////////////////// -bool NodePath:: -extend_by(const NodePath &other) { - nassertr(_error_type == ET_ok, false); - nassertr(other._error_type == ET_ok, false); - nassertr(verify_connectivity(), false); - if (is_empty()) { - // A special case: extending an empty path by another path is just - // an assignment. - (*this) = other; - return true; - } - - return r_extend_by(other._head); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::extend_by -// Access: Published -// Description: Extends the NodePath by the NodePath represented by -// the given approximate string. If the match is -// ambiguous, returns the first match found (which will -// be the shortest path). Returns true if the extension -// was made, false if the node could not be found. -//////////////////////////////////////////////////////////////////// -bool NodePath:: -extend_by(const string &path) { - nassertr(_error_type == ET_ok, false); - nassertr(verify_connectivity(), false); - NodePathCollection col; - find_matches(col, path, 1); - - if (col.is_empty()) { - if (sgmanip_cat.is_debug()) { - sgmanip_cat.debug() - << "Could not extend " << *this << " by " - << path << "; no match found.\n"; - } - return false; - } - - (*this) = col.get_path(0); - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::extend_down_to -// Access: Published -// Description: Extends the NodePath down along the shortest -// available path to the indicated node, even if the -// node is several levels below the NodePath's bottom -// node. Returns true if the extension was made, false -// if the node was not below this NodePath. -//////////////////////////////////////////////////////////////////// -bool NodePath:: -extend_down_to(Node *dnode) { - nassertr(_error_type == ET_ok, false); - if (!is_empty() && node() == dnode) { - // We're already there! - return true; - } - - nassertr(verify_connectivity(), false); - NodePathCollection col; - FindApproxPath approx_path; - approx_path.add_match_many(0); - approx_path.add_match_pointer(dnode, 0); - find_matches(col, approx_path, -1); - - if (col.is_empty()) { - if (sgmanip_cat.is_debug()) { - sgmanip_cat.debug() - << "Could not extend " << *this << " down to " - << *dnode << "; no connection found.\n"; - } - return false; - } - - (*this) = col.get_path(0); - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::shorten -// Access: Published -// Description: Shortens the NodePath by removing the indicated -// number of nodes from the bottom of the path. It -// is an error to shorten the path to less than zero -// nodes; thus, num_nodes must be <= get_num_nodes(). -//////////////////////////////////////////////////////////////////// -void NodePath:: -shorten(int num_nodes) { - nassertv(_error_type == ET_ok); - nassertv(num_nodes >= 0 && num_nodes <= get_num_nodes()); - - int count = num_nodes; - while (count > 0) { - nassertv(_head != (ArcComponent *)NULL); - _head = _head->get_next(); - count--; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::clear -// Access: Published -// Description: Resets the NodePath to an empty path. -//////////////////////////////////////////////////////////////////// -void NodePath:: -clear() { - _head.clear(); - _error_type = ET_ok; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_children -// Access: Published -// Description: Returns the set of all child nodes of the bottom -// node. -//////////////////////////////////////////////////////////////////// -NodePathCollection NodePath:: -get_children() const { - NodePathCollection result; - nassertr(verify_connectivity(), result); - nassertr(!is_empty(), result); - - Node *bottom_node = node(); - - int num_children = bottom_node->get_num_children(_graph_type); - for (int i = 0; i < num_children; i++) { - NodeRelation *child_arc = bottom_node->get_child(_graph_type, i); - NodePath child(*this); - child.extend_by(child_arc); - result.add_path(child); - } - - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_siblings -// Access: Published -// Description: Returns the set of all child nodes of the bottom -// node's parent, except the bottom node itself. -//////////////////////////////////////////////////////////////////// -NodePathCollection NodePath:: -get_siblings() const { - NodePathCollection result; - nassertr(verify_connectivity(), result); - nassertr(has_arcs(), result); - NodeRelation *my_arc = arc(); - - NodePath parent = *this; - parent.shorten(1); - - Node *parent_node = parent.node(); - - int num_children = parent_node->get_num_children(_graph_type); - for (int i = 0; i < num_children; i++) { - NodeRelation *child_arc = parent_node->get_child(_graph_type, i); - - if (child_arc != my_arc) { - NodePath sib(parent); - sib.extend_by(child_arc); - result.add_path(sib); - } - } - - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::find_all_paths_down_to -// Access: Published -// Description: Returns the set of all NodePaths that extend from -// this NodePath down to the indicated node. The -// shortest paths will be listed first. -//////////////////////////////////////////////////////////////////// -NodePathCollection NodePath:: -find_all_paths_down_to(Node *dnode) const { - NodePathCollection col; - nassertr(!is_empty(), col); - nassertr(verify_connectivity(), col); - nassertr(dnode != (Node *)NULL, col); - FindApproxPath approx_path; - approx_path.add_match_many(0); - approx_path.add_match_pointer(dnode, 0); - find_matches(col, approx_path, -1); - return col; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::find_all_matches -// Access: Published -// Description: Returns the complete set of all NodePaths that begin -// with this NodePath and can be extended by -// path. The shortest paths will be listed -// first. -//////////////////////////////////////////////////////////////////// -NodePathCollection NodePath:: -find_all_matches(const string &path) const { - NodePathCollection col; - nassertr(!is_empty(), col); - nassertr(verify_connectivity(), col); - find_matches(col, path, -1); - return col; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::find_singular_transform -// Access: Published -// Description: Scans the subgraph beginning at the bottom node of -// the scene graph, looking for a node with a singular -// matrix transform above it. Returns the first such -// node encountered, or an empty NodePath if no singular -// transforms exist in the scene graph. -// -// This is a handy function for tracking down mysterious -// "tried to invert a singular matrix" errors, which are -// almost always caused by zero-scale transform matrices -// in the scene graph. -//////////////////////////////////////////////////////////////////// -NodePath NodePath:: -find_singular_transform() const { - nassertr(!is_empty(), NodePath::fail()); - - if (has_mat()) { - LMatrix4f mat = get_mat(); - LMatrix4f inv_mat; - bool ok = inv_mat.invert_from(mat); - if (!ok) { - // Here's a singular matrix! - sgmanip_cat.info() - << "Singular transform at: " << *this << "\n"; - return *this; - } - } - - int num_children = get_num_children(); - for (int i = 0; i < num_children; i++) { - NodePath result = get_child(i).find_singular_transform(); - if (!result.is_empty()) { - return result; - } - } - - return NodePath::not_found(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::share_with -// Access: Published -// Description: Adjusts this NodePath so that it shares components -// with the other NodePath, even if the two paths were -// independently generated. -// -// Normally, if two NodePaths will share arcs, you -// should use the first one to derive the second; this -// will ensure that if one NodePath is reparented, the -// second will automatically be updated to reflect the -// change. If the two NodePaths are computed -// independently of each other, but end up sharing arcs, -// then reparenting one could invalidate the second. -// -// This operation can be applied to a NodePath that is -// known to share arcs with another NodePath, even if it -// was generated separately, so that both NodePaths will -// be considered related in the future. -// -// The return value is the number of arcs from the top -// of the path that both NodePaths had in common. -//////////////////////////////////////////////////////////////////// -int NodePath:: -share_with(const NodePath &other) { - typedef plist Comps; - Comps other_comps; - Comps this_comps; - - // First, we have to reverse the lists of this path and the other - // path, so we can compare their initial subsets. - ArcComponent *comp = other._head; - while (comp != (ArcComponent *)NULL) { - other_comps.push_front(comp); - comp = comp->get_next(); - } - - comp = _head; - while (comp != (ArcComponent *)NULL) { - this_comps.push_front(comp); - comp = comp->get_next(); - } - - // Now determine how many components this and the other path have in - // common. - int in_common = 0; - Comps::const_iterator oi = other_comps.begin(); - Comps::const_iterator ti = this_comps.begin(); - - // The first components in both chains should be the topnodes. - if (oi != other_comps.end() && - ti != this_comps.end() && - (*oi)->get_node() == (*ti)->get_node()) { - ++oi; - ++ti; - ++in_common; - } - // The remaining components are arcs. - while (oi != other_comps.end() && - ti != this_comps.end() && - (*oi)->get_arc() == (*ti)->get_arc()) { - ++oi; - ++ti; - ++in_common; - } - - if (in_common > 0) { - ArcComponent *dest; - if (oi == other_comps.end()) { - dest = other._head; - } else { - dest = (*oi); - } - - if (ti == this_comps.end()) { - _head = dest; - } else { - (*ti)->set_next(dest); - } - } - - return in_common; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::verify_connectivity -// Access: Published -// Description: Returns true if all of the arcs described in the -// NodePath are still connected, false otherwise. -//////////////////////////////////////////////////////////////////// -bool NodePath:: -verify_connectivity() const { - if (!has_arcs()) { - return true; - } - - const ArcComponent *comp = _head; - nassertr(comp != (const ArcComponent *)NULL, false); - nassertr(comp->has_arc(), false); - - NodeRelation *darc = comp->get_arc(); - Node *parent = darc->get_parent(); - Node *child = darc->get_child(); - if (parent == (Node *)NULL || child == (Node *)NULL) { - return false; - } - - comp = comp->get_next(); - nassertr(comp != (const ArcComponent *)NULL, false); - while (comp->has_arc()) { - NodeRelation *darc = comp->get_arc(); - Node *next_parent = darc->get_parent(); - Node *next_child = darc->get_child(); - if (next_parent == (Node *)NULL || next_child == (Node *)NULL) { - return false; - } - if (next_child != parent) { - return false; - } - - parent = next_parent; - child = next_child; - comp = comp->get_next(); - nassertr(comp != (const ArcComponent *)NULL, false); - } - - // Finally, verify the top node. - nassertr(comp->is_top_node(), false); - if (parent != comp->get_node()) { - return false; - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::amputate_badness -// Access: Published -// Description: If a NodePath is inadvertantly broken -// (i.e. verify_connectivity() returns false), this -// function may be called to attempt to contain the -// damage. It does this by lopping off the top of the -// NodePath above the lowest disconnected arc. You -// might end up with a very short NodePath indeed, but -// at least it will be fully connected. It returns the -// same value as verify_connectivity(): true if the path -// was already connected, false if it had been broken -// (and has therefore been truncated). -// -// See also repair_connectivity(). -//////////////////////////////////////////////////////////////////// -bool NodePath:: -amputate_badness() { - if (!has_arcs()) { - return true; - } - - ArcComponent *comp = _head; - nassertr(comp != (ArcComponent *)NULL, false); - - NodeRelation *darc = comp->get_arc(); - Node *parent = darc->get_parent(); - Node *child = darc->get_child(); - if (parent == (Node *)NULL || child == (Node *)NULL) { - // Eek! The bottom arc is broken! - _head = (ArcComponent *)NULL; - return false; - } - - ArcComponent *prev = comp; - comp = comp->get_next(); - nassertr(comp != (const ArcComponent *)NULL, false); - while (comp->has_arc()) { - NodeRelation *darc = comp->get_arc(); - Node *next_parent = darc->get_parent(); - Node *next_child = darc->get_child(); - - if (next_parent == (Node *)NULL || next_child == (Node *)NULL) { - prev->set_next(new ArcComponent(parent)); - return false; - } - if (next_child != parent) { - prev->set_next(new ArcComponent(parent)); - return false; - } - - parent = next_parent; - child = next_child; - prev = comp; - comp = comp->get_next(); - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::repair_connectivity -// Access: Published -// Description: When a NodePath has been inadvertantly disconnected, -// this attempts to repair the damage by finding a path -// from the bottom of the top NodePath to the top of the -// still-connected part of this NodePath. It returns -// true if the connection can be found, false if not (in -// which case the NodePath is unchanged). -//////////////////////////////////////////////////////////////////// -bool NodePath:: -repair_connectivity(const NodePath &top) { - nassertr(top.verify_connectivity(), false); - - NodePath new_path(*this); - new_path.amputate_badness(); - if (new_path.is_empty()) { - return false; - } - - Node *top_node = new_path.get_top_node(); - NodePath full_path(top); - if (!full_path.extend_down_to(top_node)) { - return false; - } - - if (!full_path.extend_by(new_path)) { - return false; - } - - (*this) = full_path; - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::reparent_to -// Access: Published -// Description: Removes the bottom node of the NodePath from its -// current parent and attaches it to the bottom node of -// the indicated NodePath. The arc above the bottom -// node is moved without destroying any transitions -// attached to it. -// -// It is an error to call this method on a NodePath that -// refers to just a single node, with no arcs. If you -// really want to parent just a single node somewhere, -// use instance_to() or attach_new_node(). -// -// This also updates the NodePath itself, as well as all -// NodePaths that were derived from this one, to reflect -// the new path to the node. -//////////////////////////////////////////////////////////////////// -void NodePath:: -reparent_to(const NodePath &other, int sort) { - nassertv(other.verify_connectivity()); - nassertv_always(has_arcs()); - nassertv_always(!other.is_empty()); - - NodeRelation *darc = arc(); - darc->change_parent(other.node(), sort); - - // Move our head pointer to the bottom of the new chain. This will - // update our own path, as well as all paths that share the same - // head pointer (i.e. all paths derived from this one). - _head->set_next(other._head); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::wrt_reparent_to -// Access: Published -// Description: This functions identically to reparent_to(), except -// the transform above this node is also adjusted so -// that the node remains in the same place in world -// coordinates, even if it is reparented into a -// different coordinate system. -//////////////////////////////////////////////////////////////////// -void NodePath:: -wrt_reparent_to(const NodePath &other, int sort) { - nassertv(other.verify_connectivity()); - nassertv_always(has_arcs()); - nassertv_always(!other.is_empty()); - - LMatrix4f mat = get_mat(other); - set_mat(mat); - - reparent_to(other, sort); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::instance_to -// Access: Published -// Description: Adds the bottom node of the NodePath as a child of -// the bottom node of the indicated other NodePath. Any -// other parent-child relations of the node are -// unchanged; in particular, the node is not removed -// from its existing parent, if any. -// -// A new arc is created, and its transitions are copied -// from the bottom arc of this NodePath, if any. -// -// If the node already had an existing parent, this -// method will create a new instance of the node within -// the scene graph. -// -// This does not change the NodePath itself, but does -// return a new NodePath that reflects the new instance -// node. -//////////////////////////////////////////////////////////////////// -NodePath NodePath:: -instance_to(const NodePath &other, int sort) const { - nassertr(verify_connectivity(), NodePath::fail()); - nassertr(!is_empty(), NodePath::fail()); - nassertr(!other.is_empty(), NodePath::fail()); - - Node *bottom_node = node(); - NodeRelation *darc = - NodeRelation::create_typed_arc(_graph_type, other.node(), - bottom_node, sort); - nassertr(darc != (NodeRelation *)NULL, NodePath::fail()); - nassertr(darc->is_exact_type(_graph_type), NodePath::fail()); - - if (has_arcs()) { - // Copy the transitions from this one's bottom arc, so the - // instance will inherit the same local state by default. - darc->copy_transitions_from(arc()); - } - - NodePath instance(*this); - instance._head = new ArcComponent(darc, other._head); - return instance; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::copy_to -// Access: Published -// Description: Functions exactly like instance_to(), except a deep -// copy is made of the bottom node and all of its -// descendents, which is then parented to the indicated -// node. A NodePath to the newly created copy is -// returned. -// -// Certain kinds of nodes may not be copied; if one of -// these is encountered, the node will be "copied" as -// the nearest copyable base class. For instance, a -// Camera node in the graph will become a simple -// NamedNode. -//////////////////////////////////////////////////////////////////// -NodePath NodePath:: -copy_to(const NodePath &other, int sort) const { - nassertr(verify_connectivity(), NodePath::fail()); - nassertr(!is_empty(), NodePath::fail()); - nassertr(!other.is_empty(), NodePath::fail()); - - Node *source_node = node(); - PT_Node copy_node = source_node->copy_subgraph(_graph_type); - nassertr(copy_node != (Node *)NULL, NodePath::fail()); - - NodeRelation *darc = - NodeRelation::create_typed_arc(_graph_type, other.node(), - copy_node, sort); - nassertr(darc != (NodeRelation *)NULL, NodePath::fail()); - nassertr(darc->is_exact_type(_graph_type), NodePath::fail()); - - if (has_arcs()) { - // Copy the transitions from this one's bottom arc, so the - // duplicate will inherit the same local state by default. - darc->copy_transitions_from(arc()); - } - - NodePath instance(*this); - instance._head = new ArcComponent(darc, other._head); - return instance; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::attach_new_node -// Access: Published -// Description: Attaches a new node, with or without existing -// parents, to the scene graph below the bottom node of -// this NodePath. This is the preferred way to add -// nodes to the graph. -// -// This does *not* automatically extend the current -// NodePath to reflect the attachment; however, a -// NodePath that does reflect this extension is -// returned. -//////////////////////////////////////////////////////////////////// -NodePath NodePath:: -attach_new_node(Node *dnode, int sort) const { - nassertr(verify_connectivity(), NodePath::fail()); - nassertr(!is_empty(), NodePath(_graph_type)); - nassertr(dnode != (Node *)NULL, NodePath(_graph_type)); - - NodePath path(dnode, _graph_type); - return path.instance_to(*this, sort); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::remove_node -// Access: Published -// Description: Disconnects the bottom node from the scene graph and -// destroys its arc (along with all associated -// transitions). This will also delete the node if -// there are no other pointers to it. -// -// Normally, this should be called only when you are -// really done with the node. If you want to remove a -// node from the scene graph but keep it around for -// later, you should probably use reparent_to() and put -// it under a holding node instead. -// -// After the node is removed, the NodePath will have -// been cleared. -//////////////////////////////////////////////////////////////////// -void NodePath:: -remove_node() { - nassertv(_error_type != ET_not_found); - if (!has_arcs() || !arc()->is_attached()) { - // If we have no arcs (maybe we were already removed), or if the - // bottom arc has been disconnected (maybe a parent was removed), - // quietly do nothing except to ensure the NodePath is clear. - (*this) = NodePath::removed(); - return; - } - - PT_NodeRelation darc = arc(); - PT_Node dnode = node(); - - // First, disconnect the arc from the scene graph. This will orphan - // our bottom node. - remove_arc(darc); - - // Set the chain to stop here, so that any NodePaths sharing this - // one will now begin at this "deleted" node. - ArcComponent here(dnode.p()); - (*_head) = here; - - // Now remove our own chain reference. If there were no other - // sharing NodePaths, this will also delete the complete chain, - // including the above newly-changed _head node, and all of the - // nodes at this point and below. - - // If there *are* some sharing NodePaths, they will keep this node - // from being actually destructed (although it has been removed from - // the scene graph), and they will now believe they are rooted at - // that destructed node, cut off from the rest of the world. - (*this) = NodePath::removed(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::as_string -// Access: Published -// Description: Formats the NodePath as a string, showing each node -// name (or possibly type, if the node is unnamed), -// separated by slashes. -// -// The resulting string is not necessarily unique to -// this NodePath. Some nodes may be unnamed; different -// nodes in the graph may share the same name. Even if -// this is not the case, there might be multiple -// different arcs between the same two nodes, which -// cannot be described in this string. -// -// start_at_node is the node number, zero-based, at -// which to start the string. Normally this would be 0 -// to format the entire path, or 1 to format the path -// beginning at the node below the top node (which could -// then be used to restore the path later, subject to -// the ambiguities described above). -//////////////////////////////////////////////////////////////////// -string NodePath:: -as_string(int start_at_node) const { - nassertr(start_at_node >= 0, string()); - - switch (_error_type) { - case ET_not_found: - return "**not found**"; - case ET_removed: - return "**removed**"; - case ET_fail: - return "**error**"; - default: - break; - } - - if (is_empty()) { - // An empty path always returns an empty string. - return string(); - } - - // In the normal case, we have at least one node. We must walk to - // the end of the list, then back up start_at_node times, and start - // formatting names from there. - string result; - r_as_string(_head, result, start_at_node); - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::write_transitions -// Access: Published -// Description: Writes to the indicated output stream a list of all -// transitions encountered on all arcs along the -// NodePath. -//////////////////////////////////////////////////////////////////// -void NodePath:: -write_transitions(ostream &out, int indent_level) const { - if (is_empty()) { - out << "Empty NodePath, no transitions.\n"; - } else if (is_singleton()) { - out << "Singleton NodePath, no transitions.\n"; - } else { - r_write_transitions(_head, out, indent_level); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_net_transitions -// Access: Published -// Description: Returns the set of all accumulated transitions along -// the NodePath. -//////////////////////////////////////////////////////////////////// -AllTransitionsWrapper NodePath:: -get_net_transitions() const { - AllTransitionsWrapper trans; - - if (has_arcs()) { - r_get_net_transitions(_head, trans); - } - - return trans; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::analyze -// Access: Published -// Description: Reports some statistics about the scene graph -// properties at and below this node. -//////////////////////////////////////////////////////////////////// -void NodePath:: -analyze() const { - nassertv_always(!is_empty()); - SceneGraphAnalyzer sga(_graph_type); - sga.add_node(node()); - sga.write(nout); -} - - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::flatten_light -// Access: Published -// Description: Lightly flattens out the hierarchy below this node by -// applying transforms, colors, and texture matrices -// from the arcs onto the vertices, but does not remove -// any nodes. -// -// This can result in improved rendering performance -// because there will be fewer transforms in the -// resulting scene graph, but the number of nodes will -// remain the same. -// -// Particularly, any NodePaths that reference nodes -// within this hierarchy will not be damaged. However, -// since this operation will remove transforms from the -// scene graph, it may be dangerous to apply to arcs -// where you expect to dynamically modify the transform, -// or where you expect the geometry to remain in a -// particular local coordinate system. -// -// The return value is always 0, since flatten_light -// does not remove any arcs. -//////////////////////////////////////////////////////////////////// -int NodePath:: -flatten_light() { - nassertr(!is_empty(), 0); - SceneGraphReducer gr(_graph_type); - gr.apply_transitions(arc()); - - return 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::flatten_medium -// Access: Published -// Description: A more thorough flattening than flatten_light(), this -// first applies all the transforms, colors, and texture -// matrices from the arcs onto the vertices, and then -// removes unneeded grouping nodes--nodes that have -// exactly one child, for instance, but have no special -// properties in themselves. -// -// This results in improved perforamance over -// flatten_light() because the number of nodes in the -// scene graph is reduced. -// -// If max_children is specified, it represents the -// maximum number of children a node is allowed to have -// and still be flattened. Normally, this is 1; we -// don't typically want to flatten a node that has -// multiple children. However, sometimes this may be -// desirable; set this parameter to control the limit. -// If this is set to -1, there is no limit. -// -// The return value is the number of arcs removed. -//////////////////////////////////////////////////////////////////// -int NodePath:: -flatten_medium(int max_children) { - nassertr(!is_empty(), 0); - SceneGraphReducer gr(_graph_type); - gr.set_max_children(max_children); - gr.apply_transitions(arc()); - int num_removed = gr.flatten(node(), false); - - if (sgmanip_cat.is_debug()) { - sgmanip_cat.debug() - << "flatten_medium() removed " << num_removed << " arcs.\n"; - } - - return num_removed; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::flatten_strong -// Access: Published -// Description: The strongest possible flattening. This first -// applies all of the transforms to the vertices, as in -// flatten_medium(), but then it will combine sibling -// nodes together when possible, in addition to removing -// unnecessary parent-child nodes. This can result in -// substantially fewer nodes, but any nicely-grouped -// hierachical bounding volumes may be lost. -// -// It is generally a good idea to apply this kind of -// flattening only to nodes that will be culled largely -// as a single unit, like a car. Applying this to an -// entire scene may result in overall poorer performance -// because of less-effective culling. -//////////////////////////////////////////////////////////////////// -int NodePath:: -flatten_strong(int max_children) { - nassertr(!is_empty(), 0); - SceneGraphReducer gr(_graph_type); - gr.set_max_children(max_children); - gr.apply_transitions(arc()); - int num_removed = gr.flatten(node(), true); - - if (sgmanip_cat.is_debug()) { - sgmanip_cat.debug() - << "flatten_strong() removed " << num_removed << " arcs.\n"; - } - - return num_removed; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::write_bam_file -// Access: Published -// Description: Writes the contents of this node and below out to a -// bam file with the indicated filename. This file may -// then be read in again, as is, at some later point. -// Returns true if successful, false on some kind of -// error. -//////////////////////////////////////////////////////////////////// -bool NodePath:: -write_bam_file(const string &filename) const { - nassertr(!is_empty(), false); - BamFile bam_file; - - bool okflag = false; - - if (bam_file.open_write(filename)) { - if (bam_file.write_object(node())) { - okflag = true; - } - bam_file.close(); - } - - return okflag; -} - - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_pos -// Access: Published -// Description: Sets the translation component of the transform, -// leaving rotation and scale untouched. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_pos(const LVecBase3f &pos) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(); - mat.set_row(3, pos); - set_mat(mat); -} - -void NodePath:: -set_x(float x) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(); - mat(3, 0) = x; - set_mat(mat); -} - -void NodePath:: -set_y(float y) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(); - mat(3, 1) = y; - set_mat(mat); -} - -void NodePath:: -set_z(float z) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(); - mat(3, 2) = z; - set_mat(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_pos -// Access: Published -// Description: Retrieves the translation component of the transform. -//////////////////////////////////////////////////////////////////// -LPoint3f NodePath:: -get_pos() const { - nassertr(has_arcs(), LPoint3f(0.0f, 0.0f, 0.0f)); - LMatrix4f mat = get_mat(); - return mat.get_row3(3); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_hpr -// Access: Published -// Description: Sets the rotation component of the transform, -// leaving translation and scale untouched. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_hpr(const LVecBase3f &hpr) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(); - LVecBase3f scale, old_hpr, pos; - decompose_matrix(mat, scale, old_hpr, pos); - compose_matrix(mat, scale, hpr, pos); - set_mat(mat); -} - -void NodePath:: -set_h(float h) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(); - LVecBase3f scale, old_hpr, pos; - decompose_matrix(mat, scale, old_hpr, pos); - old_hpr[0] = h; - compose_matrix(mat, scale, old_hpr, pos); - set_mat(mat); -} - -void NodePath:: -set_p(float p) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(); - LVecBase3f scale, old_hpr, pos; - decompose_matrix(mat, scale, old_hpr, pos); - old_hpr[1] = p; - compose_matrix(mat, scale, old_hpr, pos); - set_mat(mat); -} - -void NodePath:: -set_r(float r) { - LMatrix4f mat = get_mat(); - LVecBase3f scale, old_hpr, pos; - decompose_matrix(mat, scale, old_hpr, pos); - old_hpr[2] = r; - compose_matrix(mat, scale, old_hpr, pos); - set_mat(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_hpr -// Access: Published -// Description: Retrieves the rotation component of the transform. -//////////////////////////////////////////////////////////////////// -LVecBase3f NodePath:: -get_hpr() const { - nassertr(has_arcs(), LVecBase3f(0.0f, 0.0f, 0.0f)); - LMatrix4f mat = get_mat(); - LVecBase3f scale, hpr, pos; - decompose_matrix(mat, scale, hpr, pos); - return hpr; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_hpr -// Access: Published -// Description: Retrieves the rotation component of the transform. -//////////////////////////////////////////////////////////////////// -LVecBase3f NodePath:: -get_hpr(float roll) const { - nassertr(has_arcs(), LVecBase3f(0.0f, 0.0f, 0.0f)); - LMatrix4f mat = get_mat(); - LVecBase3f scale, hpr, pos; - decompose_matrix(mat, scale, hpr, pos, roll); - return hpr; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_scale -// Access: Published -// Description: Sets the scale component of the transform, -// leaving translation and rotation untouched. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_scale(const LVecBase3f &sv3) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(); - LVecBase3f old_scale, hpr, pos; - decompose_matrix(mat, old_scale, hpr, pos); - compose_matrix(mat, sv3, hpr, pos); - set_mat(mat); -} - -void NodePath:: -set_sx(float sx) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(); - LVecBase3f old_scale, hpr, pos; - decompose_matrix(mat, old_scale, hpr, pos); - old_scale[0] = sx; - compose_matrix(mat, old_scale, hpr, pos); - set_mat(mat); -} - -void NodePath:: -set_sy(float sy) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(); - LVecBase3f old_scale, hpr, pos; - decompose_matrix(mat, old_scale, hpr, pos); - old_scale[1] = sy; - compose_matrix(mat, old_scale, hpr, pos); - set_mat(mat); -} - -void NodePath:: -set_sz(float sz) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(); - LVecBase3f old_scale, hpr, pos; - decompose_matrix(mat, old_scale, hpr, pos); - old_scale[2] = sz; - compose_matrix(mat, old_scale, hpr, pos); - set_mat(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_scale -// Access: Published -// Description: Retrieves the scale component of the transform. -//////////////////////////////////////////////////////////////////// -LVecBase3f NodePath:: -get_scale() const { - nassertr(has_arcs(), LVecBase3f(1.0f, 1.0f, 1.0f)); - LMatrix4f mat = get_mat(); - - // We decompose the scale directly instead of calling - // decompose_matrix(), since we don't care about the hpr and don't - // need to go through all the work of unrolling the axes. - - // Extract the axes from the matrix. - LVector3f x, y, z; - mat.get_row3(x,0); - mat.get_row3(y,1); - mat.get_row3(z,2); - - - // Now return the lengths of these axes as the scale. - return LVecBase3f(length(x), length(y), length(z)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_color_scale -// Access: Published -// Description: Sets the color scale component of the transform, -// leaving translation and rotation untouched. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_color_scale(const LVecBase4f &sv4) { - nassertv_always(has_arcs()); - -#ifndef NDEBUG - if (_graph_type == DataRelation::get_class_type()) { - sgmanip_cat.warning() - << "Setting color scale on data graph arc.\n" - << "(This is meaningless. Did you mean to do this to the bottom node?)\n"; - } -#endif - - NodeRelation *darc = _head->get_arc(); - if (sv4[0] != 1.0f || sv4[1] != 1.0f || sv4[2] != 1.0f) { - LMatrix4f mat = LMatrix4f::scale_mat(sv4[0], sv4[1], sv4[2]); - darc->set_transition(new ColorMatrixTransition(mat)); - } - else { - darc->clear_transition(ColorMatrixTransition::get_class_type()); - } - - if (sv4[3] != 1) { - darc->set_transition(new AlphaTransformTransition(0.0f, sv4[3])); - } - else { - darc->clear_transition(AlphaTransformTransition::get_class_type()); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_color_scale -// Access: Published -// Description: Returns the complete transform vector that has been -// applied to the bottom arc, or the all 1's if no -// scale has been applied -//////////////////////////////////////////////////////////////////// -LVecBase4f NodePath:: -get_color_scale() const { - nassertr(has_arcs(), LVecBase4f(1.0f,1.0f,1.0f,1.0f)); - - LVecBase4f scale; - - NodeRelation *darc = arc(); - const ColorMatrixTransition *ct; - if (!get_transition_into(ct, darc)) { - // No relative transform. - scale[0] = 1.0f; - scale[1] = 1.0f; - scale[2] = 1.0f; - } - else - { - LVecBase3f old_scale, hpr, pos; - decompose_matrix(ct->get_matrix(), old_scale, hpr, pos); - scale[0] = old_scale[0]; - scale[1] = old_scale[1]; - scale[2] = old_scale[2]; - } - - const AlphaTransformTransition *att; - if (!get_transition_into(att, darc)) { - scale[3] = 1.0f; - } - else { - scale[3] = att->get_scale(); - } - - return scale; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_pos_hpr -// Access: Published -// Description: Sets the translation and rotation component of the -// transform, leaving scale untouched. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_pos_hpr(const LVecBase3f &pos, const LVecBase3f &hpr) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(); - LVecBase3f scale, old_hpr, old_pos; - decompose_matrix(mat, scale, old_hpr, old_pos); - compose_matrix(mat, scale, hpr, pos); - set_mat(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_hpr_scale -// Access: Published -// Description: Sets the rotation and scale components of the -// transform, leaving translation untouched. This, or -// set_pos_hpr_scale, is the preferred way to update a -// transform when both hpr and scale are to be changed. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_hpr_scale(const LVecBase3f &hpr, const LVecBase3f &scale) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(); - LVecBase3f old_pos; - mat.get_row3(old_pos, 3); - compose_matrix(mat, scale, hpr, old_pos); - set_mat(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_pos_hpr_scale -// Access: Published -// Description: Completely replaces the transform with new -// translation, rotation, and scale components. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_pos_hpr_scale(const LVecBase3f &pos, const LVecBase3f &hpr, - const LVecBase3f &scale) { - nassertv(has_arcs()); - LMatrix4f mat; - compose_matrix(mat, scale, hpr, pos); - set_mat(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_mat -// Access: Published -// Description: Directly sets an arbitrary 4x4 transform matrix. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_mat(const LMatrix4f &mat) { - nassertv_always(has_arcs()); - -#ifndef NDEBUG - if (_graph_type == DataRelation::get_class_type()) { - sgmanip_cat.warning() - << "Setting transform on data graph arc.\n" - << "(This is probably meaningless. Did you mean to do this to the bottom node?)\n"; - } -#endif // NDEBUG - -#ifndef NDEBUG - if (check_singular_transform) { - LMatrix4f inv_mat; - bool ok = inv_mat.invert_from(mat); - if (!ok) { - sgmanip_cat.error() - << "Attempt to set a singular transform on " << *this << "\n"; - nassertv(false); - } - } -#endif // NDEBUG - - arc()->set_transition(new TransformTransition(mat)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::look_at -// Access: Published -// Description: Sets the transform on this NodePath so that it -// rotates to face the indicated point in space. This -// will overwrite any previously existing scale on the -// node, although it will preserve any translation. See -// also look_at_preserve_scale(). -//////////////////////////////////////////////////////////////////// -void NodePath:: -look_at(const LPoint3f &point, const LVector3f &up) { - nassertv(has_arcs()); - - LPoint3f pos = get_pos(); - - LMatrix4f mat; - ::look_at(mat, point - pos, up); - mat.set_row(3, pos); - set_mat(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::heads_up -// Access: Published -// Description: Behaves like look_at(), but with a strong preference -// to keeping the up vector oriented in the indicated -// "up" direction. -//////////////////////////////////////////////////////////////////// -void NodePath:: -heads_up(const LPoint3f &point, const LVector3f &up) { - nassertv(has_arcs()); - - LPoint3f pos = get_pos(); - - LMatrix4f mat; - ::heads_up(mat, point - pos, up); - mat.set_row(3, pos); - set_mat(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::look_at_preserve_scale -// Access: Published -// Description: Functions like look_at(), but preforms additional -// work to preserve any scales that may already be -// present on the node. Normally, look_at() blows away -// the scale because scale and rotation are represented -// in the same part of the matrix. -//////////////////////////////////////////////////////////////////// -void NodePath:: -look_at_preserve_scale(const LPoint3f &point, const LVector3f &up) { - nassertv(has_arcs()); - - LMatrix4f mat = get_mat(); - - // Extract the axes from the matrix. - LVector3f x, y, z; - - mat.get_row3(x,0); - mat.get_row3(y,1); - mat.get_row3(z,2); - - // The lengths of the axes defines the scale. - - float scale_0 = length(x); - float scale_1 = length(y); - float scale_2 = length(z); - - LPoint3f pos; - mat.get_row3(pos,3); - ::look_at(mat, point - pos, up); - - // Now reapply the scale and position. - - mat.get_row3(x,0); - mat.get_row3(y,1); - mat.get_row3(z,2); - - x *= scale_0; - y *= scale_1; - z *= scale_2; - - mat.set_row(0, x); - mat.set_row(1, y); - mat.set_row(2, z); - mat.set_row(3, pos); - set_mat(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::heads_up_preserve_scale -// Access: Published -// Description: Functions like heads_up(), but preforms additional -// work to preserve any scales that may already be -// present on the node. Normally, heads_up() blows away -// the scale because scale and rotation are represented -// in the same part of the matrix. -//////////////////////////////////////////////////////////////////// -void NodePath:: -heads_up_preserve_scale(const LPoint3f &point, const LVector3f &up) { - nassertv(has_arcs()); - - LMatrix4f mat = get_mat(); - - // Extract the axes from the matrix. - LVector3f x, y, z; - mat.get_row3(x,0); - mat.get_row3(y,1); - mat.get_row3(z,2); - - float scale_0 = length(x); - float scale_1 = length(y); - float scale_2 = length(z); - - // The lengths of the axes defines the scale. - LPoint3f pos; - mat.get_row3(pos,3); - - ::heads_up(mat, point - pos, up); - - // Now reapply the scale and position. - - mat.get_row3(x,0); - mat.get_row3(y,1); - mat.get_row3(z,2); - - x *= scale_0; - y *= scale_1; - z *= scale_2; - - mat.set_row(0, x); - mat.set_row(1, y); - mat.set_row(2, z); - mat.set_row(3, pos); - set_mat(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_pos -// Access: Published -// Description: Sets the translation component of the transform, -// relative to the other node. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_pos(const NodePath &other, const LVecBase3f &pos) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(other); - mat.set_row(3, pos); - set_mat(other, mat); -} - -void NodePath:: -set_x(const NodePath &other, float x) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(other); - mat(3, 0) = x; - set_mat(other, mat); -} - -void NodePath:: -set_y(const NodePath &other, float y) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(other); - mat(3, 1) = y; - set_mat(other, mat); -} - -void NodePath:: -set_z(const NodePath &other, float z) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(other); - mat(3, 2) = z; - set_mat(other, mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_hpr -// Access: Published -// Description: Sets the rotation component of the transform, -// relative to the other node. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_hpr(const NodePath &other, const LVecBase3f &hpr) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(other); - LVecBase3f scale, old_hpr, pos; - decompose_matrix(mat, scale, old_hpr, pos); - compose_matrix(mat, scale, hpr, pos); - set_mat(other, mat); -} - -void NodePath:: -set_h(const NodePath &other, float h) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(other); - LVecBase3f scale, old_hpr, pos; - decompose_matrix(mat, scale, old_hpr, pos); - old_hpr[0] = h; - compose_matrix(mat, scale, old_hpr, pos); - set_mat(other, mat); -} - -void NodePath:: -set_p(const NodePath &other, float p) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(other); - LVecBase3f scale, old_hpr, pos; - decompose_matrix(mat, scale, old_hpr, pos); - old_hpr[1] = p; - compose_matrix(mat, scale, old_hpr, pos); - set_mat(other, mat); -} - -void NodePath:: -set_r(const NodePath &other, float r) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(other); - LVecBase3f scale, old_hpr, pos; - decompose_matrix(mat, scale, old_hpr, pos); - old_hpr[2] = r; - compose_matrix(mat, scale, old_hpr, pos); - set_mat(other, mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_hpr -// Access: Published -// Description: Returns the relative orientation of the bottom node -// as seen from the other node. -//////////////////////////////////////////////////////////////////// -LVecBase3f NodePath:: -get_hpr(const NodePath &other) const { - LMatrix4f mat = get_mat(other); - LVector3f scale, hpr, pos; - decompose_matrix(mat, scale, hpr, pos); - return hpr; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_hpr -// Access: Published -// Description: Returns the relative orientation of the bottom node -// as seen from the other node. -//////////////////////////////////////////////////////////////////// -LVecBase3f NodePath:: -get_hpr(const NodePath &other, float roll) const { - LMatrix4f mat = get_mat(other); - LVector3f scale, hpr, pos; - decompose_matrix(mat, scale, hpr, pos, roll); - return hpr; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_scale -// Access: Published -// Description: Sets the scale component of the transform, -// relative to the other node. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_scale(const NodePath &other, const LVecBase3f &scale) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(other); - LVecBase3f old_scale, hpr, pos; - decompose_matrix(mat, old_scale, hpr, pos); - compose_matrix(mat, scale, hpr, pos); - set_mat(other, mat); -} - -void NodePath:: -set_sx(const NodePath &other, float sx) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(other); - LVecBase3f old_scale, hpr, pos; - decompose_matrix(mat, old_scale, hpr, pos); - old_scale[0] = sx; - compose_matrix(mat, old_scale, hpr, pos); - set_mat(other, mat); -} - -void NodePath:: -set_sy(const NodePath &other, float sy) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(other); - LVecBase3f old_scale, hpr, pos; - decompose_matrix(mat, old_scale, hpr, pos); - old_scale[1] = sy; - compose_matrix(mat, old_scale, hpr, pos); - set_mat(other, mat); -} - -void NodePath:: -set_sz(const NodePath &other, float sz) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(other); - LVecBase3f old_scale, hpr, pos; - decompose_matrix(mat, old_scale, hpr, pos); - old_scale[2] = sz; - compose_matrix(mat, old_scale, hpr, pos); - set_mat(other, mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_scale -// Access: Published -// Description: Returns the relative scale of the bottom node -// as seen from the other node. -//////////////////////////////////////////////////////////////////// -LVecBase3f NodePath:: -get_scale(const NodePath &other) const { - LMatrix4f mat = get_mat(other); - - // We decompose the scale directly instead of calling - // decompose_matrix(), since we don't care about the hpr and don't - // need to go through all the work of unrolling the axes. - - // Extract the axes from the matrix. - LVector3f x, y, z; - mat.get_row3(x,0); - mat.get_row3(y,1); - mat.get_row3(z,2); - - // Now return the lengths of these axes as the scale. - return LVecBase3f(length(x), length(y), length(z)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_pos_hpr -// Access: Published -// Description: Sets the translation and rotation component of the -// transform, relative to the other node. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_pos_hpr(const NodePath &other, const LVecBase3f &pos, - const LVecBase3f &hpr) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(other); - LVecBase3f scale, old_hpr, old_pos; - decompose_matrix(mat, scale, old_hpr, old_pos); - compose_matrix(mat, scale, hpr, pos); - set_mat(other, mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_hpr_scale -// Access: Published -// Description: Sets the rotation and scale components of the -// transform, leaving translation untouched. This, or -// set_pos_hpr_scale, is the preferred way to update a -// transform when both hpr and scale are to be changed. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_hpr_scale(const NodePath &other, const LVecBase3f &hpr, const LVecBase3f &scale) { - nassertv(has_arcs()); - LMatrix4f mat = get_mat(other); - LVecBase3f old_pos; - mat.get_row3(old_pos, 3); - compose_matrix(mat, scale, hpr, old_pos); - set_mat(other, mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_pos_hpr_scale -// Access: Published -// Description: Completely replaces the transform with new -// translation, rotation, and scale components, relative -// to the other node. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_pos_hpr_scale(const NodePath &other, - const LVecBase3f &pos, const LVecBase3f &hpr, - const LVecBase3f &scale) { - nassertv(has_arcs()); - LMatrix4f mat; - compose_matrix(mat, scale, hpr, pos); - set_mat(other, mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_mat -// Access: Published -// Description: Returns the matrix that describes the coordinate -// space of the bottom node, relative to the other -// path's bottom node's coordinate space. -//////////////////////////////////////////////////////////////////// -LMatrix4f NodePath:: -get_mat(const NodePath &other) const { - nassertr(_error_type == ET_ok && other._error_type == ET_ok, - LMatrix4f::ident_mat()); - NodeTransitionWrapper ntw(TransformTransition::get_class_type()); - - if (is_empty() && other.is_empty()) { - return LMatrix4f::ident_mat(); - - } else if (is_empty()) { - wrt(NULL, other.node(), other.begin(), other.end(), - ntw, _graph_type); - - } else if (other.is_empty()) { - wrt(node(), begin(), end(), (Node *)NULL, ntw, _graph_type); - - } else { - wrt(node(), begin(), end(), - other.node(), other.begin(), other.end(), - ntw, _graph_type); - } - - const TransformTransition *tt; - if (!get_transition_into(tt, ntw)) { - // No relative transform. - return LMatrix4f::ident_mat(); - } else { - return tt->get_matrix(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_mat -// Access: Published -// Description: Converts the indicated matrix from the other's -// coordinate space to the local coordinate space, and -// applies it to the arc. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_mat(const NodePath &other, const LMatrix4f &mat) { - nassertv(_error_type == ET_ok && other._error_type == ET_ok); - nassertv_always(has_arcs()); - -#ifndef NDEBUG - if (_graph_type == DataRelation::get_class_type()) { - sgmanip_cat.warning() - << "Setting transform on data graph arc.\n" - << "(This is probably meaningless. Did you mean to do this to the bottom node?)\n"; - } -#endif - - NodeRelation *darc = arc(); - - // First, we perform a wrt to the node's parent, to get the - // conversion matrix. - NodeTransitionWrapper ntw(TransformTransition::get_class_type()); - ForwardIterator from = begin(); - ++from; - - if (other.is_empty()) { - wrt(NULL, darc->get_parent(), from, end(), ntw, _graph_type); - } else { - wrt(other.node(), other.begin(), other.end(), - darc->get_parent(), from, end(), - ntw, _graph_type); - } - - LMatrix4f new_mat,*new_mat_ptr; - const TransformTransition *tt; - - if (!get_transition_into(tt, ntw)) { - // No relative transform. - new_mat_ptr = (LMatrix4f*)&mat; - } else { - new_mat.multiply(mat,tt->get_matrix()); - new_mat_ptr = &new_mat; - } - -#ifndef NDEBUG - if (check_singular_transform) { - LMatrix4f inv_mat; - bool ok = inv_mat.invert_from(*new_mat_ptr); - if (!ok) { - sgmanip_cat.error() - << "Attempt to set a singular transform on " << *this << "\n"; - nassertv(false); - } - } -#endif // NDEBUG - - darc->set_transition(new TransformTransition(*new_mat_ptr)); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_relative_point -// Access: Published -// Description: Given that the indicated point is in the coordinate -// system of the other node, returns the same point in -// this node's coordinate system. -//////////////////////////////////////////////////////////////////// -LPoint3f NodePath:: -get_relative_point(const NodePath &other, const LVecBase3f &point) { - LPoint3f rel_point = LPoint3f(point) * other.get_mat(*this); - return rel_point; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::look_at -// Access: Published -// Description: Sets the transform on this NodePath so that it -// rotates to face the indicated point in space, which -// is relative to the other NodePath. This -// will overwrite any previously existing scale on the -// node, although it will preserve any translation. -//////////////////////////////////////////////////////////////////// -void NodePath:: -look_at(const NodePath &other, const LPoint3f &point, const LVector3f &up) { - nassertv(has_arcs()); - - LPoint3f pos = get_pos(); - - NodePath parent(*this); - parent.shorten(1); - LPoint3f rel_point = point * other.get_mat(parent); - - LMatrix4f mat; - ::look_at(mat, rel_point - pos, up); - mat.set_row(3, pos); - set_mat(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::heads_up -// Access: Published -// Description: Behaves like look_at(), but with a strong preference -// to keeping the up vector oriented in the indicated -// "up" direction. -//////////////////////////////////////////////////////////////////// -void NodePath:: -heads_up(const NodePath &other, const LPoint3f &point, const LVector3f &up) { - nassertv(has_arcs()); - - LPoint3f pos = get_pos(); - - NodePath parent(*this); - parent.shorten(1); - LPoint3f rel_point = point * other.get_mat(parent); - - LMatrix4f mat; - ::heads_up(mat, rel_point - pos, up); - mat.set_row(3, pos); - set_mat(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::look_at_preserve_scale -// Access: Published -// Description: Functions like look_at(), but preforms additional -// work to preserve any scales that may already be -// present on the node. Normally, look_at() blows away -// the scale because scale and rotation are represented -// in the same part of the matrix. -//////////////////////////////////////////////////////////////////// -void NodePath:: -look_at_preserve_scale(const NodePath &other, const LPoint3f &point, - const LVector3f &up) { - nassertv(has_arcs()); - - LMatrix4f mat = get_mat(); - - // Extract the axes from the matrix. - LVector3f x, y, z; - mat.get_row3(x,0); - mat.get_row3(y,1); - mat.get_row3(z,2); - - // The lengths of the axes defines the scale. - float scale_0 = length(x); - float scale_1 = length(y); - float scale_2 = length(z); - - LPoint3f pos; - mat.get_row3(pos,3); - - NodePath parent(*this); - parent.shorten(1); - LPoint3f rel_point = point * other.get_mat(parent); - - ::look_at(mat, rel_point - pos, up); - - // Now reapply the scale and position. - - mat.get_row3(x,0); - mat.get_row3(y,1); - mat.get_row3(z,2); - - x *= scale_0; - y *= scale_1; - z *= scale_2; - - mat.set_row(0, x); - mat.set_row(1, y); - mat.set_row(2, z); - mat.set_row(3, pos); - set_mat(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::heads_up_preserve_scale -// Access: Published -// Description: Functions like heads_up(), but preforms additional -// work to preserve any scales that may already be -// present on the node. Normally, heads_up() blows away -// the scale because scale and rotation are represented -// in the same part of the matrix. -//////////////////////////////////////////////////////////////////// -void NodePath:: -heads_up_preserve_scale(const NodePath &other, const LPoint3f &point, - const LVector3f &up) { - nassertv(has_arcs()); - - LMatrix4f mat = get_mat(); - - // Extract the axes from the matrix. - LVector3f x, y, z; - mat.get_row3(x,0); - mat.get_row3(y,1); - mat.get_row3(z,2); - - // The lengths of the axes defines the scale. - float scale_0 = length(x); - float scale_1 = length(y); - float scale_2 = length(z); - - LPoint3f pos; - mat.get_row3(pos,3); - - NodePath parent(*this); - parent.shorten(1); - LPoint3f rel_point = point * other.get_mat(parent); - - ::heads_up(mat, rel_point - pos, up); - - // Now reapply the scale and position. - mat.get_row3(x,0); - mat.get_row3(y,1); - mat.get_row3(z,2); - - x *= scale_0; - y *= scale_1; - z *= scale_2; - - mat.set_row(0, x); - mat.set_row(1, y); - mat.set_row(2, z); - mat.set_row(3, pos); - set_mat(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_color -// Access: Published -// Description: Sets the color transition for a render relation -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_color(const Colorf &color, int priority) { - nassertv_always(has_arcs()); - - ColorTransition *col_trans = new ColorTransition(color); - arc()->set_transition(col_trans, priority); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_color_off -// Access: Published -// Description: Sets the geometry at this level and below to render -// using the geometry color. This is normally the -// default, but it may be useful to use this to -// contradict set_color() at a higher node level (or, -// with a priority, to override a set_color() at a lower -// level). -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_color_off(int priority) { - nassertv_always(has_arcs()); - - ColorTransition *col_trans = - new ColorTransition(ColorTransition::off()); - arc()->set_transition(col_trans, priority); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_color -// Access: Published -// Description: Returns the color that has been assigned to the arc, -// or black if no color has been assigned. -//////////////////////////////////////////////////////////////////// -Colorf NodePath:: -get_color() const { - nassertr(has_arcs(), false); - - const ColorTransition *ct; - if (get_transition_into(ct, arc())) { - if (ct->is_on() && ct->is_real()) { - return ct->get_color(); - } - } - - sgmanip_cat.warning() - << "get_color() called on " << *this << " which has no color set.\n"; - - return Colorf(0.0f, 0.0f, 0.0f, 0.0f); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_bin -// Access: Published -// Description: Assigns the geometry at this level and below to the -// named rendering bin. It is the user's responsibility -// to ensure that such a bin already exists, either via -// the cull-bin Configrc variable, or by explicitly -// creating a GeomBin of the appropriate type at -// runtime. -// -// There are two default bins created when Panda is -// started: "default" and "fixed". Normally, all -// geometry is assigned to "default" unless specified -// otherwise. This bin renders opaque geometry in -// state-sorted order, followed by transparent geometry -// sorted back-to-front. If any geometry is assigned to -// "fixed", this will be rendered following all the -// geometry in "default", in the order specified by -// draw_order for each piece of geometry so assigned. -// -// The draw_order parameter is meaningful only for -// GeomBinFixed type bins, e.g. "fixed". Other kinds of -// bins ignore it. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_bin(const string &bin_name, int draw_order, int priority) { - nassertv_always(has_arcs()); - - GeomBinTransition *bin_trans = new GeomBinTransition(bin_name, draw_order); - arc()->set_transition(bin_trans, priority); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_bin_name -// Access: Published -// Description: Returns the name of the bin that this particular arc -// was assigned to via set_bin(), or the empty string if -// no bin was assigned. See set_bin() and has_bin(). -//////////////////////////////////////////////////////////////////// -string NodePath:: -get_bin_name() const { - nassertr(has_arcs(), string()); - - const GeomBinTransition *bt; - if (get_transition_into(bt, arc())) { - if (bt->is_on()) { - return bt->get_bin(); - } - } - - return string(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_bin_draw_order -// Access: Published -// Description: Returns the drawing order associated with the bin -// that this particular arc was assigned to via -// set_bin(), or 0 if no bin was assigned. See -// set_bin() and has_bin(). -//////////////////////////////////////////////////////////////////// -int NodePath:: -get_bin_draw_order() const { - nassertr(has_arcs(), 0); - - const GeomBinTransition *bt; - if (get_transition_into(bt, arc())) { - if (bt->is_on()) { - return bt->get_draw_order(); - } - } - - return 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_texture -// Access: Published -// Description: Sets the geometry at this level and below to render -// using the indicated texture. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_texture(Texture *tex, int priority) { - nassertv_always(has_arcs()); - nassertv(tex != NULL); - - TextureTransition *tex_trans = new TextureTransition(tex); - arc()->set_transition(tex_trans, priority); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_texture_off -// Access: Published -// Description: Sets the geometry at this level and below to render -// using no texture. This is normally the default, but -// it may be useful to use this to contradict -// set_texture() at a higher node level (or, with a -// priority, to override a set_texture() at a lower -// level). -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_texture_off(int priority) { - nassertv_always(has_arcs()); - - TextureTransition *tex_trans = - new TextureTransition(TextureTransition::off()); - arc()->set_transition(tex_trans, priority); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::has_texture -// Access: Published -// Description: Returns true if a texture has been applied to this -// particular arc via set_texture(), false otherwise. -// This is not the same thing as asking whether the -// geometry at this node will be rendered with -// texturing, as there may be a texture in effect from a -// higher or lower level. -//////////////////////////////////////////////////////////////////// -bool NodePath:: -has_texture() const { - nassertr(has_arcs(), false); - - const TextureTransition *tt; - if (get_transition_into(tt, arc())) { - return tt->is_on(); - } - - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::has_texture_off -// Access: Published -// Description: Returns true if a texture has been specifically -// disabled on this particular arc via -// set_texture_off(), false otherwise. This is not the -// same thing as asking whether the geometry at this -// node will be rendered untextured, as there may be a -// texture in effect from a higher or lower level. -//////////////////////////////////////////////////////////////////// -bool NodePath:: -has_texture_off() const { - nassertr(has_arcs(), false); - - const TextureTransition *tt; - if (get_transition_into(tt, arc())) { - return tt->is_off(); - } - - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_texture -// Access: Published -// Description: Returns the texture that has been set on this -// particular arc, or NULL if no texture has been set. -// This is not necessarily the texture that will be -// applied to the geometry at or below this level, as -// another texture at a higher or lower level may -// override. -//////////////////////////////////////////////////////////////////// -Texture *NodePath:: -get_texture() const { - nassertr(has_arcs(), NULL); - - const TextureTransition *tt; - if (get_transition_into(tt, arc())) { - if (tt->is_on()) { - return tt->get_texture(); - } - } - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_material -// Access: Published -// Description: Sets the geometry at this level and below to render -// using the indicated material. -// -// This operation copies the given material pointer. If -// the material structure is changed later, it must be -// reapplied via another call to set_material(). -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_material(Material *mat, int priority) { - nassertv_always(has_arcs()); - nassertv(mat != NULL); - - // We create a temporary Material pointer, a copy of the one we are - // given, to allow the user to monkey with the material and set it - // again later, with the desired effect. If we stored the user's - // pointer directly, it would be bad if the user later modified the - // values within the Material. - PT(Material) temp = new Material(*mat); - const Material *mp = MaterialPool::get_material(temp); - - MaterialTransition *mat_trans = new MaterialTransition(mp); - arc()->set_transition(mat_trans, priority); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_material_off -// Access: Published -// Description: Sets the geometry at this level and below to render -// using no material. This is normally the default, but -// it may be useful to use this to contradict -// set_material() at a higher node level (or, with a -// priority, to override a set_material() at a lower -// level). -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_material_off(int priority) { - nassertv_always(has_arcs()); - - MaterialTransition *mat_trans = - new MaterialTransition(MaterialTransition::off()); - arc()->set_transition(mat_trans, priority); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::has_material -// Access: Published -// Description: Returns true if a material has been applied to this -// particular arc via set_material(), false otherwise. -//////////////////////////////////////////////////////////////////// -bool NodePath:: -has_material() const { - nassertr(has_arcs(), false); - - const MaterialTransition *mt; - if (get_transition_into(mt, arc())) { - return mt->is_on(); - } - - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_material -// Access: Published -// Description: Returns the material that has been set on this -// particular arc, or NULL if no material has been set. -// This is not necessarily the material that will be -// applied to the geometry at or below this level, as -// another material at a higher or lower level may -// override. -// -// This function returns a copy of the given material, -// to allow changes, if desired. Once changes are made, -// they should be reapplied via set_material(). -//////////////////////////////////////////////////////////////////// -PT(Material) NodePath:: -get_material() const { - nassertr(has_arcs(), NULL); - - const MaterialTransition *mt; - if (get_transition_into(mt, arc())) { - if (mt->is_on()) { - return new Material(*mt->get_material()); - } - } - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_fog -// Access: Published -// Description: Sets the geometry at this level and below to render -// using the indicated fog. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_fog(Fog *fog, int priority) { - nassertv_always(has_arcs()); - nassertv(fog != NULL); - - FogTransition *fog_trans = new FogTransition(fog); - arc()->set_transition(fog_trans, priority); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_fog_off -// Access: Published -// Description: Sets the geometry at this level and below to render -// using no fog. This is normally the default, but -// it may be useful to use this to contradict -// set_fog() at a higher node level (or, with a -// priority, to override a set_fog() at a lower -// level). -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_fog_off(int priority) { - nassertv_always(has_arcs()); - - FogTransition *fog_trans = - new FogTransition(FogTransition::off()); - arc()->set_transition(fog_trans, priority); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::has_fog -// Access: Published -// Description: Returns true if a fog has been applied to this -// particular arc via set_fog(), false otherwise. -// This is not the same thing as asking whether the -// geometry at this node will be rendered with -// fog, as there may be a fog in effect from a higher or -// lower level. -//////////////////////////////////////////////////////////////////// -bool NodePath:: -has_fog() const { - nassertr(has_arcs(), false); - - const FogTransition *tt; - if (get_transition_into(tt, arc())) { - return tt->is_on(); - } - - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::has_fog_off -// Access: Published -// Description: Returns true if a fog has been specifically -// disabled on this particular arc via -// set_fog_off(), false otherwise. This is not the -// same thing as asking whether the geometry at this -// node will be rendered unfogged, as there may be a -// fog in effect from a higher or lower level. -//////////////////////////////////////////////////////////////////// -bool NodePath:: -has_fog_off() const { - nassertr(has_arcs(), false); - - const FogTransition *tt; - if (get_transition_into(tt, arc())) { - return tt->is_off(); - } - - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_fog -// Access: Published -// Description: Returns the fog that has been set on this -// particular arc, or NULL if no fog has been set. -// This is not necessarily the fog that will be -// applied to the geometry at or below this level, as -// another fog at a higher or lower level may -// override. -//////////////////////////////////////////////////////////////////// -Fog *NodePath:: -get_fog() const { - nassertr(has_arcs(), NULL); - - const FogTransition *tt; - if (get_transition_into(tt, arc())) { - if (tt->is_on()) { - return tt->get_fog(); - } - } - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_render_mode_wireframe -// Access: Published -// Description: Sets up the geometry at this level and below (unless -// overridden) to render in wireframe mode. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_render_mode_wireframe(int priority) { - nassertv_always(has_arcs()); - - arc()->set_transition(new RenderModeTransition(RenderModeProperty::M_wireframe), priority); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_render_mode_filled -// Access: Published -// Description: Sets up the geometry at this level and below (unless -// overridden) to render in filled (i.e. not wireframe) -// mode. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_render_mode_filled(int priority) { - nassertv_always(has_arcs()); - - RenderModeTransition *rmt = - new RenderModeTransition(RenderModeProperty::M_filled); - arc()->set_transition(rmt, priority); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_two_sided -// Access: Published -// Description: Specifically sets or disables two-sided rendering -// mode on this particular arc. If no other arcs -// override, this will cause backfacing polygons to be -// drawn (in two-sided mode, true) or culled (in -// one-sided mode, false). -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_two_sided(bool two_sided, int priority) { - nassertv_always(has_arcs()); - - CullFaceProperty::Mode mode = - two_sided ? - CullFaceProperty::M_cull_none : - CullFaceProperty::M_cull_clockwise; - - CullFaceTransition *cft = new CullFaceTransition(mode); - arc()->set_transition(cft, priority); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_two_sided -// Access: Published -// Description: Returns true if two-sided rendering has been -// specifically set on this arc via set_two_sided(), or -// false if one-sided rendering has been specifically -// set, or if nothing has been specifically set. See -// also has_two_sided(). This does not necessarily -// imply that the geometry will or will not be rendered -// two-sided, as there may be other arcs that override. -//////////////////////////////////////////////////////////////////// -bool NodePath:: -get_two_sided() const { - nassertr(has_arcs(), false); - - const CullFaceTransition *cft; - if (get_transition_into(cft, arc())) { - return (cft->get_mode() == CullFaceProperty::M_cull_none); - } - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::do_billboard_axis -// Access: Published -// Description: Performs a billboard-type rotate to the indicated -// camera node, one time only, and leaves the object -// rotated. This is similar in principle to heads_up(). -// However, it does lose both translate and scale -// components of the matrix. -//////////////////////////////////////////////////////////////////// -void NodePath:: -do_billboard_axis(const NodePath &camera, float offset) { - nassertv(has_arcs()); - - NodePath parent(*this); - parent.shorten(1); - LMatrix4f rel_mat = camera.get_mat(parent); - - LVector3f up = LVector3f::up(); - LVector3f rel_pos = -rel_mat.get_row3(3); - - LMatrix4f mat; - ::heads_up(mat, rel_pos, up); - - // Also slide the geometry towards the camera according to the - // offset factor. - if (offset != 0.0f) { - LVector3f translate = rel_mat.get_row3(3); - translate.normalize(); - translate *= offset; - mat.set_row(3, translate); - } - - set_mat(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::do_billboard_point_eye -// Access: Published -// Description: Performs a billboard-type rotate to the indicated -// camera node, one time only, and leaves the object -// rotated. This is similar in principle to look_at(), -// although the point_eye billboard effect cannot be -// achieved using the ordinary look_at() call. -//////////////////////////////////////////////////////////////////// -void NodePath:: -do_billboard_point_eye(const NodePath &camera, float offset) { - nassertv(has_arcs()); - - NodePath parent(*this); - parent.shorten(1); - LMatrix4f rel_mat = camera.get_mat(parent); - - LVector3f up = LVector3f::up() * rel_mat; - LVector3f rel_pos = LVector3f::forward() * rel_mat; - - LMatrix4f mat; - ::look_at(mat, rel_pos, up); - - // Also slide the geometry towards the camera according to the - // offset factor. - if (offset != 0.0f) { - LVector3f translate = rel_mat.get_row3(3); - translate.normalize(); - translate *= offset; - mat.set_row(3, translate); - } - - set_mat(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::do_billboard_point_world -// Access: Published -// Description: Performs a billboard-type rotate to the indicated -// camera node, one time only, and leaves the object -// rotated. This is similar in principle to look_at(). -//////////////////////////////////////////////////////////////////// -void NodePath:: -do_billboard_point_world(const NodePath &camera, float offset) { - nassertv(has_arcs()); - - NodePath parent(*this); - parent.shorten(1); - LMatrix4f rel_mat = camera.get_mat(parent); - - LVector3f up = LVector3f::up(); - LVector3f rel_pos = -rel_mat.get_row3(3); - - LMatrix4f mat; - ::look_at(mat, rel_pos, up); - - // Also slide the geometry towards the camera according to the - // offset factor. - if (offset != 0.0f) { - LVector3f translate = rel_mat.get_row3(3); - translate.normalize(); - translate *= offset; - mat.set_row(3, translate); - } - - set_mat(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::set_transparency -// Access: Published -// Description: Specifically sets or disables transparent rendering -// mode on this particular arc. If no other arcs -// override, this will cause items with a non-1 value -// for alpha color to be rendered partially transparent. -//////////////////////////////////////////////////////////////////// -void NodePath:: -set_transparency(bool transparency, int priority) { - nassertv_always(has_arcs()); - - TransparencyProperty::Mode mode = - transparency ? - TransparencyProperty::M_alpha : - TransparencyProperty::M_none; - - TransparencyTransition *tt = new TransparencyTransition(mode); - arc()->set_transition(tt, priority); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_transparency -// Access: Published -// Description: Returns true if transparent rendering has been -// specifically set on this arc via set_transparency(), or -// false if nontransparent rendering has been specifically -// set, or if nothing has been specifically set. See -// also has_transparency(). This does not necessarily -// imply that the geometry will or will not be rendered -// transparent, as there may be other arcs that override. -//////////////////////////////////////////////////////////////////// -bool NodePath:: -get_transparency() const { - nassertr(has_arcs(), false); - - const TransparencyTransition *tt; - if (get_transition_into(tt, arc())) { - return (tt->get_mode() != TransparencyProperty::M_none); - } - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_hidden_ancestor -// Access: Published -// Description: Returns a NodePath indicating the lowest arc above -// this node which has been set to 'hide'. Calling -// show() on the NodePath returned by this function -// should make the node visible again (unless there is -// another arc further up that also has the 'hide' -// transition set). -// -// This function returns an empty NodePath if no -// ancestors have been set to 'hide'. -//////////////////////////////////////////////////////////////////// -NodePath NodePath:: -get_hidden_ancestor() const { - if (!has_arcs()) { - return NodePath::not_found(); - } - - if (arc()->has_transition(PruneTransition::get_class_type())) { - return *this; - } - - NodePath next(*this); - next.shorten(); - return next.get_hidden_ancestor(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_stashed_ancestor -// Access: Published -// Description: Returns a NodePath indicating the lowest arc above -// this node which has been set to 'stash'. Calling -// unstash() on the NodePath returned by this function -// should make the node visible again (unless there is -// another arc further up that also has been 'stashed'. -// -// This function returns an empty NodePath if no -// ancestors have been 'stashed'. -//////////////////////////////////////////////////////////////////// -NodePath NodePath:: -get_stashed_ancestor() const { - if (!has_arcs()) { - return NodePath::not_found(); - } - - if (arc()->get_graph_type() != _graph_type) { - return *this; - } - - NodePath next(*this); - next.shorten(); - return next.get_stashed_ancestor(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::prepare_scene -// Access: Published -// Description: Walks through the scene graph beginning at the bottom -// node, and does whatever initialization is required to -// render the scene properly with the indicated GSG. It -// is not strictly necessary to call this, since the GSG -// will initialize itself when the scene is rendered, -// but this may take some of the overhead away from that -// process. -// -// If force_retained_mode is true, retained mode is set -// on the geometry encountered, regardless of the -// setting of the retained-mode Config variable. -// Otherwise, retained mode is set only if the -// retained-mode Config variable is true. -//////////////////////////////////////////////////////////////////// -void NodePath:: -prepare_scene(GraphicsStateGuardianBase *gsg, bool force_retained_mode) { - nassertv_always(!is_empty()); - - // Use the ScenePrepareVisitor and fire off a traversal of the scene - // beginning at the bottom node. The ScenePrepareVisitor (defined - // above) will call prepare() on each texture it finds in the scene - // graph at this point and below. - ScenePrepareVisitor visitor; - visitor._gsg = gsg; - visitor._retained_mode = retained_mode || force_retained_mode; - - NodeTransitionWrapper initial(TextureTransition::get_class_type()); - df_traverse(node(), visitor, initial, NullLevelState(), - RenderRelation::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::show_bounds -// Access: Published -// Description: Causes the bounding volume of the bottom node and all -// of its descendants (that is, the bounding volume -// associated with the the bottom arc) to be rendered, -// if possible. The rendering method is less than -// optimal; this is intended primarily for debugging. -//////////////////////////////////////////////////////////////////// -void NodePath:: -show_bounds() { - nassertv_always(has_arcs()); - arc()->set_transition(new DrawBoundsTransition); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::hide_bounds -// Access: Published -// Description: Stops the rendering of the bounding volume begun with -// show_bounds(). -//////////////////////////////////////////////////////////////////// -void NodePath:: -hide_bounds() { - nassertv_always(has_arcs()); - arc()->clear_transition(DrawBoundsTransition::get_class_type()); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::get_bounds -// Access: Published -// Description: Returns a newly-allocated bounding volume containing -// the bottom node and all of its descendants. This is -// the bounding volume on the bottom arc, converted to -// the local coordinate space of the node. -//////////////////////////////////////////////////////////////////// -PT(BoundingVolume) NodePath:: -get_bounds() const { - nassertr(has_arcs(), new BoundingSphere); - - NodeRelation *darc = arc(); - PT(BoundingVolume) bv = darc->get_bound().make_copy(); - if (bv->is_of_type(GeometricBoundingVolume::get_class_type()) && - darc->has_transition(TransformTransition::get_class_type())) { - - // The bounding volume has already been transformed by the arc's - // matrix. We'd rather return a bounding volume in the node's - // space, so we have to untransform it now. Ick. - GeometricBoundingVolume *gbv = DCAST(GeometricBoundingVolume, bv); - NodePath parent(*this); - parent.shorten(1); - LMatrix4f mat = parent.get_mat(*this); - gbv->xform(mat); - } - - return bv; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::write_bounds -// Access: Published -// Description: Writes a description of the bounding volume -// containing the bottom node and all of its descendants -// to the indicated output stream. -//////////////////////////////////////////////////////////////////// -void NodePath:: -write_bounds(ostream &out) const { - get_bounds()->write(out); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::calc_tight_bounds -// Access: Published -// Description: Calculates the minimum and maximum vertices of all -// Geoms at this NodePath's bottom node and below. This -// is a tight bounding box; it will generally be tighter -// than the bounding volume returned by get_bounds() -// (but it is more expensive to compute). -// -// The return value is true if any points are within the -// bounding volume, or false if none are. -//////////////////////////////////////////////////////////////////// -bool NodePath:: -calc_tight_bounds(LPoint3f &min_point, LPoint3f &max_point) { - min_point.set(0.0f, 0.0f, 0.0f); - max_point.set(0.0f, 0.0f, 0.0f); - nassertr_always(!is_empty(), false); - - bool found_any = false; - r_calc_tight_bounds(node(), min_point, max_point, found_any, LMatrix4f::ident_mat()); - - return found_any; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::r_extend -// Access: Private -// Description: The recursive implementation of extend_by(NodePath). -// This must walk to the end of the other path's -// component list and extend in forward order. -//////////////////////////////////////////////////////////////////// -bool NodePath:: -r_extend_by(const ArcComponent *other) { - if (other->is_top_node()) { - return (other->get_node() == node()); - } - - if (!r_extend_by(other->get_next())) { - return false; - } - - if (!extend_by(other->get_arc())) { - return false; - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::r_as_string -// Access: Private -// Description: The recursive implementation of as_string. This -// must reverse the order of the path components. -//////////////////////////////////////////////////////////////////// -int NodePath:: -r_as_string(const ArcComponent *comp, string &result, int skip_nodes) const { - nassertr(comp != (const ArcComponent *)NULL, 0); - - if (comp->get_next() == (const ArcComponent *)NULL) { - // Here's the end of the chain. - result = format_node_name(comp->get_node()); - - return 1; - - } else { - int nodes_before = r_as_string(comp->get_next(), result, skip_nodes); - if (skip_nodes <= nodes_before) { - if (skip_nodes != nodes_before) { - // This is not the first node, so format a slash between the - // previous node and this node. - - NodeRelation *darc = comp->get_arc(); - if (darc->get_child() == (Node *)NULL && - darc->get_parent() == (Node *)NULL) { - // Here's a deleted arc. Indicate this. - result += "/(...deleted...)"; - } else { - if (darc->get_parent() != comp->get_next()->get_node() && - comp->get_next()->get_node() != (Node *)NULL) { - // It's not a deleted arc, but something's broken. - result += "/.../" + format_node_name(darc->get_parent()); - } - result += format_arc_name(darc); - result += format_node_name(darc->get_child()); - } - } - } - return nodes_before + 1; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::r_write_transitions -// Access: Private -// Description: The recursive implementation of write_transitions(). -//////////////////////////////////////////////////////////////////// -void NodePath:: -r_write_transitions(const ArcComponent *comp, - ostream &out, int indent_level) const { - nassertv(comp != (const ArcComponent *)NULL); - nassertv(comp->has_arc()); - - if (!comp->is_top_arc()) { - r_write_transitions(comp->get_next(), out, indent_level); - } - - NodeRelation *darc = comp->get_arc(); - indent(out, indent_level) << *darc << "\n"; - darc->write_transitions(out, indent_level + 2); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::r_get_net_transitions -// Access: Private -// Description: The recursive implementation of get_net_transitions(). -//////////////////////////////////////////////////////////////////// -void NodePath:: -r_get_net_transitions(const ArcComponent *comp, - AllTransitionsWrapper &trans) const { - nassertv(comp != (const ArcComponent *)NULL); - nassertv(comp->has_arc()); - - if (!comp->is_top_arc()) { - r_get_net_transitions(comp->get_next(), trans); - } - - AllTransitionsWrapper arc_trans; - arc_trans.extract_from(comp->get_arc()); - trans.compose_in_place(arc_trans); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::format_node_name -// Access: Private -// Description: Formats one component of the as_string string: a -// node, either unnamed as a type, or as a name. -//////////////////////////////////////////////////////////////////// -string NodePath:: -format_node_name(Node *dnode) const { - if (dnode == (Node *)NULL) { - return "(NULL)"; - } - string name; - if (dnode->is_of_type(NamedNode::get_class_type())) { - name = DCAST(NamedNode, dnode)->get_name(); - } - - if (name.empty()) { - // No name. If the type isn't one of the trivial types (Node or - // NamedNode), use the type name instead, since it's likely to be - // more unique. - if (!dnode->is_of_type(Node::get_class_type()) && - !dnode->is_of_type(NamedNode::get_class_type())) { - return "-" + dnode->get_type().get_name(); - } - } - - // Use the node's name. - return name; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::format_arc_name -// Access: Private -// Description: Formats the "name" for the arc in as_string(). -// Normally, this is simply "/", but for certain arcs -// (as for stashed nodes, for instance), it might -// contain other characters. -//////////////////////////////////////////////////////////////////// -string NodePath:: -format_arc_name(NodeRelation *arc) const { - string result = "/"; - - if (arc->get_graph_type() == NodeRelation::get_stashed_type()) { - result += "@@"; - - } else if (arc->get_graph_type() != _graph_type) { - result += "@@(" + arc->get_graph_type().get_name() + ")"; - } - - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::find_matches -// Access: Private -// Description: Finds up to max_matches matches against the given -// path string from this node and deeper. The -// max_matches count indicates the maximum number of -// matches to return, or -1 not to limit the number -// returned. -//////////////////////////////////////////////////////////////////// -void NodePath:: -find_matches(NodePathCollection &result, const string &path, - int max_matches) const { - if (is_empty()) { - sgmanip_cat.warning() - << "Attempt to extend an empty NodePath by '" << path - << "'.\n"; - return; - } - FindApproxPath approx_path; - if (approx_path.add_string(path)) { - find_matches(result, approx_path, max_matches); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::find_matches -// Access: Private -// Description: Finds up to max_matches matches against the given -// approx_path from this node and deeper. The -// max_matches count indicates the maximum number of -// matches to return, or -1 not to limit the number -// returned. -//////////////////////////////////////////////////////////////////// -void NodePath:: -find_matches(NodePathCollection &result, FindApproxPath &approx_path, - int max_matches) const { - if (is_empty()) { - sgmanip_cat.warning() - << "Attempt to extend an empty NodePath by: " << approx_path << ".\n"; - return; - } - FindApproxLevelEntry start(*this, approx_path); - FindApproxLevel level; - level.add_entry(start); - r_find_matches(result, level, max_matches, _max_search_depth); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::r_find_matches -// Access: Private -// Description: The recursive implementation of find_matches. -//////////////////////////////////////////////////////////////////// -void NodePath:: -r_find_matches(NodePathCollection &result, - const FindApproxLevel &level, - int max_matches, int num_levels_remaining) const { - // Go on to the next level. If we exceeded the requested maximum - // depth, stop. - if (num_levels_remaining <= 0) { - return; - } - num_levels_remaining--; - - FindApproxLevel next_level; - bool okflag = true; - - // For each node in the current level, build up the set of possible - // matches in the next level. - FindApproxLevel::Vec::const_iterator li; - for (li = level._v.begin(); li != level._v.end() && okflag; ++li) { - const FindApproxLevelEntry &entry = (*li); - - if (entry.is_solution()) { - // Does this entry already represent a solution? - result.add_path(entry._node_path); - } else { - entry.consider_node(result, next_level, max_matches, _graph_type); - } - - if (max_matches > 0 && result.get_num_paths() >= max_matches) { - // Really, we just want to return here. But returning from - // within the conditional within the for loop seems to sometimes - // cause a compiler fault in GCC. We'll use a semaphore - // variable instead. - okflag = false; - } - } - - // Now recurse on the next level. - if (okflag) { - r_find_matches(result, next_level, max_matches, num_levels_remaining); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::r_list_descendants -// Access: Private -// Description: The recursive implementation of ls(). -//////////////////////////////////////////////////////////////////// -void NodePath:: -r_list_descendants(ostream &out, int indent_level) const { - Node *bottom_node = node(); - nassertv(bottom_node != (Node *)NULL); - indent(out, indent_level) << *bottom_node << "\n"; - - int num_children = bottom_node->get_num_children(_graph_type); - for (int i = 0; i < num_children; i++) { - NodeRelation *child_arc = bottom_node->get_child(_graph_type, i); - - NodePath next(*this); - next.extend_by(child_arc); - next.r_list_descendants(out, indent_level + 2); - } - - if (_graph_type != NodeRelation::get_stashed_type()) { - // Also report the number of stashed nodes at this level. - int num_stashed = bottom_node->get_num_children(NodeRelation::get_stashed_type()); - if (num_stashed != 0) { - indent(out, indent_level) << "(" << num_stashed << " stashed)\n"; - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::r_list_transitions -// Access: Private -// Description: The recursive implementation of ls_transitions(). -//////////////////////////////////////////////////////////////////// -void NodePath:: -r_list_transitions(ostream &out, int indent_level) const { - Node *bottom_node = node(); - nassertv(bottom_node != (Node *)NULL); - - out << "\n+"; - indent(out, indent_level + 1) << *bottom_node << "\n\n"; - - int num_children = bottom_node->get_num_children(_graph_type); - for (int i = 0; i < num_children; i++) { - NodeRelation *child_arc = bottom_node->get_child(_graph_type, i); - NodePath next(*this); - next.extend_by(child_arc); - - indent(out, indent_level + 2) << *child_arc << ":\n"; - child_arc->write_transitions(out, indent_level + 2); - next.r_list_transitions(out, indent_level + 2); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::r_list_transforms -// Access: Private -// Description: The recursive implementation of ls_transforms(). -//////////////////////////////////////////////////////////////////// -void NodePath:: -r_list_transforms(ostream &out, int indent_level) const { - if (has_mat()) { - indent(out, indent_level) << *this << ":\n"; - get_mat().write(out, indent_level + 2); - indent_level += 4; - } - - Node *bottom_node = node(); - nassertv(bottom_node != (Node *)NULL); - - int num_children = bottom_node->get_num_children(_graph_type); - for (int i = 0; i < num_children; i++) { - NodeRelation *child_arc = bottom_node->get_child(_graph_type, i); - NodePath next(*this); - next.extend_by(child_arc); - - next.r_list_transforms(out, indent_level); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::r_adjust_all_priorities -// Access: Private -// Description: The recursive implementation of -// adjust_all_priorities(). This walks through the -// subgraph defined by the indicated arc and below. -//////////////////////////////////////////////////////////////////// -void NodePath:: -r_adjust_all_priorities(NodeRelation *arc, int adjustment) { - arc->adjust_all_priorities(adjustment); - - Node *dnode = arc->get_child(); - - int num_children = dnode->get_num_children(_graph_type); - for (int i = 0; i < num_children; i++) { - NodeRelation *child_arc = dnode->get_child(_graph_type, i); - r_adjust_all_priorities(child_arc, adjustment); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::r_clear_wrt_cache -// Access: Private -// Description: The recursive implementation of -// clear_wrt_cache(). This walks through the -// subgraph defined by the indicated arc and below. -//////////////////////////////////////////////////////////////////// -void NodePath:: -r_clear_wrt_cache(NodeRelation *arc) { - arc->clear_wrt_cache(); - - Node *dnode = arc->get_child(); - - int num_children = dnode->get_num_children(_graph_type); - for (int i = 0; i < num_children; i++) { - NodeRelation *child_arc = dnode->get_child(_graph_type, i); - r_clear_wrt_cache(child_arc); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePath::r_calc_tight_bounds -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -void NodePath:: -r_calc_tight_bounds(Node *dnode, LPoint3f &min_point, LPoint3f &max_point, - bool &found_any, const LMatrix4f &transform) { - if (dnode->is_of_type(GeomNode::get_class_type())) { - GeomNode *gnode = DCAST(GeomNode, dnode); - int num_geoms = gnode->get_num_geoms(); - for (int i = 0; i < num_geoms; i++) { - dDrawable *drawable = gnode->get_geom(i); - if (drawable->is_of_type(Geom::get_class_type())) { - Geom *geom = DCAST(Geom, drawable); - - Geom::VertexIterator vi = geom->make_vertex_iterator(); - int num_prims = geom->get_num_prims(); - - for (int p = 0; p < num_prims; p++) { - int length = geom->get_length(p); - for (int v = 0; v < length; v++) { - Vertexf vertex = geom->get_next_vertex(vi) * transform; - - if (found_any) { - min_point.set(min(min_point[0], vertex[0]), - min(min_point[1], vertex[1]), - min(min_point[2], vertex[2])); - max_point.set(max(max_point[0], vertex[0]), - max(max_point[1], vertex[1]), - max(max_point[2], vertex[2])); - } else { - min_point = vertex; - max_point = vertex; - found_any = true; - } - } - } - } - } - } - - // Now consider children. - - int num_children = dnode->get_num_children(_graph_type); - for (int i = 0; i < num_children; i++) { - NodeRelation *child_arc = dnode->get_child(_graph_type, i); - - const TransformTransition *tt; - if (get_transition_into(tt, child_arc)) { - // This arc has a transform; apply it. - r_calc_tight_bounds(child_arc->get_child(), min_point, max_point, - found_any, tt->get_matrix() * transform); - } else { - // This arc doesn't have a transform. - r_calc_tight_bounds(child_arc->get_child(), min_point, max_point, - found_any, transform); - - } - } -} diff --git a/panda/src/sgmanip/nodePath.h b/panda/src/sgmanip/nodePath.h deleted file mode 100644 index ca26dcf4e1..0000000000 --- a/panda/src/sgmanip/nodePath.h +++ /dev/null @@ -1,593 +0,0 @@ -// Filename: nodePath.h -// Created by: drose (05Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef NODEPATH_H -#define NODEPATH_H - -#include - -#include "nodePathCollection.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "pmap.h" - -class FindApproxLevel; -class FindApproxPath; -class Texture; -class Fog; -class Camera; -class AllTransitionsWrapper; -class GraphicsStateGuardianBase; - -// -// A NodePath is the fundamental unit of high-level interaction with -// the scene graph. It encapsulates the complete path down to a node -// from some other node, usually the root of the scene graph. This -// conveniently resolves ambiguities associated with instancing and -// protects the user from having to keep track of nodes and arcs -// separately. -// -// NodePath also contains a number of handy methods for common -// scene-graph manipulations, such as reparenting, and common state -// changes, such as repositioning. -// -// There are also a number of NodePath methods for finding nodes deep -// within the tree by name or by type. These take a path string, -// which at its simplest consists of a series of node names separated -// by slashes, like a directory pathname. -// -// Each component of the path string may optionally consist of one of -// the following special names, instead of a node name: -// -// * -- matches exactly one node, with any name. -// ** -- matches any sequence of zero or more nodes. -// +typename -- matches any node that is or derives from the given type. -// -typename -- matches any node that is the given type exactly. -// -// Furthermore, a node name may itself contain standard filename -// globbing characters, like *, ?, and [a-z], that will be accepted as -// a partial match. (In fact, the '*' special name may be seen as -// just a special case of this.) The globbing characters may not be -// used with the typename matches. -// -// The special characters "@@", appearing at the beginning of a node -// name, indicate a stashed node. Normally, stashed nodes are not -// returned by a find (but see the special flags, below), but a -// stashed node may be found if it is explicitly named with its -// leading @@ characters. By extension, "@@*" may be used to identify -// any stashed node. -// -// Examples: -// -// "room//graph" will look for a node named "graph", which is a child -// of an unnamed node, which is a child of a node named "room", which -// is a child of the starting path. -// -// "**/red*" will look for any node anywhere in the tree (below the -// starting path) with a name that begins with "red". -// -// "**/+PartBundleNode/**/head" will look for a node named "head", -// somewhere below a PartBundleNode anywhere in the tree. -// -// -// The search is always potentially ambiguous, even if the special -// wildcard operators are not used, because there may be multiple -// nodes in the tree with the same name. In general, in the case of -// an ambiguity, the shortest path is preferred; when a method (such -// as extend_by) must choose only only one of several possible paths, -// it will choose the shortest available; on the other hand, when a -// method (such as find_all_matches) is to return all of the matching -// paths, it will sort them so that the shortest paths appear first in -// the output. -// -// -// Special flags. The entire string may optionally be followed by the -// ";" character, followed by one or more of the following special -// control flags, with no intervening spaces or punctuation: -// -// -h Do not return hidden nodes. -// +h Do return hidden nodes. -// -s Do not return stashed nodes unless explicitly referenced with @@. -// +s Return stashed nodes even without any explicit @@ characters. -// -// The default flags are +h-s. -// - -//////////////////////////////////////////////////////////////////// -// Class : NodePath -// Description : A NodePath represents a complete path through the -// scene graph between two particular nodes (e.g. render -// to a GeomNode). It thus unambiguously defines -// instances, especially when it is rooted at the top of -// the graph. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA NodePath : public ArcChain { -PUBLISHED: - // This enumeration is returned by get_error_type() for an empty - // NodePath to report the reason it's empty. - enum ErrorType { - ET_ok = 0, // i.e. not empty, or never assigned to anything. - ET_not_found, // returned from a failed find() or similar function. - ET_removed, // remove_node() was previously called on this NodePath. - ET_fail, // general failure return from some function. - }; - - INLINE NodePath(TypeHandle graph_type = RenderRelation::get_class_type()); - INLINE NodePath(Node *top_node, TypeHandle graph_type = RenderRelation::get_class_type()); - INLINE NodePath(NodeRelation *arc); - INLINE NodePath(const ArcChain &chain, TypeHandle graph_type); - - INLINE NodePath(const NodePath ©); - INLINE void operator = (const NodePath ©); - INLINE ~NodePath(); - - INLINE static NodePath not_found(); - INLINE static NodePath removed(); - INLINE static NodePath fail(); - - INLINE bool operator == (const NodePath &other) const; - INLINE bool operator != (const NodePath &other) const; - INLINE int compare_to(const NodePath &other) const; - - INLINE void set_graph_type(TypeHandle graph_type); - INLINE TypeHandle get_graph_type() const; - - INLINE static void set_max_search_depth(int max_search_depth); - INLINE static int get_max_search_depth(); - - - // Methods to extend or shorten a NodePath. - - bool extend_by(Node *dnode); - bool extend_by(NodeRelation *darc); - bool extend_by(const NodePath &other); - bool extend_by(const string &path); - bool extend_down_to(Node *dnode); - - void shorten(int num_nodes = 1); - void clear(); - - - // Methods to query a NodePath's contents. - - INLINE ErrorType get_error_type() const; - - // Most of these methods are inherited from ArcChain. - - - // Methods to manage the disconnected NodePaths that can result if - // two NodePaths independently reference the same path, and one of - // them is reparented. - - int share_with(const NodePath &other); - bool verify_connectivity() const; - bool amputate_badness(); - bool repair_connectivity(const NodePath &top); - - - // Methods that return collections of NodePaths derived from or - // related to this one. - - NodePathCollection get_siblings() const; - NodePathCollection get_children() const; - INLINE int get_num_children() const; - INLINE NodePath get_child(int n) const; - - INLINE bool has_parent() const; - INLINE NodePath get_parent() const; - - INLINE NodePath find_path_down_to(Node *dnode) const; - INLINE NodePath find(const string &path) const; - - NodePathCollection - find_all_paths_down_to(Node *dnode) const; - - NodePathCollection - find_all_matches(const string &path) const; - - NodePath find_singular_transform() const; - - - // Methods that actually move nodes around in the scene graph. The - // optional "sort" parameter can be used to force a particular - // ordering between sibling nodes, useful when dealing with LOD's - // and similar switch nodes. If the sort value is the same, bnodes - // will be arranged in the order they were added. - void reparent_to(const NodePath &other, int sort = 0); - void wrt_reparent_to(const NodePath &other, int sort = 0); - NodePath instance_to(const NodePath &other, int sort = 0) const; - NodePath copy_to(const NodePath &other, int sort = 0) const; - NodePath attach_new_node(Node *dnode, int sort = 0) const; - INLINE NodePath attach_new_node(const string &name, int sort = 0) const; - void remove_node(); - - - // Handy ways to look at what's there, and other miscellaneous - // operations. - - string as_string(int start_at_node = 0) const; - INLINE void output(ostream &out) const; - void write_transitions(ostream &out, int indent_level = 0) const; - - AllTransitionsWrapper get_net_transitions() const; - - INLINE void ls() const; - INLINE void ls(ostream &out, int indent_level = 0) const; - INLINE void ls_transitions() const; - INLINE void ls_transforms() const; - void analyze() const; - - int flatten_light(); - int flatten_medium(int max_children = 1); - int flatten_strong(int max_children = 1); - - bool write_bam_file(const string &filename) const; - - // The remaining methods operate on scene graph attributes, - // according to the arc above the bottom node. In general, it is - // valid to call these only if !is_empty() && !is_singleton(). - - - // Methods that get and set the matrix transform: pos, hpr, scale, - // in the local coordinate system. These affect the transform at - // the bottom level only. - - INLINE void set_pos(float x, float y, float z); - void set_pos(const LVecBase3f &pos); - void set_x(float x); - void set_y(float y); - void set_z(float z); - LPoint3f get_pos() const; - INLINE float get_x() const; - INLINE float get_y() const; - INLINE float get_z() const; - - INLINE void set_hpr(float h, float p, float r); - void set_hpr(const LVecBase3f &hpr); - void set_h(float h); - void set_p(float p); - void set_r(float r); - LVecBase3f get_hpr() const; - LVecBase3f get_hpr(float roll) const; - INLINE float get_h() const; - INLINE float get_p() const; - INLINE float get_r() const; - - INLINE void set_scale(float scale); - INLINE void set_scale(float sx, float sy, float sz); - void set_scale(const LVecBase3f &sv3); - void set_sx(float sx); - void set_sy(float sy); - void set_sz(float sz); - LVecBase3f get_scale() const; - INLINE float get_sx() const; - INLINE float get_sy() const; - INLINE float get_sz() const; - - INLINE void set_pos_hpr(float x, float y, float z, - float h, float p, float r); - void set_pos_hpr(const LVecBase3f &pos, - const LVecBase3f &hpr); - - INLINE void set_hpr_scale(float h, float p, float r, - float sx, float sy, float sz); - void set_hpr_scale(const LVecBase3f &hpr, - const LVecBase3f &scale); - INLINE void set_pos_hpr_scale(float x, float y, float z, - float h, float p, float r, - float sx, float sy, float sz); - void set_pos_hpr_scale(const LVecBase3f &pos, - const LVecBase3f &hpr, - const LVecBase3f &scale); - - void set_mat(const LMatrix4f &mat); - INLINE void clear_mat(); - INLINE bool has_mat() const; - INLINE LMatrix4f get_mat() const; - - INLINE bool has_color_scale() const; - INLINE void clear_color_scale(); - - void set_color_scale(const LVecBase4f &sv4); - INLINE void set_color_scale(float sx, float sy, float sz, float sa); - INLINE void set_sr(float sr); - INLINE void set_sg(float sg); - INLINE void set_sb(float sb); - INLINE void set_sa(float sa); - - LVecBase4f get_color_scale() const; - INLINE float get_sr() const; - INLINE float get_sg() const; - INLINE float get_sb() const; - INLINE float get_sa() const; - - INLINE void look_at(float x, float y, float z); - void look_at(const LPoint3f &point, const LVector3f &up = LVector3f::up()); - INLINE void heads_up(float x, float y, float z); - void heads_up(const LPoint3f &point, const LVector3f &up = LVector3f::up()); - - INLINE void look_at_preserve_scale(float x, float y, float z); - void look_at_preserve_scale(const LPoint3f &point, const LVector3f &up = LVector3f::up()); - INLINE void heads_up_preserve_scale(float x, float y, float z); - void heads_up_preserve_scale(const LPoint3f &point, const LVector3f &up = LVector3f::up()); - - INLINE void print_pos() const; - INLINE void print_hpr() const; - INLINE void print_scale() const; - INLINE void print_pos_hpr() const; - INLINE void print_pos_hpr_scale() const; - INLINE void print_mat() const; - INLINE void print_color_scale() const; - - // Methods that get and set the matrix transforms relative to some - // other node in the scene graph. These perform an implicit wrt(). - - INLINE void set_pos(const NodePath &other, float x, float y, float z); - void set_pos(const NodePath &other, const LVecBase3f &pos); - void set_x(const NodePath &other, float x); - void set_y(const NodePath &other, float y); - void set_z(const NodePath &other, float z); - INLINE LPoint3f get_pos(const NodePath &other) const; - INLINE float get_x(const NodePath &other) const; - INLINE float get_y(const NodePath &other) const; - INLINE float get_z(const NodePath &other) const; - - INLINE void set_hpr(const NodePath &other, float h, float p, float r); - void set_hpr(const NodePath &other, const LVecBase3f &hpr); - void set_h(const NodePath &other, float h); - void set_p(const NodePath &other, float p); - void set_r(const NodePath &other, float r); - LVecBase3f get_hpr(const NodePath &other) const; - LVecBase3f get_hpr(const NodePath &other, float roll) const; - INLINE float get_h(const NodePath &other) const; - INLINE float get_p(const NodePath &other) const; - INLINE float get_r(const NodePath &other) const; - - INLINE void set_scale(const NodePath &other, float sx, float sy, float sz); - void set_scale(const NodePath &other, const LVecBase3f &scale); - void set_sx(const NodePath &other, float sx); - void set_sy(const NodePath &other, float sy); - void set_sz(const NodePath &other, float sz); - LVecBase3f get_scale(const NodePath &other) const; - INLINE float get_sx(const NodePath &other) const; - INLINE float get_sy(const NodePath &other) const; - INLINE float get_sz(const NodePath &other) const; - - INLINE void set_pos_hpr(const NodePath &other, - float x, float y, float z, - float h, float p, float r); - void set_pos_hpr(const NodePath &other, - const LVecBase3f &pos, - const LVecBase3f &hpr); - INLINE void set_hpr_scale(const NodePath &other, - float h, float p, float r, - float sx, float sy, float sz); - void set_hpr_scale(const NodePath &other, - const LVecBase3f &hpr, - const LVecBase3f &scale); - INLINE void set_pos_hpr_scale(const NodePath &other, - float x, float y, float z, - float h, float p, float r, - float sx, float sy, float sz); - void set_pos_hpr_scale(const NodePath &other, - const LVecBase3f &pos, - const LVecBase3f &hpr, - const LVecBase3f &scale); - - LMatrix4f get_mat(const NodePath &other) const; - void set_mat(const NodePath &other, const LMatrix4f &mat); - - LPoint3f get_relative_point(const NodePath &other, const LVecBase3f &point); - - INLINE void look_at(const NodePath &other, - float x, float y, float z); - void look_at(const NodePath &other, - const LPoint3f &point = LPoint3f(0.0, 0.0, 0.0), - const LVector3f &up = LVector3f::up()); - INLINE void heads_up(const NodePath &other, - float x, float y, float z); - void heads_up(const NodePath &other, - const LPoint3f &point = LPoint3f(0.0, 0.0, 0.0), - const LVector3f &up = LVector3f::up()); - - INLINE void look_at_preserve_scale(const NodePath &other, - float x, float y, float z); - void look_at_preserve_scale(const NodePath &other, - const LPoint3f &point = LPoint3f(0.0, 0.0, 0.0), - const LVector3f &up = LVector3f::up()); - INLINE void heads_up_preserve_scale(const NodePath &other, - float x, float y, float z); - void heads_up_preserve_scale(const NodePath &other, - const LPoint3f &point = LPoint3f(0.0, 0.0, 0.0), - const LVector3f &up = LVector3f::up()); - - INLINE void print_pos(const NodePath &other) const; - INLINE void print_hpr(const NodePath &other) const; - INLINE void print_scale(const NodePath &other) const; - INLINE void print_pos_hpr(const NodePath &other) const; - INLINE void print_pos_hpr_scale(const NodePath &other) const; - INLINE void print_mat(const NodePath &other) const; - - INLINE float get_distance(const NodePath &other) const; - - - // Methods that affect appearance of geometry: color, texture, etc. - // These affect the state at the bottom level only. - - INLINE void set_color(float r, float g, float b, float a = 1.0, - int priority = 0); - void set_color(const Colorf &color, int priority = 0); - void set_color_off(int priority = 0); - INLINE void clear_color(); - INLINE bool has_color() const; - Colorf get_color() const; - - void set_bin(const string &bin_name, int draw_order, int priority = 0); - INLINE void clear_bin(); - INLINE bool has_bin() const; - string get_bin_name() const; - int get_bin_draw_order() const; - - void set_texture(Texture *tex, int priority = 0); - void set_texture_off(int priority = 0); - INLINE void clear_texture(); - bool has_texture() const; - bool has_texture_off() const; - Texture *get_texture() const; - - void set_material(Material *tex, int priority = 0); - void set_material_off(int priority = 0); - INLINE void clear_material(); - bool has_material() const; - PT(Material) get_material() const; - - void set_fog(Fog *fog, int priority = 0); - void set_fog_off(int priority = 0); - INLINE void clear_fog(); - bool has_fog() const; - bool has_fog_off() const; - Fog *get_fog() const; - - void set_render_mode_wireframe(int priority = 0); - void set_render_mode_filled(int priority = 0); - INLINE void clear_render_mode(); - INLINE bool has_render_mode() const; - - void set_two_sided(bool two_sided, int priority = 0); - INLINE void clear_two_sided(); - INLINE bool has_two_sided() const; - bool get_two_sided() const; - - void do_billboard_axis(const NodePath &camera, float offset); - void do_billboard_point_eye(const NodePath &camera, float offset); - void do_billboard_point_world(const NodePath &camera, float offset); - INLINE void set_billboard_axis(float offset = 0.0); - INLINE void set_billboard_point_eye(float offset = 0.0); - INLINE void set_billboard_point_world(float offset = 0.0); - INLINE void clear_billboard(); - INLINE bool has_billboard() const; - - void set_transparency(bool transparency, int priority = 0); - INLINE void clear_transparency(); - INLINE bool has_transparency() const; - bool get_transparency() const; - - INLINE void adjust_all_priorities(int adjustment); - - INLINE void show(); - INLINE void hide(); - INLINE void show_collision_solids(); - INLINE void hide_collision_solids(); - INLINE bool is_hidden() const; - NodePath get_hidden_ancestor() const; - - INLINE void stash(); - INLINE void unstash(); - INLINE bool is_stashed() const; - NodePath get_stashed_ancestor() const; - - void prepare_scene(GraphicsStateGuardianBase *gsg, bool force_retained_mode = false); - INLINE void clear_wrt_cache(); - - void show_bounds(); - void hide_bounds(); - PT(BoundingVolume) get_bounds() const; - void write_bounds(ostream &out) const; - bool calc_tight_bounds(LPoint3f &min_point, LPoint3f &max_point); - - -private: - bool r_extend_by(const ArcComponent *other); - int r_as_string(const ArcComponent *comp, string &result, - int skip_nodes) const; - void r_write_transitions(const ArcComponent *comp, - ostream &out, int indent_level) const; - void r_get_net_transitions(const ArcComponent *comp, - AllTransitionsWrapper &trans) const; - string format_node_name(Node *dnode) const; - string format_arc_name(NodeRelation *arc) const; - - void find_matches(NodePathCollection &result, - const string &approx_path_str, - int max_matches) const; - void find_matches(NodePathCollection &result, - FindApproxPath &approx_path, - int max_matches) const; - void r_find_matches(NodePathCollection &result, - const FindApproxLevel &level, - int max_matches, int num_levels_remaining) const; - - void r_list_descendants(ostream &out, int indent_level) const; - void r_list_transitions(ostream &out, int indent_level) const; - void r_list_transforms(ostream &out, int indent_level) const; - - void r_adjust_all_priorities(NodeRelation *arc, int adjustment); - void r_clear_wrt_cache(NodeRelation *arc); - - void r_calc_tight_bounds(Node *dnode, LPoint3f &min_point, - LPoint3f &max_point, - bool &found_any, const LMatrix4f &transform); - -private: - TypeHandle _graph_type; - ErrorType _error_type; - static int _max_search_depth; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - ArcChain::init_type(); - register_type(_type_handle, "NodePath", - ArcChain::get_class_type()); - } - -private: - static TypeHandle _type_handle; - - friend class NodePathCollection; -}; - -INLINE ostream &operator << (ostream &out, const NodePath &path) { - path.output(out); - return out; -} - -#include "nodePath.I" - -#endif diff --git a/panda/src/sgmanip/nodePathCollection.I b/panda/src/sgmanip/nodePathCollection.I deleted file mode 100644 index 9778eabc9f..0000000000 --- a/panda/src/sgmanip/nodePathCollection.I +++ /dev/null @@ -1,38 +0,0 @@ -// Filename: nodePathCollection.I -// Created by: drose (06Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::Destructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE NodePathCollection:: -~NodePathCollection() { -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::ls -// Access: Published -// Description: Lists all the nodes at and below each node in the -// collection hierarchically. -//////////////////////////////////////////////////////////////////// -INLINE void NodePathCollection:: -ls() const { - ls(nout); -} diff --git a/panda/src/sgmanip/nodePathCollection.cxx b/panda/src/sgmanip/nodePathCollection.cxx deleted file mode 100644 index 292d296fd0..0000000000 --- a/panda/src/sgmanip/nodePathCollection.cxx +++ /dev/null @@ -1,449 +0,0 @@ -// Filename: nodePathCollection.cxx -// Created by: drose (06Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "nodePathCollection.h" -#include "nodePath.h" -#include "findApproxPath.h" -#include "findApproxLevel.h" - -#include -#include - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -NodePathCollection:: -NodePathCollection() { - _graph_type = RenderRelation::get_class_type(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::Copy Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -NodePathCollection:: -NodePathCollection(const NodePathCollection ©) : - _node_paths(copy._node_paths), - _graph_type(copy._graph_type) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::Copy Assignment Operator -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -void NodePathCollection:: -operator = (const NodePathCollection ©) { - _node_paths = copy._node_paths; - _graph_type = copy._graph_type; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::add_path -// Access: Published -// Description: Adds a new NodePath to the collection. -//////////////////////////////////////////////////////////////////// -void NodePathCollection:: -add_path(const NodePath &node_path) { - if (_node_paths.empty()) { - // If this is the first NodePath added to the collection, it - // defines our graph_type. - _graph_type = node_path.get_graph_type(); - - } else { - // Otherwise, the graph_type must match what's already there. - nassertv(node_path.get_graph_type() == _graph_type); - } - - // If the pointer to our internal array is shared by any other - // NodePathCollections, we have to copy the array now so we won't - // inadvertently modify any of our brethren NodePathCollection - // objects. - - if (_node_paths.get_ref_count() > 1) { - PTA(ArcChain) old_node_paths = _node_paths; - _node_paths = PTA(ArcChain)::empty_array(0); - _node_paths.v() = old_node_paths.v(); - } - - _node_paths.push_back(node_path); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::remove_path -// Access: Published -// Description: Removes the indicated NodePath from the collection. -// Returns true if the path was removed, false if it was -// not a member of the collection. -//////////////////////////////////////////////////////////////////// -bool NodePathCollection:: -remove_path(const NodePath &node_path) { - int path_index = -1; - for (int i = 0; path_index == -1 && i < (int)_node_paths.size(); i++) { - if (_node_paths[i] == node_path) { - path_index = i; - } - } - - if (path_index == -1) { - // The indicated path was not a member of the collection. - return false; - } - - // If the pointer to our internal array is shared by any other - // NodePathCollections, we have to copy the array now so we won't - // inadvertently modify any of our brethren NodePathCollection - // objects. - - if (_node_paths.get_ref_count() > 1) { - PTA(ArcChain) old_node_paths = _node_paths; - _node_paths = PTA(ArcChain)::empty_array(0); - _node_paths.v() = old_node_paths.v(); - } - - _node_paths.erase(_node_paths.begin() + path_index); - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::add_paths_from -// Access: Published -// Description: Adds all the NodePaths indicated in the other -// collection to this path. The other paths are simply -// appended to the end of the paths in this list; -// duplicates are not automatically removed. -//////////////////////////////////////////////////////////////////// -void NodePathCollection:: -add_paths_from(const NodePathCollection &other) { - if (_node_paths.empty()) { - // If this is the first NodePath added to the collection, it - // defines our graph_type. - _graph_type = other.get_graph_type(); - - } else { - // Otherwise, the graph_type must match what's already there. - nassertv(other.get_graph_type() == _graph_type); - } - - int other_num_paths = other.get_num_paths(); - for (int i = 0; i < other_num_paths; i++) { - add_path(other.get_path(i)); - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::remove_paths_from -// Access: Published -// Description: Removes from this collection all of the NodePaths -// listed in the other collection. -//////////////////////////////////////////////////////////////////// -void NodePathCollection:: -remove_paths_from(const NodePathCollection &other) { - NodePaths new_paths; - int num_paths = get_num_paths(); - for (int i = 0; i < num_paths; i++) { - NodePath path = get_path(i); - if (!other.has_path(path)) { - new_paths.push_back(path); - } - } - _node_paths = new_paths; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::remove_duplicate_paths -// Access: Published -// Description: Removes any duplicate entries of the same NodePaths -// on this collection. If a NodePath appears multiple -// times, the first appearance is retained; subsequent -// appearances are removed. -//////////////////////////////////////////////////////////////////// -void NodePathCollection:: -remove_duplicate_paths() { - NodePaths new_paths; - - int num_paths = get_num_paths(); - for (int i = 0; i < num_paths; i++) { - NodePath path = get_path(i); - bool duplicated = false; - - for (int j = 0; j < i && !duplicated; j++) { - duplicated = (path == get_path(j)); - } - - if (!duplicated) { - new_paths.push_back(path); - } - } - - _node_paths = new_paths; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::has_path -// Access: Published -// Description: Returns true if the indicated NodePath appears in -// this collection, false otherwise. -//////////////////////////////////////////////////////////////////// -bool NodePathCollection:: -has_path(const NodePath &path) const { - for (int i = 0; i < get_num_paths(); i++) { - if (path == get_path(i)) { - return true; - } - } - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::clear -// Access: Published -// Description: Removes all NodePaths from the collection. -//////////////////////////////////////////////////////////////////// -void NodePathCollection:: -clear() { - _node_paths.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::is_empty -// Access: Published -// Description: Returns true if there are no NodePaths in the -// collection, false otherwise. -//////////////////////////////////////////////////////////////////// -bool NodePathCollection:: -is_empty() const { - return _node_paths.empty(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::get_num_paths -// Access: Published -// Description: Returns the number of NodePaths in the collection. -//////////////////////////////////////////////////////////////////// -int NodePathCollection:: -get_num_paths() const { - return _node_paths.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::get_path -// Access: Published -// Description: Returns the nth NodePath in the collection. -//////////////////////////////////////////////////////////////////// -NodePath NodePathCollection:: -get_path(int index) const { - nassertr(index >= 0 && index < (int)_node_paths.size(), NodePath()); - - return NodePath(_node_paths[index], _graph_type); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::operator [] -// Access: Published -// Description: Returns the nth NodePath in the collection. This is -// the same as get_path(), but it may be a more -// convenient way to access it. -//////////////////////////////////////////////////////////////////// -NodePath NodePathCollection:: -operator [] (int index) const { - nassertr(index >= 0 && index < (int)_node_paths.size(), NodePath()); - - return NodePath(_node_paths[index], _graph_type); -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::get_graph_type -// Access: Public -// Description: Returns the type of graph that all the NodePaths in -// the collection represent. -//////////////////////////////////////////////////////////////////// -TypeHandle NodePathCollection:: -get_graph_type() const { - return _graph_type; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::ls -// Access: Published -// Description: Lists all the nodes at and below each node in the -// collection hierarchically. -//////////////////////////////////////////////////////////////////// -void NodePathCollection:: -ls(ostream &out, int indent_level) const { - for (int i = 0; i < get_num_paths(); i++) { - NodePath path = get_path(i); - indent(out, indent_level) << path << "\n"; - path.ls(out, indent_level + 2); - out << "\n"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::find_all_matches -// Access: Published -// Description: Returns the complete set of all NodePaths that begin -// with any NodePath in this collection and can be -// extended by path. The shortest paths will be listed -// first. -//////////////////////////////////////////////////////////////////// -NodePathCollection NodePathCollection:: -find_all_matches(const string &path) const { - NodePathCollection result; - - FindApproxPath approx_path; - if (approx_path.add_string(path)) { - if (!is_empty()) { - FindApproxLevel level; - for (int i = 0; i < get_num_paths(); i++) { - FindApproxLevelEntry start(get_path(i), approx_path); - level.add_entry(start); - } - get_path(0).r_find_matches(result, level, -1, - NodePath::get_max_search_depth()); - } - } - - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::reparent_to -// Access: Published -// Description: Reparents all the NodePaths in the collection to the -// indicated node. -//////////////////////////////////////////////////////////////////// -void NodePathCollection:: -reparent_to(const NodePath &other) { - for (int i = 0; i < get_num_paths(); i++) { - get_path(i).reparent_to(other); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::wrt_reparent_to -// Access: Published -// Description: Reparents all the NodePaths in the collection to the -// indicated node, adjusting each transform so as not to -// move in world coordinates. -//////////////////////////////////////////////////////////////////// -void NodePathCollection:: -wrt_reparent_to(const NodePath &other) { - for (int i = 0; i < get_num_paths(); i++) { - get_path(i).wrt_reparent_to(other); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::instance_to -// Access: Published -// Description: Creates another instance for each NodePath in the -// collection under the indicated node; returns the -// collection of new instances. -//////////////////////////////////////////////////////////////////// -NodePathCollection NodePathCollection:: -instance_to(const NodePath &other) const { - NodePathCollection result; - - for (int i = 0; i < get_num_paths(); i++) { - result.add_path(get_path(i).instance_to(other)); - } - - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::show -// Access: Published -// Description: Shows all NodePaths in the collection. -//////////////////////////////////////////////////////////////////// -void NodePathCollection:: -show() { - for (int i = 0; i < get_num_paths(); i++) { - get_path(i).show(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::show -// Access: Published -// Description: Hides all NodePaths in the collection. -//////////////////////////////////////////////////////////////////// -void NodePathCollection:: -hide() { - for (int i = 0; i < get_num_paths(); i++) { - get_path(i).hide(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::stash -// Access: Published -// Description: Stashes all NodePaths in the collection. -//////////////////////////////////////////////////////////////////// -void NodePathCollection:: -stash() { - for (int i = 0; i < get_num_paths(); i++) { - get_path(i).stash(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::unstash -// Access: Published -// Description: Unstashes all NodePaths in the collection. -//////////////////////////////////////////////////////////////////// -void NodePathCollection:: -unstash() { - for (int i = 0; i < get_num_paths(); i++) { - get_path(i).unstash(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::output -// Access: Published -// Description: Writes a brief one-line description of the -// NodePathCollection to the indicated output stream. -//////////////////////////////////////////////////////////////////// -void NodePathCollection:: -output(ostream &out) const { - if (get_num_paths() == 1) { - out << "1 NodePath"; - } else { - out << get_num_paths() << " NodePaths"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: NodePathCollection::write -// Access: Published -// Description: Writes a complete multi-line description of the -// NodePathCollection to the indicated output stream. -//////////////////////////////////////////////////////////////////// -void NodePathCollection:: -write(ostream &out, int indent_level) const { - for (int i = 0; i < get_num_paths(); i++) { - indent(out, indent_level) << get_path(i) << "\n"; - } -} diff --git a/panda/src/sgmanip/nodePathCollection.h b/panda/src/sgmanip/nodePathCollection.h deleted file mode 100644 index 4ad978a8fc..0000000000 --- a/panda/src/sgmanip/nodePathCollection.h +++ /dev/null @@ -1,94 +0,0 @@ -// Filename: nodePathCollection.h -// Created by: drose (06Mar00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef NODEPATHCOLLECTION_H -#define NODEPATHCOLLECTION_H - -#include - -// We don't include NodePath in the header file, so NodePath can -// include us. -#include -#include - -class NodePath; - -//////////////////////////////////////////////////////////////////// -// Class : NodePathCollection -// Description : This is a set of zero or more NodePaths. It's handy -// for returning from functions that need to return -// multiple NodePaths (for instance, -// NodePaths::get_children). -// -// All the NodePaths added to a NodePathCollection must -// share the same graph_type. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA NodePathCollection { -PUBLISHED: - NodePathCollection(); - NodePathCollection(const NodePathCollection ©); - void operator = (const NodePathCollection ©); - INLINE ~NodePathCollection(); - - void add_path(const NodePath &node_path); - bool remove_path(const NodePath &node_path); - void add_paths_from(const NodePathCollection &other); - void remove_paths_from(const NodePathCollection &other); - void remove_duplicate_paths(); - bool has_path(const NodePath &path) const; - void clear(); - - bool is_empty() const; - int get_num_paths() const; - NodePath get_path(int index) const; - NodePath operator [] (int index) const; - TypeHandle get_graph_type() const; - - // Handy operations on many NodePaths at once. - INLINE void ls() const; - void ls(ostream &out, int indent_level = 0) const; - - NodePathCollection find_all_matches(const string &path) const; - void reparent_to(const NodePath &other); - void wrt_reparent_to(const NodePath &other); - NodePathCollection instance_to(const NodePath &other) const; - - void show(); - void hide(); - void stash(); - void unstash(); - - void output(ostream &out) const; - void write(ostream &out, int indent_level = 0) const; - -private: - typedef PTA(ArcChain) NodePaths; - NodePaths _node_paths; - TypeHandle _graph_type; -}; - -INLINE ostream &operator << (ostream &out, const NodePathCollection &col) { - col.output(out); - return out; -} - -#include "nodePathCollection.I" - -#endif - - diff --git a/panda/src/sgmanip/nodePathLerps.cxx b/panda/src/sgmanip/nodePathLerps.cxx deleted file mode 100644 index 9d72863e06..0000000000 --- a/panda/src/sgmanip/nodePathLerps.cxx +++ /dev/null @@ -1,296 +0,0 @@ -// Filename: nodePathLerps.cxx -// Created by: frang (01Jun00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "nodePathLerps.h" - -TypeHandle PosLerpFunctor::_type_handle; -TypeHandle HprLerpFunctor::_type_handle; -TypeHandle ScaleLerpFunctor::_type_handle; -TypeHandle ColorLerpFunctor::_type_handle; -TypeHandle PosHprLerpFunctor::_type_handle; -TypeHandle HprScaleLerpFunctor::_type_handle; -TypeHandle PosHprScaleLerpFunctor::_type_handle; -TypeHandle ColorScaleLerpFunctor::_type_handle; - - -PosLerpFunctor::PosLerpFunctor(const PosLerpFunctor& c) - : LPoint3fLerpFunctor(c), _node_path(c._node_path) {} - -PosLerpFunctor::~PosLerpFunctor(void) -{ -} - -PosLerpFunctor& PosLerpFunctor::operator=(const PosLerpFunctor& c) { - _node_path = c._node_path; - LPoint3fLerpFunctor::operator=(c); - return *this; -} - -void PosLerpFunctor::operator()(float t) { - if (_is_wrt) - _node_path.set_pos(_wrt_path, interpolate(t)); - else - _node_path.set_pos(interpolate(t)); -} - -HprLerpFunctor::HprLerpFunctor(const HprLerpFunctor& c) - : LVecBase3fLerpFunctor(c), _node_path(c._node_path) {} - -void HprLerpFunctor::take_shortest(void) { - // so long as these are actually degrees - for (int i=0; i!=3; ++i) - if (this->_diff_cache[i] < -180.) - _start[i] -= 360.; - else if (this->_diff_cache[i] > 180.) - _start[i] += 360.; - this->_diff_cache = this->_end - this->_start; -} - -void HprLerpFunctor::take_longest(void) { - // so long as these are actually degrees - for (int i=0; i!=3; ++i) - if ((this->_diff_cache[i] < 0.) && (this->_diff_cache[i] > -180.)) - _start[i] -= 360.; - else if ((this->_diff_cache[i] >= 0.) && (this->_diff_cache[i] < 180)) - _start[i] += 360.; - this->_diff_cache = this->_end - this->_start; -} - -HprLerpFunctor::~HprLerpFunctor(void) -{ -} - -HprLerpFunctor& HprLerpFunctor::operator=(const HprLerpFunctor& c) { - _node_path = c._node_path; - LVecBase3fLerpFunctor::operator=(c); - return *this; -} - -void HprLerpFunctor::operator()(float t) { - if (_is_wrt) - _node_path.set_hpr(_wrt_path, interpolate(t)); - else - _node_path.set_hpr(interpolate(t)); -} - -ScaleLerpFunctor::ScaleLerpFunctor(const ScaleLerpFunctor& c) - : LVecBase3fLerpFunctor(c), _node_path(c._node_path) {} - -ScaleLerpFunctor::~ScaleLerpFunctor(void) -{ -} - -ScaleLerpFunctor& ScaleLerpFunctor::operator=(const ScaleLerpFunctor& c) { - _node_path = c._node_path; - LVecBase3fLerpFunctor::operator=(c); - return *this; -} - -void ScaleLerpFunctor::operator()(float t) { - if (_is_wrt) - _node_path.set_scale(_wrt_path, interpolate(t)); - else - _node_path.set_scale(interpolate(t)); -} - -ColorLerpFunctor::ColorLerpFunctor(const ColorLerpFunctor& c) - : LVecBase4fLerpFunctor(c), _node_path(c._node_path) {} - -ColorLerpFunctor::~ColorLerpFunctor(void) -{ -} - -ColorLerpFunctor& ColorLerpFunctor::operator=(const ColorLerpFunctor& c) { - _node_path = c._node_path; - LVecBase4fLerpFunctor::operator=(c); - return *this; -} - -void ColorLerpFunctor::operator()(float t) { - _node_path.set_color(interpolate(t)); -} - - -PosHprLerpFunctor::PosHprLerpFunctor(const PosHprLerpFunctor& c) - : LerpFunctor(c), _node_path(c._node_path) {} - -void PosHprLerpFunctor::take_shortest(void) { - // so long as these are actually degrees - for (int i=0; i!=3; ++i) - if (this->_hdiff_cache[i] < -180.) - _hstart[i] -= 360.; - else if (this->_hdiff_cache[i] > 180.) - _hstart[i] += 360.; - this->_hdiff_cache = this->_hend - this->_hstart; -} - -void PosHprLerpFunctor::take_longest(void) { - // so long as these are actually degrees - for (int i=0; i!=3; ++i) - if ((this->_hdiff_cache[i] < 0.) && (this->_hdiff_cache[i] > -180.)) - _hstart[i] -= 360.; - else if ((this->_hdiff_cache[i] >= 0.) && (this->_hdiff_cache[i] < 180)) - _hstart[i] += 360.; - this->_hdiff_cache = this->_hend - this->_hstart; -} - -PosHprLerpFunctor::~PosHprLerpFunctor(void) -{ -} - -PosHprLerpFunctor& PosHprLerpFunctor::operator=(const PosHprLerpFunctor& c) { - _node_path = c._node_path; - _pstart = c._pstart; - _pend = c._pend; - _pdiff_cache = c._pdiff_cache; - _hstart = c._hstart; - _hend = c._hend; - _hdiff_cache = c._hdiff_cache; - LerpFunctor::operator=(c); - return *this; -} - -void PosHprLerpFunctor::operator()(float t) { - LPoint3f p = ((t * _pdiff_cache) + _pstart); - LVecBase3f h = ((t * _hdiff_cache) + _hstart); - if (_is_wrt) - _node_path.set_pos_hpr(_wrt_path, p, h); - else - _node_path.set_pos_hpr(p, h); -} - -HprScaleLerpFunctor::HprScaleLerpFunctor(const HprScaleLerpFunctor& c) - : LerpFunctor(c), _node_path(c._node_path) {} - -void HprScaleLerpFunctor::take_shortest(void) { - // so long as these are actually degrees - for (int i=0; i!=3; ++i) - if (this->_hdiff_cache[i] < -180.) - _hstart[i] -= 360.; - else if (this->_hdiff_cache[i] > 180.) - _hstart[i] += 360.; - this->_hdiff_cache = this->_hend - this->_hstart; -} - -void HprScaleLerpFunctor::take_longest(void) { - // so long as these are actually degrees - for (int i=0; i!=3; ++i) - if ((this->_hdiff_cache[i] < 0.) && (this->_hdiff_cache[i] > -180.)) - _hstart[i] -= 360.; - else if ((this->_hdiff_cache[i] >= 0.) && (this->_hdiff_cache[i] < 180)) - _hstart[i] += 360.; - this->_hdiff_cache = this->_hend - this->_hstart; -} - -HprScaleLerpFunctor::~HprScaleLerpFunctor(void) -{ -} - -HprScaleLerpFunctor& -HprScaleLerpFunctor::operator=(const HprScaleLerpFunctor& c) { - _node_path = c._node_path; - _hstart = c._hstart; - _hend = c._hend; - _hdiff_cache = c._hdiff_cache; - _sstart = c._sstart; - _send = c._send; - _sdiff_cache = c._sdiff_cache; - LerpFunctor::operator=(c); - return *this; -} - -void HprScaleLerpFunctor::operator()(float t) { - LVecBase3f h = ((t * _hdiff_cache) + _hstart); - LVecBase3f s = ((t * _sdiff_cache) + _sstart); - if (_is_wrt) - _node_path.set_hpr_scale(_wrt_path, h, s); - else - _node_path.set_hpr_scale(h, s); -} - -PosHprScaleLerpFunctor::PosHprScaleLerpFunctor(const PosHprScaleLerpFunctor& c) - : LerpFunctor(c), _node_path(c._node_path) {} - -void PosHprScaleLerpFunctor::take_shortest(void) { - // so long as these are actually degrees - for (int i=0; i!=3; ++i) - if (this->_hdiff_cache[i] < -180.) - _hstart[i] -= 360.; - else if (this->_hdiff_cache[i] > 180.) - _hstart[i] += 360.; - this->_hdiff_cache = this->_hend - this->_hstart; -} - -void PosHprScaleLerpFunctor::take_longest(void) { - // so long as these are actually degrees - for (int i=0; i!=3; ++i) - if ((this->_hdiff_cache[i] < 0.) && (this->_hdiff_cache[i] > -180.)) - _hstart[i] -= 360.; - else if ((this->_hdiff_cache[i] >= 0.) && (this->_hdiff_cache[i] < 180)) - _hstart[i] += 360.; - this->_hdiff_cache = this->_hend - this->_hstart; -} - -PosHprScaleLerpFunctor::~PosHprScaleLerpFunctor(void) -{ -} - -PosHprScaleLerpFunctor& -PosHprScaleLerpFunctor::operator=(const PosHprScaleLerpFunctor& c) { - _node_path = c._node_path; - _pstart = c._pstart; - _pend = c._pend; - _pdiff_cache = c._pdiff_cache; - _hstart = c._hstart; - _hend = c._hend; - _hdiff_cache = c._hdiff_cache; - _sstart = c._sstart; - _send = c._send; - _sdiff_cache = c._sdiff_cache; - LerpFunctor::operator=(c); - return *this; -} - -void PosHprScaleLerpFunctor::operator()(float t) { - LPoint3f p = ((t * _pdiff_cache) + _pstart); - LVecBase3f h = ((t * _hdiff_cache) + _hstart); - LVecBase3f s = ((t * _sdiff_cache) + _sstart); - if (_is_wrt) - _node_path.set_pos_hpr_scale(_wrt_path, p, h, s); - else - _node_path.set_pos_hpr_scale(p, h, s); -} - -ColorScaleLerpFunctor::ColorScaleLerpFunctor(const ColorScaleLerpFunctor& c) - : LVecBase4fLerpFunctor(c), _node_path(c._node_path) {} - -ColorScaleLerpFunctor::~ColorScaleLerpFunctor(void) -{ -} - -ColorScaleLerpFunctor& ColorScaleLerpFunctor::operator=(const ColorScaleLerpFunctor& c) { - _node_path = c._node_path; - LVecBase4fLerpFunctor::operator=(c); - return *this; -} - -void ColorScaleLerpFunctor::operator()(float t) { - _node_path.set_color_scale(interpolate(t)); -} - - diff --git a/panda/src/sgmanip/nodePathLerps.h b/panda/src/sgmanip/nodePathLerps.h deleted file mode 100644 index 62d20527fd..0000000000 --- a/panda/src/sgmanip/nodePathLerps.h +++ /dev/null @@ -1,526 +0,0 @@ -// Filename: nodePathLerps.h -// Created by: frang (01Jun00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef __NODEPATHLERPS_H__ -#define __NODEPATHLERPS_H__ - -#include -#include "nodePath.h" - -//////////////////////////////////////////////////////////////////// -// Class : PosLerpFunctor -// Description : Class for Lerping between positions in space -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA PosLerpFunctor : public LPoint3fLerpFunctor { -private: - NodePath _node_path; - bool _is_wrt; - NodePath _wrt_path; - -PUBLISHED: - PosLerpFunctor(NodePath np, LPoint3f start, LPoint3f end) - : LPoint3fLerpFunctor(start, end), _node_path(np), _is_wrt(false) {} - PosLerpFunctor(NodePath np, float sx, float sy, float sz, float ex, float ey, - float ez) : LPoint3fLerpFunctor(LPoint3f(sx, sy, sz), - LPoint3f(ex, ey, ez)), - _node_path(np), _is_wrt(false) {} - PosLerpFunctor(NodePath np, LPoint3f start, LPoint3f end, NodePath wrt) - : LPoint3fLerpFunctor(start, end), _node_path(np), _is_wrt(true), - _wrt_path(wrt) {} - PosLerpFunctor(NodePath np, float sx, float sy, float sz, float ex, float ey, - float ez, NodePath wrt) - : LPoint3fLerpFunctor(LPoint3f(sx, sy, sz), LPoint3f(ex, ey, ez)), - _node_path(np), _is_wrt(true), _wrt_path(wrt) {} - -public: - PosLerpFunctor(const PosLerpFunctor&); - virtual ~PosLerpFunctor(void); - PosLerpFunctor& operator=(const PosLerpFunctor&); - virtual void operator()(float); - -public: - // now for typehandle stuff - static TypeHandle get_class_type(void) { - return _type_handle; - } - static void init_type(void) { - LPoint3fLerpFunctor::init_type(); - register_type(_type_handle, "PosLerpFunctor", - LPoint3fLerpFunctor::get_class_type()); - } - virtual TypeHandle get_type(void) const { - return get_class_type(); - } - virtual TypeHandle force_init_type(void) { - init_type(); - return get_class_type(); - } -private: - static TypeHandle _type_handle; -}; - - -// evil bad bad evil HPR -//////////////////////////////////////////////////////////////////// -// Class : HprLerpFunctor -// Description : Class for Lerping between orientations in space -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA HprLerpFunctor : public LVecBase3fLerpFunctor { -private: - NodePath _node_path; - bool _is_wrt; - NodePath _wrt_path; - -PUBLISHED: - HprLerpFunctor(NodePath np, LVecBase3f start, LVecBase3f end) - : LVecBase3fLerpFunctor(start, end), _node_path(np), _is_wrt(false) {} - HprLerpFunctor(NodePath np, float sx, float sy, float sz, float ex, float ey, - float ez) : LVecBase3fLerpFunctor(LVecBase3f(sx, sy, sz), - LVecBase3f(ex, ey, ez)), - _node_path(np), _is_wrt(false) {} - HprLerpFunctor(NodePath np, LVecBase3f start, LVecBase3f end, NodePath wrt) - : LVecBase3fLerpFunctor(start, end), _node_path(np), _is_wrt(true), - _wrt_path(wrt) {} - HprLerpFunctor(NodePath np, float sx, float sy, float sz, float ex, float ey, - float ez, NodePath wrt) - : LVecBase3fLerpFunctor(LVecBase3f(sx, sy, sz), LVecBase3f(ex, ey, ez)), - _node_path(np), _is_wrt(true), _wrt_path(wrt) {} - void take_shortest(void); - void take_longest(void); - -public: - HprLerpFunctor(const HprLerpFunctor&); - virtual ~HprLerpFunctor(void); - HprLerpFunctor& operator=(const HprLerpFunctor&); - virtual void operator()(float); - -public: - // now for typehandle stuff - static TypeHandle get_class_type(void) { - return _type_handle; - } - static void init_type(void) { - LVecBase3fLerpFunctor::init_type(); - register_type(_type_handle, "HprLerpFunctor", - LVecBase3fLerpFunctor::get_class_type()); - } - virtual TypeHandle get_type(void) const { - return get_class_type(); - } - virtual TypeHandle force_init_type(void) { - init_type(); - return get_class_type(); - } -private: - static TypeHandle _type_handle; -}; - -//////////////////////////////////////////////////////////////////// -// Class : ColorLerpFunctor -// Description : Class for Lerping between scales -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ScaleLerpFunctor : public LVecBase3fLerpFunctor { -private: - NodePath _node_path; - bool _is_wrt; - NodePath _wrt_path; - -PUBLISHED: - ScaleLerpFunctor(NodePath np, LVecBase3f start, LVecBase3f end) - : LVecBase3fLerpFunctor(start, end), _node_path(np), _is_wrt(false) {} - ScaleLerpFunctor(NodePath np, float sx, float sy, float sz, float ex, - float ey, float ez) - : LVecBase3fLerpFunctor(LVecBase3f(sx, sy, sz), LVecBase3f(ex, ey, ez)), - _node_path(np), _is_wrt(false) {} - ScaleLerpFunctor(NodePath np, LVecBase3f start, LVecBase3f end, NodePath wrt) - : LVecBase3fLerpFunctor(start, end), _node_path(np), _is_wrt(true), - _wrt_path(wrt) {} - ScaleLerpFunctor(NodePath np, float sx, float sy, float sz, float ex, - float ey, float ez, NodePath wrt) - : LVecBase3fLerpFunctor(LVecBase3f(sx, sy, sz), LVecBase3f(ex, ey, ez)), - _node_path(np), _is_wrt(true), _wrt_path(wrt) {} - -public: - ScaleLerpFunctor(const ScaleLerpFunctor&); - virtual ~ScaleLerpFunctor(void); - ScaleLerpFunctor& operator=(const ScaleLerpFunctor&); - virtual void operator()(float); - -public: - // now for typehandle stuff - static TypeHandle get_class_type(void) { - return _type_handle; - } - static void init_type(void) { - LVecBase3fLerpFunctor::init_type(); - register_type(_type_handle, "ScaleLerpFunctor", - LVecBase3fLerpFunctor::get_class_type()); - } - virtual TypeHandle get_type(void) const { - return get_class_type(); - } - virtual TypeHandle force_init_type(void) { - init_type(); - return get_class_type(); - } -private: - static TypeHandle _type_handle; -}; - -//////////////////////////////////////////////////////////////////// -// Class : ColorLerpFunctor -// Description : Class for Lerping between colors -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ColorLerpFunctor : public LVecBase4fLerpFunctor { -private: - NodePath _node_path; - bool _is_wrt; - NodePath _wrt_path; - -PUBLISHED: - ColorLerpFunctor(NodePath np, LVecBase4f start, LVecBase4f end) - : LVecBase4fLerpFunctor(start, end), _node_path(np), _is_wrt(false) {} - ColorLerpFunctor(NodePath np, float sr, float sg, float sb, float sa, - float er, float eg, float eb, float ea) : LVecBase4fLerpFunctor(LVecBase4f(sr, sg, sb, sa), - LVecBase4f(er, eg, eb, ea)), _node_path(np), _is_wrt(false) {} - ColorLerpFunctor(NodePath np, LVecBase4f start, LVecBase4f end, NodePath wrt) - : LVecBase4fLerpFunctor(start, end), _node_path(np), _is_wrt(true), - _wrt_path(wrt) {} - ColorLerpFunctor(NodePath np, float sr, float sg, float sb, float sa, float er, float eg, - float eb, float ea, NodePath wrt) - : LVecBase4fLerpFunctor(LVecBase4f(sr, sg, sb, sa), LVecBase4f(er, eg, eb, ea)), - _node_path(np), _is_wrt(true), _wrt_path(wrt) {} - -public: - ColorLerpFunctor(const ColorLerpFunctor&); - virtual ~ColorLerpFunctor(void); - ColorLerpFunctor& operator=(const ColorLerpFunctor&); - virtual void operator()(float); - -public: - // now for typehandle stuff - static TypeHandle get_class_type(void) { - return _type_handle; - } - static void init_type(void) { - LVecBase4fLerpFunctor::init_type(); - register_type(_type_handle, "ColorLerpFunctor", - LVecBase4fLerpFunctor::get_class_type()); - } - virtual TypeHandle get_type(void) const { - return get_class_type(); - } - virtual TypeHandle force_init_type(void) { - init_type(); - return get_class_type(); - } -private: - static TypeHandle _type_handle; -}; - -//////////////////////////////////////////////////////////////////// -// Class : PosHprLerpFunctor -// Description : Class for Lerping between positions and orientations -// in space -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA PosHprLerpFunctor : public LerpFunctor { -private: - NodePath _node_path; - LPoint3f _pstart; - LPoint3f _pend; - LPoint3f _pdiff_cache; - LVecBase3f _hstart; - LVecBase3f _hend; - LVecBase3f _hdiff_cache; - bool _is_wrt; - NodePath _wrt_path; - -PUBLISHED: - PosHprLerpFunctor(NodePath np, LPoint3f pstart, LPoint3f pend, - LVecBase3f hstart, LVecBase3f hend) - : LerpFunctor(), _node_path(np), _pstart(pstart), _pend(pend), - _pdiff_cache(pend-pstart), _hstart(hstart), _hend(hend), - _hdiff_cache(hend-hstart), _is_wrt(false) {} - PosHprLerpFunctor(NodePath np, float psx, float psy, float psz, float pex, - float pey, float pez, float hsx, float hsy, float hsz, - float hex, float hey, float hez) - : LerpFunctor(), _node_path(np), _pstart(psx, psy, psz), - _pend(pex, pey, pez), _pdiff_cache(_pend-_pstart), - _hstart(hsx, hsy, hsz), _hend(hex, hey, hez), - _hdiff_cache(_hend - _hstart), _is_wrt(false) {} - PosHprLerpFunctor(NodePath np, LPoint3f pstart, LPoint3f pend, - LVecBase3f hstart, LVecBase3f hend, NodePath wrt) - : LerpFunctor(), _node_path(np), _pstart(pstart), _pend(pend), - _pdiff_cache(pend-pstart), _hstart(hstart), _hend(hend), - _hdiff_cache(hend-hstart), _is_wrt(true), _wrt_path(wrt) {} - PosHprLerpFunctor(NodePath np, float psx, float psy, float psz, float pex, - float pey, float pez, float hsx, float hsy, float hsz, - float hex, float hey, float hez, NodePath wrt) - : LerpFunctor(), _node_path(np), _pstart(psx, psy, psz), - _pend(pex, pey, pez), _pdiff_cache(_pend-_pstart), - _hstart(hsx, hsy, hsz), _hend(hex, hey, hez), - _hdiff_cache(_hend - _hstart), _is_wrt(true), _wrt_path(wrt) {} - void take_shortest(void); - void take_longest(void); - -public: - PosHprLerpFunctor(const PosHprLerpFunctor&); - virtual ~PosHprLerpFunctor(void); - PosHprLerpFunctor& operator=(const PosHprLerpFunctor&); - virtual void operator()(float); - -public: - // now for typehandle stuff - static TypeHandle get_class_type(void) { - return _type_handle; - } - static void init_type(void) { - LerpFunctor::init_type(); - register_type(_type_handle, "PosHprLerpFunctor", - LerpFunctor::get_class_type()); - } - virtual TypeHandle get_type(void) const { - return get_class_type(); - } - virtual TypeHandle force_init_type(void) { - init_type(); - return get_class_type(); - } -private: - static TypeHandle _type_handle; -}; - -//////////////////////////////////////////////////////////////////// -// Class : HprScaleLerpFunctor -// Description : Class for Lerping between orientation -// and scale -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA HprScaleLerpFunctor : public LerpFunctor { -private: - NodePath _node_path; - LVecBase3f _hstart; - LVecBase3f _hend; - LVecBase3f _hdiff_cache; - LVecBase3f _sstart; - LVecBase3f _send; - LVecBase3f _sdiff_cache; - bool _is_wrt; - NodePath _wrt_path; - -PUBLISHED: - HprScaleLerpFunctor(NodePath np, - LVecBase3f hstart, LVecBase3f hend, LVecBase3f sstart, - LVecBase3f send) - : LerpFunctor(), _node_path(np), - _hstart(hstart), _hend(hend), - _hdiff_cache(hend-hstart), _sstart(sstart), _send(send), - _sdiff_cache(send-sstart), _is_wrt(false) {} - HprScaleLerpFunctor(NodePath np, float hsx, float hsy, - float hsz, float hex, float hey, float hez, float ssx, - float ssy, float ssz, float sex, float sey, float sez) - : LerpFunctor(), _node_path(np), - _hstart(hsx, hsy, hsz), _hend(hex, hey, hez), - _hdiff_cache(_hend-_hstart), _sstart(ssx, ssy, ssz), - _send(sex, sey, sez), _sdiff_cache(_send-_sstart), _is_wrt(false) {} - HprScaleLerpFunctor(NodePath np, - LVecBase3f hstart, LVecBase3f hend, LVecBase3f sstart, - LVecBase3f send, NodePath wrt) - : LerpFunctor(), _node_path(np), _hstart(hstart), _hend(hend), - _hdiff_cache(hend-hstart), _sstart(sstart), _send(send), - _sdiff_cache(send-sstart), _is_wrt(true), _wrt_path(wrt) {} - HprScaleLerpFunctor(NodePath np, float hsx, float hsy, - float hsz, float hex, float hey, float hez, float ssx, - float ssy, float ssz, float sex, float sey, float sez, - NodePath wrt) - : LerpFunctor(), _node_path(np), - _hstart(hsx, hsy, hsz), _hend(hex, hey, hez), - _hdiff_cache(_hend-_hstart), _sstart(ssx, ssy, ssz), - _send(sex, sey, sez), _sdiff_cache(_send-_sstart), _is_wrt(true), - _wrt_path(wrt) {} - void take_shortest(void); - void take_longest(void); - -public: - HprScaleLerpFunctor(const HprScaleLerpFunctor&); - virtual ~HprScaleLerpFunctor(void); - HprScaleLerpFunctor& operator=(const HprScaleLerpFunctor&); - virtual void operator()(float); - -public: - // now for typehandle stuff - static TypeHandle get_class_type(void) { - return _type_handle; - } - static void init_type(void) { - LerpFunctor::init_type(); - register_type(_type_handle, "HprScaleLerpFunctor", - LerpFunctor::get_class_type()); - } - virtual TypeHandle get_type(void) const { - return get_class_type(); - } - virtual TypeHandle force_init_type(void) { - init_type(); - return get_class_type(); - } -private: - static TypeHandle _type_handle; -}; - -//////////////////////////////////////////////////////////////////// -// Class : PosHprScaleLerpFunctor -// Description : Class for Lerping between position, orientation, -// and scale -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA PosHprScaleLerpFunctor : public LerpFunctor { -private: - NodePath _node_path; - LPoint3f _pstart; - LPoint3f _pend; - LPoint3f _pdiff_cache; - LVecBase3f _hstart; - LVecBase3f _hend; - LVecBase3f _hdiff_cache; - LVecBase3f _sstart; - LVecBase3f _send; - LVecBase3f _sdiff_cache; - bool _is_wrt; - NodePath _wrt_path; - -PUBLISHED: - PosHprScaleLerpFunctor(NodePath np, LPoint3f pstart, LPoint3f pend, - LVecBase3f hstart, LVecBase3f hend, LVecBase3f sstart, - LVecBase3f send) - : LerpFunctor(), _node_path(np), _pstart(pstart), _pend(pend), - _pdiff_cache(pend-pstart), _hstart(hstart), _hend(hend), - _hdiff_cache(hend-hstart), _sstart(sstart), _send(send), - _sdiff_cache(send-sstart), _is_wrt(false) {} - PosHprScaleLerpFunctor(NodePath np, float psx, float psy, float psz, - float pex, float pey, float pez, float hsx, float hsy, - float hsz, float hex, float hey, float hez, float ssx, - float ssy, float ssz, float sex, float sey, float sez) - : LerpFunctor(), _node_path(np), _pstart(psx, psy, psz), - _pend(pex, pey, pez), _pdiff_cache(_pend-_pstart), - _hstart(hsx, hsy, hsz), _hend(hex, hey, hez), - _hdiff_cache(_hend-_hstart), _sstart(ssx, ssy, ssz), - _send(sex, sey, sez), _sdiff_cache(_send-_sstart), _is_wrt(false) {} - PosHprScaleLerpFunctor(NodePath np, LPoint3f pstart, LPoint3f pend, - LVecBase3f hstart, LVecBase3f hend, LVecBase3f sstart, - LVecBase3f send, NodePath wrt) - : LerpFunctor(), _node_path(np), _pstart(pstart), _pend(pend), - _pdiff_cache(pend-pstart), _hstart(hstart), _hend(hend), - _hdiff_cache(hend-hstart), _sstart(sstart), _send(send), - _sdiff_cache(send-sstart), _is_wrt(true), _wrt_path(wrt) {} - PosHprScaleLerpFunctor(NodePath np, float psx, float psy, float psz, - float pex, float pey, float pez, float hsx, float hsy, - float hsz, float hex, float hey, float hez, float ssx, - float ssy, float ssz, float sex, float sey, float sez, - NodePath wrt) - : LerpFunctor(), _node_path(np), _pstart(psx, psy, psz), - _pend(pex, pey, pez), _pdiff_cache(_pend-_pstart), - _hstart(hsx, hsy, hsz), _hend(hex, hey, hez), - _hdiff_cache(_hend-_hstart), _sstart(ssx, ssy, ssz), - _send(sex, sey, sez), _sdiff_cache(_send-_sstart), _is_wrt(true), - _wrt_path(wrt) {} - void take_shortest(void); - void take_longest(void); - -public: - PosHprScaleLerpFunctor(const PosHprScaleLerpFunctor&); - virtual ~PosHprScaleLerpFunctor(void); - PosHprScaleLerpFunctor& operator=(const PosHprScaleLerpFunctor&); - virtual void operator()(float); - -public: - // now for typehandle stuff - static TypeHandle get_class_type(void) { - return _type_handle; - } - static void init_type(void) { - LerpFunctor::init_type(); - register_type(_type_handle, "PosHprScaleLerpFunctor", - LerpFunctor::get_class_type()); - } - virtual TypeHandle get_type(void) const { - return get_class_type(); - } - virtual TypeHandle force_init_type(void) { - init_type(); - return get_class_type(); - } -private: - static TypeHandle _type_handle; -}; - -//////////////////////////////////////////////////////////////////// -// Class : ColorScaleLerpFunctor -// Description : Class for Lerping between color scales -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ColorScaleLerpFunctor : public LVecBase4fLerpFunctor { -private: - NodePath _node_path; - bool _is_wrt; - NodePath _wrt_path; - -PUBLISHED: - ColorScaleLerpFunctor(NodePath np, LVecBase4f start, LVecBase4f end) - : LVecBase4fLerpFunctor(start, end), _node_path(np), _is_wrt(false) {} - ColorScaleLerpFunctor(NodePath np, float sr, float sg, float sb, float sa, - float er, float eg, float eb, float ea) : LVecBase4fLerpFunctor(LVecBase4f(sr, sg, sb, sa), - LVecBase4f(er, eg, eb, ea)), _node_path(np), _is_wrt(false) {} - ColorScaleLerpFunctor(NodePath np, LVecBase4f start, LVecBase4f end, NodePath wrt) - : LVecBase4fLerpFunctor(start, end), _node_path(np), _is_wrt(true), - _wrt_path(wrt) {} - ColorScaleLerpFunctor(NodePath np, float sr, float sg, float sb, float sa, float er, float eg, - float eb, float ea, NodePath wrt) - : LVecBase4fLerpFunctor(LVecBase4f(sr, sg, sb, sa), LVecBase4f(er, eg, eb, ea)), - _node_path(np), _is_wrt(true), _wrt_path(wrt) {} - -public: - ColorScaleLerpFunctor(const ColorScaleLerpFunctor&); - virtual ~ColorScaleLerpFunctor(void); - ColorScaleLerpFunctor& operator=(const ColorScaleLerpFunctor&); - virtual void operator()(float); - -public: - // now for typehandle stuff - static TypeHandle get_class_type(void) { - return _type_handle; - } - static void init_type(void) { - LVecBase4fLerpFunctor::init_type(); - register_type(_type_handle, "ColorScaleLerpFunctor", - LVecBase4fLerpFunctor::get_class_type()); - } - virtual TypeHandle get_type(void) const { - return get_class_type(); - } - virtual TypeHandle force_init_type(void) { - init_type(); - return get_class_type(); - } -private: - static TypeHandle _type_handle; -}; - -#endif /* __NODEPATHLERPS_H__ */ - - - - - diff --git a/panda/src/sgmanip/sgmanip_composite1.cxx b/panda/src/sgmanip/sgmanip_composite1.cxx deleted file mode 100644 index 76cea34c2c..0000000000 --- a/panda/src/sgmanip/sgmanip_composite1.cxx +++ /dev/null @@ -1,6 +0,0 @@ - -#include "config_sgmanip.cxx" -#include "findApproxLevel.cxx" -#include "findApproxPath.cxx" -#include "nodePathCollection.cxx" -#include "nodePathLerps.cxx" diff --git a/panda/src/sgmanip/test_sgmanip.cxx b/panda/src/sgmanip/test_sgmanip.cxx deleted file mode 100644 index f3ea239e55..0000000000 --- a/panda/src/sgmanip/test_sgmanip.cxx +++ /dev/null @@ -1,133 +0,0 @@ -// Filename: test_sgmanip.cxx -// Created by: drose (18Feb00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include - -#include "nodePath.h" - -#include -#include -#include -#include -#include - -int -main() { - PT_Node render = new NamedNode("render"); - - PT_Node apples = new NamedNode("apples"); - PT(RenderRelation) apples_arc = new RenderRelation(render, apples); - PT_Node mcintosh = new NamedNode("mcintosh"); - PT(RenderRelation) mcintosh_arc = new RenderRelation(apples, mcintosh); - PT_Node grannysmith = new NamedNode("grannysmith"); - PT(RenderRelation) grannysmith_arc = new RenderRelation(apples, grannysmith); - PT_Node delicious = new NamedNode("delicious"); - PT(RenderRelation) delicious_arc = new RenderRelation(apples, delicious); - PT_Node golden = new NamedNode("golden"); - PT(RenderRelation) golden_arc = new RenderRelation(delicious, golden); - PT_Node red = new NamedNode("red"); - PT(RenderRelation) red_arc = new RenderRelation(delicious, red); - - PT_Node oranges = new NamedNode("oranges"); - PT(RenderRelation) oranges_arc = new RenderRelation(render, oranges); - PT_Node navel = new NamedNode("navel"); - PT(RenderRelation) navel_arc = new RenderRelation(oranges, navel); - PT_Node red_orange = new NamedNode("red"); - PT(RenderRelation) red_orange_arc = new RenderRelation(oranges, red_orange); - - NodePath render_path(render); - render_path.ls(); - - NodePath del_path(render_path, "apples/delicious"); - nout << "\ndel_path = " << del_path << "\n"; - nout << "del_path.get_parent() = " << del_path.get_parent() << "\n"; - NodePath red_path(del_path, "red"); - nout << "red_path = " << red_path << "\n"; - NodePath del_path2(render_path, delicious); - nout << "del_path2 = " << del_path2 << "\n"; - NodePath mc_path(NodePath(del_path, 1), "mcintosh"); - nout << "mc_path = " << mc_path << "\n"; - NodePath apples_path(del_path, 1); - nout << "apples_path = " << apples_path << "\n"; - NodePath oranges_path(render_path, oranges); - nout << "oranges_path = " << oranges_path << "\n"; - - /* - nout << "\ndel_path2.share_with(del_path) = " - << del_path2.share_with(del_path) << "\n"; - nout << "del_path2 = " << del_path2 << "\n"; - */ - - nout << "\nChildren of del_path:\n"; - del_path.get_children().write(nout, 2); - nout << "Sibs:\n"; - del_path.get_siblings().write(nout, 2); - nout << "Descendants:\n"; - del_path.ls(nout); - nout << "Nodes:\n"; - int i; - for (i = 0; i < del_path.get_num_nodes(); i++) { - nout << " " << *del_path.get_node(i) << "\n"; - } - nout << "Arcs:\n"; - for (i = 0; i < del_path.get_num_arcs(); i++) { - nout << " " << *del_path.get_arc(i) << "\n"; - } - nout << "As strings:\n"; - for (i = 0; i <= del_path.get_num_nodes(); i++) { - nout << " " << i << ": " << del_path.as_string(i) << "\n"; - } - nout << "Connectivity = " << del_path.verify_connectivity() << "\n"; - - nout << "\nEquivalence to self = " << (del_path == del_path) << "\n"; - nout << "Equivalence to del_path2 = " << (del_path == del_path2) << "\n"; - nout << "Equivalence to mc_path = " << (del_path == mc_path) << "\n"; - - nout << "\nAll paths to red_orange:\n"; - render_path.find_all_paths_down_to(red_orange).write(nout, 2); - - nout << "\nMoving del_path to oranges\n"; - del_path.reparent_to(oranges_path); - nout << "del_path = " << del_path << "\n" - << "red_path = " << red_path << "\n" - << "del_path2 = " << del_path2 << "\n" - << "mc_path = " << mc_path << "\n" - << "apples_path = " << apples_path << "\n" - << "oranges_path = " << oranges_path << "\n"; - - render_path.ls(nout); - - nout << "\nInstancing del_path back under apples\n"; - NodePath new_del_path = del_path.instance_to(apples_path); - nout << "del_path = " << del_path << "\n" - << "new_del_path = " << new_del_path << "\n" - << "red_path = " << red_path << "\n" - << "del_path2 = " << del_path2 << "\n" - << "mc_path = " << mc_path << "\n" - << "apples_path = " << apples_path << "\n" - << "oranges_path = " << oranges_path << "\n"; - - render_path.ls(nout); - - nout << "\nRepairing del_path2, result is " - << del_path2.repair_connectivity(render_path) << "\n"; - nout << "del_path2 = " << del_path2 << "\n\n"; - - return (0); -} - diff --git a/panda/src/sgraph/Sources.pp b/panda/src/sgraph/Sources.pp deleted file mode 100644 index 37d5aca8ca..0000000000 --- a/panda/src/sgraph/Sources.pp +++ /dev/null @@ -1,46 +0,0 @@ -#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \ - dtoolutil:c dtoolbase:c dtool:m - -#begin lib_target - #define TARGET sgraph - #define LOCAL_LIBS \ - gobj putil graph mathutil linmath event - - #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx - - #define SOURCES \ - camera.I camera.h config_sgraph.h geomNode.I geomNode.h \ - geomTransformer.I geomTransformer.h modelNode.I modelNode.h \ - modelRoot.I modelRoot.h planeNode.I planeNode.h \ - lensNode.I lensNode.h renderTraverser.I \ - renderTraverser.h switchNode.I switchNode.h - - #define INCLUDED_SOURCES \ - camera.cxx config_sgraph.cxx geomNode.cxx geomTransformer.cxx \ - modelNode.cxx modelRoot.cxx planeNode.cxx lensNode.cxx \ - renderTraverser.cxx switchNode.cxx - - #define INSTALL_HEADERS \ - camera.I camera.h config_sgraph.h \ - geomNode.I geomNode.h geomTransformer.I \ - geomTransformer.h modelNode.I modelNode.h modelRoot.I \ - modelRoot.h planeNode.I planeNode.h lensNode.I \ - lensNode.h renderTraverser.I renderTraverser.h \ - switchNode.I switchNode.h - - #define IGATESCAN all - -#end lib_target - -#begin test_bin_target - #define TARGET test_sgraph - #define LOCAL_LIBS \ - sgraph mathutil graph putil - #define OTHER_LIBS \ - $[OTHER_LIBS] pystub - - #define SOURCES \ - test_sgraph.cxx - -#end test_bin_target - diff --git a/panda/src/sgraph/camera.I b/panda/src/sgraph/camera.I deleted file mode 100644 index 9602cc92d5..0000000000 --- a/panda/src/sgraph/camera.I +++ /dev/null @@ -1,88 +0,0 @@ -// Filename: camera.I -// Created by: drose (27Sep99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: Camera::set_active -// Access: Public -// Description: Sets the active flag on the camera. When the camera -// is not active, nothing will be rendered. -//////////////////////////////////////////////////////////////////// -INLINE void Camera:: -set_active(bool active) { - _active = active; -} - -//////////////////////////////////////////////////////////////////// -// Function: Camera::is_active -// Access: Public -// Description: Returns the current setting of the active flag on the -// camera. -//////////////////////////////////////////////////////////////////// -INLINE bool Camera:: -is_active() const { - return _active; -} - -//////////////////////////////////////////////////////////////////// -// Function: Camera::set_scene -// Access: Public -// Description: Sets the scene that will be rendered by the camera. -// This is normally the root node of a scene graph, -// typically a node called 'render', although it could -// represent the root of any subgraph. -//////////////////////////////////////////////////////////////////// -INLINE void Camera:: -set_scene(Node *scene) { - _scene = scene; -} - -//////////////////////////////////////////////////////////////////// -// Function: Camera::get_scene -// Access: Public -// Description: Returns the scene that will be rendered by the -// camera. See set_scene(). -//////////////////////////////////////////////////////////////////// -INLINE Node *Camera:: -get_scene() const { - return _scene; -} - -//////////////////////////////////////////////////////////////////// -// Function: Camera::set_qpscene -// Access: Public -// Description: Sets the scene that will be rendered by the camera. -// This is normally the root node of a scene graph, -// typically a node called 'render', although it could -// represent the root of any subgraph. -//////////////////////////////////////////////////////////////////// -INLINE void Camera:: -set_qpscene(PandaNode *scene) { - _qpscene = scene; -} - -//////////////////////////////////////////////////////////////////// -// Function: Camera::get_qpscene -// Access: Public -// Description: Returns the scene that will be rendered by the -// camera. See set_qpscene(). -//////////////////////////////////////////////////////////////////// -INLINE PandaNode *Camera:: -get_qpscene() const { - return _qpscene; -} diff --git a/panda/src/sgraph/camera.cxx b/panda/src/sgraph/camera.cxx deleted file mode 100644 index e03ed8d095..0000000000 --- a/panda/src/sgraph/camera.cxx +++ /dev/null @@ -1,168 +0,0 @@ -// Filename: camera.cxx -// Created by: mike (09Jan97) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// -#include "pandabase.h" -#include "camera.h" -#include "lens.h" -#include "throw_event.h" - -TypeHandle Camera::_type_handle; - - -//////////////////////////////////////////////////////////////////// -// Function: Camera::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -Camera:: -Camera(const string &name) : - LensNode(name), - _active(true) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: Camera::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -Camera:: -Camera(const Camera ©) : - LensNode(copy), - _active(copy._active), - _scene(copy._scene) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: Camera::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void Camera:: -operator = (const Camera ©) { - LensNode::operator = (copy); - _active = copy._active; - _scene = copy._scene; -} - -//////////////////////////////////////////////////////////////////// -// Function: Camera::make_copy -// Access: Public, Virtual -// Description: Returns a newly-allocated Node that is a shallow copy -// of this one. It will be a different Node pointer, -// but its internal data may or may not be shared with -// that of the original Node. -//////////////////////////////////////////////////////////////////// -Node *Camera:: -make_copy() const { - return new Camera(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: Camera::safe_to_flatten -// Access: Public, Virtual -// Description: Returns true if it is generally safe to flatten out -// this particular kind of Node by duplicating -// instances, false otherwise (for instance, a Camera -// cannot be safely flattened, because the Camera -// pointer itself is meaningful). -//////////////////////////////////////////////////////////////////// -bool Camera:: -safe_to_flatten() const { - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: Camera::safe_to_transform -// Access: Public, Virtual -// Description: Returns true if it is generally safe to transform -// this particular kind of Node by calling the xform() -// method, false otherwise. For instance, it's usually -// a bad idea to attempt to xform a Character. -//////////////////////////////////////////////////////////////////// -bool Camera:: -safe_to_transform() const { - return false; -} - - -//////////////////////////////////////////////////////////////////// -// Function: Camera::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -Camera:: -~Camera(void) { - // We don't have to destroy the display regions associated with the - // camera; they're responsible for themselves. - - // We don't have to remove the camera from the global list, because - // it must have already been removed--otherwise we couldn't be - // deleting it! -} - -//////////////////////////////////////////////////////////////////// -// Function: Camera::get_num_drs -// Access: Public -// Description: Returns the number of display regions that share this -// camera. -//////////////////////////////////////////////////////////////////// -int Camera:: -get_num_drs() const { - return _display_regions.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: Camera::get_dr -// Access: Public -// Description: Returns the nth display region that shares this -// camera. -//////////////////////////////////////////////////////////////////// -DisplayRegion *Camera:: -get_dr(int index) const { - nassertr(index >= 0 && index < get_num_drs(), NULL); - return _display_regions[index]; -} - -//////////////////////////////////////////////////////////////////// -// Function: Camera::add_display_region -// Access: Private -// Description: Adds the indicated DisplayRegion to the set of -// DisplayRegions shared by the camera. This is only -// intended to be called from the DisplayRegion. -//////////////////////////////////////////////////////////////////// -void Camera:: -add_display_region(DisplayRegion *display_region) { - _display_regions.push_back(display_region); -} - -//////////////////////////////////////////////////////////////////// -// Function: Camera::remove_display_region -// Access: Private -// Description: Removes the indicated DisplayRegion from the set of -// DisplayRegions shared by the camera. This is only -// intended to be called from the DisplayRegion. -//////////////////////////////////////////////////////////////////// -void Camera:: -remove_display_region(DisplayRegion *display_region) { - DisplayRegions::iterator dri = - find(_display_regions.begin(), _display_regions.end(), display_region); - if (dri != _display_regions.end()) { - _display_regions.erase(dri); - } -} diff --git a/panda/src/sgraph/camera.h b/panda/src/sgraph/camera.h deleted file mode 100644 index e79d40db33..0000000000 --- a/panda/src/sgraph/camera.h +++ /dev/null @@ -1,101 +0,0 @@ -// Filename: camera.h -// Created by: mike (09Jan97) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// -#ifndef CAMERA_H -#define CAMERA_H -// -//////////////////////////////////////////////////////////////////// -// Includes -//////////////////////////////////////////////////////////////////// -#include "pandabase.h" - -#include "lensNode.h" -#include "pt_Node.h" -#include "pvector.h" - -class DisplayRegion; -class PandaNode; - -//////////////////////////////////////////////////////////////////// -// Class : Camera -// Description : -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA Camera : public LensNode { -PUBLISHED: - Camera(const string &name = ""); - -public: - Camera(const Camera ©); - void operator = (const Camera ©); - virtual ~Camera(); - - virtual Node *make_copy() const; - virtual bool safe_to_flatten() const; - virtual bool safe_to_transform() const; - - //virtual void output(ostream &out) const; - virtual void config() { } - -PUBLISHED: - INLINE void set_active(bool active); - INLINE bool is_active() const; - - INLINE void set_scene(Node *scene); - INLINE Node *get_scene() const; - - INLINE void set_qpscene(PandaNode *scene); - INLINE PandaNode *get_qpscene() const; - - int get_num_drs() const; - DisplayRegion *get_dr(int index) const; - -private: - void add_display_region(DisplayRegion *display_region); - void remove_display_region(DisplayRegion *display_region); - - bool _active; - PT_Node _scene; - PandaNode *_qpscene; - - typedef pvector DisplayRegions; - DisplayRegions _display_regions; - - static const std::string _CHANGE_CAM; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - LensNode::init_type(); - register_type(_type_handle, "Camera", - LensNode::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; - -friend class DisplayRegion; -}; - -#include "camera.I" - -#endif diff --git a/panda/src/sgraph/config_sgraph.cxx b/panda/src/sgraph/config_sgraph.cxx deleted file mode 100644 index b7c2f26a05..0000000000 --- a/panda/src/sgraph/config_sgraph.cxx +++ /dev/null @@ -1,71 +0,0 @@ -// Filename: config_sgraph.cxx -// Created by: drose (12Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "config_sgraph.h" -#include "renderTraverser.h" -#include "geomNode.h" -#include "camera.h" -#include "planeNode.h" -#include "modelNode.h" -#include "modelRoot.h" -#include "lensNode.h" -#include "switchNode.h" - -#include -#include - -Configure(config_sgraph); -NotifyCategoryDef(sgraph, ""); - -ConfigureFn(config_sgraph) { - init_libsgraph(); -} - -//////////////////////////////////////////////////////////////////// -// Function: init_libsgraph -// Description: Initializes the library. This must be called at -// least once before any of the functions or classes in -// this library can be used. Normally it will be -// called by the static initializers and need not be -// called explicitly, but special cases exist. -//////////////////////////////////////////////////////////////////// -void -init_libsgraph() { - static bool initialized = false; - if (initialized) { - return; - } - initialized = true; - - init_libgraph(); - - RenderTraverser::init_type(); - GeomNode::init_type(); - Camera::init_type(); - PlaneNode::init_type(); - ModelNode::init_type(); - ModelRoot::init_type(); - LensNode::init_type(); - SwitchNode::init_type(); - - //Registration of writeable object's creation - //functions with BamReader's factory - GeomNode::register_with_read_factory(); - ModelNode::register_with_read_factory(); - ModelRoot::register_with_read_factory(); -} diff --git a/panda/src/sgraph/config_sgraph.h b/panda/src/sgraph/config_sgraph.h deleted file mode 100644 index 39da04e720..0000000000 --- a/panda/src/sgraph/config_sgraph.h +++ /dev/null @@ -1,29 +0,0 @@ -// Filename: config_sgraph.h -// Created by: drose (12Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CONFIG_SGRAPH_H -#define CONFIG_SGRAPH_H - -#include -#include - -NotifyCategoryDecl(sgraph, EXPCL_PANDA, EXPTP_PANDA); - -extern EXPCL_PANDA void init_libsgraph(); - -#endif diff --git a/panda/src/sgraph/geomNode.I b/panda/src/sgraph/geomNode.I deleted file mode 100644 index 13c7a4778b..0000000000 --- a/panda/src/sgraph/geomNode.I +++ /dev/null @@ -1,17 +0,0 @@ -// Filename: geomNode.I -// Created by: drose (16Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// diff --git a/panda/src/sgraph/geomNode.cxx b/panda/src/sgraph/geomNode.cxx deleted file mode 100644 index e124145db3..0000000000 --- a/panda/src/sgraph/geomNode.cxx +++ /dev/null @@ -1,530 +0,0 @@ -// Filename: geomNode.cxx -// Created by: mike (09Jan97) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "geomNode.h" -#include "geomTransformer.h" -#include "config_sgraph.h" - -#include -#include -#include -#include - -//////////////////////////////////////////////////////////////////// -// Static variables -//////////////////////////////////////////////////////////////////// -TypeHandle GeomNode::_type_handle; - - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -GeomNode:: -GeomNode(const string &name) : NamedNode(name), _num_geoms(0) { - _prepared_gsg = (GraphicsStateGuardianBase *)NULL; - _prepared_context = (GeomNodeContext *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -GeomNode:: -GeomNode(const GeomNode ©) : - NamedNode(copy), - _geoms(copy._geoms), - _num_geoms(0) -{ - _prepared_gsg = (GraphicsStateGuardianBase *)NULL; - _prepared_context = (GeomNodeContext *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void GeomNode:: -operator = (const GeomNode ©) { - unprepare(); - NamedNode::operator = (copy); - _geoms = copy._geoms; - _num_geoms = 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -GeomNode:: -~GeomNode() { - unprepare(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::make_copy -// Access: Public, Virtual -// Description: Returns a newly-allocated Node that is a shallow copy -// of this one. It will be a different Node pointer, -// but its internal data may or may not be shared with -// that of the original Node. -//////////////////////////////////////////////////////////////////// -Node *GeomNode:: -make_copy() const { - return new GeomNode(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::xform -// Access: Public, Virtual -// Description: Transforms the contents of this node by the indicated -// matrix, if it means anything to do so. For most -// kinds of nodes, this does nothing. -// -// For a GeomNode, this does the right thing, but it is -// better to use a GeomTransformer instead, since it -// will share the new arrays properly between different -// GeomNodes. -//////////////////////////////////////////////////////////////////// -void GeomNode:: -xform(const LMatrix4f &mat) { - GeomTransformer transformer; - transformer.transform_vertices(this, mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::combine_with -// Access: Public, Virtual -// Description: Collapses this node with the other node, if possible, -// and returns a pointer to the combined node, or NULL -// if the two nodes cannot safely be combined. -// -// The return value may be this, other, or a new node -// altogether. -// -// This function is called from GraphReducer::flatten(), -// and need not deal with children; its job is just to -// decide whether to collapse the two nodes and what the -// collapsed node should look like. -//////////////////////////////////////////////////////////////////// -Node *GeomNode:: -combine_with(Node *other) { - if (is_exact_type(get_class_type()) && - other->is_exact_type(get_class_type())) { - // Two GeomNodes can combine by moving Geoms from one to the other. - GeomNode *gother = DCAST(GeomNode, other); - add_geoms_from(gother); - return this; - } - - return NamedNode::combine_with(other); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::write -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void GeomNode:: -write(ostream &out, int indent_level) const { - Geoms::const_iterator gi; - for (gi = _geoms.begin(); gi != _geoms.end(); ++gi) { - dDrawable *drawable = (*gi); - if (drawable->is_of_type(Geom::get_class_type())) { - indent(out, indent_level) << *DCAST(Geom, drawable) << "\n"; - } else { - indent(out, indent_level) << drawable->get_type() << "\n"; - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::write_verbose -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void GeomNode:: -write_verbose(ostream &out, int indent_level) const { - Geoms::const_iterator gi; - for (gi = _geoms.begin(); gi != _geoms.end(); ++gi) { - dDrawable *drawable = (*gi); - if (drawable->is_of_type(Geom::get_class_type())) { - DCAST(Geom, drawable)->write_verbose(out, indent_level); - } else { - out << drawable->get_type() << "\n"; - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::draw -// Access: Public -// Description: Draws all the geometry belonging to the geom node, -// in the gsg's current state. -//////////////////////////////////////////////////////////////////// -void GeomNode:: -draw(GraphicsStateGuardianBase *gsg) { - if (_prepared_gsg == gsg) { - gsg->draw_geom_node(this, _prepared_context); - } else { - Geoms::const_iterator gi; - for (gi = _geoms.begin(); gi != _geoms.end(); ++gi) { - (*gi)->draw(gsg); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::prepare -// Access: Public -// Description: Creates a context for the GeomNode on the particular -// GSG, if it does not already exist. Returns the new -// (or old) GeomNodeContext. -// -// If the given GeomNodeContext pointer is non-NULL, it will -// be passed to the GSG, which may or may not choose to -// extend the existing GeomNodeContext, or create a totally -// new one. -//////////////////////////////////////////////////////////////////// -GeomNodeContext *GeomNode:: -prepare(GraphicsStateGuardianBase *gsg) { - if (gsg != _prepared_gsg) { - GeomNodeContext *gc = gsg->prepare_geom_node(this); - if (gc != (GeomNodeContext *)NULL) { - unprepare(); - _prepared_context = gc; - _prepared_gsg = gsg; - - if (!keep_geom_ram) { - // Once we have prepared the GeomNode, we can generally safely - // remove the vertices from main RAM. The GSG is now - // responsible for remembering what it looks like. - - if (sgraph_cat.is_debug()) { - sgraph_cat.debug() - << "Dumping RAM for " << *this << "\n"; - } - - // First, change our bounding volume to a static volume, so it - // won't try to recompute itself once we clear out the Geoms. - set_bound(get_bound()); - - // Now remove the set of Geoms, since we don't need them any - // more. - _geoms.clear(); - } - } - return gc; - } - - return _prepared_context; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::unprepare -// Access: Public -// Description: Frees the context allocated on all GSG's for which -// the geom has been declared. -//////////////////////////////////////////////////////////////////// -void GeomNode:: -unprepare() { - if (_prepared_gsg != (GraphicsStateGuardianBase *)NULL) { - _prepared_gsg->release_geom_node(_prepared_context); - _prepared_gsg = (GraphicsStateGuardianBase *)NULL; - _prepared_context = (GeomNodeContext *)NULL; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::unprepare -// Access: Public -// Description: Frees the geom context only on the indicated GSG, -// if it exists there. -//////////////////////////////////////////////////////////////////// -void GeomNode:: -unprepare(GraphicsStateGuardianBase *gsg) { - if (_prepared_gsg == gsg) { - _prepared_gsg->release_geom_node(_prepared_context); - _prepared_gsg = (GraphicsStateGuardianBase *)NULL; - _prepared_context = (GeomNodeContext *)NULL; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::clear_gsg -// Access: Public -// Description: Removes the indicated GSG from the Geom's known -// GSG's, without actually releasing the geom on that -// GSG. This is intended to be called only from -// GSG::release_geom_node(); it should never be called by -// user code. -//////////////////////////////////////////////////////////////////// -void GeomNode:: -clear_gsg(GraphicsStateGuardianBase *gsg) { - if (_prepared_gsg == gsg) { - _prepared_gsg = (GraphicsStateGuardianBase *)NULL; - _prepared_context = (GeomNodeContext *)NULL; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::get_num_geoms -// Access: Public -// Description: Returns the number of geoms stored in the node. -//////////////////////////////////////////////////////////////////// -int GeomNode:: -get_num_geoms() const { - return _geoms.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::get_geom -// Access: Public -// Description: Returns a pointer to the nth Geom (actually, -// Drawable) stored in the node. -//////////////////////////////////////////////////////////////////// -dDrawable *GeomNode:: -get_geom(int n) const { - nassertr(n >= 0 && n < get_num_geoms(), (dDrawable *)NULL); - return _geoms[n]; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::remove_geom -// Access: Public -// Description: Removes the nth Geom from the node. All subsequent -// index numbers are shifted down by one. -//////////////////////////////////////////////////////////////////// -void GeomNode:: -remove_geom(int n) { - nassertv(n >= 0 && n < get_num_geoms()); - if (_geoms.get_ref_count() == 1) { - // The normal case; we own the only pointer to the array. - _geoms.erase(_geoms.begin() + n); - - } else { - // Copy-on-write. - int num_geoms = _geoms.size(); - Geoms new_geoms; - new_geoms.reserve(num_geoms - 1); - int i; - for (i = 0; i < n; i++) { - new_geoms.push_back(_geoms[i]); - } - for (i = n + 1; i < num_geoms; i++) { - new_geoms.push_back(_geoms[i]); - } - nassertv(new_geoms.size() == _geoms.size()); - _geoms = new_geoms; - nassertv(_geoms.get_ref_count() == 1); - } - - unprepare(); - mark_bound_stale(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::clear -// Access: Public -// Description: Removes all the Geoms from the node. -//////////////////////////////////////////////////////////////////// -void GeomNode:: -clear() { - _geoms.clear(); - unprepare(); - mark_bound_stale(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::add_geom -// Access: Public -// Description: Adds a new Geom to the end of the list. Returns the -// new Geom's index number within the node. -//////////////////////////////////////////////////////////////////// -int GeomNode:: -add_geom(dDrawable *geom, const RenderState *) { - if (_geoms.get_ref_count() == 1) { - // The normal case; we own the only pointer to the array. - _geoms.push_back(geom); - } else { - // Copy on write. - Geoms new_geoms = Geoms::empty_array(0); - if (_geoms.size() != 0) { - new_geoms.v() = _geoms.v(); - } - _geoms = new_geoms; - _geoms.push_back(geom); - } - - unprepare(); - mark_bound_stale(); - return _geoms.size() - 1; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::add_geoms_from -// Access: Public -// Description: Adds all the Geoms in the indicated GeomNode to the -// end of the list. -//////////////////////////////////////////////////////////////////// -void GeomNode:: -add_geoms_from(const GeomNode *other) { - const PT(dDrawable) *geoms_begin = &other->_geoms[0]; - const PT(dDrawable) *geoms_end = geoms_begin + other->_geoms.size(); - - if (_geoms.get_ref_count() == 1) { - // The normal case; we own the only pointer to the array. - _geoms.v().insert(_geoms.end(), geoms_begin, geoms_end); - - } else { - // Copy on write. - Geoms new_geoms = Geoms::empty_array(0); - if (_geoms.size() != 0) { - new_geoms.v() = _geoms.v(); - } - _geoms = new_geoms; - _geoms.v().insert(_geoms.end(), geoms_begin, geoms_end); - } - - unprepare(); - mark_bound_stale(); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::recompute_bound -// Access: Protected, Virtual -// Description: Recomputes the dynamic bounding volume for this node. -//////////////////////////////////////////////////////////////////// -BoundingVolume *GeomNode:: -recompute_bound() { - // First, get ourselves a fresh, empty bounding volume. - BoundingVolume *bound = BoundedObject::recompute_bound(); - nassertr(bound != (BoundingVolume *)NULL, bound); - - // Now actually compute the bounding volume by putting it around all - // of our drawable's bounding volumes. - pvector child_volumes; - - Geoms::const_iterator gi; - for (gi = _geoms.begin(); gi != _geoms.end(); ++gi) { - child_volumes.push_back(&(*gi)->get_bound()); - } - - const BoundingVolume **child_begin = &child_volumes[0]; - const BoundingVolume **child_end = child_begin + child_volumes.size(); - - bound->around(child_begin, child_end); - return bound; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::write_datagram -// Access: Public -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void GeomNode:: -write_datagram(BamWriter *manager, Datagram &me) -{ - NamedNode::write_datagram(manager, me); - //Write out all of the Geom objects that this node - //stores - me.add_uint16(_geoms.size()); - for(int i = 0; i < (int)_geoms.size(); i++) - { - manager->write_pointer(me, _geoms[i]); - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::complete_pointers -// Access: Public -// Description: Takes in a vector of pointes to TypedWritable -// objects that correspond to all the requests for -// pointers that this object made to BamReader. -//////////////////////////////////////////////////////////////////// -int GeomNode:: -complete_pointers(TypedWritable **p_list, BamReader* manager) -{ - int start = NamedNode::complete_pointers(p_list, manager); - for(int i = start; i < _num_geoms+start; i++) - { - PT(dDrawable) temp = DCAST(dDrawable, p_list[i]); - _geoms.push_back(temp); - } - return start+_num_geoms; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::make_GeomNode -// Access: Protected -// Description: Factory method to generate a GeomNode object -//////////////////////////////////////////////////////////////////// -TypedWritable* GeomNode:: -make_GeomNode(const FactoryParams ¶ms) -{ - GeomNode *me = new GeomNode; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void GeomNode:: -fillin(DatagramIterator& scan, BamReader* manager) -{ - NamedNode::fillin(scan, manager); - _num_geoms = scan.get_uint16(); - for(int i = 0; i < _num_geoms; i++) - { - manager->read_pointer(scan); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomNode::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a GeomNode object -//////////////////////////////////////////////////////////////////// -void GeomNode:: -register_with_read_factory(void) -{ - BamReader::get_factory()->register_factory(get_class_type(), make_GeomNode); -} - - - - - - - diff --git a/panda/src/sgraph/geomNode.h b/panda/src/sgraph/geomNode.h deleted file mode 100644 index 90ae9b0956..0000000000 --- a/panda/src/sgraph/geomNode.h +++ /dev/null @@ -1,126 +0,0 @@ -// Filename: geomNode.h -// Created by: mike (09Jan97) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// -#ifndef GEOMNODE_H -#define GEOMNODE_H -// -//////////////////////////////////////////////////////////////////// -// Includes -//////////////////////////////////////////////////////////////////// -#include - -#include -#include -#include -#include - -class GraphicsStateGuardianBase; -class GeomNodeContext; -class RenderState; - -//////////////////////////////////////////////////////////////////// -// Class : GeomNode -// Description : Scene graph node that holds drawable geometry -// elements -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA GeomNode : public NamedNode { -PUBLISHED: - GeomNode(const string &name = ""); - -public: - GeomNode(const GeomNode ©); - void operator = (const GeomNode ©); - virtual ~GeomNode(); - - virtual Node *make_copy() const; - virtual void xform(const LMatrix4f &mat); - virtual Node *combine_with(Node *other); - - virtual void write(ostream &out, int indent_level = 0) const; - -PUBLISHED: - void write_verbose(ostream &out, int indent_level) const; - -public: - void draw(GraphicsStateGuardianBase *gsg); - - GeomNodeContext *prepare(GraphicsStateGuardianBase *gsg); - void unprepare(); - void unprepare(GraphicsStateGuardianBase *gsg); - void clear_gsg(GraphicsStateGuardianBase *gsg); - -PUBLISHED: - int get_num_geoms() const; - dDrawable *get_geom(int n) const; - void remove_geom(int n); - void clear(); - // RenderState pointer here as a temporary builder hack. - int add_geom(dDrawable *geom, const RenderState *ptr = NULL); - void add_geoms_from(const GeomNode *other); - -protected: - virtual BoundingVolume *recompute_bound(); - -private: - typedef PTA(PT(dDrawable)) Geoms; - Geoms _geoms; - - // These are essentially similar to the same fields in Geom. They - // are used only if the GSG supports a node-level Geom context, as - // opposed to strictly a Geom-level context. - GraphicsStateGuardianBase *_prepared_gsg; - GeomNodeContext *_prepared_context; - -public: - static void register_with_read_factory(void); - virtual void write_datagram(BamWriter* manager, Datagram &me); - virtual int complete_pointers(TypedWritable **plist, - BamReader *manager); - - static TypedWritable *make_GeomNode(const FactoryParams ¶ms); - -protected: - void fillin(DatagramIterator& scan, BamReader* manager); - -private: - //This value is only used for the process of re-construction - //from a binary source. DO NOT ACCESS. The value is only - //guaranteed to be accurate during that process - int _num_geoms; - -public: - static TypeHandle get_class_type(void) { - return _type_handle; - } - static void init_type(void) { - NamedNode::init_type(); - register_type(_type_handle, "GeomNode", - NamedNode::get_class_type()); - } - virtual TypeHandle get_type(void) const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; - friend class GeomTransformer; -}; - -#include "geomNode.I" - -#endif diff --git a/panda/src/sgraph/geomTransformer.I b/panda/src/sgraph/geomTransformer.I deleted file mode 100644 index be89a735f9..0000000000 --- a/panda/src/sgraph/geomTransformer.I +++ /dev/null @@ -1,76 +0,0 @@ -// Filename: geomTransformer.I -// Created by: drose (23May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: GeomTransformer::SourceVertices::Ordering Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool GeomTransformer::SourceVertices:: -operator < (const GeomTransformer::SourceVertices &other) const { - if (_coords != other._coords) { - return _coords < other._coords; - } - return (_mat.compare_to(other._mat) < 0); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomTransformer::SourceNormals::Ordering Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool GeomTransformer::SourceNormals:: -operator < (const GeomTransformer::SourceNormals &other) const { - if (_norms != other._norms) { - return _norms < other._norms; - } - return (_mat.compare_to(other._mat) < 0); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomTransformer::SourceTexCoords::Ordering Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool GeomTransformer::SourceTexCoords:: -operator < (const GeomTransformer::SourceTexCoords &other) const { - if (_texcoords != other._texcoords) { - return _texcoords < other._texcoords; - } - return (_mat.compare_to(other._mat) < 0); -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomTransformer::SourceColors::Ordering Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool GeomTransformer::SourceColors:: -operator < (const GeomTransformer::SourceColors &other) const { - if (_colors != other._colors) { - return _colors < other._colors; - } - if (_alpha_scale != other._alpha_scale) { - return _alpha_scale < other._alpha_scale; - } - if (_alpha_offset != other._alpha_offset) { - return _alpha_offset < other._alpha_offset; - } - return (_mat.compare_to(other._mat) < 0); -} diff --git a/panda/src/sgraph/geomTransformer.cxx b/panda/src/sgraph/geomTransformer.cxx deleted file mode 100644 index 20e2da8890..0000000000 --- a/panda/src/sgraph/geomTransformer.cxx +++ /dev/null @@ -1,413 +0,0 @@ -// Filename: geomTransformer.cxx -// Created by: drose (23May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "geomTransformer.h" -#include "geomNode.h" - - -//////////////////////////////////////////////////////////////////// -// Function: GeomTransformer::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -GeomTransformer:: -GeomTransformer() { -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomTransformer::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -GeomTransformer:: -~GeomTransformer() { -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomTransformer::transform_vertices -// Access: Public -// Description: Transforms the vertices and the normals in the -// indicated Geom by the indicated matrix. Returns true -// if the Geom was changed, false otherwise. -//////////////////////////////////////////////////////////////////// -bool GeomTransformer:: -transform_vertices(Geom *geom, const LMatrix4f &mat) { - bool transformed = false; - - nassertr(geom != (Geom *)NULL, false); - - PTA_Vertexf coords; - PTA_ushort index; - - geom->get_coords(coords, index); - - if (!coords.empty()) { - // Look up the Geom's coords in our table--have we already - // transformed this array? - SourceVertices sv; - sv._mat = mat; - sv._coords = coords; - - PTA_Vertexf &new_coords = _vertices[sv]; - - if (new_coords.is_null()) { - // We have not transformed the array yet. Do so now. - new_coords.reserve(coords.size()); - PTA_Vertexf::const_iterator vi; - for (vi = coords.begin(); vi != coords.end(); ++vi) { - new_coords.push_back((*vi) * mat); - } - nassertr(new_coords.size() == coords.size(), false); - } - - geom->set_coords(new_coords, index); - transformed = true; - } - - // Now do the same thing for normals. - PTA_Normalf norms; - GeomBindType bind; - - geom->get_normals(norms, bind, index); - - if (bind != G_OFF) { - SourceNormals sn; - sn._mat = mat; - sn._norms = norms; - - PTA_Normalf &new_norms = _normals[sn]; - - if (new_norms.is_null()) { - // We have not transformed the array yet. Do so now. - new_norms.reserve(norms.size()); - PTA_Normalf::const_iterator ni; - for (ni = norms.begin(); ni != norms.end(); ++ni) { - Normalf new_norm = (*ni) * mat; - new_norm.normalize(); - new_norms.push_back(new_norm); - } - nassertr(new_norms.size() == norms.size(), false); - } - - geom->set_normals(new_norms, bind, index); - transformed = true; - } - - return transformed; -} - - -//////////////////////////////////////////////////////////////////// -// Function: GeomTransformer::transform_vertices -// Access: Public -// Description: Transforms the vertices and the normals in all of the -// Geoms within the indicated GeomNode by the indicated -// matrix. Does not destructively change Geoms; -// instead, a copy will be made of each Geom to be -// changed, in case multiple GeomNodes reference the -// same Geom. Returns true if the GeomNode was changed, -// false otherwise. -//////////////////////////////////////////////////////////////////// -bool GeomTransformer:: -transform_vertices(GeomNode *node, const LMatrix4f &mat) { - bool any_changed = false; - - GeomNode::Geoms new_geoms; - - GeomNode::Geoms::const_iterator gi; - for (gi = node->_geoms.begin(); gi != node->_geoms.end(); ++gi) { - dDrawable *drawable = (*gi); - if (drawable->is_of_type(Geom::get_class_type())) { - Geom *geom = DCAST(Geom, drawable); - PT(Geom) new_geom = geom->make_copy(); - if (transform_vertices(new_geom, mat)) { - new_geoms.push_back(new_geom.p()); - any_changed = true; - } else { - new_geoms.push_back(geom); - } - } else { - new_geoms.push_back(drawable); - } - } - - if (any_changed) { - node->_geoms = new_geoms; - node->unprepare(); - node->mark_bound_stale(); - return true; - } - - return false; -} - - -//////////////////////////////////////////////////////////////////// -// Function: GeomTransformer::transform_texcoords -// Access: Public -// Description: Transforms the texture coordinates in the indicated -// Geom by the indicated matrix. Returns true if the -// Geom was changed, false otherwise. -//////////////////////////////////////////////////////////////////// -bool GeomTransformer:: -transform_texcoords(Geom *geom, const LMatrix4f &mat) { - bool transformed = false; - - nassertr(geom != (Geom *)NULL, false); - - PTA_TexCoordf texcoords; - GeomBindType bind; - PTA_ushort index; - - geom->get_texcoords(texcoords, bind, index); - - if (bind != G_OFF) { - // Look up the Geom's texcoords in our table--have we already - // transformed this array? - SourceTexCoords stc; - stc._mat = mat; - stc._texcoords = texcoords; - - PTA_TexCoordf &new_texcoords = _texcoords[stc]; - - if (new_texcoords.is_null()) { - // We have not transformed the array yet. Do so now. - new_texcoords.reserve(texcoords.size()); - PTA_TexCoordf::const_iterator tci; - for (tci = texcoords.begin(); tci != texcoords.end(); ++tci) { - const TexCoordf &tc = (*tci); - LVecBase4f v4(tc[0], tc[1], 0.0f, 1.0f); - v4 = v4 * mat; - new_texcoords.push_back(TexCoordf(v4[0] / v4[3], v4[1] / v4[3])); - } - nassertr(new_texcoords.size() == texcoords.size(), false); - } - - geom->set_texcoords(new_texcoords, bind, index); - transformed = true; - } - - return transformed; -} - - -//////////////////////////////////////////////////////////////////// -// Function: GeomTransformer::transform_texcoords -// Access: Public -// Description: Transforms the texcoords and the normals in all of the -// Geoms within the indicated GeomNode by the indicated -// matrix. Does not destructively change Geoms; -// instead, a copy will be made of each Geom to be -// changed, in case multiple GeomNodes reference the -// same Geom. Returns true if the GeomNode was changed, -// false otherwise. -//////////////////////////////////////////////////////////////////// -bool GeomTransformer:: -transform_texcoords(GeomNode *node, const LMatrix4f &mat) { - bool any_changed = false; - - GeomNode::Geoms new_geoms; - - GeomNode::Geoms::const_iterator gi; - for (gi = node->_geoms.begin(); gi != node->_geoms.end(); ++gi) { - dDrawable *drawable = (*gi); - if (drawable->is_of_type(Geom::get_class_type())) { - Geom *geom = DCAST(Geom, drawable); - PT(Geom) new_geom = geom->make_copy(); - if (transform_texcoords(new_geom, mat)) { - new_geoms.push_back(new_geom.p()); - any_changed = true; - } else { - new_geoms.push_back(geom); - } - } else { - new_geoms.push_back(drawable); - } - } - - if (any_changed) { - node->_geoms = new_geoms; - return true; - } - - return false; -} - - -//////////////////////////////////////////////////////////////////// -// Function: GeomTransformer::set_color -// Access: Public -// Description: Overrides the color indicated within the Geom with -// the given replacement color. Returns true if the -// Geom was changed, false otherwise. -//////////////////////////////////////////////////////////////////// -bool GeomTransformer:: -set_color(Geom *geom, const Colorf &color) { - // In this case, we always replace whatever color array was there - // with a new color array containing just this color. - - // We do want to share this one-element array between Geoms, though. - PTA_Colorf &new_colors = _fcolors[color]; - - if (new_colors.is_null()) { - // We haven't seen this color before; define a new color array. - new_colors.push_back(color); - } - - geom->set_colors(new_colors, G_OVERALL); - return true; -} - - -//////////////////////////////////////////////////////////////////// -// Function: GeomTransformer::transform_texcoords -// Access: Public -// Description: Overrides the color indicated within the GeomNode -// with the given replacement color. Returns true if -// any Geom in the GeomNode was changed, false -// otherwise. -//////////////////////////////////////////////////////////////////// -bool GeomTransformer:: -set_color(GeomNode *node, const Colorf &color) { - bool any_changed = false; - - GeomNode::Geoms new_geoms; - - GeomNode::Geoms::const_iterator gi; - for (gi = node->_geoms.begin(); gi != node->_geoms.end(); ++gi) { - dDrawable *drawable = (*gi); - if (drawable->is_of_type(Geom::get_class_type())) { - Geom *geom = DCAST(Geom, drawable); - PT(Geom) new_geom = geom->make_copy(); - if (set_color(new_geom, color)) { - new_geoms.push_back(new_geom.p()); - any_changed = true; - } else { - new_geoms.push_back(geom); - } - } else { - new_geoms.push_back(drawable); - } - } - - if (any_changed) { - node->_geoms = new_geoms; - return true; - } - - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: GeomTransformer::transform_colors -// Access: Public -// Description: Transforms the colors in the indicated -// Geom by the indicated matrix. Returns true if the -// Geom was changed, false otherwise. -//////////////////////////////////////////////////////////////////// -bool GeomTransformer:: -transform_colors(Geom *geom, const LMatrix4f &mat, - float alpha_scale, float alpha_offset) { - bool transformed = false; - - nassertr(geom != (Geom *)NULL, false); - - PTA_Colorf colors; - GeomBindType bind; - PTA_ushort index; - - geom->get_colors(colors, bind, index); - - if (bind != G_OFF) { - // Look up the Geom's colors in our table--have we already - // transformed this array? - SourceColors sc; - sc._mat = mat; - sc._alpha_scale = alpha_scale; - sc._alpha_offset = alpha_offset; - sc._colors = colors; - - PTA_Colorf &new_colors = _tcolors[sc]; - - if (new_colors.is_null()) { - // We have not transformed the array yet. Do so now. - new_colors.reserve(colors.size()); - PTA_Colorf::const_iterator ci; - for (ci = colors.begin(); ci != colors.end(); ++ci) { - const Colorf &c = (*ci); - - LPoint3f temp(c[0], c[1], c[2]); - temp = temp * mat; - float alpha = (c[3] * alpha_scale) + alpha_offset; - - Colorf transformed(temp[0], temp[1], temp[2], alpha); - new_colors.push_back(transformed); - } - nassertr(new_colors.size() == colors.size(), false); - } - - geom->set_colors(new_colors, bind, index); - transformed = true; - } - - return transformed; -} - - -//////////////////////////////////////////////////////////////////// -// Function: GeomTransformer::transform_colors -// Access: Public -// Description: Transforms the colors and the normals in all of the -// Geoms within the indicated GeomNode by the indicated -// matrix. Does not destructively change Geoms; -// instead, a copy will be made of each Geom to be -// changed, in case multiple GeomNodes reference the -// same Geom. Returns true if the GeomNode was changed, -// false otherwise. -//////////////////////////////////////////////////////////////////// -bool GeomTransformer:: -transform_colors(GeomNode *node, const LMatrix4f &mat, - float alpha_scale, float alpha_offset) { - bool any_changed = false; - - GeomNode::Geoms new_geoms; - - GeomNode::Geoms::const_iterator gi; - for (gi = node->_geoms.begin(); gi != node->_geoms.end(); ++gi) { - dDrawable *drawable = (*gi); - if (drawable->is_of_type(Geom::get_class_type())) { - Geom *geom = DCAST(Geom, drawable); - PT(Geom) new_geom = geom->make_copy(); - if (transform_colors(new_geom, mat, alpha_scale, alpha_offset)) { - new_geoms.push_back(new_geom.p()); - any_changed = true; - } else { - new_geoms.push_back(geom); - } - } else { - new_geoms.push_back(drawable); - } - } - - if (any_changed) { - node->_geoms = new_geoms; - return true; - } - - return false; -} diff --git a/panda/src/sgraph/geomTransformer.h b/panda/src/sgraph/geomTransformer.h deleted file mode 100644 index afbc7d3680..0000000000 --- a/panda/src/sgraph/geomTransformer.h +++ /dev/null @@ -1,119 +0,0 @@ -// Filename: geomTransformer.h -// Created by: drose (23May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef GEOMTRANSFORMER_H -#define GEOMTRANSFORMER_H - -#include - -#include -#include - -class GeomNode; - -/////////////////////////////////////////////////////////////////// -// Class : GeomTransformer -// Description : An object specifically designed to transform the -// vertices of a Geom without disturbing indexing or -// affecting any other Geoms that may share the same -// vertex arrays, and without needlessly wasting memory -// when different Geoms sharing the same vertex arrays -// are transformed by the same amount. -// -// If you create a single GeomTransformer and use it to -// transform a number of different Geoms by various -// transformations, then those Geoms which happen to -// share the same arrays and are transformed by the same -// amounts will still share the same arrays as each -// other (but different from the original arrays). -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA GeomTransformer { -public: - GeomTransformer(); - ~GeomTransformer(); - - bool transform_vertices(Geom *geom, const LMatrix4f &mat); - bool transform_vertices(GeomNode *node, const LMatrix4f &mat); - - bool transform_texcoords(Geom *geom, const LMatrix4f &mat); - bool transform_texcoords(GeomNode *node, const LMatrix4f &mat); - - bool set_color(Geom *geom, const Colorf &color); - bool set_color(GeomNode *node, const Colorf &color); - - bool transform_colors(Geom *geom, const LMatrix4f &mat, - float alpha_scale, float alpha_offset); - bool transform_colors(GeomNode *node, const LMatrix4f &mat, - float alpha_scale, float alpha_offset); - -private: - class SourceVertices { - public: - INLINE bool operator < (const SourceVertices &other) const; - - LMatrix4f _mat; - PTA_Vertexf _coords; - }; - typedef pmap Vertices; - Vertices _vertices; - - class SourceNormals { - public: - INLINE bool operator < (const SourceNormals &other) const; - - LMatrix4f _mat; - PTA_Normalf _norms; - }; - typedef pmap Normals; - Normals _normals; - - class SourceTexCoords { - public: - INLINE bool operator < (const SourceTexCoords &other) const; - - LMatrix4f _mat; - PTA_TexCoordf _texcoords; - }; - typedef pmap TexCoords; - TexCoords _texcoords; - - // We have two concepts of colors: the "fixed" colors, which are - // slapped in complete replacement of the original colors (e.g. via - // a ColorTransition), and the "transformed" colors, which are - // modified from the original colors (e.g. via a - // ColorMatrixTransition). - typedef pmap FColors; - FColors _fcolors; - - class SourceColors { - public: - INLINE bool operator < (const SourceColors &other) const; - - LMatrix4f _mat; - float _alpha_scale; - float _alpha_offset; - PTA_Colorf _colors; - }; - typedef pmap TColors; - TColors _tcolors; -}; - -#include "geomTransformer.I" - -#endif - diff --git a/panda/src/sgraph/lensNode.I b/panda/src/sgraph/lensNode.I deleted file mode 100644 index a59ff410c0..0000000000 --- a/panda/src/sgraph/lensNode.I +++ /dev/null @@ -1,88 +0,0 @@ -// Filename: lensNode.I -// Created by: drose (23May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: LensNode::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE LensNode:: -LensNode(const string &name) : - NamedNode(name) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: LensNode::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE LensNode:: -LensNode(const LensNode ©) : - NamedNode(copy), - _lens(copy._lens) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: LensNode::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void LensNode:: -operator = (const LensNode ©) { - NamedNode::operator = (copy); - _lens = copy._lens; -} - -//////////////////////////////////////////////////////////////////// -// Function: copy_lens -// Access: Public -// Description: Sets up the LensNode using a copy of the -// indicated Lens. If the original Lens is -// changed or destroyed, this LensNode is not -// affected. -//////////////////////////////////////////////////////////////////// -INLINE void LensNode:: -copy_lens(const Lens &lens) { - _lens = lens.make_copy(); -} - -//////////////////////////////////////////////////////////////////// -// Function: set_lens -// Access: Public -// Description: Sets up the LensNode using this particular Lens -// pointer. If the lens is subsequently modified, the -// LensNode properties immediately reflect the change. -//////////////////////////////////////////////////////////////////// -INLINE void LensNode:: -set_lens(Lens *lens) { - _lens = lens; -} - -//////////////////////////////////////////////////////////////////// -// Function: get_lens -// Access: Public -// Description: Returns a pointer to the particular Lens -// associated with this LensNode, or NULL if there is -// not yet a Lens associated. -//////////////////////////////////////////////////////////////////// -INLINE Lens *LensNode:: -get_lens() { - return _lens; -} diff --git a/panda/src/sgraph/lensNode.cxx b/panda/src/sgraph/lensNode.cxx deleted file mode 100644 index 03f1dab5cc..0000000000 --- a/panda/src/sgraph/lensNode.cxx +++ /dev/null @@ -1,85 +0,0 @@ -// Filename: lensNode.cxx -// Created by: mike (09Jan97) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// -#include "lensNode.h" -#include "geometricBoundingVolume.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Static variables -//////////////////////////////////////////////////////////////////// -TypeHandle LensNode::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: LensNode::make_copy -// Access: Public, Virtual -// Description: Returns a newly-allocated Node that is a shallow copy -// of this one. It will be a different Node pointer, -// but its internal data may or may not be shared with -// that of the original Node. -//////////////////////////////////////////////////////////////////// -Node *LensNode:: -make_copy() const { - return new LensNode(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: LensNode::is_in_view -// Access: Public -// Description: Returns true if the given point is within the bounds -// of the lens of the LensNode (i.e. if the camera can -// see the point). -//////////////////////////////////////////////////////////////////// -bool LensNode:: -is_in_view(const LPoint3f &pos) { - PT(BoundingVolume) bv = _lens->make_bounds(); - if (bv == NULL) - return false; - GeometricBoundingVolume *gbv = DCAST(GeometricBoundingVolume, bv); - int ret = gbv->contains(pos); - return (ret != 0); -} - -//////////////////////////////////////////////////////////////////// -// Function: LensNode::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void LensNode:: -output(ostream &out) const { - NamedNode::output(out); - if (_lens != (Lens *)NULL) { - out << " ("; - _lens->output(out); - out << ")"; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: LensNode::write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void LensNode:: -write(ostream &out, int indent_level) const { - NamedNode::write(out, indent_level); - if (_lens != (Lens *)NULL) { - _lens->write(out, indent_level + 2); - } -} - diff --git a/panda/src/sgraph/lensNode.h b/panda/src/sgraph/lensNode.h deleted file mode 100644 index 37f442d255..0000000000 --- a/panda/src/sgraph/lensNode.h +++ /dev/null @@ -1,80 +0,0 @@ -// Filename: lensNode.h -// Created by: mike (09Jan97) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// -#ifndef LENSNODE_H -#define LENSNODE_H -// -//////////////////////////////////////////////////////////////////// -// Includes -//////////////////////////////////////////////////////////////////// -#include "pandabase.h" - -#include "namedNode.h" -#include "lens.h" - -//////////////////////////////////////////////////////////////////// -// Class : LensNode -// Description : A node that contains a Lens. The most important -// example of this kind of node is a Camera, but other -// kinds of nodes also contain a lens (for instance, a -// Spotlight). -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA LensNode : public NamedNode { -PUBLISHED: - INLINE LensNode(const string &name = ""); - -public: - INLINE LensNode(const LensNode ©); - INLINE void operator = (const LensNode ©); - - virtual void output(ostream &out) const; - virtual void write(ostream &out, int indent_level = 0) const; - - virtual Node *make_copy() const; - -PUBLISHED: - INLINE void copy_lens(const Lens &lens); - INLINE void set_lens(Lens *lens); - INLINE Lens *get_lens(); - - bool is_in_view(const LPoint3f &pos); - -protected: - PT(Lens) _lens; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - NamedNode::init_type(); - register_type( _type_handle, "LensNode", - NamedNode::get_class_type() ); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - - static TypeHandle _type_handle; -}; - -#include "lensNode.I" - -#endif diff --git a/panda/src/sgraph/modelNode.I b/panda/src/sgraph/modelNode.I deleted file mode 100644 index 82ac8a6efd..0000000000 --- a/panda/src/sgraph/modelNode.I +++ /dev/null @@ -1,78 +0,0 @@ -// Filename: modelNode.I -// Created by: drose (09Nov00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: ModelNode::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ModelNode:: -ModelNode(const string &name) : - NamedNode(name) -{ - _preserve_transform = false; -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelNode::set_preserve_transform -// Access: Public -// Description: Sets the preserve_transform flag. When this flag is -// true, flattening the scene graph will not flatten out -// any transformation assigned above this node; -// otherwise, any transforms applying to this node may -// or may not be flattened. -//////////////////////////////////////////////////////////////////// -INLINE void ModelNode:: -set_preserve_transform(bool preserve_transform) { - _preserve_transform = preserve_transform; -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelNode::get_preserve_transform -// Access: Public -// Description: Returns the current setting of the preserve_transform -// flag. See set_preserve_transform(). -//////////////////////////////////////////////////////////////////// -INLINE bool ModelNode:: -get_preserve_transform() const { - return _preserve_transform; -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelNode::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ModelNode:: -ModelNode(const ModelNode ©) : - NamedNode(copy), - _preserve_transform(copy._preserve_transform) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelNode::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void ModelNode:: -operator = (const ModelNode ©) { - NamedNode::operator = (copy); - _preserve_transform = copy._preserve_transform; -} diff --git a/panda/src/sgraph/modelNode.cxx b/panda/src/sgraph/modelNode.cxx deleted file mode 100644 index 15a40407cf..0000000000 --- a/panda/src/sgraph/modelNode.cxx +++ /dev/null @@ -1,138 +0,0 @@ -// Filename: modelNode.cxx -// Created by: drose (09Nov00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "modelNode.h" - -#include -#include -#include - -TypeHandle ModelNode::_type_handle; - - -//////////////////////////////////////////////////////////////////// -// Function: ModelNode::make_copy -// Access: Public, Virtual -// Description: Returns a newly-allocated Node that is a shallow copy -// of this one. It will be a different Node pointer, -// but its internal data may or may not be shared with -// that of the original Node. -//////////////////////////////////////////////////////////////////// -Node *ModelNode:: -make_copy() const { - return new ModelNode(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelNode::safe_to_flatten -// Access: Public, Virtual -// Description: Returns true if it is generally safe to flatten out -// this particular kind of Node by duplicating -// instances, false otherwise (for instance, a Camera -// cannot be safely flattened, because the Camera -// pointer itself is meaningful). -//////////////////////////////////////////////////////////////////// -bool ModelNode:: -safe_to_flatten() const { - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelNode::safe_to_transform -// Access: Public, Virtual -// Description: Returns true if it is generally safe to transform -// this particular kind of Node by calling the xform() -// method, false otherwise. For instance, it's usually -// a bad idea to attempt to xform a Character. -//////////////////////////////////////////////////////////////////// -bool ModelNode:: -safe_to_transform() const { - return !_preserve_transform; -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelNode::preserve_name -// Access: Public, Virtual -// Description: Returns true if the node's name has extrinsic meaning -// and must be preserved across a flatten operation, -// false otherwise. -//////////////////////////////////////////////////////////////////// -bool ModelNode:: -preserve_name() const { - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelNode::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a node object -//////////////////////////////////////////////////////////////////// -void ModelNode:: -register_with_read_factory() { - BamReader::get_factory()->register_factory(get_class_type(), make_ModelNode); -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelNode::make_ModelNode -// Access: Protected, Static -// Description: Factory method to generate a node object -//////////////////////////////////////////////////////////////////// -TypedWritable* ModelNode:: -make_ModelNode(const FactoryParams ¶ms) { - ModelNode *me = new ModelNode; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelNode::write_datagram -// Access: Public, Virtual -// Description: Function to write the important information in -// the particular object to a Datagram -//////////////////////////////////////////////////////////////////// -void ModelNode:: -write_datagram(BamWriter *manager, Datagram &me) { - NamedNode::write_datagram(manager, me); - - me.add_bool(_preserve_transform); -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelNode::fillin -// Access: Protected -// Description: Function that reads out of the datagram (or asks -// manager to read) all of the data that is needed to -// re-create this object and stores it in the appropiate -// place -//////////////////////////////////////////////////////////////////// -void ModelNode:: -fillin(DatagramIterator &scan, BamReader *manager) { - NamedNode::fillin(scan, manager); - - if (manager->get_file_minor_ver() < 2) { - // No _preserve_transform before bams 3.2. - _preserve_transform = false; - } else { - _preserve_transform = scan.get_bool(); - } - -} diff --git a/panda/src/sgraph/modelNode.h b/panda/src/sgraph/modelNode.h deleted file mode 100644 index a386975c6d..0000000000 --- a/panda/src/sgraph/modelNode.h +++ /dev/null @@ -1,88 +0,0 @@ -// Filename: modelNode.h -// Created by: drose (09Nov00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef MODELNODE_H -#define MODELNODE_H - -#include - -#include - -//////////////////////////////////////////////////////////////////// -// Class : ModelNode -// Description : This node is placed at key points within the scene -// graph to indicate the roots of "models": subtrees -// that are conceptually to be treated as a single unit, -// like a car or a room, for instance. It doesn't -// affect rendering or any other operations; it's -// primarily useful as a high-level model indication. -// -// ModelNodes are created in response to a { 1 } -// flag within an egg file. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ModelNode : public NamedNode { -PUBLISHED: - INLINE ModelNode(const string &name = ""); - - INLINE void set_preserve_transform(bool preserve_transform); - INLINE bool get_preserve_transform() const; - -public: - INLINE ModelNode(const ModelNode ©); - INLINE void operator = (const ModelNode ©); - - virtual Node *make_copy() const; - - virtual bool safe_to_flatten() const; - virtual bool safe_to_transform() const; - virtual bool preserve_name() const; - -public: - static void register_with_read_factory(void); - -protected: - virtual void write_datagram(BamWriter *manager, Datagram &me); - void fillin(DatagramIterator &scan, BamReader *manager); - static TypedWritable *make_ModelNode(const FactoryParams ¶ms); - -private: - bool _preserve_transform; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - NamedNode::init_type(); - register_type(_type_handle, "ModelNode", - NamedNode::get_class_type()); - } - virtual TypeHandle get_type(void) const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "modelNode.I" - -#endif - - diff --git a/panda/src/sgraph/modelRoot.I b/panda/src/sgraph/modelRoot.I deleted file mode 100644 index b24e87b568..0000000000 --- a/panda/src/sgraph/modelRoot.I +++ /dev/null @@ -1,49 +0,0 @@ -// Filename: modelRoot.I -// Created by: drose (09Nov00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: ModelRoot::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ModelRoot:: -ModelRoot(const string &name) : - ModelNode(name) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelRoot::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE ModelRoot:: -ModelRoot(const ModelRoot ©) : - ModelNode(copy) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelRoot::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void ModelRoot:: -operator = (const ModelRoot ©) { - ModelNode::operator = (copy); -} diff --git a/panda/src/sgraph/modelRoot.cxx b/panda/src/sgraph/modelRoot.cxx deleted file mode 100644 index 137fa413c1..0000000000 --- a/panda/src/sgraph/modelRoot.cxx +++ /dev/null @@ -1,61 +0,0 @@ -// Filename: modelRoot.cxx -// Created by: drose (09Nov00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "modelRoot.h" - -TypeHandle ModelRoot::_type_handle; - - -//////////////////////////////////////////////////////////////////// -// Function: ModelRoot::make_copy -// Access: Public, Virtual -// Description: Returns a newly-allocated Node that is a shallow copy -// of this one. It will be a different Node pointer, -// but its internal data may or may not be shared with -// that of the original Node. -//////////////////////////////////////////////////////////////////// -Node *ModelRoot:: -make_copy() const { - return new ModelRoot(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelRoot::register_with_factory -// Access: Public, Static -// Description: Factory method to generate a node object -//////////////////////////////////////////////////////////////////// -void ModelRoot:: -register_with_read_factory() { - BamReader::get_factory()->register_factory(get_class_type(), make_ModelRoot); -} - -//////////////////////////////////////////////////////////////////// -// Function: ModelRoot::make_ModelRoot -// Access: Protected, Static -// Description: Factory method to generate a node object -//////////////////////////////////////////////////////////////////// -TypedWritable* ModelRoot:: -make_ModelRoot(const FactoryParams ¶ms) { - ModelRoot *me = new ModelRoot; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} diff --git a/panda/src/sgraph/modelRoot.h b/panda/src/sgraph/modelRoot.h deleted file mode 100644 index ca5e0df924..0000000000 --- a/panda/src/sgraph/modelRoot.h +++ /dev/null @@ -1,73 +0,0 @@ -// Filename: modelRoot.h -// Created by: drose (09Nov00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef MODELROOT_H -#define MODELROOT_H - -#include - -#include "modelNode.h" - -//////////////////////////////////////////////////////////////////// -// Class : ModelRoot -// Description : A node of this type is created automatically at the -// root of each model file that is loaded. It may -// eventually contain some information about the -// contents of the model; at the moment, it contains no -// special information, but can be used as a flag to -// indicate the presence of a loaded model file. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ModelRoot : public ModelNode { -PUBLISHED: - INLINE ModelRoot(const string &name = ""); - -public: - INLINE ModelRoot(const ModelRoot ©); - INLINE void operator = (const ModelRoot ©); - - virtual Node *make_copy() const; - -public: - static void register_with_read_factory(void); - -protected: - static TypedWritable *make_ModelRoot(const FactoryParams ¶ms); - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - ModelNode::init_type(); - register_type(_type_handle, "ModelRoot", - ModelNode::get_class_type()); - } - virtual TypeHandle get_type(void) const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "modelRoot.I" - -#endif - - diff --git a/panda/src/sgraph/planeNode.I b/panda/src/sgraph/planeNode.I deleted file mode 100644 index 5edbb37243..0000000000 --- a/panda/src/sgraph/planeNode.I +++ /dev/null @@ -1,51 +0,0 @@ -// Filename: planeNode.I -// Created by: drose (23May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: PlaneNode::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE PlaneNode:: -PlaneNode(const string &name) : - NamedNode(name) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: PlaneNode::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE PlaneNode:: -PlaneNode(const PlaneNode ©) : - NamedNode(copy), - _plane(copy._plane) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: PlaneNode::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void PlaneNode:: -operator = (const PlaneNode ©) { - NamedNode::operator = (copy); - _plane = copy._plane; -} diff --git a/panda/src/sgraph/planeNode.cxx b/panda/src/sgraph/planeNode.cxx deleted file mode 100644 index 4d7ba5ee80..0000000000 --- a/panda/src/sgraph/planeNode.cxx +++ /dev/null @@ -1,57 +0,0 @@ -// Filename: planeNode.cxx -// Created by: mike (09Jan97) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// -#include "planeNode.h" - -//////////////////////////////////////////////////////////////////// -// Static variables -//////////////////////////////////////////////////////////////////// -TypeHandle PlaneNode::_type_handle; - - -//////////////////////////////////////////////////////////////////// -// Function: PlaneNode::make_copy -// Access: Public, Virtual -// Description: Returns a newly-allocated Node that is a shallow copy -// of this one. It will be a different Node pointer, -// but its internal data may or may not be shared with -// that of the original Node. -//////////////////////////////////////////////////////////////////// -Node *PlaneNode:: -make_copy() const { - return new PlaneNode(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: set_plane -// Access: -// Description: -//////////////////////////////////////////////////////////////////// -void PlaneNode::set_plane(const Planef& plane) -{ - _plane = plane; -} - -//////////////////////////////////////////////////////////////////// -// Function: get_plane -// Access: -// Description: -//////////////////////////////////////////////////////////////////// -const Planef& PlaneNode::get_plane(void) const -{ - return _plane; -} diff --git a/panda/src/sgraph/planeNode.h b/panda/src/sgraph/planeNode.h deleted file mode 100644 index 6d85f08912..0000000000 --- a/panda/src/sgraph/planeNode.h +++ /dev/null @@ -1,78 +0,0 @@ -// Filename: planeNode.h -// Created by: mike (09Jan97) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// -#ifndef PLANENODE_H -#define PLANENODE_H -// -//////////////////////////////////////////////////////////////////// -// Includes -//////////////////////////////////////////////////////////////////// -#include - -#include -#include - -//////////////////////////////////////////////////////////////////// -// Defines -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Class : PlaneNode -// Description : A node that has a plane -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA PlaneNode : public NamedNode -{ -PUBLISHED: - INLINE PlaneNode(const string& name = ""); - -public: - INLINE PlaneNode(const PlaneNode ©); - INLINE void operator = (const PlaneNode ©); - - virtual Node *make_copy() const; - -PUBLISHED: - void set_plane(const Planef& plane); - const Planef& get_plane(void) const; - -protected: - - Planef _plane; - -public: - - static TypeHandle get_class_type( void ) { - return _type_handle; - } - static void init_type(void) { - NamedNode::init_type(); - register_type(_type_handle, "PlaneNode", - NamedNode::get_class_type()); - } - virtual TypeHandle get_type(void) const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - - static TypeHandle _type_handle; -}; - -#include "planeNode.I" - -#endif diff --git a/panda/src/sgraph/renderTraverser.I b/panda/src/sgraph/renderTraverser.I deleted file mode 100644 index 5b7fba0bf5..0000000000 --- a/panda/src/sgraph/renderTraverser.I +++ /dev/null @@ -1,137 +0,0 @@ -// Filename: renderTraverser.I -// Created by: drose (12Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: RenderTraverser::Constructor -// Access: Public -// Description: Creates a new RenderTraverser ready to traverse a -// scene graph beginning at the end of the arc chain -// indicated in arc_chain (either an empty ArcChain, or -// the result of get_arc_chain() from some other -// traverser), with the indicated graph_type (usually -// RenderRelation) and for the indicated gsg. -//////////////////////////////////////////////////////////////////// -INLINE RenderTraverser:: -RenderTraverser(GraphicsStateGuardian *gsg, TypeHandle graph_type, - const ArcChain &arc_chain) : - _gsg(gsg), - _graph_type(graph_type), - _arc_chain(arc_chain) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderTraverser::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE RenderTraverser:: -~RenderTraverser() { -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderTraverser::get_arc_chain -// Access: Public -// Description: Returns the complete chain of arcs from the root to -// the current node in the traversal. -//////////////////////////////////////////////////////////////////// -INLINE const ArcChain &RenderTraverser:: -get_arc_chain() const { - return _arc_chain; -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderTraverser::begin -// Access: Public -// Description: Returns an iterator that can be used to traverse the -// list of arcs from the root to the current node in the -// traversal. -//////////////////////////////////////////////////////////////////// -INLINE RenderTraverser::const_iterator RenderTraverser:: -begin() const { - return _arc_chain.begin(); -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderTraverser::end -// Access: Public -// Description: Returns an iterator that can be used to traverse the -// list of arcs from the root to the current node in the -// traversal. -//////////////////////////////////////////////////////////////////// -INLINE RenderTraverser::const_iterator RenderTraverser:: -end() const { - return _arc_chain.end(); -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderTraverser::empty -// Access: Public -// Description: Returns true if the list of arcs returned by begin() -// .. end() is empty (i.e. begin() == end()), false -// otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool RenderTraverser:: -empty() const { - return _arc_chain.empty(); -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderTraverser::get_gsg -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE GraphicsStateGuardian *RenderTraverser:: -get_gsg() const { - return _gsg; -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderTraverser::get_graph_type -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TypeHandle RenderTraverser:: -get_graph_type() const { - return _graph_type; -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderTraverser::mark_forward_arc -// Access: Public -// Description: To be called by the derived class's forward_arc() -// method, this updates the list of arcs traversed to -// include the current arc. -//////////////////////////////////////////////////////////////////// -INLINE void RenderTraverser:: -mark_forward_arc(NodeRelation *arc) { - // This is now done by the FrustumCullTraverser. -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderTraverser::mark_backward_arc -// Access: Public -// Description: To be called by the derived class's forward_arc() -// method, this updates the list of arcs traversed to -// remove the current arc. -//////////////////////////////////////////////////////////////////// -INLINE void RenderTraverser:: -mark_backward_arc(NodeRelation *arc) { - // This is now done by the FrustumCullTraverser. -} diff --git a/panda/src/sgraph/renderTraverser.cxx b/panda/src/sgraph/renderTraverser.cxx deleted file mode 100644 index 4988d9a766..0000000000 --- a/panda/src/sgraph/renderTraverser.cxx +++ /dev/null @@ -1,44 +0,0 @@ -// Filename: renderTraverser.cxx -// Created by: drose (12Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "renderTraverser.h" - -#include - -TypeHandle RenderTraverser::_type_handle; - - -//////////////////////////////////////////////////////////////////// -// Function: RenderTraverser::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void RenderTraverser:: -output(ostream &out) const { - out << get_type(); -} - -//////////////////////////////////////////////////////////////////// -// Function: RenderTraverser::write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void RenderTraverser:: -write(ostream &out, int indent_level) const { - indent(out, indent_level) << *this << "\n"; -} diff --git a/panda/src/sgraph/renderTraverser.h b/panda/src/sgraph/renderTraverser.h deleted file mode 100644 index aa2bd3d215..0000000000 --- a/panda/src/sgraph/renderTraverser.h +++ /dev/null @@ -1,105 +0,0 @@ -// Filename: renderTraverser.h -// Created by: drose (12Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef RENDERTRAVERSER_H -#define RENDERTRAVERSER_H - -#include - -#include -#include -#include -#include - -class GraphicsStateGuardian; -class Node; -class NodeRelation; -class AllTransitionsWrapper; - -//////////////////////////////////////////////////////////////////// -// Class : RenderTraverser -// Description : This is the abstract base class that defines the -// interface for any number of different kinds of -// specialized traversers that walk over the scene graph -// and render it with a given GraphicsStateGuardian, -// such as DirectRenderTraverser and CullTraverser. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA RenderTraverser : public TypedReferenceCount { -public: - INLINE RenderTraverser(GraphicsStateGuardian *gsg, - TypeHandle graph_type, - const ArcChain &arc_chain); - INLINE ~RenderTraverser(); - - typedef ArcChain::iterator iterator; - typedef ArcChain::const_iterator const_iterator; - - INLINE const ArcChain &get_arc_chain() const; - INLINE const_iterator begin() const; - INLINE const_iterator end() const; - INLINE bool empty() const; - -PUBLISHED: - INLINE GraphicsStateGuardian *get_gsg() const; - INLINE TypeHandle get_graph_type() const; - -public: - virtual void traverse(Node *root, - const AllTransitionsWrapper &initial_state)=0; - -PUBLISHED: - virtual void output(ostream &out) const; - virtual void write(ostream &out, int indent_level = 0) const; - -protected: - // These methods are to be called by derived classes as we traverse - // each arc. They update the arc list returned by begin()/end(). - INLINE void mark_forward_arc(NodeRelation *arc); - INLINE void mark_backward_arc(NodeRelation *arc); - -protected: - GraphicsStateGuardian *_gsg; - TypeHandle _graph_type; - ArcChain _arc_chain; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - TypedReferenceCount::init_type(); - register_type(_type_handle, "RenderTraverser", - TypedReferenceCount::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -INLINE ostream &operator << (ostream &out, const RenderTraverser &rt) { - rt.output(out); - return out; -} - -#include "renderTraverser.I" - -#endif diff --git a/panda/src/sgraph/sgraph_composite1.cxx b/panda/src/sgraph/sgraph_composite1.cxx deleted file mode 100644 index 81a44d63de..0000000000 --- a/panda/src/sgraph/sgraph_composite1.cxx +++ /dev/null @@ -1,8 +0,0 @@ - -#include "geomNode.cxx" -#include "geomTransformer.cxx" -#include "modelNode.cxx" -#include "modelRoot.cxx" -#include "planeNode.cxx" - - diff --git a/panda/src/sgraph/sgraph_composite2.cxx b/panda/src/sgraph/sgraph_composite2.cxx deleted file mode 100644 index 039e7730fc..0000000000 --- a/panda/src/sgraph/sgraph_composite2.cxx +++ /dev/null @@ -1,7 +0,0 @@ - -#include "config_sgraph.cxx" -#include "camera.cxx" -#include "lensNode.cxx" -#include "renderTraverser.cxx" -#include "switchNode.cxx" - diff --git a/panda/src/sgraph/switchNode.I b/panda/src/sgraph/switchNode.I deleted file mode 100644 index 03f32ba85d..0000000000 --- a/panda/src/sgraph/switchNode.I +++ /dev/null @@ -1,50 +0,0 @@ -// Filename: switchNode.I -// Created by: drose (15May01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: SwitchNode::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE SwitchNode:: -SwitchNode(const string &name) : - NamedNode(name) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: SwitchNode::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE SwitchNode:: -SwitchNode(const SwitchNode ©) : - NamedNode(copy) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: SwitchNode::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void SwitchNode:: -operator = (const SwitchNode ©) { - NamedNode::operator = (copy); -} diff --git a/panda/src/sgraph/switchNode.cxx b/panda/src/sgraph/switchNode.cxx deleted file mode 100644 index e25232c0e2..0000000000 --- a/panda/src/sgraph/switchNode.cxx +++ /dev/null @@ -1,36 +0,0 @@ -// Filename: switchNode.cxx -// Created by: drose (15May01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "switchNode.h" - -TypeHandle SwitchNode::_type_handle; - - -//////////////////////////////////////////////////////////////////// -// Function: SwitchNode::safe_to_combine -// Access: Public, Virtual -// Description: Returns true if it is generally safe to combine -// this particular kind of Node with other kinds of -// Nodes, adding children or whatever. For instance, an -// LODNode should not be combined with any other node, -// because its set of children is meaningful. -//////////////////////////////////////////////////////////////////// -bool SwitchNode:: -safe_to_combine() const { - return false; -} diff --git a/panda/src/sgraph/switchNode.h b/panda/src/sgraph/switchNode.h deleted file mode 100644 index b276842105..0000000000 --- a/panda/src/sgraph/switchNode.h +++ /dev/null @@ -1,72 +0,0 @@ -// Filename: switchNode.h -// Created by: drose (15May01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef SWITCHNODE_H -#define SWITCHNODE_H - -#include - -#include - -class RenderTraverser; - -//////////////////////////////////////////////////////////////////// -// Class : SwitchNode -// Description : A base class for nodes that may choose to render only -// some subset of their children, based on some internal -// criteria. -// -// This is an abstract base class, and is only -// interface; it is defined in this directory so that -// FrustumCullTraverser can access it. All of the -// implementations of this class are defined in the -// switchnode directory. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA SwitchNode : public NamedNode { -PUBLISHED: - INLINE SwitchNode(const string &name = ""); - INLINE SwitchNode(const SwitchNode ©); - INLINE void operator = (const SwitchNode ©); - -public: - virtual bool safe_to_combine() const; - virtual void compute_switch(RenderTraverser *trav)=0; - - virtual bool is_child_visible(TypeHandle type, int index)=0; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - NamedNode::init_type(); - register_type( _type_handle, "SwitchNode", - NamedNode::get_class_type() ); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "switchNode.I" - -#endif diff --git a/panda/src/sgraph/test_sgraph.cxx b/panda/src/sgraph/test_sgraph.cxx deleted file mode 100644 index b2bcdd7adc..0000000000 --- a/panda/src/sgraph/test_sgraph.cxx +++ /dev/null @@ -1,55 +0,0 @@ -// Filename: test_sgraph.cxx -// Created by: mike (02Feb00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "geomNode.h" - -#include "pointerTo.h" -#include "clockObject.h" -#include "notify.h" - -int main() { - nout << "running test_sgraph" << endl; - - ClockObject *c = ClockObject::get_global_clock(); - int i; - int count = 100000; - double start, finish; - PT(Node) node; - - node = new GeomNode("foo"); - start = c->get_real_time(); - for (i = 0; i < count; i++) { - node->is_of_type(GeomNode::get_class_type()); - } - finish = c->get_real_time(); - - cerr << "test 1: " << (finish - start) / (double)count * 1000.0 - << " ms\n"; - - node = new NamedNode("foo"); - start = c->get_real_time(); - for (i = 0; i < count; i++) { - node->is_of_type(GeomNode::get_class_type()); - } - finish = c->get_real_time(); - - cerr << "test 2: " << (finish - start) / (double)count * 1000.0 - << " ms\n"; - - return 0; -} diff --git a/panda/src/sgraphutil/Sources.pp b/panda/src/sgraphutil/Sources.pp deleted file mode 100644 index 954ce9253c..0000000000 --- a/panda/src/sgraphutil/Sources.pp +++ /dev/null @@ -1,40 +0,0 @@ -#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \ - dtoolutil:c dtoolbase:c dtool:m - -#begin lib_target - #define TARGET sgraphutil - #define LOCAL_LIBS \ - pstatclient graph sgraph sgattrib linmath putil gobj mathutil \ - gsgbase display pnmimage - - #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx - - #define SOURCES \ - appTraverser.I appTraverser.h config_sgraphutil.h \ - directRenderTraverser.I directRenderTraverser.h \ - frustumCullTraverser.I frustumCullTraverser.h get_rel_pos.I \ - get_rel_pos.h \ - quickRenderLevelState.h \ - quickRenderTraverser.I quickRenderTraverser.h \ - sceneGraphAnalyzer.h \ - sceneGraphReducer.I sceneGraphReducer.h - - #define INCLUDED_SOURCES \ - appTraverser.cxx config_sgraphutil.cxx directRenderTraverser.cxx \ - frustumCullTraverser.cxx get_rel_pos.cxx \ - quickRenderTraverser.cxx \ - sceneGraphAnalyzer.cxx sceneGraphReducer.cxx - - #define INSTALL_HEADERS \ - appTraverser.I appTraverser.h config_sgraphutil.h \ - directRenderLevelState.h directRenderTraverser.I \ - directRenderTraverser.h frustumCullTraverser.I \ - frustumCullTraverser.h get_rel_pos.I get_rel_pos.h \ - quickRenderLevelState.h \ - quickRenderTraverser.I quickRenderTraverser.h \ - sceneGraphAnalyzer.h sceneGraphReducer.I sceneGraphReducer.h - - #define IGATESCAN all - -#end lib_target - diff --git a/panda/src/sgraphutil/appTraverser.I b/panda/src/sgraphutil/appTraverser.I deleted file mode 100644 index 4be73db6ec..0000000000 --- a/panda/src/sgraphutil/appTraverser.I +++ /dev/null @@ -1,38 +0,0 @@ -// Filename: appTraverser.I -// Created by: drose (25Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: AppTraverser::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE AppTraverser:: -AppTraverser(TypeHandle graph_type) : - _graph_type(graph_type) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: AppTraverser::Destructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE AppTraverser:: -~AppTraverser() { -} diff --git a/panda/src/sgraphutil/appTraverser.cxx b/panda/src/sgraphutil/appTraverser.cxx deleted file mode 100644 index 35154af7a4..0000000000 --- a/panda/src/sgraphutil/appTraverser.cxx +++ /dev/null @@ -1,48 +0,0 @@ -// Filename: appTraverser.cxx -// Created by: drose (25Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "appTraverser.h" -#include "config_sgraphutil.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Function: AppTraverser::traverse -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void AppTraverser:: -traverse(Node *root) { - if (!implicit_app_traversal) { - df_traverse(root, *this, NullTransitionWrapper(), NullLevelState(), - _graph_type); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: AppTraverser::reached_node -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -bool AppTraverser:: -reached_node(Node *node, NullTransitionWrapper &, NullLevelState &) { - ArcChain bogus; - node->app_traverse(bogus); - - return true; -} diff --git a/panda/src/sgraphutil/appTraverser.h b/panda/src/sgraphutil/appTraverser.h deleted file mode 100644 index f1cfaf03b2..0000000000 --- a/panda/src/sgraphutil/appTraverser.h +++ /dev/null @@ -1,60 +0,0 @@ -// Filename: appTraverser.h -// Created by: drose (25Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef APPTRAVERSER_H -#define APPTRAVERSER_H - -#include - -#include -#include -#include -#include -#include - -class Node; - -//////////////////////////////////////////////////////////////////// -// Class : AppTraverser -// Description : This traverser is designed to make a per-frame pass -// over the scene graph before rendering, to update any -// internal nodes as appropriate. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA AppTraverser : - public TraverserVisitor { -PUBLISHED: - INLINE AppTraverser(TypeHandle graph_type); - INLINE ~AppTraverser(); - - void traverse(Node *root); - -public: - // These methods, from parent class TraverserVisitor, define the - // behavior of the AppTraverser as it traverses the graph. - // Normally you would never call these directly. - bool reached_node(Node *node, NullTransitionWrapper &render_state, - NullLevelState &level_state); - -private: - TypeHandle _graph_type; -}; - -#include "appTraverser.I" - -#endif - diff --git a/panda/src/sgraphutil/config_sgraphutil.cxx b/panda/src/sgraphutil/config_sgraphutil.cxx deleted file mode 100644 index 8f49dbeb58..0000000000 --- a/panda/src/sgraphutil/config_sgraphutil.cxx +++ /dev/null @@ -1,48 +0,0 @@ -// Filename: config_sgraphutil.cxx -// Created by: drose (21Feb00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "config_sgraphutil.h" -#include "directRenderTraverser.h" - -#include - -Configure(config_sgraphutil); -NotifyCategoryDef(sgraphutil, ""); - -ConfigureFn(config_sgraphutil) { - DirectRenderTraverser::init_type(); -} - -// Set this true to enable simple view-frustum culling: the -// elimination of branches of the scene graph from the drawing -// pipeline, based on the intersection test of its bounding sphere -// with the viewing frustum. Usually you'd only want to turn it off -// if it misbehaved, although there are rare cases in whice the -// culling logic is more expensive than the cost of drawing more than -// you can see. -const bool view_frustum_cull = config_sgraphutil.GetBool("view-frustum-cull", true); - -// Set this to color everything outside of the frustum red instead of -// culling it. Presumably this is only useful for debugging culling. -const bool fake_view_frustum_cull = config_sgraphutil.GetBool("fake-view-frustum-cull", false); - -// Setting this true causes the app traversal to be done during the -// draw traversal, instead of explicitly when the AppTraverser is -// called. -const bool implicit_app_traversal = config_sgraphutil.GetBool("implicit-app-traversal", true); - diff --git a/panda/src/sgraphutil/config_sgraphutil.h b/panda/src/sgraphutil/config_sgraphutil.h deleted file mode 100644 index ebd8ecd0d2..0000000000 --- a/panda/src/sgraphutil/config_sgraphutil.h +++ /dev/null @@ -1,34 +0,0 @@ -// Filename: config_sgraphutil.h -// Created by: drose (21Feb00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CONFIG_SGRAPHUTIL_H -#define CONFIG_SGRAPHUTIL_H - -#include -#include - -// Configure variables for sgraphutil package. - -NotifyCategoryDecl(sgraphutil, EXPCL_PANDA, EXPTP_PANDA); - -extern EXPCL_PANDA const bool view_frustum_cull; -extern EXPCL_PANDA const bool fake_view_frustum_cull; -extern EXPCL_PANDA const bool implicit_app_traversal; - - -#endif diff --git a/panda/src/sgraphutil/directRenderLevelState.h b/panda/src/sgraphutil/directRenderLevelState.h deleted file mode 100644 index 0acb252267..0000000000 --- a/panda/src/sgraphutil/directRenderLevelState.h +++ /dev/null @@ -1,36 +0,0 @@ -// Filename: directRenderLevelState.h -// Created by: drose (17Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DIRECTRENDERLEVELSTATE_H -#define DIRECTRENDERLEVELSTATE_H - -#include - -//////////////////////////////////////////////////////////////////// -// Class : DirectRenderLevelState -// Description : This is the state information the -// DirectRenderTraverser retains for each level during -// traversal. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA DirectRenderLevelState { -public: - bool _decal_mode; -}; - -#endif - diff --git a/panda/src/sgraphutil/directRenderTraverser.I b/panda/src/sgraphutil/directRenderTraverser.I deleted file mode 100644 index 037f25f87d..0000000000 --- a/panda/src/sgraphutil/directRenderTraverser.I +++ /dev/null @@ -1,30 +0,0 @@ -// Filename: directRenderTraverser.I -// Created by: drose (02Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: DirectRenderTraverser::set_view_frustum_cull -// Access: Public -// Description: Sets the flag that indicates whether view-frustum -// culling should be performed during this traversal. -// This is normally true. -//////////////////////////////////////////////////////////////////// -INLINE void DirectRenderTraverser:: -set_view_frustum_cull(bool flag) { - _view_frustum_cull = flag; -} diff --git a/panda/src/sgraphutil/directRenderTraverser.cxx b/panda/src/sgraphutil/directRenderTraverser.cxx deleted file mode 100644 index 664c8f955c..0000000000 --- a/panda/src/sgraphutil/directRenderTraverser.cxx +++ /dev/null @@ -1,264 +0,0 @@ -// Filename: directRenderTraverser.cxx -// Created by: drose (18Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "directRenderTraverser.h" -#include "config_sgraphutil.h" -#include "frustumCullTraverser.h" -#include "dftraverser.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include // for support_decals -#include - -TypeHandle DirectRenderTraverser::_type_handle; - -#ifndef CPPPARSER -PStatCollector DirectRenderTraverser::_draw_pcollector("Draw:Direct"); -#endif - -//////////////////////////////////////////////////////////////////// -// Function: DirectRenderTraverser::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -DirectRenderTraverser:: -DirectRenderTraverser(GraphicsStateGuardian *gsg, TypeHandle graph_type, - const ArcChain &arc_chain) : - RenderTraverser(gsg, graph_type, arc_chain) -{ - _view_frustum_cull = true; -} - - -//////////////////////////////////////////////////////////////////// -// Function: DirectRenderTraverser::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -DirectRenderTraverser:: -~DirectRenderTraverser() { -} - - -//////////////////////////////////////////////////////////////////// -// Function: DirectRenderTraverser::traverse -// Access: Public, Virtual -// Description: This performs a normal, complete render traversal -// using this DirectRenderTraverser object. -//////////////////////////////////////////////////////////////////// -void DirectRenderTraverser:: -traverse(Node *root, - const AllTransitionsWrapper &initial_state) { - // Statistics - PStatTimer timer(_draw_pcollector); - - DirectRenderLevelState level_state; - -#ifndef NDEBUG - if (support_decals != SD_off) -#endif - { - DecalTransition *decal_trans; - if (get_transition_into(decal_trans, initial_state)) { - level_state._decal_mode = decal_trans->is_on(); - } - } - - if (_view_frustum_cull) { - // Determine the relative transform matrix from the camera to our - // starting node. This is important for proper view-frustum - // culling. - LMatrix4f rel_from_camera; - NodeTransitionWrapper ntw(TransformTransition::get_class_type()); - const DisplayRegion *dr = _gsg->get_current_display_region(); - LensNode *camera = dr->get_cull_frustum(); - wrt(camera, root, begin(), end(), ntw, get_graph_type()); - const TransformTransition *tt; - if (get_transition_into(tt, ntw)) { - rel_from_camera = tt->get_matrix(); - } else { - // No relative transform. - rel_from_camera = LMatrix4f::ident_mat(); - } - fc_traverse(_arc_chain, root, rel_from_camera, *this, - initial_state, level_state, _gsg, _graph_type); - - } else { - // No view-frustum culling is requested; just do a normal - // depth-first traversal of the complete tree. - df_traverse(root, *this, initial_state, level_state, _graph_type); - } - - if (level_state._decal_mode && - root->is_of_type(GeomNode::get_class_type())) { -#ifndef NDEBUG - if (support_decals == SD_hide) { - return; - } -#endif - // Close the decal. - _gsg->end_decal(DCAST(GeomNode, root)); - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: DirectRenderTraverser::reached_node -// Access: -// Description: -//////////////////////////////////////////////////////////////////// -bool DirectRenderTraverser:: -reached_node(Node *node, AllTransitionsWrapper &render_state, - DirectRenderLevelState &level_state) { - if (implicit_app_traversal) { - node->app_traverse(_arc_chain); - } - node->draw_traverse(_arc_chain); - - level_state._decal_mode = false; - - AllTransitionsWrapper new_trans; - - _gsg->_nodes_pcollector.add_level(1); - -#ifndef NDEBUG - if (support_subrender == SD_on) -#endif - { - AllTransitionsWrapper modify_trans; - if (!node->sub_render(render_state, modify_trans, this)) { - return false; - } - render_state.compose_in_place(modify_trans); - } - - if (node->is_of_type(GeomNode::get_class_type())) { - _gsg->_geom_nodes_pcollector.add_level(1); - _gsg->set_state(render_state); - // Make sure the current display region is still in effect. - _gsg->prepare_display_region(); - - GeomNode *geom = DCAST(GeomNode, node); - - // We must make decals a special case, because they're so strange. -#ifndef NDEBUG - if (support_decals != SD_off) -#endif - { - DecalTransition *decal_trans; - if (get_transition_into(decal_trans, render_state)) { - level_state._decal_mode = decal_trans->is_on(); - } - } - - if (level_state._decal_mode) { -#ifndef NDEBUG - if (support_decals == SD_hide) { - level_state._decal_mode = false; - geom->draw(_gsg); - return false; - } -#endif - _gsg->begin_decal(geom, render_state); - - } else { - geom->draw(_gsg); - } - - } else if (node->is_of_type(SwitchNode::get_class_type())) { - SwitchNode *swnode = DCAST(SwitchNode, node); - swnode->compute_switch(this); - } - - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: DirectRenderTraverser::forward_arc -// Access: -// Description: -//////////////////////////////////////////////////////////////////// -bool DirectRenderTraverser:: -forward_arc(NodeRelation *arc, AllTransitionsWrapper &trans, - AllTransitionsWrapper &, AllTransitionsWrapper &post, - DirectRenderLevelState &) { - bool carry_on = true; - - // Go through all the transitions on the arc and sub_render() on - // each one. For most transition types, this will be a no-op and - // return true. For Shader types, this will fire off another render - // and return false. - - mark_forward_arc(arc); - -#ifndef NDEBUG - if (support_subrender == SD_on) -#endif - { - AllTransitionsWrapper::const_iterator nti; - for (nti = trans.begin(); nti != trans.end(); ++nti) { - NodeTransition *t = (*nti).second.get_trans(); - AllTransitionsWrapper modify_trans; - if (!t->sub_render(arc, post, modify_trans, this)) { - carry_on = false; - } - post.compose_in_place(modify_trans); - } - } - - if (!carry_on) { - mark_backward_arc(arc); - } - - return carry_on; -} - - -//////////////////////////////////////////////////////////////////// -// Function: DirectRenderTraverser::backward_arc -// Access: -// Description: -//////////////////////////////////////////////////////////////////// -void DirectRenderTraverser:: -backward_arc(NodeRelation *arc, AllTransitionsWrapper &, - AllTransitionsWrapper &, AllTransitionsWrapper &post, - const DirectRenderLevelState &level_state) { - mark_backward_arc(arc); - if (level_state._decal_mode) { - // Reset the state to redraw the base geometry. - _gsg->set_state(post); - _gsg->prepare_display_region(); - _gsg->end_decal(DCAST(GeomNode, arc->get_child())); - } -} - diff --git a/panda/src/sgraphutil/directRenderTraverser.h b/panda/src/sgraphutil/directRenderTraverser.h deleted file mode 100644 index fcfe9fc6e0..0000000000 --- a/panda/src/sgraphutil/directRenderTraverser.h +++ /dev/null @@ -1,101 +0,0 @@ -// Filename: directRenderTraverser.h -// Created by: drose (18Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DIRECTRENDERTRAVERSER_H -#define DIRECTRENDERTRAVERSER_H - -#include - -#include "directRenderLevelState.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -class Node; -class GraphicsStateGuardian; -class GeometricBoundingVolume; - -//////////////////////////////////////////////////////////////////// -// Class : DirectRenderTraverser -// Description : A kind of RenderTraverser that renders each GeomNode -// it encounters immediately as it is encountered. No -// attempt is made to perform state-sorting or binning; -// however, view-frustum culling is performed. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA DirectRenderTraverser : - public RenderTraverser, - public TraverserVisitor { -public: - DirectRenderTraverser(GraphicsStateGuardian *gsg, TypeHandle graph_type, - const ArcChain &arc_chain = ArcChain()); - virtual ~DirectRenderTraverser(); - - virtual void traverse(Node *root, - const AllTransitionsWrapper &initial_state); - - INLINE void set_view_frustum_cull(bool flag); - -public: - // These methods, from parent class TraverserVisitor, define the - // behavior of the DirectRenderTraverser as it traverses the graph. - // Normally you would never call these directly. - bool reached_node(Node *node, AllTransitionsWrapper &render_state, - DirectRenderLevelState &level_state); - - bool forward_arc(NodeRelation *arc, AllTransitionsWrapper &trans, - AllTransitionsWrapper &pre, AllTransitionsWrapper &post, - DirectRenderLevelState &level_state); - - void backward_arc(NodeRelation *arc, AllTransitionsWrapper &trans, - AllTransitionsWrapper &pre, AllTransitionsWrapper &post, - const DirectRenderLevelState &level_state); - -private: - bool _view_frustum_cull; - - // Statistics - static PStatCollector _draw_pcollector; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - RenderTraverser::init_type(); - register_type(_type_handle, "DirectRenderTraverser", - RenderTraverser::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "directRenderTraverser.I" - -#endif - diff --git a/panda/src/sgraphutil/frustumCullTraverser.I b/panda/src/sgraphutil/frustumCullTraverser.I deleted file mode 100644 index ff41e38f23..0000000000 --- a/panda/src/sgraphutil/frustumCullTraverser.I +++ /dev/null @@ -1,292 +0,0 @@ -// Filename: frustumCullTraverser.I -// Created by: drose (14Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: FrustumCullTraverser::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -template -FrustumCullTraverser:: -FrustumCullTraverser(ArcChain &arc_chain, Node *root, - const LMatrix4f &rel_from_camera, Visitor &visitor, - const TransitionWrapper &initial_render_state, - const LevelState &initial_level_state, - GraphicsStateGuardian *gsg, - TypeHandle graph_type) : - _arc_chain(arc_chain), - _visitor(visitor), - _initial_render_state(initial_render_state), - _gsg(gsg), - _graph_type(graph_type) -{ - _view_frustum = NULL; - PT(GeometricBoundingVolume) local_frustum; - - if (view_frustum_cull && _gsg != (GraphicsStateGuardian *)NULL) { - // If we're to be performing view-frustum culling, determine the - // bounding volume associated with the current viewing frustum. - - // First, we have to get the current viewing frustum. This is - // normally the same thing as the current camera, but the - // DisplayRegion may have some override in effect, so we ask the - // DisplayRegion instead of the GSG. - const DisplayRegion *dr = _gsg->get_current_display_region(); - LensNode *camera = dr->get_cull_frustum(); - if (camera != (const LensNode *)NULL) { - const Lens *lens = camera->get_lens(); - nassertv(lens != (const Lens *)NULL); - PT(BoundingVolume) bv = lens->make_bounds(); - - if (bv != (BoundingVolume *)NULL && - bv->is_of_type(GeometricBoundingVolume::get_class_type())) { - _view_frustum = DCAST(GeometricBoundingVolume, bv); - } - } - - if (_view_frustum != (GeometricBoundingVolume *)NULL) { - local_frustum = DCAST(GeometricBoundingVolume, _view_frustum->make_copy()); - local_frustum->xform(rel_from_camera); - GraphicsStateGuardian::_frustum_cull_volumes_pcollector.add_level(1); - GraphicsStateGuardian::_frustum_cull_transforms_pcollector.add_level(1); - - if (sgraphutil_cat.is_spam()) { - sgraphutil_cat.spam() - << "Beginning frustum cull, frustum is: " << *local_frustum << "\n" - << "Transform is:\n"; - rel_from_camera.write(sgraphutil_cat.spam(false), 2); - } - } - } - - bool needs_top_node = _arc_chain.is_empty(); - if (needs_top_node) { - // If the ArcChain supplied in is initially empty, put the root - // node in it. - _arc_chain = ArcChain(root); - } - - LevelState level_state(initial_level_state); - traverse(root, _initial_render_state, level_state, local_frustum, false); - - _view_frustum = NULL; - - if (needs_top_node) { - // Restore the ArcChain to its initial empty state (if that's what - // it was). - _arc_chain = ArcChain(); - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: FrustumCullTraverser::Traverse -// Access: Public -// Description: Walks to the next arc of the graph. -//////////////////////////////////////////////////////////////////// -template -void FrustumCullTraverser:: -traverse(NodeRelation *arc, TransitionWrapper render_state, - LevelState level_state, PT(GeometricBoundingVolume) local_frustum, - bool all_in) { - // local_frustum, above, is a PT(GeometricBoundingVolume), instead - // of just an ordinary GeometricBoundingVolume*, because we might - // reassign it within this function to a locally-allocated volume - // which we expect to automatically destruct when the function - // terminates. - nassertv(arc->get_child() != (Node *)NULL); - - bool carry_on = true; - - _arc_chain.push_back(arc); - - // First, if we're performing view-frustum culling, check the - // bounding volume associated with this arc (which bounds all of its - // children) against the bounding volume of our view frustum. - - if (_view_frustum != (GeometricBoundingVolume *)NULL) { - // If this arc's child has multiple parents, we need to save the - // arc on the arc stack, so we can unambiguously wrt(). - - if (!all_in) { - // Now test for intersection with the bounding volume. - const BoundingVolume &arc_volume = arc->get_bound(); - if (arc_volume.is_of_type(GeometricBoundingVolume::get_class_type())) { - const GeometricBoundingVolume *arc_gbv = - DCAST(GeometricBoundingVolume, &arc_volume); - - nassertv(local_frustum != (GeometricBoundingVolume *)NULL); - int result = local_frustum->contains(arc_gbv); - GraphicsStateGuardian::_frustum_cull_volumes_pcollector.add_level(1); - if (result == BoundingVolume::IF_no_intersection) { - // No intersection at all. Cull. - if (sgraphutil_cat.is_spam()) { - if (!arc_volume.is_empty()) { - sgraphutil_cat.spam() - << "Culling " << *arc->get_child() << " with volume " - << arc_volume << "\n"; - } - } - - /* - if (fake_view_frustum_cull) { - // In fake mode, we just render everything in red - // wireframe instead of actually culling it. - - ColorTransition *c = - new ColorTransition(1.0, 0.0, 0.0, 1.0); - RenderModeTransition *w = - new RenderModeTransition(RenderModeProperty::M_wireframe); - TextureTransition *t = - new TextureTransition(TextureTransition::off()); - - c->set_priority(100); - w->set_priority(100); - t->set_priority(100); - AllTransitionsWrapper trans; - trans.set_transition(c); - trans.set_transition(w); - trans.set_transition(t); - - post.apply_in_place(trans); - all_in = true; - - } else */ { - carry_on = false; - } - - } else if ((result & BoundingVolume::IF_all) != 0) { - // The arc and its descendants are completely enclosed within - // the frustum. No need to cull further. - all_in = true; - } - } - - if (carry_on) { - if (arc->is_final() || - arc->has_transition(BillboardTransition::get_class_type())) { - // We can't reliably cull within a billboard, because the - // geometry might get rotated out of its bounding volume. - // So once we get within a billboard, we consider it all - // visible. - - // Also, if the arc has the "final" flag, the user is - // claiming that there is some other reason we should - // consider everything visible at this point. So be it. - all_in = true; - } - - if (!all_in && - arc->has_transition(TransformTransition::get_class_type())) { - // Now apply the transform associated with this arc. We do - // this after the bounding volume test, because the bounding - // volume has already been transformed. - - local_frustum = - DCAST(GeometricBoundingVolume, _view_frustum->make_copy()); - - NodeTransitionWrapper ntw(TransformTransition::get_class_type()); - const DisplayRegion *dr = _gsg->get_current_display_region(); - LensNode *camera = dr->get_cull_frustum(); - wrt(camera, - arc->get_child(), _arc_chain.begin(), _arc_chain.end(), - ntw, _graph_type); - - const TransformTransition *tt; - if (get_transition_into(tt, ntw)) { - // This frustum is transformed from the camera. Most will - // be. - nassertv(local_frustum != (GeometricBoundingVolume *)NULL); - local_frustum->xform(tt->get_matrix()); - GraphicsStateGuardian::_frustum_cull_transforms_pcollector.add_level(1); - - if (sgraphutil_cat.is_spam()) { - sgraphutil_cat.spam() - << "Transforming frustum into local space of " << *arc - << ": " << *local_frustum << "\n" - << "Transform is:\n"; - tt->get_matrix().write(sgraphutil_cat.spam(false), 2); - } - } - } - } - } - } - - if (carry_on) { - // Now give the visitor a chance to veto this arc. - TransitionWrapper trans = - TransitionWrapper::init_from(_initial_render_state); - trans.extract_from(arc); - - TransitionWrapper post_state(render_state); - post_state.compose_in_place(trans); - if (_visitor.forward_arc(arc, trans, render_state, post_state, - level_state)) { - - traverse(arc->get_child(), post_state, level_state, - local_frustum, all_in); - _visitor.backward_arc(arc, trans, render_state, post_state, - level_state); - } - } - - _arc_chain.pop_back(); -} - - - -//////////////////////////////////////////////////////////////////// -// Function: FrustumCullTraverser::Traverse -// Access: Public -// Description: Walks to the next node of the graph. -//////////////////////////////////////////////////////////////////// -template -void FrustumCullTraverser:: -traverse(Node *node, TransitionWrapper &render_state, LevelState &level_state, - GeometricBoundingVolume *local_frustum, bool all_in) { - // Tell the visitor we reached the node, and give it a chance to - // veto our further progress. - if (_visitor.reached_node(node, render_state, level_state)) { - - // Look for further children of the given NodeRelation. - const DownRelationPointers &drp = - node->find_connection(_graph_type).get_down(); - - // Now visit each of the children in turn. - if (node->is_of_type(SwitchNode::get_class_type())) { - SwitchNode *swnode = DCAST(SwitchNode, node); - // Presumably, the visitor called compute_switch() on the - // SwitchNode during the reached_node() call, above. We can't - // call it directly since we don't have enough information. - size_t i = 0; - for (i = 0; i < drp.size(); i++) { - if (swnode->is_child_visible(_graph_type, i)) { - traverse(drp[i], render_state, level_state, local_frustum, all_in); - } - } - } else { - DownRelationPointers::const_iterator drpi; - for (drpi = drp.begin(); drpi != drp.end(); ++drpi) { - traverse(*drpi, render_state, level_state, local_frustum, all_in); - } - } - } -} - diff --git a/panda/src/sgraphutil/frustumCullTraverser.cxx b/panda/src/sgraphutil/frustumCullTraverser.cxx deleted file mode 100644 index f43665d99b..0000000000 --- a/panda/src/sgraphutil/frustumCullTraverser.cxx +++ /dev/null @@ -1,19 +0,0 @@ -// Filename: frustumCullTraverser.cxx -// Created by: drose (14Jun01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "frustumCullTraverser.h" diff --git a/panda/src/sgraphutil/frustumCullTraverser.h b/panda/src/sgraphutil/frustumCullTraverser.h deleted file mode 100644 index 357e6c0685..0000000000 --- a/panda/src/sgraphutil/frustumCullTraverser.h +++ /dev/null @@ -1,100 +0,0 @@ -// Filename: frustumCullTraverser.h -// Created by: drose (14Apr00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef FRUSTUMCULLTRAVERSER_H -#define FRUSTUMCULLTRAVERSER_H - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "config_sgraphutil.h" - - -/////////////////////////////////////////////////////////////////// -// Class : FrustumCullTraverser -// Description : A special kind of depth-first traverser that can -// prune the graph based on a lack of intersection with -// a given bounding volume; i.e. it performs -// view-frustum culling. -//////////////////////////////////////////////////////////////////// -template -class FrustumCullTraverser { -public: - typedef TYPENAME Visitor::TransitionWrapper TransitionWrapper; - - FrustumCullTraverser(ArcChain &arc_chain, Node *root, - const LMatrix4f &rel_from_camera, Visitor &visitor, - const TransitionWrapper &initial_render_state, - const LevelState &initial_level_state, - GraphicsStateGuardian *gsg, - TypeHandle graph_type); - -protected: - void traverse(NodeRelation *arc, - TransitionWrapper render_state, - LevelState level_state, - PT(GeometricBoundingVolume) local_frustum, - bool all_in); - void traverse(Node *node, - TransitionWrapper &render_state, - LevelState &level_state, - GeometricBoundingVolume *local_frustum, - bool all_in); - - ArcChain &_arc_chain; - Visitor &_visitor; - TransitionWrapper _initial_render_state; - GraphicsStateGuardian *_gsg; - TypeHandle _graph_type; - - // If we are performing view-frustum culling, this is a pointer to - // the bounding volume that encloses the view frustum, in its own - // coordinate space. If we are not performing view-frustum culling, - // this will be a NULL pointer. - PT(GeometricBoundingVolume) _view_frustum; -}; - -// Convenience function. -template -INLINE void -fc_traverse(ArcChain &arc_chain, Node *root, - const LMatrix4f &rel_from_camera, Visitor &visitor, - const TransitionWrapper &initial_render_state, - const LevelState &initial_level_state, - GraphicsStateGuardian *gsg, TypeHandle graph_type) { - FrustumCullTraverser - fct(arc_chain, root, rel_from_camera, visitor, initial_render_state, - initial_level_state, gsg, graph_type); -} - -#include "frustumCullTraverser.I" - -#endif diff --git a/panda/src/sgraphutil/get_rel_pos.I b/panda/src/sgraphutil/get_rel_pos.I deleted file mode 100644 index 199abab26c..0000000000 --- a/panda/src/sgraphutil/get_rel_pos.I +++ /dev/null @@ -1,108 +0,0 @@ -// Filename: get_rel_pos.I -// Created by: drose (18Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: get_up -// Description: Returns the vector which indicates "up" -// (e.g. the positive z axis, in a Z-up right-handed -// system) to the the indicated node, relative to -// another node (such as render). -//////////////////////////////////////////////////////////////////// -INLINE LVector3f -get_rel_up(const Node *node, const Node *relative_to, - CoordinateSystem cs) { - LMatrix4f mat; - get_rel_rot_mat(node, relative_to, mat); - return LVector3f::up(cs) * mat; -} - -//////////////////////////////////////////////////////////////////// -// Function: get_right -// Description: Returns the vector which indicates "right" -// (e.g. the positive x axis, in a Z-up right-handed -// system) to the the indicated node, relative to -// another node (such as render). -//////////////////////////////////////////////////////////////////// -INLINE LVector3f -get_rel_right(const Node *node, const Node *relative_to, - CoordinateSystem cs) { - LMatrix4f mat; - get_rel_rot_mat(node, relative_to, mat); - return LVector3f::right(cs) * mat; -} - -//////////////////////////////////////////////////////////////////// -// Function: get_forward -// Description: Returns the vector which indicates "forward" -// (e.g. the positive y axis, in a Z-up right-handed -// system) to the the indicated node, relative to -// another node (such as render). -//////////////////////////////////////////////////////////////////// -INLINE LVector3f -get_rel_forward(const Node *node, const Node *relative_to, - CoordinateSystem cs) { - LMatrix4f mat; - get_rel_rot_mat(node, relative_to, mat); - return LVector3f::forward(cs) * mat; -} - -//////////////////////////////////////////////////////////////////// -// Function: get_down -// Description: Returns the vector which indicates "down" -// (e.g. the negative y axis, in a Z-up right-handed -// system) to the the indicated node, relative to -// another node (such as render). -//////////////////////////////////////////////////////////////////// -INLINE LVector3f -get_rel_down(const Node *node, const Node *relative_to, - CoordinateSystem cs) { - LMatrix4f mat; - get_rel_rot_mat(node, relative_to, mat); - return LVector3f::down(cs) * mat; -} - -//////////////////////////////////////////////////////////////////// -// Function: get_left -// Description: Returns the vector which indicates "left" -// (e.g. the negative x axis, in a Z-up right-handed -// system) to the the indicated node, relative to -// another node (such as render). -//////////////////////////////////////////////////////////////////// -INLINE LVector3f -get_rel_left(const Node *node, const Node *relative_to, - CoordinateSystem cs) { - LMatrix4f mat; - get_rel_rot_mat(node, relative_to, mat); - return LVector3f::left(cs) * mat; -} - -//////////////////////////////////////////////////////////////////// -// Function: get_back -// Description: Returns the vector which indicates "back" -// (e.g. the negative y axis, in a Z-up right-handed -// system) to the the indicated node, relative to -// another node (such as render). -//////////////////////////////////////////////////////////////////// -INLINE LVector3f -get_rel_back(const Node *node, const Node *relative_to, - CoordinateSystem cs) { - LMatrix4f mat; - get_rel_rot_mat(node, relative_to, mat); - return LVector3f::back(cs) * mat; -} diff --git a/panda/src/sgraphutil/get_rel_pos.cxx b/panda/src/sgraphutil/get_rel_pos.cxx deleted file mode 100644 index 08d71a5cf2..0000000000 --- a/panda/src/sgraphutil/get_rel_pos.cxx +++ /dev/null @@ -1,159 +0,0 @@ -// Filename: get_rel_pos.cxx -// Created by: drose (18Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "get_rel_pos.h" - -#include "transformTransition.h" -#include "nodeTransitionWrapper.h" -#include "wrt.h" -#include "arcChain.h" - -//////////////////////////////////////////////////////////////////// -// Function: get_rel_pos -// Description: Returns the position in space of the node's origin, -// relative to another node (such as render). -//////////////////////////////////////////////////////////////////// -LPoint3f -get_rel_pos(const Node *node, const Node *relative_to, - TypeHandle graph_type) { - NodeTransitionWrapper ntw(TransformTransition::get_class_type()); - wrt(node, relative_to, ntw, graph_type); - const TransformTransition *tt; - - if (!get_transition_into(tt, ntw)) { - // No relative transform. - return LPoint3f(0.0f, 0.0f, 0.0f); - } - - LVector3f pos; - tt->get_matrix().get_row3(pos,3); - return pos; -} - -//////////////////////////////////////////////////////////////////// -// Function: get_rel_mat -// Description: Returns the net transform of the node, relative to -// another node (such as render). -//////////////////////////////////////////////////////////////////// -void -get_rel_mat(const Node *node, const Node *relative_to, - LMatrix4f &mat, TypeHandle graph_type) { - NodeTransitionWrapper ntw(TransformTransition::get_class_type()); - wrt(node, relative_to, ntw, graph_type); - const TransformTransition *tt; - if (!get_transition_into(tt, ntw)) { - // No relative transform. - mat = LMatrix4f::ident_mat(); - return; - } - - mat = tt->get_matrix(); -} - -//////////////////////////////////////////////////////////////////// -// Function: get_rel_mat -// Description: Returns the net transform of the node, relative to -// another node (such as render). This flavor of -// get_rel_mat() uses ArcChains to resolve ambiguities -// due to instancing. -//////////////////////////////////////////////////////////////////// -void -get_rel_mat(const Node *from, const ArcChain &from_arcs, - const Node *to, const ArcChain &to_arcs, - LMatrix4f &mat, TypeHandle graph_type) { - NodeTransitionWrapper ntw(TransformTransition::get_class_type()); - wrt(from, from_arcs.begin(), from_arcs.end(), - to, to_arcs.begin(), to_arcs.end(), - ntw, graph_type); - const TransformTransition *tt; - if (!get_transition_into(tt, ntw)) { - // No relative transform. - mat = LMatrix4f::ident_mat(); - return; - } - - mat = tt->get_matrix(); -} - -//////////////////////////////////////////////////////////////////// -// Function: get_rot_mat -// Description: Returns a rotation-only matrix that corresponds to -// the position in space of the node's origin, relative -// to another node (such as render). -//////////////////////////////////////////////////////////////////// -void -get_rel_rot_mat(const Node *node, const Node *relative_to, - LMatrix4f &mat, TypeHandle graph_type) { - NodeTransitionWrapper ntw(TransformTransition::get_class_type()); - wrt(node, relative_to, ntw, graph_type); - const TransformTransition *tt; - if (!get_transition_into(tt, ntw)) { - // No relative transform. - mat = LMatrix4f::ident_mat(); - return; - } - - // Extract the axes from the matrix. - const LMatrix4f &rel_mat = tt->get_matrix(); - LVector3f x, y, z; - rel_mat.get_row3(x,0); - rel_mat.get_row3(y,1); - rel_mat.get_row3(z,2); - - // Normalize these axes to eliminate scale. - x.normalize(); - y.normalize(); - z.normalize(); - - // Now build a new matrix which just represents these axes. - mat.set(x[0], x[1], x[2], 0.0f, - y[0], y[1], y[2], 0.0f, - z[0], z[1], z[2], 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f); -} - - -//////////////////////////////////////////////////////////////////// -// Function: get_scale -// Description: Returns the relative scale between the indicated node -// and the other node. -//////////////////////////////////////////////////////////////////// -LVecBase3f -get_rel_scale(const Node *node, const Node *relative_to, - TypeHandle graph_type) { - NodeTransitionWrapper ntw(TransformTransition::get_class_type()); - wrt(node, relative_to, ntw, graph_type); - const TransformTransition *tt; - if (!get_transition_into(tt, ntw)) { - // No relative transform. - return LVecBase3f(1.0f, 1.0f, 1.0f); - } - - // Extract the axes from the matrix. - const LMatrix4f &rel_mat = tt->get_matrix(); - LVector3f x, y, z; - rel_mat.get_row3(x,0); - rel_mat.get_row3(y,1); - rel_mat.get_row3(z,2); - - // Now return the lengths of these axes as the scale. - - return LVecBase3f(length(x), length(y), length(z)); -} - - diff --git a/panda/src/sgraphutil/get_rel_pos.h b/panda/src/sgraphutil/get_rel_pos.h deleted file mode 100644 index dcb7672429..0000000000 --- a/panda/src/sgraphutil/get_rel_pos.h +++ /dev/null @@ -1,77 +0,0 @@ -// Filename: get_rel_pos.h -// Created by: drose (18Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef GET_REL_POS_H -#define GET_REL_POS_H - -#include "pandabase.h" - -#include "luse.h" -#include "lmatrix.h" -#include "coordinateSystem.h" -#include "renderRelation.h" - - -class Node; -class ArcChain; - -LPoint3f EXPCL_PANDA -get_rel_pos(const Node *node, const Node *relative_to, - TypeHandle graph_type = RenderRelation::get_class_type()); -void EXPCL_PANDA -get_rel_mat(const Node *node, const Node *relative_to, - LMatrix4f &mat, - TypeHandle graph_type = RenderRelation::get_class_type()); -void EXPCL_PANDA -get_rel_mat(const Node *from, const ArcChain &from_arcs, - const Node *to, const ArcChain &to_arcs, - LMatrix4f &mat, - TypeHandle graph_type = RenderRelation::get_class_type()); -void EXPCL_PANDA -get_rel_rot_mat(const Node *node, const Node *relative_to, - LMatrix4f &mat, - TypeHandle graph_type = RenderRelation::get_class_type()); - -LVecBase3f EXPCL_PANDA -get_rel_scale(const Node *node, const Node *relative_to, - TypeHandle graph_type = RenderRelation::get_class_type()); - - -INLINE LVector3f EXPCL_PANDA -get_rel_up(const Node *node, const Node *relative_to, - CoordinateSystem cs = CS_default); -INLINE LVector3f EXPCL_PANDA -get_rel_right(const Node *node, const Node *relative_to, - CoordinateSystem cs = CS_default); -INLINE LVector3f EXPCL_PANDA -get_rel_forward(const Node *node, const Node *relative_to, - CoordinateSystem cs = CS_default); -INLINE LVector3f EXPCL_PANDA -get_rel_down(const Node *node, const Node *relative_to, - CoordinateSystem cs = CS_default); -INLINE LVector3f EXPCL_PANDA -get_rel_left(const Node *node, const Node *relative_to, - CoordinateSystem cs = CS_default); -INLINE LVector3f EXPCL_PANDA -get_rel_back(const Node *node, const Node *relative_to, - CoordinateSystem cs = CS_default); - -#include "get_rel_pos.I" - -#endif - diff --git a/panda/src/sgraphutil/quickRenderLevelState.h b/panda/src/sgraphutil/quickRenderLevelState.h deleted file mode 100644 index 546bfd2108..0000000000 --- a/panda/src/sgraphutil/quickRenderLevelState.h +++ /dev/null @@ -1,39 +0,0 @@ -// Filename: quickRenderLevelState.h -// Created by: drose (24Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef QUICKRENDERLEVELSTATE_H -#define QUICKRENDERLEVELSTATE_H - -#include "pandabase.h" - -#include "updateSeq.h" - -//////////////////////////////////////////////////////////////////// -// Class : QuickRenderLevelState -// Description : This is the state information the -// QuickRenderTraverser retains for each level during -// traversal. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA QuickRenderLevelState { -public: - UpdateSeq _as_of; - bool _under_instance; -}; - -#endif - diff --git a/panda/src/sgraphutil/quickRenderTraverser.I b/panda/src/sgraphutil/quickRenderTraverser.I deleted file mode 100644 index ff2e8753a3..0000000000 --- a/panda/src/sgraphutil/quickRenderTraverser.I +++ /dev/null @@ -1,18 +0,0 @@ -// Filename: quickRenderTraverser.I -// Created by: drose (24Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - diff --git a/panda/src/sgraphutil/quickRenderTraverser.cxx b/panda/src/sgraphutil/quickRenderTraverser.cxx deleted file mode 100644 index e66148a158..0000000000 --- a/panda/src/sgraphutil/quickRenderTraverser.cxx +++ /dev/null @@ -1,167 +0,0 @@ -// Filename: quickRenderTraverser.cxx -// Created by: drose (24Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "quickRenderTraverser.h" -#include "config_sgraphutil.h" - -#include "allTransitionsWrapper.h" -#include "graphicsStateGuardian.h" -#include "dftraverser.h" -#include "pruneTransition.h" -#include "geomNode.h" -#include "pStatTimer.h" -#include "wrt.h" - -TypeHandle QuickRenderTraverser::_type_handle; - -#ifndef CPPPARSER -PStatCollector QuickRenderTraverser::_draw_pcollector("Draw:Quick"); -static PStatCollector _fooby_pcollector("Draw:Quick:Fooby"); -#endif - -//////////////////////////////////////////////////////////////////// -// Function: QuickRenderTraverser::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -QuickRenderTraverser:: -QuickRenderTraverser(GraphicsStateGuardian *gsg, TypeHandle graph_type, - const ArcChain &arc_chain) : - RenderTraverser(gsg, graph_type, arc_chain) -{ - _root = (Node *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: QuickRenderTraverser::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -QuickRenderTraverser:: -~QuickRenderTraverser() { -} - -//////////////////////////////////////////////////////////////////// -// Function: QuickRenderTraverser::traverse -// Access: Public, Virtual -// Description: This performs a normal, complete cull-and-render -// traversal using this QuickRenderTraverser object. State is -// saved within the QuickRenderTraverser object so that the -// next frame will be processed much more quickly than -// the first frame. -//////////////////////////////////////////////////////////////////// -void QuickRenderTraverser:: -traverse(Node *root, const AllTransitionsWrapper &initial_state) { - // Statistics - PStatTimer timer(_draw_pcollector); - - _root = root; - _initial_state = initial_state; - _arc_chain = ArcChain(_root); - - QuickRenderLevelState level_state; - level_state._as_of = UpdateSeq::initial(); - level_state._under_instance = false; - - const DownRelationPointers &drp = - _root->find_connection(_graph_type).get_down(); - - // Now visit each of the children in turn. - DownRelationPointers::const_iterator drpi; - for (drpi = drp.begin(); drpi != drp.end(); ++drpi) { - NodeRelation *arc = *drpi; - r_traverse(DCAST(RenderRelation, arc), level_state); - } - - _root = (Node *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: QuickRenderTraverser::r_traverse -// Access: Private -// Description: -//////////////////////////////////////////////////////////////////// -void QuickRenderTraverser:: -r_traverse(RenderRelation *arc, const QuickRenderLevelState &level_state) { - if (arc->has_transition(PruneTransition::get_class_type())) { - return; - } - - QuickRenderLevelState next_level_state(level_state); - Node *node = arc->get_child(); - - if (node->get_num_parents(_graph_type) != 1) { - next_level_state._under_instance = true; - } - - _arc_chain.push_back(arc); - - if (implicit_app_traversal) { - node->app_traverse(_arc_chain); - } - node->draw_traverse(_arc_chain); - - // We have to get a new _now timestamp, just in case either of the - // above traversals changed it. - UpdateSeq now = last_graph_update(_graph_type); - - UpdateSeq last_update = arc->get_last_update(); - if (next_level_state._as_of < last_update) { - next_level_state._as_of = last_update; - } - - _gsg->_nodes_pcollector.add_level(1); - - if (node->is_of_type(GeomNode::get_class_type())) { - _gsg->_geom_nodes_pcollector.add_level(1); - - // Determine the net transition to this GeomNode, and render it. - GeomNode *gnode = DCAST(GeomNode, node); - AllTransitionsWrapper trans; - - if (next_level_state._under_instance) { - // If we're under an instance node, we have to use the more - // expensive wrt() operation. - wrt(node, begin(), end(), (Node *)NULL, trans, _graph_type); - - } else { - // Otherwise, we can use wrt_subtree() to get better caching. - wrt_subtree(arc, NULL, - next_level_state._as_of, now, - trans, _graph_type); - } - - AllTransitionsWrapper attrib; - attrib.compose_from(_initial_state, trans); - - _gsg->set_state(attrib); - gnode->draw(_gsg); - } - - const DownRelationPointers &drp = - node->find_connection(_graph_type).get_down(); - - // Now visit each of the children in turn. - DownRelationPointers::const_iterator drpi; - for (drpi = drp.begin(); drpi != drp.end(); ++drpi) { - NodeRelation *arc = *drpi; - r_traverse(DCAST(RenderRelation, arc), next_level_state); - } - - _arc_chain.pop_back(); -} diff --git a/panda/src/sgraphutil/quickRenderTraverser.h b/panda/src/sgraphutil/quickRenderTraverser.h deleted file mode 100644 index 068b8e463e..0000000000 --- a/panda/src/sgraphutil/quickRenderTraverser.h +++ /dev/null @@ -1,84 +0,0 @@ -// Filename: quickRenderTraverser.h -// Created by: drose (24Jul01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef QUICKRENDERTRAVERSER_H -#define QUICKRENDERTRAVERSER_H - -#include "pandabase.h" - -#include "quickRenderLevelState.h" - -#include "renderTraverser.h" -#include "allTransitionsWrapper.h" -#include "pStatCollector.h" - -class GraphicsStateGuardian; -class AllTransitionsWrapper; -class RenderRelation; - -//////////////////////////////////////////////////////////////////// -// Class : QuickRenderTraverser -// Description : A small RenderTraverser that performs a left-to-right -// depth-first traversal of the scene graph, rendering -// nodes as it encounters them, like a -// DirectRenderTraverser. -// -// However, it does not support instancing, nor -// view-frustum culling. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA QuickRenderTraverser : public RenderTraverser { -public: - QuickRenderTraverser(GraphicsStateGuardian *gsg, TypeHandle graph_type, - const ArcChain &arc_chain = ArcChain()); - virtual ~QuickRenderTraverser(); - - virtual void traverse(Node *root, - const AllTransitionsWrapper &initial_state); - -private: - void r_traverse(RenderRelation *arc, const QuickRenderLevelState &level_state); - -private: - Node *_root; - AllTransitionsWrapper _initial_state; - - // Statistics - static PStatCollector _draw_pcollector; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - RenderTraverser::init_type(); - register_type(_type_handle, "QuickRenderTraverser", - RenderTraverser::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "quickRenderTraverser.I" - -#endif - diff --git a/panda/src/sgraphutil/sceneGraphReducer.I b/panda/src/sgraphutil/sceneGraphReducer.I deleted file mode 100644 index 6643528c92..0000000000 --- a/panda/src/sgraphutil/sceneGraphReducer.I +++ /dev/null @@ -1,56 +0,0 @@ -// Filename: sceneGraphReducer.I -// Created by: drose (22May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: SceneGraphReducer::AccumulatedTransitions::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE SceneGraphReducer::AccumulatedTransitions:: -AccumulatedTransitions() { -} - -//////////////////////////////////////////////////////////////////// -// Function: SceneGraphReducer::AccumulatedTransitions::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE SceneGraphReducer::AccumulatedTransitions:: -AccumulatedTransitions(const SceneGraphReducer::AccumulatedTransitions ©) : - _transform(copy._transform), - _color(copy._color), - _texture_matrix(copy._texture_matrix), - _color_matrix(copy._color_matrix), - _alpha_transform(copy._alpha_transform) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: SceneGraphReducer::AccumulatedTransitions::Copy Assignment -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void SceneGraphReducer::AccumulatedTransitions:: -operator = (const SceneGraphReducer::AccumulatedTransitions ©) { - _transform = copy._transform; - _color = copy._color; - _texture_matrix = copy._texture_matrix; - _color_matrix = copy._color_matrix; - _alpha_transform = copy._alpha_transform; -} diff --git a/panda/src/sgraphutil/sceneGraphReducer.cxx b/panda/src/sgraphutil/sceneGraphReducer.cxx deleted file mode 100644 index 580b01fc10..0000000000 --- a/panda/src/sgraphutil/sceneGraphReducer.cxx +++ /dev/null @@ -1,383 +0,0 @@ -// Filename: sceneGraphReducer.cxx -// Created by: drose (22May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "sceneGraphReducer.h" -#include "config_sgraphutil.h" - -#include "geomNode.h" -#include "geom.h" -#include "indent.h" -#include "billboardTransition.h" -#include "decalTransition.h" - - -//////////////////////////////////////////////////////////////////// -// Function: SceneGraphReducer::AccumulatedTransitions::apply_to_arc -// Access: Public -// Description: Stores the relevant transitions on the indicated arc, -// and clears the transitions for continuing. -//////////////////////////////////////////////////////////////////// -void SceneGraphReducer::AccumulatedTransitions:: -apply_to_arc(NodeRelation *arc, int transition_types) { - if ((transition_types & TT_transform) != 0) { - if (!_transform->get_matrix().almost_equal(LMatrix4f::ident_mat())) { - arc->set_transition(_transform); - } - _transform = new TransformTransition; - } - - if ((transition_types & TT_color) != 0) { - if (!_color->is_identity()) { - arc->set_transition(_color); - _color = new ColorTransition; - } - } - - if ((transition_types & TT_texture_matrix) != 0) { - if (!_texture_matrix->get_matrix().almost_equal(LMatrix4f::ident_mat())) { - arc->set_transition(_texture_matrix); - } - _texture_matrix = new TexMatrixTransition; - } - - if ((transition_types & TT_color_matrix) != 0) { - if (!_color_matrix->get_matrix().almost_equal(LMatrix4f::ident_mat())) { - arc->set_transition(_color_matrix); - } - if (_alpha_transform->get_scale() != 1.0f || - _alpha_transform->get_offset() != 0.0f) { - arc->set_transition(_alpha_transform); - } - _color_matrix = new ColorMatrixTransition; - _alpha_transform = new AlphaTransformTransition; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: SceneGraphReducer::AccumulatedTransitions::write -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void SceneGraphReducer::AccumulatedTransitions:: -write(ostream &out, int transition_types, int indent_level) const { - if ((transition_types & TT_transform) != 0) { - _transform->write(out, indent_level); - } - if ((transition_types & TT_color) != 0) { - _color->write(out, indent_level); - } - if ((transition_types & TT_texture_matrix) != 0) { - _texture_matrix->write(out, indent_level); - } - if ((transition_types & TT_color_matrix) != 0) { - _color_matrix->write(out, indent_level); - _alpha_transform->write(out, indent_level); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: SceneGraphReducer::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -SceneGraphReducer:: -SceneGraphReducer(TypeHandle graph_type) : - GraphReducer(graph_type) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: SceneGraphReducer::apply_transitions -// Access: Public -// Description: Walks the scene graph, accumulating transitions of -// the indicated types, applying them to the vertices, -// and removing them from the scene graph. This has a -// performance optimization benefit in itself, but is -// especially useful to pave the way for a call to -// flatten() and greatly improve the effectiveness of -// the flattening operation. -// -// Multiply instanced geometry is duplicated before the -// transitions are applied. -// -// Of course, this operation does make certain dynamic -// operations impossible. -//////////////////////////////////////////////////////////////////// -void SceneGraphReducer:: -apply_transitions(NodeRelation *arc, int transition_types) { - AccumulatedTransitions trans; - if ((transition_types & TT_transform) != 0) { - trans._transform = new TransformTransition; - } - if ((transition_types & TT_color) != 0) { - trans._color = new ColorTransition; - } - if ((transition_types & TT_texture_matrix) != 0) { - trans._texture_matrix = new TexMatrixTransition; - } - if ((transition_types & TT_color_matrix) != 0) { - trans._color_matrix = new ColorMatrixTransition; - trans._alpha_transform = new AlphaTransformTransition; - } - - r_apply_transitions(arc, transition_types, trans, false); -} - -//////////////////////////////////////////////////////////////////// -// Function: SceneGraphReducer::r_apply_transitions -// Access: Protected -// Description: The recursive implementation of apply_transitions(). -//////////////////////////////////////////////////////////////////// -void SceneGraphReducer:: -r_apply_transitions(NodeRelation *arc, int transition_types, - SceneGraphReducer::AccumulatedTransitions trans, - bool duplicate) { - if (sgraphutil_cat.is_debug()) { - sgraphutil_cat.debug() - << "r_apply_transitions(" << *arc << "), arc's transitions are:\n"; - arc->write_transitions(sgraphutil_cat.debug(false), 2); - } - - if ((transition_types & TT_transform) != 0) { - nassertv(trans._transform != (TransformTransition *)NULL); - TransformTransition *tt; - if (get_transition_into(tt, arc)) { - trans._transform = - DCAST(TransformTransition, trans._transform->compose(tt)); - arc->clear_transition(TransformTransition::get_class_type()); - } - } - - if ((transition_types & TT_color) != 0) { - nassertv(trans._color != (ColorTransition *)NULL); - ColorTransition *ct; - if (get_transition_into(ct, arc)) { - trans._color = - DCAST(ColorTransition, trans._color->compose(ct)); - arc->clear_transition(ColorTransition::get_class_type()); - } - } - - if ((transition_types & TT_texture_matrix) != 0) { - nassertv(trans._texture_matrix != (TexMatrixTransition *)NULL); - TexMatrixTransition *tmt; - if (get_transition_into(tmt, arc)) { - trans._texture_matrix = - DCAST(TexMatrixTransition, trans._texture_matrix->compose(tmt)); - arc->clear_transition(TexMatrixTransition::get_class_type()); - } - } - - if ((transition_types & TT_color_matrix) != 0) { - nassertv(trans._color_matrix != (ColorMatrixTransition *)NULL); - ColorMatrixTransition *cmt; - if (get_transition_into(cmt, arc)) { - trans._color_matrix = - DCAST(ColorMatrixTransition, trans._color_matrix->compose(cmt)); - arc->clear_transition(ColorMatrixTransition::get_class_type()); - } - - nassertv(trans._alpha_transform != (AlphaTransformTransition *)NULL); - AlphaTransformTransition *att; - if (get_transition_into(att, arc)) { - trans._alpha_transform = - DCAST(AlphaTransformTransition, trans._alpha_transform->compose(att)); - arc->clear_transition(AlphaTransformTransition::get_class_type()); - } - } - - PT(Node) node = arc->get_child(); - nassertv(node != (Node *)NULL); - - if (sgraphutil_cat.is_debug()) { - sgraphutil_cat.debug() - << "Applying transitions to " << *node << "\n" - << "Accumulated transitions are:\n"; - trans.write(sgraphutil_cat.debug(false), transition_types, 2); - } - - - if (node->get_num_parents(_graph_type) > 1) { - // This node has multiple instances; we need to duplicate - // everything in the graph from this point down. - duplicate = true; - } - - if (duplicate) { - // Make another copy of the Node. - - if (!node->safe_to_flatten()) { - // Oops! We *can't* flatten below this node. We'll have to stop - // here. Drop transitions onto this arc to reflect what's been - // accumulated so far. - if (sgraphutil_cat.is_debug()) { - sgraphutil_cat.debug() - << "Cannot duplicate nodes of type " << node->get_type() - << "; dropping transitions here and stopping.\n"; - } - - trans.apply_to_arc(arc, transition_types); - return; - } - - PT(Node) new_node = node->make_copy(); - if (new_node->get_type() != node->get_type()) { - sgraphutil_cat.error() - << "Cannot apply transitions to " << *node - << "; don't know how to copy nodes of this type.\n"; - - trans.apply_to_arc(arc, transition_types); - return; - } - - if (sgraphutil_cat.is_debug()) { - sgraphutil_cat.debug() - << "Duplicated " << *node << "\n"; - } - - copy_children(new_node, node); - node = new_node.p(); - arc->change_child(node); - } - - // Check to see if we can't propagate any of these transitions past - // this arc for some reason. A little bit kludgey, since we have to - // know about all the special kinds of transitions, but attempting - // to make this general and also work correctly is kind of tricky. - int apply_types = 0; - if (arc->has_transition(BillboardTransition::get_class_type())) { - if (sgraphutil_cat.is_debug()) { - sgraphutil_cat.debug() - << "Arc " << *arc - << " contains a BillboardTransition; leaving transform here.\n"; - } - apply_types |= TT_transform; - } - if (!node->safe_to_transform()) { - if (sgraphutil_cat.is_debug()) { - sgraphutil_cat.debug() - << "Cannot safely transform nodes of type " << node->get_type() - << "; leaving a transform here but carrying on otherwise.\n"; - } - apply_types |= TT_transform; - } - trans.apply_to_arc(arc, transition_types & apply_types); - - // Now apply what's left to the vertices. - if (node->is_of_type(GeomNode::get_class_type())) { - if (sgraphutil_cat.is_debug()) { - sgraphutil_cat.debug() - << "Transforming geometry.\n"; - } - - // We treat GeomNodes as a special case, since we can apply more - // than just a transform matrix and so we can share vertex arrays - // across different GeomNodes. - GeomNode *gnode = DCAST(GeomNode, node); - if ((transition_types & TT_transform) != 0) { - if (trans._transform->get_matrix() != LMatrix4f::ident_mat()) { - _transformer.transform_vertices(gnode, trans._transform->get_matrix()); - } - } - if ((transition_types & TT_color) != 0) { - if (trans._color->is_on() && trans._color->is_real()) { - _transformer.set_color(gnode, trans._color->get_color()); - } - } - if ((transition_types & TT_texture_matrix) != 0) { - if (trans._texture_matrix->get_matrix() != LMatrix4f::ident_mat()) { - _transformer.transform_texcoords(gnode, - trans._texture_matrix->get_matrix()); - } - } - if ((transition_types & TT_color_matrix) != 0) { - if (trans._color_matrix->get_matrix() != LMatrix4f::ident_mat() || - trans._alpha_transform->get_scale() != 1.0f || - trans._alpha_transform->get_offset() != 0.0f) { - _transformer.transform_colors(gnode, - trans._color_matrix->get_matrix(), - trans._alpha_transform->get_scale(), - trans._alpha_transform->get_offset()); - } - } - - } else { - // This handles any kind of node other than a GeomNode. - if ((transition_types & TT_transform) != 0) { - node->xform(trans._transform->get_matrix()); - } - } - - const DownRelationPointers &drp = - node->find_connection(_graph_type).get_down(); - DownRelationPointers drp_copy = drp; - - DownRelationPointers::const_iterator drpi; - for (drpi = drp_copy.begin(); drpi != drp_copy.end(); ++drpi) { - NodeRelation *child_arc = (*drpi); - r_apply_transitions(child_arc, transition_types, trans, duplicate); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: SceneGraphReducer::consider_siblings -// Access: Protected, Virtual -// Description: Decides whether or not the indicated sibling nodes -// (and their associated arcs) should be collapsed into -// a single node or not. Returns true if the arcs may -// be collapsed, false if they should be kept distinct. -//////////////////////////////////////////////////////////////////// -bool SceneGraphReducer:: -consider_siblings(Node *parent, NodeRelation *arc1, NodeRelation *arc2) { - // We can't collapse siblings with arcs that contain the - // DecalTransition; however, other transitions are OK. - if (arc1->has_transition(DecalTransition::get_class_type())) { - return false; - } - - return GraphReducer::consider_siblings(parent, arc1, arc2); -} - -//////////////////////////////////////////////////////////////////// -// Function: SceneGraphReducer::collapse_nodes -// Access: Protected, Virtual -// Description: Collapses the two nodes into a single node, if -// possible. The 'siblings' flag is true if the two -// nodes are siblings nodes; otherwise, node1 is a -// parent of node2. The return value is the resulting -// node, which may be either one of the source nodes, or -// a new node altogether, or it may be NULL to indicate -// that the collapse operation could not take place. -// -// This function may be extended in a user class to -// handle combining special kinds of nodes. -//////////////////////////////////////////////////////////////////// -Node *SceneGraphReducer:: -collapse_nodes(Node *node1, Node *node2, bool siblings) { - // We can collapse two GeomNodes easily, if they're siblings. If - // they're parent-child, we'd probably better not (it might - // interfere with decaling). - if (node1->is_exact_type(GeomNode::get_class_type()) && - node2->is_exact_type(GeomNode::get_class_type())) { - if (!siblings) { - return (Node *)NULL; - } - } - - return GraphReducer::collapse_nodes(node1, node2, siblings); -} diff --git a/panda/src/sgraphutil/sceneGraphReducer.h b/panda/src/sgraphutil/sceneGraphReducer.h deleted file mode 100644 index 766833f7a7..0000000000 --- a/panda/src/sgraphutil/sceneGraphReducer.h +++ /dev/null @@ -1,89 +0,0 @@ -// Filename: sceneGraphReducer.h -// Created by: drose (22May00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef SCENEGRAPHREDUCER_H -#define SCENEGRAPHREDUCER_H - -#include "pandabase.h" - -#include "graphReducer.h" -#include "typedObject.h" -#include "pointerTo.h" -#include "transformTransition.h" -#include "colorTransition.h" -#include "texMatrixTransition.h" -#include "colorMatrixTransition.h" -#include "alphaTransformTransition.h" -#include "geomTransformer.h" -#include "renderRelation.h" - -class Geom; - -/////////////////////////////////////////////////////////////////// -// Class : SceneGraphReducer -// Description : A specialization on GraphReducer for reducing scene -// graphs. This GraphReducer knows about special kinds -// of nodes like GeomNodes and can combine them -// appropriately. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA SceneGraphReducer : public GraphReducer { -public: - SceneGraphReducer(TypeHandle graph_type = RenderRelation::get_class_type()); - - enum TransitionTypes { - TT_transform = 0x001, - TT_color = 0x002, - TT_texture_matrix = 0x004, - TT_color_matrix = 0x008, - }; - - void apply_transitions(NodeRelation *arc, int transition_types = ~0); - -protected: - class AccumulatedTransitions { - public: - INLINE AccumulatedTransitions(); - INLINE AccumulatedTransitions(const AccumulatedTransitions ©); - INLINE void operator = (const AccumulatedTransitions ©); - - void write(ostream &out, int transition_types, int indent_level) const; - void apply_to_arc(NodeRelation *arc, int transition_types); - - PT(TransformTransition) _transform; - PT(ColorTransition) _color; - PT(TexMatrixTransition) _texture_matrix; - PT(ColorMatrixTransition) _color_matrix; - PT(AlphaTransformTransition) _alpha_transform; - }; - - void r_apply_transitions(NodeRelation *arc, int transition_types, - AccumulatedTransitions trans, - bool duplicate); - - virtual bool consider_siblings(Node *parent, - NodeRelation *arc1, NodeRelation *arc2); - - virtual Node *collapse_nodes(Node *node1, Node *node2, bool siblings); - -private: - GeomTransformer _transformer; -}; - -#include "sceneGraphReducer.I" - -#endif diff --git a/panda/src/sgraphutil/sgraphutil_composite1.cxx b/panda/src/sgraphutil/sgraphutil_composite1.cxx deleted file mode 100644 index 08ae1ce9ae..0000000000 --- a/panda/src/sgraphutil/sgraphutil_composite1.cxx +++ /dev/null @@ -1,6 +0,0 @@ - -#include "appTraverser.cxx" -#include "config_sgraphutil.cxx" -#include "directRenderTraverser.cxx" -#include "frustumCullTraverser.cxx" - diff --git a/panda/src/sgraphutil/sgraphutil_composite2.cxx b/panda/src/sgraphutil/sgraphutil_composite2.cxx deleted file mode 100644 index 61e521b7ba..0000000000 --- a/panda/src/sgraphutil/sgraphutil_composite2.cxx +++ /dev/null @@ -1,5 +0,0 @@ - -#include "get_rel_pos.cxx" -#include "quickRenderTraverser.cxx" -#include "sceneGraphAnalyzer.cxx" -#include "sceneGraphReducer.cxx" diff --git a/panda/src/switchnode/LODNode.I b/panda/src/switchnode/LODNode.I deleted file mode 100644 index a29040d890..0000000000 --- a/panda/src/switchnode/LODNode.I +++ /dev/null @@ -1,124 +0,0 @@ -// Filename: LODNode.I -// Created by: mike (27Sep99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include -#include - -//////////////////////////////////////////////////////////////////// -// Function: LODNode::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE LODNode:: -LODNode(const string &name) : SwitchNodeOne(name) { -} - -//////////////////////////////////////////////////////////////////// -// Function: LODNode::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE LODNode:: -LODNode(const LODNode ©) : - SwitchNodeOne(copy), - _lod(copy._lod) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: LODNode::add_switch -// Access: Public -// Description: Adds a switch range to the LODNode. This implies -// that the corresponding child node has been parented -// to the node. -// -// The sense of in vs. out distances is as if the object -// were coming towards you from far away: it switches -// "in" at the far distance, and switches "out" at the -// close distance. Thus, "in" should be larger than -// "out". -//////////////////////////////////////////////////////////////////// -INLINE void LODNode:: -add_switch(float in, float out) { - _lod._switch_vector.push_back(LODSwitch(in, out)); -} - -//////////////////////////////////////////////////////////////////// -// Function: LODNode::set_switch -// Access: Public -// Description: Changes the switching range of a particular child of -// the LODNode. See add_switch(). -//////////////////////////////////////////////////////////////////// -INLINE bool LODNode:: -set_switch(int index, float in, float out) { - nassertr(index >= 0 && index < (int)_lod._switch_vector.size(), false); - _lod._switch_vector[index].set_range(in, out); - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: LODNode::clear_switches -// Access: Public -// Description: Removes the set of switching ranges for the LODNode, -// presumably in conjunction with removing all of its -// children. See add_switch(). -//////////////////////////////////////////////////////////////////// -INLINE void LODNode:: -clear_switches(void) { - _lod._switch_vector.erase(_lod._switch_vector.begin(), - _lod._switch_vector.end()); -} - -//////////////////////////////////////////////////////////////////// -// Function: LODNode::get_num_switches -// Access: Public -// Description: Returns the number of switch ranges added to the -// LODNode. This should correspond to the number of -// children of the node in order for the LODNode to -// function correctly. -//////////////////////////////////////////////////////////////////// -INLINE int LODNode:: -get_num_switches() const { - return _lod._switch_vector.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: LODNode::get_in -// Access: Public -// Description: Returns the "in" distance of the indicated switch -// range. This should be larger than the "out" distance -// of the same range. -//////////////////////////////////////////////////////////////////// -INLINE float LODNode:: -get_in(int index) const { - nassertr(index >= 0 && index < (int)_lod._switch_vector.size(), 0.0); - return _lod._switch_vector[index].get_in(); -} - -//////////////////////////////////////////////////////////////////// -// Function: LODNode::get_out -// Access: Public -// Description: Returns the "out" distance of the indicated switch -// range. This should be smaller than the "in" distance -// of the same range. -//////////////////////////////////////////////////////////////////// -INLINE float LODNode:: -get_out(int index) const { - nassertr(index >= 0 && index < (int)_lod._switch_vector.size(), 0.0); - return _lod._switch_vector[index].get_out(); -} diff --git a/panda/src/switchnode/LODNode.cxx b/panda/src/switchnode/LODNode.cxx deleted file mode 100644 index dac85d9885..0000000000 --- a/panda/src/switchnode/LODNode.cxx +++ /dev/null @@ -1,170 +0,0 @@ -// Filename: LODNode.cxx -// Created by: mike (09Jan97) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// -#include "LODNode.h" -#include "lensNode.h" -#include "config_switchnode.h" - -#include "graphicsStateGuardian.h" -#include "displayRegion.h" -#include "get_rel_pos.h" -#include "luse.h" -#include "renderRelation.h" -#include "transformTransition.h" -#include "allTransitionsWrapper.h" -#include "nodeTransitionWrapper.h" -#include "renderTraverser.h" -#include "wrt.h" - -//////////////////////////////////////////////////////////////////// -// Static variables -//////////////////////////////////////////////////////////////////// -TypeHandle LODNode::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: LODNode::make_copy -// Access: Public, Virtual -// Description: Returns a newly-allocated Node that is a shallow copy -// of this one. It will be a different Node pointer, -// but its internal data may or may not be shared with -// that of the original Node. No children will be -// copied. -//////////////////////////////////////////////////////////////////// -Node *LODNode:: -make_copy() const { - return new LODNode(*this); -} - - -//////////////////////////////////////////////////////////////////// -// Function: LODNode::xform -// Access: Public, Virtual -// Description: Transforms the contents of this node by the indicated -// matrix, if it means anything to do so. -//////////////////////////////////////////////////////////////////// -void LODNode:: -xform(const LMatrix4f &mat) { - _lod.xform(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: LODNode::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void LODNode:: -output(ostream &out) const { - SwitchNodeOne::output(out); - out << " "; - _lod.output(out); -} - -//////////////////////////////////////////////////////////////////// -// Function: LODNode::compute_switch -// Access: Public, Virtual -// Description: Computes the node's switching properties, to decide -// what children should be visible in the given -// rendering situation. -// -// In the case of an LODNode, this decides which child -// is visible based on the distance from the camera. -//////////////////////////////////////////////////////////////////// -void LODNode:: -compute_switch(RenderTraverser *trav) { - GraphicsStateGuardian *gsg = trav->get_gsg(); - - // First, we have to get the current viewing frustum. This is - // normally the same thing as the current camera, but the - // DisplayRegion may have some override in effect, so we ask the - // DisplayRegion instead of the GSG. - const DisplayRegion *dr = gsg->get_current_display_region(); - LensNode *camera = dr->get_cull_frustum(); - if (camera != (LensNode *)NULL) { - LPoint3f camera_pos(0, 0, 0); - - // Get the LOD center in camera space - LPoint3f LOD_pos; - - NodeTransitionWrapper ntw(TransformTransition::get_class_type()); - wrt(this, trav->begin(), trav->end(), - camera, ntw, RenderRelation::get_class_type()); - const TransformTransition *tt; - if (get_transition_into(tt, ntw)) { - LOD_pos = _lod._center * tt->get_matrix(); - } else { - LOD_pos = _lod._center; - } - - // Determine which child to traverse - int index = _lod.compute_child(camera_pos, LOD_pos); - select_child(index); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: LODNode::register_with_read_factory -// Access: Public, Static -// Description: Tells the BamReader how to create objects of type -// LODNode. -//////////////////////////////////////////////////////////////////// -void LODNode:: -register_with_read_factory() { - BamReader::get_factory()->register_factory(get_class_type(), make_LODNode); -} - -//////////////////////////////////////////////////////////////////// -// Function: LODNode::write_object -// Description: Writes the contents of this object to the datagram -// for shipping out to a Bam file. -//////////////////////////////////////////////////////////////////// -void LODNode:: -write_datagram(BamWriter *manager, Datagram &me) { - SwitchNodeOne::write_datagram(manager, me); - _lod.write_datagram(me); -} - -//////////////////////////////////////////////////////////////////// -// Function: LODNode::make_LODNode -// Access: Protected -// Description: This function is called by the BamReader's factory -// when a new object of type LODNode is encountered in -// the Bam file. It should create the LODNode and -// extract its information from the file. -//////////////////////////////////////////////////////////////////// -TypedWritable *LODNode:: -make_LODNode(const FactoryParams ¶ms) { - LODNode *me = new LODNode; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: LODNode::fillin -// Access: Protected -// Description: This internal function is called by make_LODNode to -// read in all of the relevant data from the BamFile for -// the new LODNode. -//////////////////////////////////////////////////////////////////// -void LODNode:: -fillin(DatagramIterator &scan, BamReader *manager) { - SwitchNodeOne::fillin(scan, manager); - _lod.read_datagram(scan); -} diff --git a/panda/src/switchnode/LODNode.h b/panda/src/switchnode/LODNode.h deleted file mode 100644 index b5722dea58..0000000000 --- a/panda/src/switchnode/LODNode.h +++ /dev/null @@ -1,92 +0,0 @@ -// Filename: LODNode.h -// Created by: mike (09Jan97) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef LODNODE_H -#define LODNODE_H - -#include - -#include "switchNodeOne.h" - -#include - -//////////////////////////////////////////////////////////////////// -// Class : LODNode -// Description : A node that implements level of detail -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA LODNode : public SwitchNodeOne { -PUBLISHED: - INLINE LODNode(const string &name = ""); - -public: - INLINE LODNode(const LODNode ©); - - virtual Node *make_copy() const; - virtual void xform(const LMatrix4f &mat); - -PUBLISHED: - // The sense of in vs. out distances is as if the object were coming - // towards you from far away: it switches "in" at the far distance, - // and switches "out" at the close distance. Thus, "in" should be - // larger than "out". - - INLINE void add_switch(float in, float out); - INLINE bool set_switch(int index, float in, float out); - INLINE void clear_switches(void); - - INLINE int get_num_switches() const; - INLINE float get_in(int index) const; - INLINE float get_out(int index) const; - -public: - virtual void output(ostream &out) const; - virtual void compute_switch(RenderTraverser *trav); - -public: - static void register_with_read_factory(); - virtual void write_datagram(BamWriter *manager, Datagram &me); - - static TypedWritable *make_LODNode(const FactoryParams ¶ms); - -protected: - void fillin(DatagramIterator &scan, BamReader *manager); - -public: - LOD _lod; - -public: - static TypeHandle get_class_type( void ) { - return _type_handle; - } - static void init_type( void ) { - SwitchNodeOne::init_type(); - register_type( _type_handle, "LODNode", - SwitchNodeOne::get_class_type() ); - } - virtual TypeHandle get_type( void ) const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "LODNode.I" - -#endif diff --git a/panda/src/switchnode/Sources.pp b/panda/src/switchnode/Sources.pp deleted file mode 100644 index 30941a05df..0000000000 --- a/panda/src/switchnode/Sources.pp +++ /dev/null @@ -1,37 +0,0 @@ -#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \ - dtoolutil:c dtoolbase:c dtool:m - -#begin lib_target - #define TARGET switchnode - #define LOCAL_LIBS \ - display sgraph graph sgraphutil sgattrib gobj putil gsgbase linmath \ - mathutil - - #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx - - #define SOURCES \ - LODNode.I LODNode.h \ - config_switchnode.h sequenceNode.h \ - switchNodeOne.I switchNodeOne.h - - #define INCLUDED_SOURCES \ - LODNode.cxx config_switchnode.cxx \ - sequenceNode.cxx switchNodeOne.cxx - - #define INSTALL_HEADERS \ - config_switchnode.h LODNode.I LODNode.h sequenceNode.h \ - switchNodeOne.I switchNodeOne.h - - #define IGATESCAN all - -#end lib_target - -#begin test_bin_target - #define TARGET test_sequences - #define LOCAL_LIBS switchnode - - #define SOURCES \ - test_sequences.cxx - -#end test_bin_target - diff --git a/panda/src/switchnode/config_switchnode.cxx b/panda/src/switchnode/config_switchnode.cxx deleted file mode 100644 index 20ab132780..0000000000 --- a/panda/src/switchnode/config_switchnode.cxx +++ /dev/null @@ -1,36 +0,0 @@ -// Filename: config_switchnode.cxx -// Created by: drose (19Jan00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "config_switchnode.h" -#include "LODNode.h" -#include "sequenceNode.h" - -#include - -Configure(config_switchnode); -NotifyCategoryDef(switchnode, ""); - -ConfigureFn(config_switchnode) { - LODNode::init_type(); - SequenceNode::init_type(); - - //Registration of writeable object's creation - //functions with BamReader's factory - LODNode::register_with_read_factory(); - SequenceNode::register_with_read_factory(); -} diff --git a/panda/src/switchnode/config_switchnode.h b/panda/src/switchnode/config_switchnode.h deleted file mode 100644 index 7bc90d434c..0000000000 --- a/panda/src/switchnode/config_switchnode.h +++ /dev/null @@ -1,27 +0,0 @@ -// Filename: config_switchnode.h -// Created by: drose (19Jan00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef CONFIG_SWITCHNODE_H -#define CONFIG_SWITCHNODE_H - -#include -#include - -NotifyCategoryDecl(switchnode, EXPCL_PANDA, EXPTP_PANDA); - -#endif /* CONFIG_SWITCHNODE_H */ diff --git a/panda/src/switchnode/sequenceNode.cxx b/panda/src/switchnode/sequenceNode.cxx deleted file mode 100644 index 62e6895f66..0000000000 --- a/panda/src/switchnode/sequenceNode.cxx +++ /dev/null @@ -1,156 +0,0 @@ -// Filename: sequenceNode.cxx -// Created by: jason (18Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Includes -//////////////////////////////////////////////////////////////////// -#include -#include - -#include "sequenceNode.h" -#include "config_switchnode.h" - -#include -#include -#include -#include - -//////////////////////////////////////////////////////////////////// -// Static variables -//////////////////////////////////////////////////////////////////// -TypeHandle SequenceNode::_type_handle; - -//////////////////////////////////////////////////////////////////// -// Function: SequenceNode::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -SequenceNode:: -SequenceNode(const string &initial_name) : - SwitchNodeOne(initial_name), TimedCycle() -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: SequenceNode::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -SequenceNode:: -SequenceNode(float switch_time, const string &initial_name) : - SwitchNodeOne(initial_name), TimedCycle(switch_time, 0) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: SequenceNode::set_switch_time -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void SequenceNode:: -set_switch_time(float switch_time) -{ - set_cycle_time(switch_time); -} - -//////////////////////////////////////////////////////////////////// -// Function: SequenceNode::make_copy -// Access: Public, Virtual -// Description: Returns a newly-allocated Node that is a shallow copy -// of this one. It will be a different Node pointer, -// but its internal data may or may not be shared with -// that of the original Node. No children will be -// copied. -//////////////////////////////////////////////////////////////////// -Node *SequenceNode:: -make_copy() const { - return new SequenceNode(*this); -} - -//////////////////////////////////////////////////////////////////// -// Function: SequenceNode::compute_switch -// Access: Public, Virtual -// Description: Computes the node's switching properties, to decide -// what children should be visible in the given -// rendering situation. -// -// In the case of a SequenceNode, this simply selects -// the appropriate child based on the elapsed time. -//////////////////////////////////////////////////////////////////// -void SequenceNode:: -compute_switch(RenderTraverser *) { - // Determine which child to traverse - int num_children = get_num_children(RenderRelation::get_class_type()); - set_element_count(num_children); - int index = next_element(); - select_child(index); -} - -//////////////////////////////////////////////////////////////////// -// Function: SequenceNode::write_object -// Description: Writes the contents of this object to the datagram -// for shipping out to a Bam file. -//////////////////////////////////////////////////////////////////// -void SequenceNode:: -write_datagram(BamWriter *manager, Datagram &me) { - SwitchNodeOne::write_datagram(manager, me); - TimedCycle::write_datagram(me); -} - -//////////////////////////////////////////////////////////////////// -// Function: SequenceNode::fillin -// Access: Protected -// Description: This internal function is called by make_SequenceNode to -// read in all of the relevant data from the BamFile for -// the new SequenceNode. -//////////////////////////////////////////////////////////////////// -void SequenceNode:: -fillin(DatagramIterator &scan, BamReader *manager) { - SwitchNodeOne::fillin(scan, manager); - TimedCycle::fillin(scan); -} - -//////////////////////////////////////////////////////////////////// -// Function: SequenceNode::make_SequenceNode -// Access: Protected -// Description: This function is called by the BamReader's factory -// when a new object of type SequenceNode is encountered in -// the Bam file. It should create the SequenceNode and -// extract its information from the file. -//////////////////////////////////////////////////////////////////// -TypedWritable *SequenceNode:: -make_SequenceNode(const FactoryParams ¶ms) { - SequenceNode *me = new SequenceNode; - DatagramIterator scan; - BamReader *manager; - - parse_params(params, scan, manager); - me->fillin(scan, manager); - return me; -} - -//////////////////////////////////////////////////////////////////// -// Function: SequenceNode::register_with_read_factory -// Access: Public, Static -// Description: Tells the BamReader how to create objects of type -// SequenceNode. -//////////////////////////////////////////////////////////////////// -void SequenceNode:: -register_with_read_factory() { - BamReader::get_factory()->register_factory(get_class_type(), make_SequenceNode); -} diff --git a/panda/src/switchnode/sequenceNode.h b/panda/src/switchnode/sequenceNode.h deleted file mode 100644 index 56dd564933..0000000000 --- a/panda/src/switchnode/sequenceNode.h +++ /dev/null @@ -1,74 +0,0 @@ -// Filename: sequenceNode.h -// Created by: jason (18Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef SEQUENCENODE_H -#define SEQUENCENODE_H - -#include - -#include "switchNodeOne.h" - -#include -#include - -//////////////////////////////////////////////////////////////////// -// Class : SequenceNode -// Description : A node that implements the ability to switch out -// what node is rendered based on time -//////////////////////////////////////////////////////////////////// - -class EXPCL_PANDA SequenceNode : public SwitchNodeOne, public TimedCycle -{ -PUBLISHED: - SequenceNode(const string &initial_name = ""); - SequenceNode(float switch_time, const string &initial_name = ""); - - void set_switch_time(float switch_time); - -public: - virtual Node *make_copy() const; - virtual void compute_switch(RenderTraverser *trav); - -public: - static void register_with_read_factory(); - virtual void write_datagram(BamWriter *manager, Datagram &me); - - static TypedWritable *make_SequenceNode(const FactoryParams ¶ms); - -protected: - void fillin(DatagramIterator &scan, BamReader *manager); - -public: - static TypeHandle get_class_type( void ) { - return _type_handle; - } - static void init_type( void ) { - SwitchNodeOne::init_type(); - register_type( _type_handle, "SequenceNode", - SwitchNodeOne::get_class_type() ); - } - virtual TypeHandle get_type( void ) const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#endif diff --git a/panda/src/switchnode/switchNodeOne.I b/panda/src/switchnode/switchNodeOne.I deleted file mode 100644 index ae7e4aadfe..0000000000 --- a/panda/src/switchnode/switchNodeOne.I +++ /dev/null @@ -1,71 +0,0 @@ -// Filename: switchNodeOne.I -// Created by: drose (15May01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: SwitchNodeOne::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE SwitchNodeOne:: -SwitchNodeOne(const string &name) : - SwitchNode(name) -{ - _selected_child_index = 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: SwitchNodeOne::Copy Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE SwitchNodeOne:: -SwitchNodeOne(const SwitchNodeOne ©) : - SwitchNode(copy), - _selected_child_index(copy._selected_child_index) -{ -} - -//////////////////////////////////////////////////////////////////// -// Function: SwitchNodeOne::Copy Assignment Operator -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void SwitchNodeOne:: -operator = (const SwitchNodeOne ©) { - SwitchNode::operator = (copy); - _selected_child_index = copy._selected_child_index; -} - -//////////////////////////////////////////////////////////////////// -// Function: SwitchNodeOne::select_child -// Access: Public -// Description: Indicates the particular child which should be -// visible. -//////////////////////////////////////////////////////////////////// -INLINE void SwitchNodeOne:: -select_child(int index) { - if (switchnode_cat.is_debug()) { - if (_selected_child_index != index) { - switchnode_cat.debug() - << *this << " selecting child " << index << "\n"; - } - } - - _selected_child_index = index; -} diff --git a/panda/src/switchnode/switchNodeOne.cxx b/panda/src/switchnode/switchNodeOne.cxx deleted file mode 100644 index 656a2f7124..0000000000 --- a/panda/src/switchnode/switchNodeOne.cxx +++ /dev/null @@ -1,34 +0,0 @@ -// Filename: switchNodeOne.cxx -// Created by: drose (15May01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "switchNodeOne.h" - -TypeHandle SwitchNodeOne::_type_handle; - - -//////////////////////////////////////////////////////////////////// -// Function: SwitchNodeOne::is_child_visible -// Access: Public, Virtual -// Description: Returns true if the indicated child is one that -// should be considered visible (rendered), false if it -// should be suppressed. -//////////////////////////////////////////////////////////////////// -bool SwitchNodeOne:: -is_child_visible(TypeHandle, int index) { - return (index == _selected_child_index); -} diff --git a/panda/src/switchnode/switchNodeOne.h b/panda/src/switchnode/switchNodeOne.h deleted file mode 100644 index 97bd6ac722..0000000000 --- a/panda/src/switchnode/switchNodeOne.h +++ /dev/null @@ -1,71 +0,0 @@ -// Filename: switchNodeOne.h -// Created by: drose (15May01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef SWITCHNODEONE_H -#define SWITCHNODEONE_H - -#include - -#include -#include "config_switchnode.h" - -class RenderTraverser; -class ArcChain; - -//////////////////////////////////////////////////////////////////// -// Class : SwitchNodeOne -// Description : A specialization on SwitchNode for the common kind of -// switching node that will only select one child of its -// several available. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA SwitchNodeOne : public SwitchNode { -PUBLISHED: - INLINE SwitchNodeOne(const string &name = ""); - INLINE SwitchNodeOne(const SwitchNodeOne ©); - INLINE void operator = (const SwitchNodeOne ©); - -public: - virtual bool is_child_visible(TypeHandle type, int index); - -protected: - INLINE void select_child(int index); - -private: - int _selected_child_index; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - SwitchNode::init_type(); - register_type( _type_handle, "SwitchNodeOne", - SwitchNode::get_class_type() ); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "switchNodeOne.I" - -#endif diff --git a/panda/src/switchnode/switchnode_composite1.cxx b/panda/src/switchnode/switchnode_composite1.cxx deleted file mode 100644 index ac68da40cb..0000000000 --- a/panda/src/switchnode/switchnode_composite1.cxx +++ /dev/null @@ -1,5 +0,0 @@ - -#include "config_switchnode.cxx" -#include "LODNode.cxx" - - diff --git a/panda/src/switchnode/switchnode_composite2.cxx b/panda/src/switchnode/switchnode_composite2.cxx deleted file mode 100644 index ccb96ae159..0000000000 --- a/panda/src/switchnode/switchnode_composite2.cxx +++ /dev/null @@ -1,4 +0,0 @@ - -#include "sequenceNode.cxx" -#include "switchNodeOne.cxx" - diff --git a/panda/src/switchnode/test_sequences.cxx b/panda/src/switchnode/test_sequences.cxx deleted file mode 100644 index cde542cdc6..0000000000 --- a/panda/src/switchnode/test_sequences.cxx +++ /dev/null @@ -1,137 +0,0 @@ -// Filename: test_sequences.cxx -// Created by: -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// -#include -#include - -//Relations (arcs) -#include -#include - -//Misc -#include -#include -#include -#include - -#include - -#include "sequenceNode.h" - -Configure(sequences); -ConfigureFn(sequences) { -} - -//Framework extern variables and functions -extern PT_NamedNode render; -extern RenderRelation* first_arc; -extern PT_NamedNode lights; -extern PT_NamedNode root; -extern PT(GeomNode) geomnode; -extern PT_NamedNode cameras; -extern PT(MouseAndKeyboard) mak; - -extern void set_alt_trackball(Node *trackball); - -extern int framework_main(int argc, char *argv[]); -extern void (*extra_display_func)(); -extern void (*define_keys)(EventHandler&); - -extern PT(GraphicsWindow) main_win; - -//////////////////////////////////////////////////////////////////// -// Function: keys -// Access: Public -// Description: Set event handlers for the various keys needed, and -// do any initialization necessary -//////////////////////////////////////////////////////////////////// -void keys(EventHandler &eh) -{ - PTA_Vertexf c1, c2, c3, c4, c5, c6; - GeomSphere *s1, *s2, *s3, *s4, *s5, *s6; - GeomNode *n1, *n2, *n3, *n4, *n5, *n6; - - s1 = new GeomSphere(); - s2 = new GeomSphere(); - s3 = new GeomSphere(); - s4 = new GeomSphere(); - s5 = new GeomSphere(); - s6 = new GeomSphere(); - - n1 = new GeomNode("Sphere 1"); - n2 = new GeomNode("Sphere 2"); - n3 = new GeomNode("Sphere 3"); - n4 = new GeomNode("Sphere 4"); - n5 = new GeomNode("Sphere 5"); - n6 = new GeomNode("Sphere 6"); - - c1.push_back(Vertexf(0,0,0)); - c1.push_back(Vertexf(0,0,4)); - - c2.push_back(Vertexf(0,0,0)); - c2.push_back(Vertexf(0,0,6)); - - c3.push_back(Vertexf(0,0,0)); - c3.push_back(Vertexf(0,0,8)); - - c4.push_back(Vertexf(0,0,0)); - c4.push_back(Vertexf(0,0,10)); - - c5.push_back(Vertexf(0,0,0)); - c5.push_back(Vertexf(0,0,8)); - - c6.push_back(Vertexf(0,0,0)); - c6.push_back(Vertexf(0,0,6)); - - s1->set_coords(c1, G_PER_VERTEX); - s1->set_num_prims(1); - s2->set_coords(c2, G_PER_VERTEX); - s2->set_num_prims(1); - s3->set_coords(c3, G_PER_VERTEX); - s3->set_num_prims(1); - s4->set_coords(c4, G_PER_VERTEX); - s4->set_num_prims(1); - s5->set_coords(c5, G_PER_VERTEX); - s5->set_num_prims(1); - s6->set_coords(c6, G_PER_VERTEX); - s6->set_num_prims(1); - - n1->add_geom(s1); - n2->add_geom(s2); - n3->add_geom(s3); - n4->add_geom(s4); - n5->add_geom(s5); - n6->add_geom(s6); - - PT_NamedNode sn = DCAST(NamedNode, new SequenceNode(1)); - - new RenderRelation(render, sn); - - new RenderRelation(sn, n1); - new RenderRelation(sn, n2); - new RenderRelation(sn, n3); - new RenderRelation(sn, n4); - new RenderRelation(sn, n5); - new RenderRelation(sn, n6); - - remove_arc(first_arc); -} - -int main(int argc, char *argv[]) { - define_keys = &keys; - return framework_main(argc, argv); -} diff --git a/panda/src/testbed/Sources.pp b/panda/src/testbed/Sources.pp index a6adbb4bd3..b47d1360ea 100644 --- a/panda/src/testbed/Sources.pp +++ b/panda/src/testbed/Sources.pp @@ -2,10 +2,10 @@ dtoolutil:c dtoolbase:c dtool:m pystub #define LOCAL_LIBS \ - framework putil collide loader sgmanip chan text chancfg cull \ - pnmimage pnmimagetypes event effects graph gobj display \ - mathutil sgattrib putil express dgraph device tform sgraph \ - linmath sgraphutil pstatclient panda + framework putil collide loader chan text chancfg \ + pnmimage pnmimagetypes event effects gobj display \ + mathutil putil express dgraph device tform \ + linmath pstatclient panda #if $[LINK_ALL_STATIC] // If we're statically linking, we need to explicitly link with diff --git a/panda/src/text/Sources.pp b/panda/src/text/Sources.pp index 8f6978ba64..495f69894f 100644 --- a/panda/src/text/Sources.pp +++ b/panda/src/text/Sources.pp @@ -6,9 +6,8 @@ #define TARGET text #define LOCAL_LIBS \ - cull putil gobj sgattrib pgraph graph sgraph linmath \ - sgraphutil pnmimage gsgbase \ - mathutil + putil gobj pgraph linmath \ + pnmimage gsgbase mathutil #define COMBINED_SOURCES $[TARGET]_composite1.cxx @@ -22,7 +21,6 @@ stringDecoder.I stringDecoder.h \ textFont.I textFont.h \ textGlyph.I textGlyph.h \ - textNode.I textNode.h textNode.cxx \ qptextNode.I qptextNode.h qptextNode.cxx #define INCLUDED_SOURCES \ @@ -45,7 +43,6 @@ stringDecoder.I stringDecoder.h \ textFont.I textFont.h \ textGlyph.I textGlyph.h \ - textNode.I textNode.h \ qptextNode.I qptextNode.h #define IGATESCAN all diff --git a/panda/src/text/config_text.cxx b/panda/src/text/config_text.cxx index 7a6fa3eeee..689679fc5d 100644 --- a/panda/src/text/config_text.cxx +++ b/panda/src/text/config_text.cxx @@ -19,7 +19,6 @@ #include "config_text.h" #include "staticTextFont.h" #include "textFont.h" -#include "textNode.h" #include "qptextNode.h" #include "dynamicTextFont.h" #include "dynamicTextPage.h" @@ -68,7 +67,6 @@ init_libtext() { StaticTextFont::init_type(); TextFont::init_type(); - TextNode::init_type(); qpTextNode::init_type(); #ifdef HAVE_FREETYPE @@ -80,13 +78,10 @@ init_libtext() { string text_encoding = config_text.GetString("text-encoding", "iso8859"); if (text_encoding == "iso8859") { - TextNode::_default_encoding = TextNode::E_iso8859; qpTextNode::_default_encoding = qpTextNode::E_iso8859; } else if (text_encoding == "utf8") { - TextNode::_default_encoding = TextNode::E_utf8; qpTextNode::_default_encoding = qpTextNode::E_utf8; } else if (text_encoding == "unicode") { - TextNode::_default_encoding = TextNode::E_unicode; qpTextNode::_default_encoding = qpTextNode::E_unicode; } else { text_cat.error() diff --git a/panda/src/text/dynamicTextGlyph.cxx b/panda/src/text/dynamicTextGlyph.cxx index 21517e16b2..5b6110e5c7 100644 --- a/panda/src/text/dynamicTextGlyph.cxx +++ b/panda/src/text/dynamicTextGlyph.cxx @@ -25,8 +25,6 @@ #include "textureAttrib.h" #include "transparencyAttrib.h" #include "renderState.h" -#include "textureTransition.h" -#include "transparencyTransition.h" //////////////////////////////////////////////////////////////////// // Function: DynamicTextGlyph::Destructor @@ -161,12 +159,6 @@ make_geom(int bitmap_top, int bitmap_left, _geom->set_lengths(lengths); _geom->set_num_prims(1); - TextureTransition *tex = new TextureTransition(_page); - TransparencyTransition *trans = new TransparencyTransition(TransparencyProperty::M_alpha); - - _trans.set_transition(tex); - _trans.set_transition(trans); - _state = RenderState::make(TextureAttrib::make(_page), TransparencyAttrib::make(TransparencyAttrib::M_alpha)); diff --git a/panda/src/text/staticTextFont.cxx b/panda/src/text/staticTextFont.cxx index 770e915049..a466cd7eb6 100644 --- a/panda/src/text/staticTextFont.cxx +++ b/panda/src/text/staticTextFont.cxx @@ -24,34 +24,8 @@ #include "qpgeomNode.h" #include "renderState.h" -#include "geomNode.h" -#include "namedNode.h" -#include "renderRelation.h" - TypeHandle StaticTextFont::_type_handle; -//////////////////////////////////////////////////////////////////// -// Function: StaticTextFont::Constructor -// Access: Published -// Description: The constructor expects the root node to a model -// generated via egg-mkfont, which consists of a set of -// models, one per each character in the font. -//////////////////////////////////////////////////////////////////// -StaticTextFont:: -StaticTextFont(Node *font_def) { - nassertv(font_def != (Node *)NULL); - _font = font_def; - _glyphs.clear(); - - find_characters(font_def); - _is_valid = !_glyphs.empty(); - - if (_font->is_of_type(NamedNode::get_class_type())) { - NamedNode *named_node = DCAST(NamedNode, _font); - set_name(named_node->get_name()); - } -} - //////////////////////////////////////////////////////////////////// // Function: StaticTextFont::Constructor // Access: Published @@ -201,126 +175,6 @@ get_glyph(int character, const TextGlyph *&glyph, float &glyph_scale) { return true; } -//////////////////////////////////////////////////////////////////// -// Function: StaticTextFont::find_character_gsets -// Access: Private -// Description: Given that 'root' is a Node containing at least a -// polygon and a point which define the character's -// appearance and kern position, respectively, -// recursively walk the hierarchy and root and locate -// those two Geoms. -//////////////////////////////////////////////////////////////////// -bool StaticTextFont:: -find_character_gsets(Node *root, Geom *&ch, GeomPoint *&dot, - AllTransitionsWrapper &trans) { - if (root->is_of_type(GeomNode::get_class_type())) { - GeomNode *geode = (GeomNode *)root; - - bool found = false; - for (int i = 0; i < geode->get_num_geoms(); i++) { - dDrawable *geom = geode->get_geom(i); - if (geom->is_of_type(GeomPoint::get_class_type())) { - dot = DCAST(GeomPoint, geom); - - } else if (geom->is_of_type(Geom::get_class_type())) { - ch = DCAST(Geom, geom); - found = true; - } - } - return found; - - } else { - TypeHandle graph_type = RenderRelation::get_class_type(); - int num_children = root->get_num_children(graph_type); - for (int i = 0; i < num_children; i++) { - NodeRelation *child_arc = root->get_child(graph_type, i); - if (find_character_gsets(child_arc->get_child(), ch, dot, trans)) { - trans.extract_from(child_arc); - } - } - return false; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: StaticTextFont::find_characters -// Access: Private -// Description: Walk the hierarchy beginning at the indicated root -// and locate any nodes whose names are just integers. -// These are taken to be characters, and their -// definitions and kern informations are retrieved. -//////////////////////////////////////////////////////////////////// -void StaticTextFont:: -find_characters(Node *root) { - string name; - if (root->is_of_type(NamedNode::get_class_type())) { - name = DCAST(NamedNode, root)->get_name(); - } - - bool all_digits = !name.empty(); - const char *p = name.c_str(); - while (all_digits && *p != '\0') { - // VC++ complains if we treat an int as a bool, so we have to do - // this != 0 comparsion on the int isdigit() function to shut it - // up. - all_digits = (isdigit(*p) != 0); - p++; - } - - if (all_digits) { - int character = atoi(name.c_str()); - Geom *ch = NULL; - GeomPoint *dot = NULL; - AllTransitionsWrapper trans; - find_character_gsets(root, ch, dot, trans); - if (dot != NULL) { - // Get the first vertex from the "dot" geoset. This will be the - // origin of the next character. - PTA_Vertexf alist; - PTA_ushort ilist; - float width; - dot->get_coords(alist, ilist); - if (ilist.empty()) { - width = alist[0][0]; - } else { - width = alist[ilist[0]][0]; - } - - _glyphs[character] = new TextGlyph(ch, trans, width); - } - - } else if (name == "ds") { - // The group "ds" is a special node that indicate's the font's - // design size, or line height. - - Geom *ch = NULL; - GeomPoint *dot = NULL; - AllTransitionsWrapper trans; - find_character_gsets(root, ch, dot, trans); - if (dot != NULL) { - // Get the first vertex from the "dot" geoset. This will be the - // design size indicator. - PTA_Vertexf alist; - PTA_ushort ilist; - dot->get_coords(alist, ilist); - if (ilist.empty()) { - _line_height = alist[0][2]; - } else { - _line_height = alist[ilist[0]][2]; - } - _space_advance = 0.25f * _line_height; - } - - } else { - TypeHandle graph_type = RenderRelation::get_class_type(); - int num_children = root->get_num_children(graph_type); - for (int i = 0; i < num_children; i++) { - NodeRelation *child_arc = root->get_child(graph_type, i); - find_characters(child_arc->get_child()); - } - } -} - //////////////////////////////////////////////////////////////////// // Function: StaticTextFont::find_character_gsets // Access: Private diff --git a/panda/src/text/staticTextFont.h b/panda/src/text/staticTextFont.h index 464d6d48d2..347aa3b89e 100644 --- a/panda/src/text/staticTextFont.h +++ b/panda/src/text/staticTextFont.h @@ -24,7 +24,6 @@ #include "config_text.h" #include "textFont.h" #include "textGlyph.h" -#include "pt_Node.h" #include "pandaNode.h" #include "pointerTo.h" #include "pmap.h" @@ -43,7 +42,6 @@ class GeomPoint; //////////////////////////////////////////////////////////////////// class EXPCL_PANDA StaticTextFont : public TextFont { PUBLISHED: - StaticTextFont(Node *font_def); StaticTextFont(PandaNode *font_def); virtual void write(ostream &out, int indent_level) const; @@ -53,9 +51,6 @@ public: float &glyph_scale); private: - bool find_character_gsets(Node *root, Geom *&ch, GeomPoint *&dot, - AllTransitionsWrapper &trans); - void find_characters(Node *root); void find_character_gsets(PandaNode *root, Geom *&ch, GeomPoint *&dot, const RenderState *&state, const RenderState *net_state); @@ -65,7 +60,6 @@ private: typedef pmap Glyphs; Glyphs _glyphs; float _font_height; - PT_Node _font; PT(PandaNode) _qpfont; public: diff --git a/panda/src/text/textGlyph.I b/panda/src/text/textGlyph.I index 3e80b1c490..3c765774a9 100644 --- a/panda/src/text/textGlyph.I +++ b/panda/src/text/textGlyph.I @@ -28,18 +28,6 @@ TextGlyph() { _advance = 0.0f; } -//////////////////////////////////////////////////////////////////// -// Function: TextGlyph::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TextGlyph:: -TextGlyph(Geom *geom, const AllTransitionsWrapper &trans, float advance) : - _geom(geom), _trans(trans), _advance(advance) -{ - _state = RenderState::make_empty(); -} - //////////////////////////////////////////////////////////////////// // Function: TextGlyph::Constructor // Access: Public @@ -62,7 +50,6 @@ TextGlyph(Geom *geom, const RenderState *state, float advance) : INLINE TextGlyph:: TextGlyph(const TextGlyph ©) : _geom(copy._geom), - _trans(copy._trans), _state(copy._state), _advance(copy._advance) { @@ -76,22 +63,10 @@ TextGlyph(const TextGlyph ©) : INLINE void TextGlyph:: operator = (const TextGlyph ©) { _geom = copy._geom; - _trans = copy._trans; _state = copy._state; _advance = copy._advance; } -//////////////////////////////////////////////////////////////////// -// Function: TextGlyph::get_trans -// Access: Public -// Description: Returns the state transitions that should be applied -// to the glyph geometry to render it correctly. -//////////////////////////////////////////////////////////////////// -INLINE const AllTransitionsWrapper &TextGlyph:: -get_trans() const { - return _trans; -} - //////////////////////////////////////////////////////////////////// // Function: TextGlyph::get_state // Access: Public diff --git a/panda/src/text/textGlyph.h b/panda/src/text/textGlyph.h index 283b2df74d..39a7519fbc 100644 --- a/panda/src/text/textGlyph.h +++ b/panda/src/text/textGlyph.h @@ -20,14 +20,11 @@ #define TEXTGLYPH_H #include "pandabase.h" -#include "allTransitionsWrapper.h" #include "renderState.h" #include "referenceCount.h" #include "geom.h" #include "pointerTo.h" -class TextGlyph; - //////////////////////////////////////////////////////////////////// // Class : TextGlyph // Description : A representation of a single glyph (character) from a @@ -37,20 +34,17 @@ class TextGlyph; class EXPCL_PANDA TextGlyph : public ReferenceCount { public: INLINE TextGlyph(); - INLINE TextGlyph(Geom *geom, const AllTransitionsWrapper &trans, float advance); INLINE TextGlyph(Geom *geom, const RenderState *state, float advance); INLINE TextGlyph(const TextGlyph ©); INLINE void operator = (const TextGlyph ©); virtual ~TextGlyph(); virtual PT(Geom) get_geom() const; - INLINE const AllTransitionsWrapper &get_trans() const; INLINE const RenderState *get_state() const; INLINE float get_advance() const; protected: PT(Geom) _geom; - AllTransitionsWrapper _trans; CPT(RenderState) _state; float _advance; }; diff --git a/panda/src/text/textNode.I b/panda/src/text/textNode.I deleted file mode 100644 index 496c9f56a2..0000000000 --- a/panda/src/text/textNode.I +++ /dev/null @@ -1,1295 +0,0 @@ -// Filename: textNode.I -// Created by: mike (04Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::freeze -// Access: Published -// Description: Freezes the TextNode in its current state, so that -// updates will not immediately be displayed. A series -// of state changes may then be applied in succession, -// which will not force the TextNode to be recomputed. -// When thaw() is later called, the TextNode will update -// itself exactly once to reflect all the state changes -// that were made. -// -// freeze() and thaw() can nest. Strictly speaking, -// each call to freeze() increments the current freeze -// level, while each call to thaw() decrements it. The -// TextNode will only be updated when the current freeze -// level is zero. -// -// The return value of freeze() is the freeze level -// *before* the freeze took place. This number should -// match the return value of the matching thaw(). -//////////////////////////////////////////////////////////////////// -INLINE int TextNode:: -freeze() { - if (text_cat.is_debug()) { - text_cat.debug() - << "Freezing " << this->get_name() << ", level = " - << _freeze_level << "\n"; - } - return _freeze_level++; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_freeze_level -// Access: Published -// Description: Returns the current freeze level. The TextNode will -// not be updated visually unless this number is zero. -// See freeze(). -//////////////////////////////////////////////////////////////////// -INLINE int TextNode:: -get_freeze_level() const { - return _freeze_level; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::thaw -// Access: Published -// Description: Allows changes made since the last freeze() to be -// visible. Strictly speaking, this actually decrements -// the freeze level, and updates the TextNode if the -// level reaches zero. The return value is the new -// freeze level after adjusting. See freeze(). -//////////////////////////////////////////////////////////////////// -INLINE int TextNode:: -thaw() { - if (text_cat.is_debug()) { - text_cat.debug() - << "Thawing " << this->get_name() << ", level = " - << _freeze_level-1 << "\n"; - } - nassertr(_freeze_level > 0, _freeze_level); - _freeze_level--; - - if (_freeze_level == 0 && _needs_rebuild) { - do_rebuild(); - } - - return _freeze_level; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_font -// Access: Published -// Description: Sets the font that will be used when making text. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_font(TextFont *font) { - if (_font != font) { - _font = font; - rebuild(true); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_font -// Access: Published -// Description: Returns the font currently in use. -//////////////////////////////////////////////////////////////////// -INLINE TextFont *TextNode:: -get_font() const { - return _font; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_encoding -// Access: Published -// Description: Specifies how the string set via set_text() is to be -// interpreted. The default, E_iso8859, means a -// standard string with one-byte characters -// (i.e. ASCII). Other encodings are possible to take -// advantage of character sets with more than 256 -// characters. -// -// This affects only future calls to set_text(); it does -// not change text that was set previously. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_encoding(TextNode::Encoding encoding) { - _encoding = encoding; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_encoding -// Access: Published -// Description: Returns the encoding by which the string set via -// set_text() is to be interpreted. See set_encoding(). -//////////////////////////////////////////////////////////////////// -INLINE TextNode::Encoding TextNode:: -get_encoding() const { - return _encoding; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_expand_amp -// Access: Published -// Description: Sets the state of the expand_amp flag. When this is -// true, embedded ampersands in the text string are -// expanded to special characters according to a subset -// of the HTML conventions. When this is false, -// ampersands are treated as ordinary characters. -// -// This affects only future calls to set_text(); it does -// not change text that was set previously. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_expand_amp(bool expand_amp) { - if (expand_amp) { - _flags |= F_expand_amp; - } else { - _flags &= ~F_expand_amp; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_expand_amp -// Access: Published -// Description: Returns the state of the expand_amp flag. See -// set_expand_amp(). -//////////////////////////////////////////////////////////////////// -INLINE bool TextNode:: -get_expand_amp() const { - return (_flags & F_expand_amp) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_line_height -// Access: Published -// Description: Returns the number of units high each line of text -// is. This is based on the font. -//////////////////////////////////////////////////////////////////// -INLINE float TextNode:: -get_line_height() const { - return (_font == (TextFont *)NULL) ? 0.0 : _font->get_line_height(); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_slant -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_slant(float slant) { - if (_slant != slant) { - _slant = slant; - rebuild(true); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_slant -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE float TextNode:: -get_slant() const { - return _slant; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_align -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_align(TextNode::Alignment align_type) { - if (_align != align_type) { - _align = align_type; - rebuild(true); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_align -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE TextNode::Alignment TextNode:: -get_align() const { - return _align; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_wordwrap -// Access: Published -// Description: Sets the TextNode up to automatically wordwrap text -// that exceeds the indicated width. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_wordwrap(float wordwrap) { - if (!has_wordwrap() || _wordwrap_width != wordwrap) { - _flags |= F_has_wordwrap; - _wordwrap_width = wordwrap; - rebuild(true); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::clear_wordwrap -// Access: Published -// Description: Removes the wordwrap setting from the TextNode. Text -// will be as wide as it is. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -clear_wordwrap() { - if (has_wordwrap()) { - _flags &= ~F_has_wordwrap; - rebuild(true); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::has_wordwrap -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool TextNode:: -has_wordwrap() const { - return (_flags & F_has_wordwrap) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_wordwrap -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE float TextNode:: -get_wordwrap() const { - return _wordwrap_width; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_text_color -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_text_color(float r, float g, float b, float a) { - set_text_color(Colorf(r, g, b, a)); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_text_color -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_text_color(const Colorf &text_color) { - if (!has_text_color() || _text_color != text_color) { - _text_color = text_color; - _flags |= F_has_text_color; - rebuild(false); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::clear_text_color -// Access: Published -// Description: Removes the text color specification; the text will -// be colored whatever it was in the source font file. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -clear_text_color() { - if (has_text_color()) { - _flags &= ~F_has_text_color; - rebuild(false); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::has_text_color -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool TextNode:: -has_text_color() const { - return (_flags & F_has_text_color) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_text_color -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE Colorf TextNode:: -get_text_color() const { - return _text_color; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_frame_color -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_frame_color(float r, float g, float b, float a) { - set_frame_color(Colorf(r, g, b, a)); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_frame_color -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_frame_color(const Colorf &frame_color) { - if (_frame_color != frame_color) { - _frame_color = frame_color; - rebuild(false); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_frame_color -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE Colorf TextNode:: -get_frame_color() const { - return _frame_color; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_card_border -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_card_border(float size, float uv_portion) { - if (!has_card_border() || _card_border_size != size || _card_border_uv_portion != uv_portion) { - _flags |= F_has_card_border; - _card_border_size = size; - _card_border_uv_portion = uv_portion; - rebuild(false); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::clear_card_border -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -clear_card_border() { - if (has_card_border()) { - _flags &= ~F_has_card_border; - rebuild(false); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_card_border_size -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE float TextNode:: -get_card_border_size() const { - return _card_border_size; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_card_border_uv_portion -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE float TextNode:: -get_card_border_uv_portion() const { - return _card_border_uv_portion; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::has_card_border -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool TextNode:: -has_card_border() const { - return (_flags & F_has_card_border) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_card_color -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_card_color(float r, float g, float b, float a) { - set_card_color(Colorf(r, g, b, a)); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_card_color -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_card_color(const Colorf &card_color) { - if (_card_color != card_color) { - _card_color = card_color; - rebuild(false); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_card_color -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE Colorf TextNode:: -get_card_color() const { - return _card_color; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_card_texture -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_card_texture(Texture *card_texture) { - if (card_texture == (Texture *)NULL) { - clear_card_texture(); - } else { - if (!has_card_texture() || _card_texture != card_texture) { - _flags |= F_has_card_texture; - _card_texture = card_texture; - rebuild(false); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::clear_card_texture -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -clear_card_texture() { - if (has_card_texture()) { - _flags &= ~F_has_card_texture; - _card_texture = NULL; - rebuild(false); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::has_card_texture -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool TextNode:: -has_card_texture() const { - return (_flags & F_has_card_texture) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_card_texture -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE Texture *TextNode:: -get_card_texture() const { - return _card_texture; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_shadow_color -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_shadow_color(float r, float g, float b, float a) { - set_shadow_color(Colorf(r, g, b, a)); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_shadow_color -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_shadow_color(const Colorf &shadow_color) { - if (_shadow_color != shadow_color) { - _shadow_color = shadow_color; - rebuild(false); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_shadow_color -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE Colorf TextNode:: -get_shadow_color() const { - return _shadow_color; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_frame_as_margin -// Access: Published -// Description: Specifies that a border will be drawn around the text -// when it is next created. The parameters are the -// amount of additional padding to insert between the -// frame and the text in each dimension, and all should -// generally be positive. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_frame_as_margin(float left, float right, float bottom, float top) { - _flags |= (F_has_frame | F_frame_as_margin); - _frame_ul.set(left, top); - _frame_lr.set(right, bottom); - rebuild(false); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_frame_actual -// Access: Published -// Description: Similar to set_frame_as_margin, except the frame is -// specified in actual coordinate units (relative to -// the text's origin), irrespective of the size of the -// text. The left and bottom coordinates should -// generally be negative, while the right and top -// coordinates should generally be positive. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_frame_actual(float left, float right, float bottom, float top) { - _flags |= F_has_frame; - _flags &= ~F_frame_as_margin; - _frame_ul.set(left, top); - _frame_lr.set(right, bottom); - rebuild(false); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::clear_frame -// Access: Published -// Description: Specifies that a border will not be drawn around the -// text. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -clear_frame() { - _flags &= ~F_has_frame; - rebuild(false); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::has_frame -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool TextNode:: -has_frame() const { - return (_flags & F_has_frame) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::is_frame_as_margin -// Access: Published -// Description: If this is true, the frame was set via a call to -// set_frame_as_margin(), and the dimension of the frame -// as returned by get_frame_as_set() represent a margin -// all around the text. If false, then the frame was -// set via a call to set_frame_actual(), and the -// dimensions of the frame as returned by -// get_frame_as_set() are relative to the text's origin. -//////////////////////////////////////////////////////////////////// -INLINE bool TextNode:: -is_frame_as_margin() const { - nassertr(has_frame(), false); - return (_flags & F_frame_as_margin) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_frame_as_set -// Access: Published -// Description: Returns the dimensions of the frame as set by -// set_frame_as_margin() or set_frame_actual(). Use -// is_frame_actual() to determine how to interpret the -// values returned by this function. It is an error to -// call this if has_frame() is false. -//////////////////////////////////////////////////////////////////// -INLINE LVecBase4f TextNode:: -get_frame_as_set() const { - nassertr(has_frame(), LVecBase4f(0.0, 0.0, 0.0, 0.0)); - return LVecBase4f(_frame_ul[0], _frame_lr[0], _frame_lr[1], _frame_ul[1]); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_frame_actual -// Access: Published -// Description: Returns the actual dimensions of the frame around the -// text. If the frame was set via set_frame_as_margin(), -// the result returned by this function reflects the -// size of the current text; if the frame was set via -// set_frame_actual(), this returns the values -// actually set. -//////////////////////////////////////////////////////////////////// -INLINE LVecBase4f TextNode:: -get_frame_actual() const { - nassertr(has_frame(), LVecBase4f(0.0, 0.0, 0.0, 0.0)); - if (is_frame_as_margin()) { - return LVecBase4f(get_left() - _frame_ul[0], - get_right() + _frame_lr[0], - get_bottom() - _frame_lr[1], - get_top() + _frame_ul[1]); - } else { - return get_frame_as_set(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_frame_line_width -// Access: Published -// Description: Specifies the thickness of the lines that will be -// used to draw the frame. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_frame_line_width(float frame_width) { - _frame_width = frame_width; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_frame_line_width -// Access: Published -// Description: Returns the thickness of the lines that will be -// used to draw the frame. -//////////////////////////////////////////////////////////////////// -INLINE float TextNode:: -get_frame_line_width() const { - return _frame_width; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_frame_corners -// Access: Published -// Description: Enables or disables the drawing of corners for the -// frame. These are extra points drawn at each of the -// four corners, to soften the ugly edges generated when -// the line width is greater than one. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_frame_corners(bool corners) { - if (corners) { - _flags |= F_frame_corners; - } else { - _flags &= ~F_frame_corners; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_frame_corners -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool TextNode:: -get_frame_corners() const { - return (_flags & F_frame_corners) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_card_as_margin -// Access: Published -// Description: Specifies that a (possibly opaque or semitransparent) -// card will be held behind the text when it is next -// created. Like set_frame_as_margin, the parameters are -// the amount of additional padding to insert around the -// text in each dimension, and all should generally be -// positive. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_card_as_margin(float left, float right, float bottom, float top) { - _flags |= (F_has_card | F_card_as_margin); - _card_ul.set(left, top); - _card_lr.set(right, bottom); - rebuild(false); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_card_actual -// Access: Published -// Description: Similar to set_card_as_margin, except the card is -// specified in actual coordinate units (relative to -// the text's origin), irrespective of the size of the -// text. The left and bottom coordinates should -// generally be negative, while the right and top -// coordinates should generally be positive. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_card_actual(float left, float right, float bottom, float top) { - _flags |= F_has_card; - _flags &= ~F_card_as_margin; - _card_ul.set(left, top); - _card_lr.set(right, bottom); - rebuild(false); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::clear_card -// Access: Published -// Description: Specifies that a card will not be drawn behind the -// text. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -clear_card() { - _flags &= ~F_has_card; - rebuild(false); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::has_card -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool TextNode:: -has_card() const { - return (_flags & F_has_card) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::is_card_as_margin -// Access: Published -// Description: If this is true, the card was set via a call to -// set_card_as_margin(), and the dimension of the card -// as returned by get_card_as_set() represent a margin -// all around the text. If false, then the card was -// set via a call to set_card_actual(), and the -// dimensions of the card as returned by -// get_card_as_set() are relative to the text's origin. -//////////////////////////////////////////////////////////////////// -INLINE bool TextNode:: -is_card_as_margin() const { - nassertr(has_card(), false); - return (_flags & F_card_as_margin) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_card_as_set -// Access: Published -// Description: Returns the dimensions of the card as set by -// set_card_as_margin() or set_card_actual(). Use -// is_card_actual() to determine how to interpret the -// values returned by this function. It is an error to -// call this if has_card() is false. -//////////////////////////////////////////////////////////////////// -INLINE LVecBase4f TextNode:: -get_card_as_set() const { - nassertr(has_card(), LVecBase4f(0.0, 0.0, 0.0, 0.0)); - return LVecBase4f(_card_ul[0], _card_lr[0], _card_lr[1], _card_ul[1]); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_card_actual -// Access: Published -// Description: Returns the actual dimensions of the card around the -// text. If the card was set via set_card_as_margin(), -// the result returned by this function reflects the -// size of the current text; if the card was set via -// set_card_actual(), this returns the values -// actually set. -// -// If the text has no card at all, this returns the -// dimensions of the text itself, as if the card were -// set with a margin of 0, 0, 0, 0. -//////////////////////////////////////////////////////////////////// -INLINE LVecBase4f TextNode:: -get_card_actual() const { - if (!has_card()) { - return LVecBase4f(get_left(), get_right(), get_bottom(), get_top()); - - } else if (is_card_as_margin()) { - return LVecBase4f(get_left() - _card_ul[0], - get_right() + _card_lr[0], - get_bottom() - _card_lr[1], - get_top() + _card_ul[1]); - } else { - return get_card_as_set(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_card_transformed -// Access: Published -// Description: Returns the actual card dimensions, transformed by -// the matrix set by set_transform(). This returns the -// card dimensions in actual coordinates as seen by the -// rest of the world. Also see get_upper_left_3d() and -// get_lower_right_3d(). -//////////////////////////////////////////////////////////////////// -INLINE LVecBase4f TextNode:: -get_card_transformed() const { - LVecBase4f card = get_card_actual(); - LPoint3f ul = LPoint3f(card[0], 0.0, card[3]) * _transform; - LPoint3f lr = LPoint3f(card[1], 0.0, card[2]) * _transform; - - return LVecBase4f(ul[0], lr[0], lr[2], ul[2]); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_shadow -// Access: Published -// Description: Specifies that the text should be drawn with a -// shadow, by creating a second copy of the text and -// offsetting it slightly behind the first. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_shadow(float xoffset, float yoffset) { - _flags |= F_has_shadow; - _shadow_offset.set(xoffset, yoffset); - rebuild(false); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::clear_shadow -// Access: Published -// Description: Specifies that a shadow will not be drawn behind the -// text. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -clear_shadow() { - _flags &= ~F_has_shadow; - rebuild(false); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::has_shadow -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool TextNode:: -has_shadow() const { - return (_flags & F_has_shadow) != 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_shadow -// Access: Published -// Description: Returns the offset of the shadow as set by -// set_shadow(). It is an error to call this if -// has_shadow() is false. -//////////////////////////////////////////////////////////////////// -INLINE LVecBase2f TextNode:: -get_shadow() const { - nassertr(has_shadow(), LVecBase2f(0.0, 0.0)); - return _shadow_offset; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_bin -// Access: Published -// Description: Names the GeomBin that the TextNode geometry should -// be assigned to. If this is set, then a -// GeomBinTransition will be created to explicitly place -// each component in the named bin. -// -// The draw_order value will also be passed to each -// GeomBinTransition as appropriate; this is -// particularly useful if this names a GeomBinFixed, -// e.g. "fixed". -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_bin(const string &bin) { - _bin = bin; - rebuild(false); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::clear_bin -// Access: Published -// Description: Removes the effect of a previous call to -// set_bin(). Text will be drawn in whatever bin -// it would like to be drawn in, with no explicit -// ordering. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -clear_bin() { - _bin = string(); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::has_bin -// Access: Published -// Description: Returns true if an explicit drawing bin has been -// set via set_bin(), false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool TextNode:: -has_bin() const { - return !_bin.empty(); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_bin -// Access: Published -// Description: Returns the drawing bin set with set_bin(), or empty -// string if no bin has been set. -//////////////////////////////////////////////////////////////////// -INLINE const string &TextNode:: -get_bin() const { - return _bin; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_draw_order -// Access: Published -// Description: Sets the drawing order of text created by the -// TextMaker. This is actually the draw order of the -// card and frame. The shadow is drawn at -// _draw_order+1, and the text at _draw_order+2. -// -// This affects the sorting order assigned to the arcs -// as they are created, and also is passed to whatever -// bin may be assigned via set_bin(). -// -// The return value is the first unused draw_order -// number, e.g. _draw_order + 3. -//////////////////////////////////////////////////////////////////// -INLINE int TextNode:: -set_draw_order(int draw_order) { - _draw_order = draw_order; - rebuild(false); - return _draw_order + 3; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_draw_order -// Access: Published -// Description: Returns the drawing order set with set_draw_order(). -//////////////////////////////////////////////////////////////////// -INLINE int TextNode:: -get_draw_order() const { - return _draw_order; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_transform -// Access: Published -// Description: Sets an additional transform that is applied to the -// entire text paragraph. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_transform(const LMatrix4f &transform) { - _transform = transform; - rebuild(true); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_transform -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE LMatrix4f TextNode:: -get_transform() const { - return _transform; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_coordinate_system -// Access: Published -// Description: Specifies the coordinate system in which the text -// will be generated. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_coordinate_system(CoordinateSystem coordinate_system) { - _coordinate_system = coordinate_system; - rebuild(true); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_coordinate_system -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE CoordinateSystem TextNode:: -get_coordinate_system() const { - return _coordinate_system; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_text -// Access: Published -// Description: Changes the text that is displayed under the -// TextNode. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_text(const string &text) { - _text = text; - _wtext = decode_text(text); - rebuild(true); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::clear_text -// Access: Published -// Description: Removes the text from the TextNode. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -clear_text() { - _text = ""; - rebuild(true); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::has_text -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE bool TextNode:: -has_text() const { - return !_text.empty(); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_text -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -INLINE string TextNode:: -get_text() const { - return _text; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::calc_width -// Access: Published -// Description: Returns the width of a single character of the font, -// or 0.0 if the character is not known. -//////////////////////////////////////////////////////////////////// -INLINE float TextNode:: -calc_width(int character) const { - nassertr(_font != (TextFont *)NULL, 0.0); - return _font->calc_width(character); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::calc_width -// Access: Published -// Description: Returns the width of a line of text of arbitrary -// characters. The line should not include the newline -// character. -//////////////////////////////////////////////////////////////////// -INLINE float TextNode:: -calc_width(const string &line) const { - nassertr(_font != (TextFont *)NULL, 0.0); - return _font->calc_width(decode_text(line)); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::rebuild -// Access: Published -// Description: Updates the TextNode, if it is not frozen, or marks -// the TextNode as requiring an update if it is. If the -// text is currently frozen, nothing will be done until -// it is thawed, unless needs_measure is true, in which -// case the text will be re-measured even if it is -// currently frozen. -// -// Normally, this function is called automatically -// whenever any of the parameters changes. It should -// not need to be called explicitly unless something -// goes wrong. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -rebuild(bool needs_measure) { - if (_freeze_level <= 0) { - do_rebuild(); - } else { - _needs_rebuild = true; - - if (needs_measure) { - measure(); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::measure -// Access: Published -// Description: Measures the extent of the text as it will be placed, -// without actually placing it. Normally, this function -// is called automatically whenever any of the -// parameters changes. It should not need to be called -// explicitly unless something goes wrong. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -measure() { - do_measure(); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_left -// Access: Published -// Description: Returns the leftmost extent of the text in local 2-d -// coordinates, unmodified by the set_transform() -// matrix. -//////////////////////////////////////////////////////////////////// -INLINE float TextNode:: -get_left() const { - return _ul2d[0]; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_right -// Access: Published -// Description: Returns the rightmost extent of the text in local 2-d -// coordinates, unmodified by the set_transform() -// matrix. -//////////////////////////////////////////////////////////////////// -INLINE float TextNode:: -get_right() const { - return _lr2d[0]; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_bottom -// Access: Published -// Description: Returns the bottommost extent of the text in local -// 2-d coordinates, unmodified by the set_transform() -// matrix. -//////////////////////////////////////////////////////////////////// -INLINE float TextNode:: -get_bottom() const { - return _lr2d[1]; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_top -// Access: Published -// Description: Returns the topmost extent of the text in local 2-d -// coordinates, unmodified by the set_transform() -// matrix. -//////////////////////////////////////////////////////////////////// -INLINE float TextNode:: -get_top() const { - return _ul2d[1]; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_height -// Access: Published -// Description: Returns the net height of the text in local 2-d -// coordinates. -//////////////////////////////////////////////////////////////////// -INLINE float TextNode:: -get_height() const { - return get_top() - get_bottom(); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_width -// Access: Published -// Description: Returns the net width of the text in local 2-d -// coordinates. -//////////////////////////////////////////////////////////////////// -INLINE float TextNode:: -get_width() const { - return get_right() - get_left(); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_upper_left_3d -// Access: Published -// Description: Returns the upper-left extent of the text object, -// after it has been transformed into 3-d space by -// applying the set_transform() matrix. -//////////////////////////////////////////////////////////////////// -INLINE LPoint3f TextNode:: -get_upper_left_3d() const { - return _ul3d; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_lower_right_3d -// Access: Published -// Description: Returns the lower-right extent of the text object, -// after it has been transformed into 3-d space by -// applying the set_transform() matrix. -//////////////////////////////////////////////////////////////////// -INLINE LPoint3f TextNode:: -get_lower_right_3d() const { - return _lr3d; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_num_rows -// Access: Published -// Description: Returns the number of rows of text that were -// generated. This counts word-wrapped rows as well as -// rows generated due to embedded newlines. -//////////////////////////////////////////////////////////////////// -INLINE int TextNode:: -get_num_rows() const { - return _num_rows; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::set_wtext -// Access: Public -// Description: Changes the text that is displayed under the -// TextNode, with a wide text. This automatically sets -// the string reported by get_text() to the 8-bit -// encoded version of the same string. -//////////////////////////////////////////////////////////////////// -INLINE void TextNode:: -set_wtext(const wstring &wtext) { - _wtext = wtext; - _text = encode_wtext(wtext); - rebuild(true); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::get_wtext -// Access: Public -// Description: Returns the text associated with the TextNode, as a -// wide-character string. -//////////////////////////////////////////////////////////////////// -INLINE const wstring &TextNode:: -get_wtext() const { - return _wtext; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::calc_width -// Access: Published -// Description: Returns the width of a line of text of arbitrary -// characters. The line should not include the newline -// character. -//////////////////////////////////////////////////////////////////// -INLINE float TextNode:: -calc_width(const wstring &line) const { - nassertr(_font != (TextFont *)NULL, 0.0); - return _font->calc_width(line); -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::wordwrap_to -// Access: Published -// Description: Inserts newlines into the given text at the -// appropriate places in order to make each line be the -// longest possible line that is not longer than -// wordwrap_width (and does not break any words, if -// possible). Returns the new string. -//////////////////////////////////////////////////////////////////// -INLINE wstring TextNode:: -wordwrap_to(const wstring &wtext, float wordwrap_width, - bool preserve_trailing_whitespace) const { - nassertr(_font != (TextFont *)NULL, wtext); - return _font->wordwrap_to(wtext, wordwrap_width, preserve_trailing_whitespace); -} diff --git a/panda/src/text/textNode.cxx b/panda/src/text/textNode.cxx deleted file mode 100644 index 42adc9843a..0000000000 --- a/panda/src/text/textNode.cxx +++ /dev/null @@ -1,1080 +0,0 @@ -// Filename: textNode.cxx -// Created by: drose (12May99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// -#include "textNode.h" -#include "textGlyph.h" -#include "stringDecoder.h" -#include "config_text.h" - -#include "compose_matrix.h" -#include "transformTransition.h" -#include "colorTransition.h" -#include "geom.h" -#include "geomprimitives.h" -#include "renderRelation.h" -#include "notify.h" -#include "sceneGraphReducer.h" -#include "geomBinTransition.h" -#include "indent.h" - -#include "stdio.h" -#include "ctype.h" - -//////////////////////////////////////////////////////////////////// -// Static variables -//////////////////////////////////////////////////////////////////// -TypeHandle TextNode::_type_handle; - -TextNode::Encoding TextNode::_default_encoding; - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -TextNode:: -TextNode(const string &name) : NamedNode(name) { - _encoding = _default_encoding; - _slant = 0.0f; - - _flags = 0; - _align = A_left; - _wordwrap_width = 1.0f; - - _text_color.set(1.0f, 1.0f, 1.0f, 1.0f); - _frame_color.set(1.0f, 1.0f, 1.0f, 1.0f); - _card_color.set(1.0f, 1.0f, 1.0f, 1.0f); - _shadow_color.set(1.0f, 1.0f, 1.0f, 1.0f); - - _frame_width = 1.0f; - - _frame_ul.set(0.0f, 0.0f); - _frame_lr.set(0.0f, 0.0f); - _card_ul.set(0.0f, 0.0f); - _card_lr.set(0.0f, 0.0f); - _shadow_offset.set(0.0f, 0.0f); - - _draw_order = 1; - - _transform = LMatrix4f::ident_mat(); - _coordinate_system = CS_default; - - _ul2d.set(0.0f, 0.0f); - _lr2d.set(0.0f, 0.0f); - _ul3d.set(0.0f, 0.0f, 0.0f); - _lr3d.set(0.0f, 0.0f, 0.0f); - _num_rows = 0; - - _freeze_level = 0; - _needs_rebuild = false; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::Destructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -TextNode:: -~TextNode() { -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::wordwrap_to -// Access: Published -// Description: Inserts newlines into the given text at the -// appropriate places in order to make each line be the -// longest possible line that is not longer than -// wordwrap_width (and does not break any words, if -// possible). Returns the new string. -//////////////////////////////////////////////////////////////////// -string TextNode:: -wordwrap_to(const string &text, float wordwrap_width, - bool preserve_trailing_whitespace) const { - nassertr(_font != (TextFont *)NULL, text); - wstring decoded = decode_text(text); - wstring wrapped = - _font->wordwrap_to(decoded, wordwrap_width, preserve_trailing_whitespace); - return encode_wtext(wrapped); -} - - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::write -// Access: Published, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void TextNode:: -write(ostream &out, int indent_level) const { - indent(out, indent_level) - << "TextNode " << get_name() << "\n"; - if (_font != (TextFont *)NULL) { - indent(out, indent_level + 2) - << "with font " << _font->get_name() << "\n"; - } - if (has_text_color()) { - indent(out, indent_level + 2) - << "text color is " << _text_color << "\n"; - } else { - indent(out, indent_level + 2) - << "text color is unchanged from source\n"; - } - indent(out, indent_level + 2) - << "alignment is "; - switch (_align) { - case A_left: - out << "A_left\n"; - break; - - case A_right: - out << "A_right\n"; - break; - - case A_center: - out << "A_center\n"; - break; - } - - if (has_wordwrap()) { - indent(out, indent_level + 2) - << "Word-wrapping at " << _wordwrap_width << " units.\n"; - } - - if (has_frame()) { - indent(out, indent_level + 2) - << "frame of color " << _frame_color << " at " - << get_frame_as_set() << " line width " << _frame_width << "\n"; - if (get_frame_corners()) { - indent(out, indent_level + 2) - << "frame corners are enabled\n"; - } - if (is_frame_as_margin()) { - indent(out, indent_level + 2) - << "frame coordinates are specified as margin; actual frame is:\n" - << get_frame_actual() << "\n"; - } else { - indent(out, indent_level + 2) - << "frame coordinates are actual\n"; - } - } - if (has_card()) { - indent(out, indent_level + 2) - << "card of color " << _card_color << " at " - << get_card_as_set() << "\n"; - if (is_card_as_margin()) { - indent(out, indent_level + 2) - << "card coordinates are specified as margin; actual card is:\n" - << get_card_actual() << "\n"; - } else { - indent(out, indent_level + 2) - << "card coordinates are actual\n"; - } - } - if (has_shadow()) { - indent(out, indent_level + 2) - << "shadow of color " << _shadow_color << " at " - << _shadow_offset << "\n"; - } - if (has_bin()) { - indent(out, indent_level + 2) - << "bin is " << _bin << "\n"; - } - indent(out, indent_level + 2) - << "draw order is " << _draw_order << ", " - << _draw_order + 1 << ", " << _draw_order + 2 << "\n"; - - LVecBase3f scale, hpr, trans; - if (decompose_matrix(_transform, scale, hpr, trans, _coordinate_system)) { - indent(out, indent_level + 2) - << "transform is:\n" - << " scale: " << scale << "\n" - << " hpr: " << hpr << "\n" - << " trans: " << hpr << "\n"; - } else { - indent(out, indent_level + 2) - << "transform is:\n" << _transform; - } - indent(out, indent_level + 2) - << "in coordinate system " << _coordinate_system << "\n"; - - indent(out, indent_level + 2) - << "\ntext is " << _text << "\n"; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::generate -// Access: Published -// Description: Generates the text, according to the parameters -// indicated within the TextNode, and returns a Node -// that may be parented within the tree to represent it. -//////////////////////////////////////////////////////////////////// -PT_Node TextNode:: -generate() { - if (text_cat.is_debug()) { - text_cat.debug() - << "Rebuilding " << *this << " with '" << _text << "'\n"; - } - - // The strategy here will be to assemble together a bunch of - // letters, instanced from the letter hierarchy of font_def, into - // our own little hierarchy. - - // There will be one root over the whole text block, that - // contains the transform passed in. Under this root there will be - // another node for each row, that moves the row into the right place - // horizontally and vertically, and for each row, there is another - // node for each character. - - _ul2d.set(0.0f, 0.0f); - _lr2d.set(0.0f, 0.0f); - _ul3d.set(0.0f, 0.0f, 0.0f); - _lr3d.set(0.0f, 0.0f, 0.0f); - _num_rows = 0; - - // Now build a new sub-tree for all the text components. - PT_Node root = new NamedNode(_text); - - if (_text.empty() || _font.is_null()) { - return root; - } - - PT_Node sub_root = new NamedNode(); - RenderRelation *root_arc = new RenderRelation(root, sub_root); - - // Compute the overall text transform matrix. We build the text in - // a Z-up coordinate system and then convert it to whatever the user - // asked for. - LMatrix4f mat = - LMatrix4f::convert_mat(CS_zup_right, _coordinate_system) * - _transform; - - root_arc->set_transition(new TransformTransition(mat)); - - wstring wtext = _wtext; - if (has_wordwrap()) { - wtext = _font->wordwrap_to(wtext, _wordwrap_width, false); - } - - // Assemble the text. - LVector2f ul, lr; - int num_rows = 0; - PT_Node text_root = assemble_text(wtext.begin(), wtext.end(), ul, lr, num_rows); - RenderRelation *text_arc = - new RenderRelation(sub_root, text_root, _draw_order + 2); - - - if (has_text_color()) { - text_arc->set_transition(new ColorTransition(_text_color)); - if (_text_color[3] != 1.0) { - text_arc->set_transition - (new TransparencyTransition(TransparencyProperty::M_alpha)); - } - } - - if (has_bin()) { - text_arc->set_transition - (new GeomBinTransition(_bin, _draw_order + 2)); - } - - // Save the bounding-box information about the text in a form - // friendly to the user. - _num_rows = num_rows; - _ul2d = ul; - _lr2d = lr; - _ul3d.set(ul[0], 0.0f, ul[1]); - _lr3d.set(lr[0], 0.0f, lr[1]); - - _ul3d = _ul3d * _transform; - _lr3d = _lr3d * _transform; - - - // Now deal with all the decorations. - - if (has_shadow()) { - // Make a shadow by instancing the text behind itself. - - // For now, the depth offset is 0.0 because we don't expect to see - // text with shadows in the 3-d world that aren't decals. Maybe - // this will need to be addressed in the future. - - LMatrix4f offset = - LMatrix4f::translate_mat(_shadow_offset[0], 0.0f, -_shadow_offset[1]); - RenderRelation *shadow_arc = - new RenderRelation(sub_root, text_root, _draw_order + 1); - shadow_arc->set_transition(new TransformTransition(offset)); - shadow_arc->set_transition(new ColorTransition(_shadow_color)); - - if (_shadow_color[3] != 1.0f) { - shadow_arc->set_transition - (new TransparencyTransition(TransparencyProperty::M_alpha)); - } - - if (has_bin()) { - shadow_arc->set_transition - (new GeomBinTransition(_bin, _draw_order + 1)); - } - } - - if (has_frame()) { - PT_Node frame_root = make_frame(); - RenderRelation *frame_arc = - new RenderRelation(sub_root, frame_root, _draw_order + 1); - frame_arc->set_transition(new ColorTransition(_frame_color)); - if (_frame_color[3] != 1.0f) { - frame_arc->set_transition - (new TransparencyTransition(TransparencyProperty::M_alpha)); - } - - if (has_bin()) { - frame_arc->set_transition - (new GeomBinTransition(_bin, _draw_order + 1)); - } - } - - if (has_card()) { - PT_Node card_root; - if (has_card_border()) - card_root = make_card_with_border(); - else - card_root = make_card(); - RenderRelation *card_arc = - new RenderRelation(sub_root, card_root, _draw_order); - card_arc->set_transition(new ColorTransition(_card_color)); - if (_card_color[3] != 1.0f) { - card_arc->set_transition - (new TransparencyTransition(TransparencyProperty::M_alpha)); - } - if (has_card_texture()) { - card_arc->set_transition(new TextureTransition(_card_texture)); - } - - if (has_bin()) { - card_arc->set_transition - (new GeomBinTransition(_bin, _draw_order)); - } - } - - // Now flatten our hierarchy to get rid of the transforms we put in, - // applying them to the vertices. - - if (text_flatten) { - SceneGraphReducer gr(RenderRelation::get_class_type()); - gr.apply_transitions(root_arc); - gr.flatten(root, true); - } - - return root; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::encode_wchar -// Access: Public -// Description: Encodes a single wide char into a one-, two-, or -// three-byte string, according to the current encoding -// system in effect. -//////////////////////////////////////////////////////////////////// -string TextNode:: -encode_wchar(wchar_t ch) const { - switch (_encoding) { - case E_iso8859: - if (isascii(ch)) { - return string(1, (char)ch); - } else { - return "."; - } - - case E_utf8: - if (ch < 0x80) { - return string(1, (char)ch); - } else if (ch < 0x800) { - return - string(1, (char)((ch >> 6) | 0xc0)) + - string(1, (char)((ch & 0x3f) | 0x80)); - } else { - return - string(1, (char)((ch >> 12) | 0xe0)) + - string(1, (char)(((ch >> 6) & 0x3f) | 0x80)) + - string(1, (char)((ch & 0x3f) | 0x80)); - } - - case E_unicode: - return - string(1, (char)(ch >> 8)) + - string(1, (char)(ch & 0xff)); - } - - return ""; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::encode_wtext -// Access: Public -// Description: Encodes a wide-text string into a single-char string, -// accoding to the current encoding. -//////////////////////////////////////////////////////////////////// -string TextNode:: -encode_wtext(const wstring &wtext) const { - string result; - - for (wstring::const_iterator pi = wtext.begin(); pi != wtext.end(); ++pi) { - result += encode_wchar(*pi); - } - - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::decode_text -// Access: Public -// Description: Returns the given wstring decoded to a single-byte -// string, via the current encoding system. -//////////////////////////////////////////////////////////////////// -wstring TextNode:: -decode_text(const string &text) const { - switch (_encoding) { - case E_utf8: - { - StringUtf8Decoder decoder(text); - return decode_text_impl(decoder); - } - break; - - case E_unicode: - { - StringUnicodeDecoder decoder(text); - return decode_text_impl(decoder); - } - break; - - case E_iso8859: - default: - { - StringDecoder decoder(text); - return decode_text_impl(decoder); - } - }; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::decode_text_impl -// Access: Private -// Description: Decodes the eight-bit stream from the indicated -// decoder, storing the decoded unicode characters in -// _wtext. -//////////////////////////////////////////////////////////////////// -wstring TextNode:: -decode_text_impl(StringDecoder &decoder) const { - wstring result; - bool expand_amp = get_expand_amp(); - - wchar_t character = decoder.get_next_character(); - while (!decoder.is_eof()) { - if (character == '&' && expand_amp) { - // An ampersand in expand_amp mode is treated as an escape - // character. - character = expand_amp_sequence(decoder); - } - result += character; - character = decoder.get_next_character(); - } - - return result; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::expand_amp_sequence -// Access: Private -// Description: Given that we have just read an ampersand from the -// StringDecoder, and that we have expand_amp in effect -// and are therefore expected to expand the sequence -// that this ampersand begins into a single unicode -// character, do the expansion and return the character. -//////////////////////////////////////////////////////////////////// -int TextNode:: -expand_amp_sequence(StringDecoder &decoder) const { - int result = 0; - - int character = decoder.get_next_character(); - if (!decoder.is_eof() && character == '#') { - // An explicit numeric sequence: &#nnn; - result = 0; - character = decoder.get_next_character(); - while (!decoder.is_eof() && character < 128 && isdigit(character)) { - result = (result * 10) + (character - '0'); - character = decoder.get_next_character(); - } - if (character != ';') { - // Invalid sequence. - return 0; - } - - return result; - } - - string sequence; - - // Some non-numeric sequence. - while (!decoder.is_eof() && character < 128 && isalpha(character)) { - sequence += character; - character = decoder.get_next_character(); - } - if (character != ';') { - // Invalid sequence. - return 0; - } - - static const struct { - const char *name; - int code; - } tokens[] = { - { "amp", '&' }, { "lt", '<' }, { "gt", '>' }, { "quot", '"' }, - { "nbsp", ' ' /* 160 */ }, - - { "iexcl", 161 }, { "cent", 162 }, { "pound", 163 }, { "curren", 164 }, - { "yen", 165 }, { "brvbar", 166 }, { "brkbar", 166 }, { "sect", 167 }, - { "uml", 168 }, { "die", 168 }, { "copy", 169 }, { "ordf", 170 }, - { "laquo", 171 }, { "not", 172 }, { "shy", 173 }, { "reg", 174 }, - { "macr", 175 }, { "hibar", 175 }, { "deg", 176 }, { "plusmn", 177 }, - { "sup2", 178 }, { "sup3", 179 }, { "acute", 180 }, { "micro", 181 }, - { "para", 182 }, { "middot", 183 }, { "cedil", 184 }, { "sup1", 185 }, - { "ordm", 186 }, { "raquo", 187 }, { "frac14", 188 }, { "frac12", 189 }, - { "frac34", 190 }, { "iquest", 191 }, { "Agrave", 192 }, { "Aacute", 193 }, - { "Acirc", 194 }, { "Atilde", 195 }, { "Auml", 196 }, { "Aring", 197 }, - { "AElig", 198 }, { "Ccedil", 199 }, { "Egrave", 200 }, { "Eacute", 201 }, - { "Ecirc", 202 }, { "Euml", 203 }, { "Igrave", 204 }, { "Iacute", 205 }, - { "Icirc", 206 }, { "Iuml", 207 }, { "ETH", 208 }, { "Dstrok", 208 }, - { "Ntilde", 209 }, { "Ograve", 210 }, { "Oacute", 211 }, { "Ocirc", 212 }, - { "Otilde", 213 }, { "Ouml", 214 }, { "times", 215 }, { "Oslash", 216 }, - { "Ugrave", 217 }, { "Uacute", 218 }, { "Ucirc", 219 }, { "Uuml", 220 }, - { "Yacute", 221 }, { "THORN", 222 }, { "szlig", 223 }, { "agrave", 224 }, - { "aacute", 225 }, { "acirc", 226 }, { "atilde", 227 }, { "auml", 228 }, - { "aring", 229 }, { "aelig", 230 }, { "ccedil", 231 }, { "egrave", 232 }, - { "eacute", 233 }, { "ecirc", 234 }, { "euml", 235 }, { "igrave", 236 }, - { "iacute", 237 }, { "icirc", 238 }, { "iuml", 239 }, { "eth", 240 }, - { "ntilde", 241 }, { "ograve", 242 }, { "oacute", 243 }, { "ocirc", 244 }, - { "otilde", 245 }, { "ouml", 246 }, { "divide", 247 }, { "oslash", 248 }, - { "ugrave", 249 }, { "uacute", 250 }, { "ucirc", 251 }, { "uuml", 252 }, - { "yacute", 253 }, { "thorn", 254 }, { "yuml", 255 }, - - { NULL, 0 }, - }; - - for (int i = 0; tokens[i].name != NULL; i++) { - if (sequence == tokens[i].name) { - // Here's a match. - return tokens[i].code; - } - } - - // Some unrecognized sequence. - return 0; -} - - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::do_rebuild -// Access: Private -// Description: Removes any existing children of the TextNode, and -// adds the newly generated text instead. -//////////////////////////////////////////////////////////////////// -void TextNode:: -do_rebuild() { - _needs_rebuild = false; - - int num_children = get_num_children(RenderRelation::get_class_type()); - while (num_children > 0) { - NodeRelation *arc = get_child(RenderRelation::get_class_type(), 0); - remove_arc(arc); - num_children--; - } - - PT_Node new_text = generate(); - if (new_text != (Node *)NULL) { - new RenderRelation(this, new_text); - - // And we flatten one more time, to remove the new node itself if - // possible (it might be an unneeded node above multiple - // children). This flatten operation should be fairly - // lightweight; it's already pretty flat. - SceneGraphReducer gr(RenderRelation::get_class_type()); - gr.flatten(this, false); - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::do_measure -// Access: Private -// Description: Can be called in lieu of do_rebuild() to measure the -// text and set up the bounding boxes properly without -// actually assembling it. -//////////////////////////////////////////////////////////////////// -void TextNode:: -do_measure() { - _ul2d.set(0.0f, 0.0f); - _lr2d.set(0.0f, 0.0f); - _ul3d.set(0.0f, 0.0f, 0.0f); - _lr3d.set(0.0f, 0.0f, 0.0f); - _num_rows = 0; - - if (_text.empty() || _font.is_null()) { - return; - } - - wstring wtext = _wtext; - if (has_wordwrap()) { - wtext = _font->wordwrap_to(wtext, _wordwrap_width, false); - } - - LVector2f ul, lr; - int num_rows = 0; - measure_text(wtext.begin(), wtext.end(), ul, lr, num_rows); - - _num_rows = num_rows; - _ul2d = ul; - _lr2d = lr; - _ul3d.set(ul[0], 0.0f, ul[1]); - _lr3d.set(lr[0], 0.0f, lr[1]); - - _ul3d = _ul3d * _transform; - _lr3d = _lr3d * _transform; -} - -#ifndef CPPPARSER // interrogate has a bit of trouble with wstring. - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::assemble_row -// Access: Private -// Description: Assembles the letters in the source string, up until -// the first newline or the end of the string into a -// single row (which is parented to 'dest'), and returns -// the length of the row. The source pointer is moved -// to the terminating character. -//////////////////////////////////////////////////////////////////// -float TextNode:: -assemble_row(wstring::iterator &si, const wstring::iterator &send, - Node *dest) { - nassertr(_font != (TextFont *)NULL, 0.0f); - - float xpos = 0.0f; - while (si != send && (*si) != '\n') { - wchar_t character = *si; - - if (character == ' ') { - // A space is a special case. - xpos += _font->get_space_advance(); - - } else { - // A printable character. - - const TextGlyph *glyph; - float glyph_scale; - if (!_font->get_glyph(character, glyph, glyph_scale)) { - text_cat.warning() - << "No definition in " << _font->get_name() - << " for character " << character; - if (character < 128 && isprint(character)) { - text_cat.warning(false) - << " ('" << (char)character << "')"; - } - text_cat.warning(false) - << "\n"; - } - - if (glyph != (TextGlyph *)NULL) { - PT(Geom) char_geom = glyph->get_geom(); - const AllTransitionsWrapper &trans = glyph->get_trans(); - - if (char_geom != (Geom *)NULL) { - LMatrix4f mat = LMatrix4f::scale_mat(glyph_scale); - mat.set_row(3, LVector3f(xpos, 0.0f, 0.0f)); - - string ch(1, (char)character); - GeomNode *geode = new GeomNode(ch); - geode->add_geom(char_geom); - RenderRelation* rel = new RenderRelation(dest, geode); - rel->set_transition(new TransformTransition(mat)); - trans.store_to(rel); - } - - xpos += glyph->get_advance() * glyph_scale; - } - } - ++si; - } - - return xpos; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::assemble_text -// Access: Private -// Description: Constructs a hierarchy of nodes that contain the -// geometry representing the indicated source text, and -// returns it. Also sets the ul, lr corners. -//////////////////////////////////////////////////////////////////// -Node *TextNode:: -assemble_text(wstring::iterator si, const wstring::iterator &send, - LVector2f &ul, LVector2f &lr, int &num_rows) { - nassertr(_font != (TextFont *)NULL, (Node *)NULL); - float line_height = get_line_height(); - - ul.set(0.0f, 0.8f * line_height); - lr.set(0.0f, 0.0f); - - // Make a group node to hold our formatted text geometry. - Node *root_node = new NamedNode("text"); - - float posy = 0.0f; - int row_index = 0; - while (si != send) { - char numstr[20]; - sprintf(numstr, "row%d", row_index); - nassertr(strlen(numstr) < 20, root_node); - - Node *row = new NamedNode(numstr); - float row_width = assemble_row(si, send, row); - if (si != send) { - // Skip past the newline. - ++si; - } - - LMatrix4f mat = LMatrix4f::ident_mat(); - if (_align == A_left) { - mat.set_row(3, LVector3f(0.0f, 0.0f, posy)); - lr[0] = max(lr[0], row_width); - - } else if (_align == A_right) { - mat.set_row(3, LVector3f(-row_width, 0.0f, posy)); - ul[0] = min(ul[0], -row_width); - - } else { - float half_row_width=0.5f*row_width; - mat.set_row(3, LVector3f(-half_row_width, 0.0f, posy)); - lr[0] = max(lr[0], half_row_width); - ul[0] = min(ul[0], -half_row_width); - } - - // Also apply whatever slant the user has asked for to the entire - // row. This is an X shear. - if (_slant != 0.0f) { - LMatrix4f shear(1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - _slant, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f); - mat = shear * mat; - } - - RenderRelation *arc = new RenderRelation(root_node, row); - arc->set_transition(new TransformTransition(mat)); - - posy -= line_height; - num_rows++; - } - - lr[1] = posy + 0.8f * line_height; - - return root_node; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::measure_row -// Access: Private -// Description: Returns the length of the row in units, as it would -// be if it were assembled, without actually assembling -// it. -//////////////////////////////////////////////////////////////////// -float TextNode:: -measure_row(wstring::iterator &si, const wstring::iterator &send) { - float xpos = 0.0f; - while (si != send && *si != '\n') { - wchar_t character = *si; - - if (character == ' ') { - // A space is a special case. - xpos += _font->get_space_advance(); - - } else { - // A printable character. - - const TextGlyph *glyph; - float glyph_scale; - if (_font->get_glyph(character, glyph, glyph_scale)) { - xpos += glyph->get_advance() * glyph_scale; - } - } - ++si; - } - - return xpos; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::measure_text -// Access: Private -// Description: Sets the ul, lr corners to fit the text, without -// actually assembling it. -//////////////////////////////////////////////////////////////////// -void TextNode:: -measure_text(wstring::iterator si, const wstring::iterator &send, - LVector2f &ul, LVector2f &lr, int &num_rows) { - nassertv(_font != (TextFont *)NULL); - float line_height = get_line_height(); - - ul.set(0.0f, 0.8f * line_height); - lr.set(0.0f, 0.0f); - - float posy = 0.0f; - while (si != send) { - float row_width = measure_row(si, send); - if (si != send) { - // Skip past the newline. - ++si; - } - - if (_align == A_left) { - lr[0] = max(lr[0], row_width); - - } else if (_align == A_right) { - ul[0] = min(ul[0], -row_width); - - } else { - float half_row_width=0.5f*row_width; - - lr[0] = max(lr[0], half_row_width); - ul[0] = min(ul[0], -half_row_width); - } - - posy -= line_height; - num_rows++; - } - - lr[1] = posy + 0.8f * line_height; -} -#endif // CPPPARSER - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::make_frame -// Access: Private -// Description: Creates a frame around the text. -//////////////////////////////////////////////////////////////////// -Node *TextNode:: -make_frame() { - GeomNode *frame_geode = new GeomNode("frame"); - - LVector4f dimensions = get_frame_actual(); - float left = dimensions[0]; - float right = dimensions[1]; - float bottom = dimensions[2]; - float top = dimensions[3]; - - GeomLinestrip *geoset = new GeomLinestrip; - PTA_int lengths=PTA_int::empty_array(0); - PTA_Vertexf verts; - lengths.push_back(5); - verts.push_back(Vertexf(left, 0.0f, top)); - verts.push_back(Vertexf(left, 0.0f, bottom)); - verts.push_back(Vertexf(right, 0.0f, bottom)); - verts.push_back(Vertexf(right, 0.0f, top)); - verts.push_back(Vertexf(left, 0.0f, top)); - - geoset->set_num_prims(1); - geoset->set_lengths(lengths); - - geoset->set_coords(verts); - geoset->set_width(_frame_width); - frame_geode->add_geom(geoset); - - if (get_frame_corners()) { - GeomPoint *geoset = new GeomPoint; - - geoset->set_num_prims(4); - geoset->set_coords(verts); - geoset->set_size(_frame_width); - frame_geode->add_geom(geoset); - } - - return frame_geode; -} - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::make_card -// Access: Private -// Description: Creates a card behind the text. -//////////////////////////////////////////////////////////////////// -Node *TextNode:: -make_card() { - GeomNode *card_geode = new GeomNode("card"); - - LVector4f dimensions = get_card_actual(); - float left = dimensions[0]; - float right = dimensions[1]; - float bottom = dimensions[2]; - float top = dimensions[3]; - - GeomTristrip *geoset = new GeomTristrip; - PTA_int lengths=PTA_int::empty_array(0); - lengths.push_back(4); - - PTA_Vertexf verts; - verts.push_back(Vertexf::rfu(left, 0.02f, top)); - verts.push_back(Vertexf::rfu(left, 0.02f, bottom)); - verts.push_back(Vertexf::rfu(right, 0.02f, top)); - verts.push_back(Vertexf::rfu(right, 0.02f, bottom)); - - geoset->set_num_prims(1); - geoset->set_lengths(lengths); - - geoset->set_coords(verts); - - if (has_card_texture()) { - PTA_TexCoordf uvs; - uvs.push_back(TexCoordf(0.0f, 1.0f)); - uvs.push_back(TexCoordf(0.0f, 0.0f)); - uvs.push_back(TexCoordf(1.0f, 1.0f)); - uvs.push_back(TexCoordf(1.0f, 0.0f)); - - geoset->set_texcoords(uvs, G_PER_VERTEX); - } - - card_geode->add_geom(geoset); - - return card_geode; -} - - -//////////////////////////////////////////////////////////////////// -// Function: TextNode::make_card_with_border -// Access: Private -// Description: Creates a card behind the text with a specified border -// for button edge or what have you. -//////////////////////////////////////////////////////////////////// -Node *TextNode:: -make_card_with_border() { - GeomNode *card_geode = new GeomNode("card"); - - LVector4f dimensions = get_card_actual(); - float left = dimensions[0]; - float right = dimensions[1]; - float bottom = dimensions[2]; - float top = dimensions[3]; - - // we now create three tri-strips instead of one - // with vertices arranged as follows: - // - // 1 3 5 7 - one - // 2 4 6 8 / \ two - // 9 11 13 15 \ / - // 10 12 14 16 - three - // - GeomTristrip *geoset = new GeomTristrip; - PTA_int lengths; - lengths.push_back(8); - lengths.push_back(8); - lengths.push_back(8); - - PTA_Vertexf verts; - // verts 1,2,3,4 - verts.push_back(Vertexf::rfu(left, 0.02f, top)); - verts.push_back(Vertexf::rfu(left, 0.02f, top - _card_border_size)); - verts.push_back(Vertexf::rfu(left + _card_border_size, 0.02f, top)); - verts.push_back(Vertexf::rfu(left + _card_border_size, 0.02f, - top - _card_border_size)); - // verts 5,6,7,8 - verts.push_back(Vertexf::rfu(right - _card_border_size, 0.02f, top)); - verts.push_back(Vertexf::rfu(right - _card_border_size, 0.02f, - top - _card_border_size)); - verts.push_back(Vertexf::rfu(right, 0.02f, top)); - verts.push_back(Vertexf::rfu(right, 0.02f, top - _card_border_size)); - // verts 9,10,11,12 - verts.push_back(Vertexf::rfu(left, 0.02f, bottom + _card_border_size)); - verts.push_back(Vertexf::rfu(left, 0.02f, bottom)); - verts.push_back(Vertexf::rfu(left + _card_border_size, 0.02f, - bottom + _card_border_size)); - verts.push_back(Vertexf::rfu(left + _card_border_size, 0.02f, bottom)); - // verts 13,14,15,16 - verts.push_back(Vertexf::rfu(right - _card_border_size, 0.02f, - bottom + _card_border_size)); - verts.push_back(Vertexf::rfu(right - _card_border_size, 0.02f, bottom)); - verts.push_back(Vertexf::rfu(right, 0.02f, bottom + _card_border_size)); - verts.push_back(Vertexf::rfu(right, 0.02f, bottom)); - - PTA_ushort indices; - // tristrip #1 - indices.push_back(0); - indices.push_back(1); - indices.push_back(2); - indices.push_back(3); - indices.push_back(4); - indices.push_back(5); - indices.push_back(6); - indices.push_back(7); - // tristrip #2 - indices.push_back(1); - indices.push_back(8); - indices.push_back(3); - indices.push_back(10); - indices.push_back(5); - indices.push_back(12); - indices.push_back(7); - indices.push_back(14); - // tristrip #3 - indices.push_back(8); - indices.push_back(9); - indices.push_back(10); - indices.push_back(11); - indices.push_back(12); - indices.push_back(13); - indices.push_back(14); - indices.push_back(15); - - geoset->set_num_prims(3); - geoset->set_lengths(lengths); - - geoset->set_coords(verts,indices); - - if (has_card_texture()) { - PTA_TexCoordf uvs; - uvs.push_back(TexCoordf(0.0f, 1.0f)); //1 - uvs.push_back(TexCoordf(0.0f, 1.0f - _card_border_uv_portion)); //2 - uvs.push_back(TexCoordf(0.0f + _card_border_uv_portion, 1.0f)); //3 - uvs.push_back(TexCoordf(0.0f + _card_border_uv_portion, - 1.0f - _card_border_uv_portion)); //4 - uvs.push_back(TexCoordf( 1.0f -_card_border_uv_portion, 1.0f)); //5 - uvs.push_back(TexCoordf( 1.0f -_card_border_uv_portion, - 1.0f - _card_border_uv_portion)); //6 - uvs.push_back(TexCoordf(1.0f, 1.0f)); //7 - uvs.push_back(TexCoordf(1.0f, 1.0f - _card_border_uv_portion)); //8 - - uvs.push_back(TexCoordf(0.0f, _card_border_uv_portion)); //9 - uvs.push_back(TexCoordf(0.0f, 0.0f)); //10 - uvs.push_back(TexCoordf(_card_border_uv_portion, _card_border_uv_portion)); //11 - uvs.push_back(TexCoordf(_card_border_uv_portion, 0.0f)); //12 - - uvs.push_back(TexCoordf(1.0f - _card_border_uv_portion, _card_border_uv_portion));//13 - uvs.push_back(TexCoordf(1.0f - _card_border_uv_portion, 0.0f));//14 - uvs.push_back(TexCoordf(1.0f, _card_border_uv_portion));//15 - uvs.push_back(TexCoordf(1.0f, 0.0f));//16 - - // we can use same ref's as before (same order) - geoset->set_texcoords(uvs, G_PER_VERTEX, indices); - - } - - card_geode->add_geom(geoset); - - return card_geode; -} diff --git a/panda/src/text/textNode.h b/panda/src/text/textNode.h deleted file mode 100644 index 7adcc63a36..0000000000 --- a/panda/src/text/textNode.h +++ /dev/null @@ -1,327 +0,0 @@ -// Filename: textNode.h -// Created by: drose (12May99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef TEXTNODE_H -#define TEXTNODE_H - -#include "pandabase.h" - -#include "config_text.h" -#include "textFont.h" - -#include "pt_Node.h" -#include "namedNode.h" -#include "luse.h" -#include "geom.h" -#include "geomNode.h" -#include "renderRelation.h" -#include "textureTransition.h" -#include "transparencyTransition.h" -#include "allTransitionsWrapper.h" - -// These are deprecated. Use TextNode::Alignment instead. -#define TM_ALIGN_LEFT 1 -#define TM_ALIGN_RIGHT 2 -#define TM_ALIGN_CENTER 3 - -class StringDecoder; - -//////////////////////////////////////////////////////////////////// -// Class : TextNode -// Description : The primary interface to this module. This class -// does basic text assembly; given a string of text and -// a TextFont object, it creates a piece of geometry -// that may be placed in the 3-d or 2-d world to -// represent the indicated text. -// -// The TextNode may be used in one of two ways. -// Naively, it may be parented to the scene graph -// directly; used in this way, you can optionally call -// freeze() and thaw() between changing many parameters -// in the text at once, to avoid unnecessary expensive -// regeneration with each parameter change. However, it -// will work, if slowly, even if you never call freeze() -// and thaw(). -// -// The second way TextNode may be used is as a text -// generator. To use it in this way, call freeze() once -// on the TextNode when you create it, and never call -// thaw(). Do not parent the TextNode to the scene -// graph; instea, set the properties of the text and -// call generate() to return a node which you may parent -// wherever you like. Each time you call generate() a -// new node is returned. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA TextNode : public NamedNode { -PUBLISHED: - TextNode(const string &name = ""); - ~TextNode(); - - enum Alignment { - A_left = TM_ALIGN_LEFT, - A_right = TM_ALIGN_RIGHT, - A_center = TM_ALIGN_CENTER, - }; - - enum Encoding { - E_iso8859, - E_utf8, - E_unicode - }; - - INLINE int freeze(); - INLINE int get_freeze_level() const; - INLINE int thaw(); - - INLINE void set_font(TextFont *font); - INLINE TextFont *get_font() const; - - INLINE void set_encoding(Encoding encoding); - INLINE Encoding get_encoding() const; - - INLINE void set_expand_amp(bool expand_amp); - INLINE bool get_expand_amp() const; - - INLINE float get_line_height() const; - - INLINE void set_slant(float slant); - INLINE float get_slant() const; - - INLINE void set_align(Alignment align_type); - INLINE Alignment get_align() const; - - INLINE void set_wordwrap(float width); - INLINE void clear_wordwrap(); - INLINE bool has_wordwrap() const; - INLINE float get_wordwrap() const; - - INLINE void set_text_color(float r, float g, float b, float a); - INLINE void set_text_color(const Colorf &text_color); - INLINE void clear_text_color(); - INLINE bool has_text_color() const; - INLINE Colorf get_text_color() const; - - INLINE void set_frame_color(float r, float g, float b, float a); - INLINE void set_frame_color(const Colorf &frame_color); - INLINE Colorf get_frame_color() const; - - INLINE void set_card_border(float size, float uv_portion); - INLINE void clear_card_border(); - INLINE float get_card_border_size() const; - INLINE float get_card_border_uv_portion() const; - INLINE bool has_card_border() const; - - INLINE void set_card_color(float r, float g, float b, float a); - INLINE void set_card_color(const Colorf &card_color); - INLINE Colorf get_card_color() const; - - INLINE void set_card_texture(Texture *card_texture); - INLINE void clear_card_texture(); - INLINE bool has_card_texture() const; - INLINE Texture *get_card_texture() const; - - INLINE void set_shadow_color(float r, float g, float b, float a); - INLINE void set_shadow_color(const Colorf &shadow_color); - INLINE Colorf get_shadow_color() const; - - INLINE void set_frame_as_margin(float left, float right, - float bottom, float top); - INLINE void set_frame_actual(float left, float right, - float bottom, float top); - INLINE void clear_frame(); - INLINE bool has_frame() const; - INLINE bool is_frame_as_margin() const; - INLINE LVecBase4f get_frame_as_set() const; - INLINE LVecBase4f get_frame_actual() const; - - INLINE void set_frame_line_width(float line_width); - INLINE float get_frame_line_width() const; - INLINE void set_frame_corners(bool corners); - INLINE bool get_frame_corners() const; - - INLINE void set_card_as_margin(float left, float right, - float bottom, float top); - INLINE void set_card_actual(float left, float right, - float bottom, float top); - INLINE void clear_card(); - INLINE bool has_card() const; - INLINE bool is_card_as_margin() const; - INLINE LVecBase4f get_card_as_set() const; - INLINE LVecBase4f get_card_actual() const; - INLINE LVecBase4f get_card_transformed() const; - - INLINE void set_shadow(float xoffset, float yoffset); - INLINE void clear_shadow(); - INLINE bool has_shadow() const; - INLINE LVecBase2f get_shadow() const; - - INLINE void set_bin(const string &bin); - INLINE void clear_bin(); - INLINE bool has_bin() const; - INLINE const string &get_bin() const; - - INLINE int set_draw_order(int draw_order); - INLINE int get_draw_order() const; - - INLINE void set_transform(const LMatrix4f &transform); - INLINE LMatrix4f get_transform() const; - - INLINE void set_coordinate_system(CoordinateSystem cs); - INLINE CoordinateSystem get_coordinate_system() const; - - INLINE void set_text(const string &text); - INLINE void clear_text(); - INLINE bool has_text() const; - INLINE string get_text() const; - - INLINE float calc_width(int character) const; - INLINE float calc_width(const string &line) const; - string wordwrap_to(const string &text, float wordwrap_width, - bool preserve_trailing_whitespace) const; - - virtual void write(ostream &out, int indent_level = 0) const; - - INLINE void rebuild(bool needs_measure); - INLINE void measure(); - - // The following functions return information about the text that - // was last built (and is currently visible). - INLINE float get_left() const; - INLINE float get_right() const; - INLINE float get_bottom() const; - INLINE float get_top() const; - INLINE float get_height() const; - INLINE float get_width() const; - - INLINE LPoint3f get_upper_left_3d() const; - INLINE LPoint3f get_lower_right_3d() const; - - INLINE int get_num_rows() const; - - PT_Node generate(); - -public: - // Direct support for wide-character strings. - INLINE void set_wtext(const wstring &wtext); - INLINE const wstring &get_wtext() const; - - INLINE float calc_width(const wstring &line) const; - INLINE wstring wordwrap_to(const wstring &wtext, float wordwrap_width, - bool preserve_trailing_whitespace) const; - - string encode_wchar(wchar_t ch) const; - string encode_wtext(const wstring &wtext) const; - wstring decode_text(const string &text) const; - -private: - wstring decode_text_impl(StringDecoder &decoder) const; - int expand_amp_sequence(StringDecoder &decoder) const; - - void do_rebuild(); - void do_measure(); - -#ifndef CPPPARSER // interrogate has a bit of trouble with wstring. - float assemble_row(wstring::iterator &si, const wstring::iterator &send, - Node *dest); - Node *assemble_text(wstring::iterator si, const wstring::iterator &send, - LVector2f &ul, LVector2f &lr, int &num_rows); - float measure_row(wstring::iterator &si, const wstring::iterator &send); - void measure_text(wstring::iterator si, const wstring::iterator &send, - LVector2f &ul, LVector2f &lr, int &num_rows); -#endif // CPPPARSER - - Node *make_frame(); - Node *make_card(); - Node *make_card_with_border(); - - PT(TextFont) _font; - - Encoding _encoding; - float _slant; - - PT(Texture) _card_texture; - Colorf _text_color; - Colorf _shadow_color; - Colorf _frame_color; - Colorf _card_color; - - enum Flags { - F_has_text_color = 0x0001, - F_has_wordwrap = 0x0002, - F_has_frame = 0x0004, - F_frame_as_margin = 0x0008, - F_has_card = 0x0010, - F_card_as_margin = 0x0020, - F_has_card_texture = 0x0040, - F_has_shadow = 0x0080, - F_frame_corners = 0x0100, - F_card_transp = 0x0200, - F_has_card_border = 0x0400, - F_expand_amp = 0x0800, - }; - - int _flags; - Alignment _align; - float _wordwrap_width; - float _frame_width; - float _card_border_size; - float _card_border_uv_portion; - - LVector2f _frame_ul, _frame_lr; - LVector2f _card_ul, _card_lr; - LVector2f _shadow_offset; - - string _bin; - int _draw_order; - - LMatrix4f _transform; - CoordinateSystem _coordinate_system; - - string _text; - wstring _wtext; - - LPoint2f _ul2d, _lr2d; - LPoint3f _ul3d, _lr3d; - int _num_rows; - int _freeze_level; - bool _needs_rebuild; - -public: - static Encoding _default_encoding; - -public: - static TypeHandle get_class_type() { - return _type_handle; - } - static void init_type() { - NamedNode::init_type(); - register_type(_type_handle, "TextNode", - NamedNode::get_class_type()); - } - virtual TypeHandle get_type() const { - return get_class_type(); - } - virtual TypeHandle force_init_type() {init_type(); return get_class_type();} - -private: - static TypeHandle _type_handle; -}; - -#include "textNode.I" - -#endif diff --git a/panda/src/tform/Sources.pp b/panda/src/tform/Sources.pp index 1d37229065..242d77cbc0 100644 --- a/panda/src/tform/Sources.pp +++ b/panda/src/tform/Sources.pp @@ -4,56 +4,40 @@ #begin lib_target #define TARGET tform #define LOCAL_LIBS \ - dgraph pgraph graph linmath sgattrib display event putil gobj gsgbase \ - mathutil sgraph device sgraphutil + dgraph pgraph linmath display event putil gobj gsgbase \ + mathutil device #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx #define SOURCES \ - buttonThrower.h \ qpbuttonThrower.h \ - config_tform.h dataValve.I dataValve.h \ - driveInterface.I driveInterface.h \ + config_tform.h \ qpdriveInterface.I qpdriveInterface.h \ - mouseWatcher.I mouseWatcher.h \ qpmouseWatcher.I qpmouseWatcher.h \ mouseWatcherGroup.h \ mouseWatcherParameter.I mouseWatcherParameter.h \ mouseWatcherRegion.I mouseWatcherRegion.h \ - planarSlider.h trackball.h \ qptrackball.h \ - transform2sg.h \ qptransform2sg.h #define INCLUDED_SOURCES \ - buttonThrower.cxx \ qpbuttonThrower.cxx \ - config_tform.cxx dataValve.cxx \ - driveInterface.cxx \ + config_tform.cxx \ qpdriveInterface.cxx \ - mouseWatcher.cxx \ qpmouseWatcher.cxx \ mouseWatcherGroup.cxx \ mouseWatcherParameter.cxx mouseWatcherRegion.cxx \ - planarSlider.cxx trackball.cxx \ qptrackball.cxx \ - transform2sg.cxx \ qptransform2sg.cxx #define INSTALL_HEADERS \ - buttonThrower.h \ qpbuttonThrower.h \ - dataValve.I dataValve.h \ - driveInterface.I driveInterface.h \ qpdriveInterface.I qpdriveInterface.h \ - mouseWatcher.I mouseWatcher.h \ qpmouseWatcher.I qpmouseWatcher.h \ mouseWatcherGroup.h \ mouseWatcherParameter.I mouseWatcherParameter.h \ mouseWatcherRegion.I mouseWatcherRegion.h \ - planarSlider.h trackball.h \ qptrackball.h \ - transform2sg.h \ qptransform2sg.h #define IGATESCAN all diff --git a/panda/src/tform/buttonThrower.cxx b/panda/src/tform/buttonThrower.cxx deleted file mode 100644 index d6b3ca85c0..0000000000 --- a/panda/src/tform/buttonThrower.cxx +++ /dev/null @@ -1,412 +0,0 @@ -// Filename: buttonThrower.cxx -// Created by: drose (09Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "buttonThrower.h" - -#include "buttonEventDataTransition.h" -#include "buttonEventDataTransition.h" -#include "buttonEvent.h" -#include "allTransitionsWrapper.h" -#include "throw_event.h" -#include "indent.h" - -TypeHandle ButtonThrower::_type_handle; -TypeHandle ButtonThrower::_button_events_type; - - -//////////////////////////////////////////////////////////////////// -// Function: ButtonThrower::Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -ButtonThrower:: -ButtonThrower(const string &name) : DataNode(name) { - _throw_buttons_active = false; -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonThrower::Destructor -// Access: Published, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -ButtonThrower:: -~ButtonThrower() { -} - - -//////////////////////////////////////////////////////////////////// -// Function: ButtonThrower::set_prefix -// Access: Published -// Description: Sets the prefix which is prepended to all event names -// thrown by this object. -//////////////////////////////////////////////////////////////////// -void ButtonThrower:: -set_prefix(const string &prefix) { - _prefix = prefix; -} - - -//////////////////////////////////////////////////////////////////// -// Function: ButtonThrower::has_prefix -// Access: Published -// Description: Returns true if the ButtonThrower has a prefix set, -// false otherwise. -//////////////////////////////////////////////////////////////////// -bool ButtonThrower:: -has_prefix() const { - return !_prefix.empty(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonThrower::get_prefix -// Access: Published -// Description: Returns the prefix that has been set on this -// ButtonThrower. See set_prefix(). -//////////////////////////////////////////////////////////////////// -string ButtonThrower:: -get_prefix() const { - return _prefix; -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonThrower::get_modifier_buttons -// Access: Published -// Description: Returns the set of ModifierButtons that the -// ButtonThrower will consider important enough to -// prepend the event name with. Normally, this set will -// be empty, and the ButtonThrower will therefore ignore -// all ModifierButtons attached to the key events, but -// if one or more buttons have been added to this set, -// and those modifier buttons are set on the button -// event, then the event name will be prepended with the -// names of the modifier buttons. -//////////////////////////////////////////////////////////////////// -const ModifierButtons &ButtonThrower:: -get_modifier_buttons() const { - return _mods; -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonThrower::set_modifier_buttons -// Access: Published -// Description: Changes the set of ModifierButtons that the -// ButtonThrower will consider important enough to -// prepend the event name with. Normally, this set will -// be empty, and the ButtonThrower will therefore ignore -// all ModifierButtons attached to the key events, but -// if one or more buttons have been added to this set, -// then the event name will be prepended with the names -// of the modifier buttons. -// -// It is recommended that you change this setting by -// first calling get_modifier_buttons(), making -// adjustments, and passing the new value to -// set_modifier_buttons(). This way the current state -// of the modifier buttons will not be lost. -//////////////////////////////////////////////////////////////////// -void ButtonThrower:: -set_modifier_buttons(const ModifierButtons &mods) { - _mods = mods; -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonThrower::set_throw_buttons_active -// Access: Published -// Description: Sets the flag that indicates whether the -// ButtonThrower will only process events for the -// explicitly named buttons or not. Normally this is -// false, meaning all buttons are processed; set it true -// to indicate that only some buttons should be -// processed. See add_throw_button(). -//////////////////////////////////////////////////////////////////// -void ButtonThrower:: -set_throw_buttons_active(bool flag) { - _throw_buttons_active = flag; -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonThrower::get_throw_buttons_active -// Access: Published -// Description: Returns the flag that indicates whether the -// ButtonThrower will only process events for the -// explicitly named buttons or not. See -// set_throw_buttons_active(). -//////////////////////////////////////////////////////////////////// -bool ButtonThrower:: -get_throw_buttons_active() const { - return _throw_buttons_active; -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonThrower::add_throw_button -// Access: Published -// Description: Adds a new button to the set of buttons that the -// ButtonThrower explicitly processes. -// -// If set_throw_buttons_active is false (which is the -// default), the ButtonThrower will process all buttons. -// Otherwise, the ButtonThrower will only process events -// for the button(s) explicitly named by this function; -// buttons not on the list will be ignored by this -// object and passed on downstream to the child node(s) -// in the data graph. A button that *is* on the list -// will be processed by the ButtonThrower and not passed -// on to the child node(s). -// -// The return value is true if the button is added, or -// false if it was already in the set. -//////////////////////////////////////////////////////////////////// -bool ButtonThrower:: -add_throw_button(const ModifierButtons &mods, const ButtonHandle &button) { - ThrowButtonDef &def = _throw_buttons[button]; - - // This is a vector of ModifierButtons for which the indicated - // button is handled. Make sure the current ModifierButtons object - // is not already on the list. - ThrowButtonDef::iterator di; - for (di = def.begin(); di != def.end(); ++di) { - if (mods.matches(*di)) { - return false; - } - } - - def.push_back(mods); - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonThrower::remove_throw_button -// Access: Published -// Description: Removes the indicated button from the set of buttons -// that the ButtonThrower explicitly processes. See -// add_throw_button(). -// -// The return value is true if the button is removed, or -// false if it was not on the set. -//////////////////////////////////////////////////////////////////// -bool ButtonThrower:: -remove_throw_button(const ModifierButtons &mods, const ButtonHandle &button) { - ThrowButtons::iterator ti = _throw_buttons.find(button); - if (ti == _throw_buttons.end()) { - // No buttons of this kind are in the set. - return false; - } - - ThrowButtonDef &def = (*ti).second; - - // This is a vector of ModifierButtons for which the indicated - // button is handled. - ThrowButtonDef::iterator di; - for (di = def.begin(); di != def.end(); ++di) { - if (mods.matches(*di)) { - def.erase(di); - if (def.empty()) { - _throw_buttons.erase(ti); - } - return true; - } - } - - // The indicated ModifierButtons are not applied to this button in - // the set. - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonThrower::has_throw_button -// Access: Published -// Description: Returns true if the indicated button is on the set of -// buttons that will be processed by the ButtonThrower, -// false otherwise. See add_throw_button(). -//////////////////////////////////////////////////////////////////// -bool ButtonThrower:: -has_throw_button(const ModifierButtons &mods, const ButtonHandle &button) const { - ThrowButtons::const_iterator ti = _throw_buttons.find(button); - if (ti == _throw_buttons.end()) { - // No buttons of this kind are in the set. - return false; - } - - const ThrowButtonDef &def = (*ti).second; - - // This is a vector of ModifierButtons for which the indicated - // button is handled. - ThrowButtonDef::const_iterator di; - for (di = def.begin(); di != def.end(); ++di) { - if (mods.matches(*di)) { - return true; - } - } - - // The indicated ModifierButtons are not applied to this button in - // the set. - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonThrower::has_throw_button -// Access: Published -// Description: Returns true if the indicated button, in conjunction -// with any nonspecified modifier buttons, is on the set -// of buttons that will be processed by the -// ButtonThrower. That is to say, returns true if this -// button was ever passed as the second parameter -// add_throw_button(), regardless of what the first -// parameter was. -//////////////////////////////////////////////////////////////////// -bool ButtonThrower:: -has_throw_button(const ButtonHandle &button) const { - ThrowButtons::const_iterator ti = _throw_buttons.find(button); - if (ti == _throw_buttons.end()) { - // No buttons of this kind are in the set. - return false; - } - - const ThrowButtonDef &def = (*ti).second; - return !def.empty(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonThrower::clear_throw_buttons -// Access: Published -// Description: Empties the set of buttons that were added via -// add_throw_button(). See add_throw_button(). -//////////////////////////////////////////////////////////////////// -void ButtonThrower:: -clear_throw_buttons() { - _throw_buttons.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonThrower::write -// Access: Public, Virtual -// Description: Throw all events for button events found in the data -// element. -//////////////////////////////////////////////////////////////////// -void ButtonThrower:: -write(ostream &out, int indent_level) const { - DataNode::write(out, indent_level); - if (_throw_buttons_active) { - indent(out, indent_level) - << "Processing keys:\n"; - // Write the list of buttons that we're processing too. - ThrowButtons::const_iterator ti; - for (ti = _throw_buttons.begin(); ti != _throw_buttons.end(); ++ti) { - ButtonHandle button = (*ti).first; - const ThrowButtonDef &def = (*ti).second; - ThrowButtonDef::const_iterator di; - for (di = def.begin(); di != def.end(); ++di) { - indent(out, indent_level + 2) - << (*di).get_prefix() << button.get_name() << "\n"; - } - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonThrower::transmit_data -// Access: Public, Virtual -// Description: Throw all events for button events found in the data -// element. -//////////////////////////////////////////////////////////////////// -void ButtonThrower:: -transmit_data(AllTransitionsWrapper &data) { - const ButtonEventDataTransition *b; - ButtonEventDataTransition *new_b = (ButtonEventDataTransition *)NULL; - - if (get_transition_into(b, data, _button_events_type)) { - ButtonEventDataTransition::const_iterator bi; - for (bi = b->begin(); bi != b->end(); ++bi) { - const ButtonEvent &be = (*bi); - string event_name = be._button.get_name(); - - if (be._type == ButtonEvent::T_down) { - // Button down. - if (!_mods.button_down(be._button)) { - // We only prepend modifier names on the button-down events, - // and only for buttons which are not themselves modifiers. - event_name = _mods.get_prefix() + event_name; - } - - if (!_throw_buttons_active || has_throw_button(_mods, be._button)) { - // Process this button. - throw_event(_prefix + event_name); - - } else { - // Don't process this button; instead, pass it down to future - // generations. - if (new_b == (ButtonEventDataTransition *)NULL) { - new_b = new ButtonEventDataTransition; - } - new_b->push_back(be); - } - - } else if (be._type == ButtonEvent::T_up) { - // Button up. - _mods.button_up(be._button); - - // We always throw button "up" events if we have any - // definition for the button at all, regardless of the state - // of the modifier keys. - if (!_throw_buttons_active || has_throw_button(be._button)) { - throw_event(_prefix + event_name + "-up"); - } - if (_throw_buttons_active) { - // Now pass the event on to future generations. We always - // pass "up" events, even if we are intercepting this - // particular button; unless we're processing all buttons in - // which case it doesn't matter. - if (new_b == (ButtonEventDataTransition *)NULL) { - new_b = new ButtonEventDataTransition; - } - new_b->push_back(be); - } - - } else { - // Some other kind of button event (e.g. keypress). Don't - // throw an event for this, but do pass it down. - if (new_b == (ButtonEventDataTransition *)NULL) { - new_b = new ButtonEventDataTransition; - } - new_b->push_back(be); - } - } - } - - if (new_b == (ButtonEventDataTransition *)NULL) { - data.clear_transition(_button_events_type); - } else { - data.set_transition(_button_events_type, new_b); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: ButtonThrower::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -void ButtonThrower:: -init_type() { - DataNode::init_type(); - register_type(_type_handle, "ButtonThrower", - DataNode::get_class_type()); - - ButtonEventDataTransition::init_type(); - register_data_transition(_button_events_type, "ButtonEvents", - ButtonEventDataTransition::get_class_type()); -} diff --git a/panda/src/tform/buttonThrower.h b/panda/src/tform/buttonThrower.h deleted file mode 100644 index f6a5013a65..0000000000 --- a/panda/src/tform/buttonThrower.h +++ /dev/null @@ -1,99 +0,0 @@ -// Filename: buttonThrower.h -// Created by: drose (09Feb99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef BUTTONTHROWER_H -#define BUTTONTHROWER_H - -#include "pandabase.h" - -#include "dataNode.h" -#include "modifierButtons.h" -#include "pvector.h" -#include "pmap.h" - -//////////////////////////////////////////////////////////////////// -// Class : ButtonThrower -// Description : Throws Panda Events for button down/up events -// generated within the data graph. -// -// This is a DataNode which is intended to be parented -// to the data graph below a device which is generating -// a sequence of button events as stored in an -// ButtonEventDataTransitions data member. It simply -// takes each button it finds and throws a corresponding -// event based on the button name via the throw_event() -// call. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA ButtonThrower : public DataNode { -PUBLISHED: - ButtonThrower(const string &name = ""); - ~ButtonThrower(); - - void set_prefix(const string &prefix); - bool has_prefix() const; - string get_prefix() const; - - const ModifierButtons &get_modifier_buttons() const; - void set_modifier_buttons(const ModifierButtons &mods); - - void set_throw_buttons_active(bool flag); - bool get_throw_buttons_active() const; - - bool add_throw_button(const ModifierButtons &mods, const ButtonHandle &button); - bool remove_throw_button(const ModifierButtons &mods, const ButtonHandle &button); - bool has_throw_button(const ModifierButtons &mods, const ButtonHandle &button) const; - bool has_throw_button(const ButtonHandle &button) const; - void clear_throw_buttons(); - -public: - virtual void write(ostream &out, int indent_level = 0) const; - -private: - string _prefix; - ModifierButtons _mods; - - typedef pvector ThrowButtonDef; - typedef pmap ThrowButtons; - ThrowButtons _throw_buttons; - bool _throw_buttons_active; - -//////////////////////////////////////////////////////////////////// -// From parent class DataNode -//////////////////////////////////////////////////////////////////// -public: - virtual void - transmit_data(AllTransitionsWrapper &data); - - // inputs - static TypeHandle _button_events_type; - -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(); - -private: - static TypeHandle _type_handle; -}; - -#endif diff --git a/panda/src/tform/config_tform.cxx b/panda/src/tform/config_tform.cxx index 7493068021..242c5edd62 100644 --- a/panda/src/tform/config_tform.cxx +++ b/panda/src/tform/config_tform.cxx @@ -18,19 +18,12 @@ #include "config_tform.h" -#include "dataValve.h" -#include "driveInterface.h" #include "qpdriveInterface.h" -#include "buttonThrower.h" #include "qpbuttonThrower.h" -#include "mouseWatcher.h" #include "qpmouseWatcher.h" #include "mouseWatcherGroup.h" #include "mouseWatcherRegion.h" -#include "planarSlider.h" -#include "trackball.h" #include "qptrackball.h" -#include "transform2sg.h" #include "qptransform2sg.h" #include @@ -51,18 +44,11 @@ const double drive_horizontal_ramp_up_time = config_tform.GetDouble("drive-horiz const double drive_horizontal_ramp_down_time = config_tform.GetDouble("drive-horizontal-ramp-down-time", 0.0); ConfigureFn(config_tform) { - DataValve::init_type(); - DriveInterface::init_type(); qpDriveInterface::init_type(); - ButtonThrower::init_type(); qpButtonThrower::init_type(); - MouseWatcher::init_type(); qpMouseWatcher::init_type(); MouseWatcherGroup::init_type(); MouseWatcherRegion::init_type(); - PlanarSlider::init_type(); - Trackball::init_type(); qpTrackball::init_type(); - Transform2SG::init_type(); qpTransform2SG::init_type(); } diff --git a/panda/src/tform/dataValve.I b/panda/src/tform/dataValve.I deleted file mode 100644 index eda5fe5051..0000000000 --- a/panda/src/tform/dataValve.I +++ /dev/null @@ -1,136 +0,0 @@ -// Filename: dataValve.I -// Created by: drose (05Feb01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::Control::Constructor -// Access: Published -// Description: A unique Control can be assigned to each child of the -// DataValve, or the same Control may be shared between -// different children as desired. Each Control may be -// explicitly set on or off to enable or disable all -// data flow to that child, respectively; it may also be -// set to a "buttons" state, in which it enables or -// disables data flow to the child based on the current -// state of the modifier buttons as held by the user. -// -// In addition to being assigned to control all data to -// a particular child, a particular Control may be set -// to control only data of a particular type to a -// particular child. See set_control() and -// set_fine_control() on DataValve. -//////////////////////////////////////////////////////////////////// -INLINE DataValve::Control:: -Control() { - _state = S_on; -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::Control::set_on -// Access: Published -// Description: Sets the state on this particular Control to be on -// until further notice. Child nodes guarded by this -// Control will receive data. -//////////////////////////////////////////////////////////////////// -INLINE void DataValve::Control:: -set_on() { - _state = S_on; -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::Control::set_off -// Access: Published -// Description: Sets the state on this particular Control to be off -// until further notice. Child nodes guarded by this -// Control will not receive data. -//////////////////////////////////////////////////////////////////// -INLINE void DataValve::Control:: -set_off() { - _state = S_off; -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::Control::set_buttons -// Access: Published -// Description: Sets the state on this particular Control to be -// dependent on the current set of buttons being held -// down by the user. The ModifierButtons object here -// must exactly match the ModifierButtons object set on -// the DataValve in order and number of buttons. -// -// The best way to generate the ModifierButtons list is -// to create a new ModifierButtons based on the value -// returned by DataValve::get_modifier_buttons(), then -// explicitly call button_up() and button_down() on each -// button that you want to be up or down. -//////////////////////////////////////////////////////////////////// -INLINE void DataValve::Control:: -set_buttons(const ModifierButtons &mods) { - _state = S_buttons; - _mods = mods; -} - - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::set_default_control -// Access: Public -// Description: Sets the Control that will apply to each child that -// does not have a particular control set via -// set_control(). -//////////////////////////////////////////////////////////////////// -INLINE void DataValve:: -set_default_control(DataValve::Control *control) { - _default_control = control; -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::get_default_control -// Access: Public -// Description: Returns the Control that will apply to each child -// that does not have a particular control set via -// set_control(). -//////////////////////////////////////////////////////////////////// -INLINE DataValve::Control *DataValve:: -get_default_control() const { - return _default_control; -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::set_modifier_buttons -// Access: Public -// Description: Specifies the set of buttons that the DataValve will -// monitor as modifier buttons. The exact same set of -// ModifierButtons must be specified on the DataValve as -// well as on all of its Controls in order to -// successfully use modifier buttons to switch the -// valves automatically. -//////////////////////////////////////////////////////////////////// -INLINE void DataValve:: -set_modifier_buttons(const ModifierButtons &mods) { - _mods = mods; -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::get_modifier_buttons -// Access: Public -// Description: Returns the set of ModifierButtons currently being -// monitored. See set_modifier_buttons(). -//////////////////////////////////////////////////////////////////// -INLINE const ModifierButtons &DataValve:: -get_modifier_buttons() const { - return _mods; -} diff --git a/panda/src/tform/dataValve.cxx b/panda/src/tform/dataValve.cxx deleted file mode 100644 index a65755d221..0000000000 --- a/panda/src/tform/dataValve.cxx +++ /dev/null @@ -1,401 +0,0 @@ -// Filename: dataValve.cxx -// Created by: drose (05Feb01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "dataValve.h" - -#include "dataRelation.h" -#include "buttonEventDataTransition.h" -#include "allTransitionsWrapper.h" - -TypeHandle DataValve::_type_handle; - -TypeHandle DataValve::_button_events_type; - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::Control::is_on -// Access: Published -// Description: Returns true if the indicated Control is currently -// on, given the particular DataNode it applies to. -// (The DataNode is necessary to determine the current -// state of the ModiferButtons. -//////////////////////////////////////////////////////////////////// -bool DataValve::Control:: -is_on(const DataValve &valve) const { - switch (_state) { - case S_on: - return true; - - case S_off: - return false; - - case S_buttons: - return _mods == valve.get_modifier_buttons(); - } - - // Invalid state. - nassertr(false, false); - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::Control::output -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -void DataValve::Control:: -output(ostream &out) const { - switch (_state) { - case S_on: - out << "on"; - break; - - case S_off: - out << "off"; - break; - - case S_buttons: - out << _mods; - break; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -DataValve:: -DataValve(const string &name) : DataNode(name) { - _default_control = new Control; -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::Destructor -// Access: Published, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -DataValve:: -~DataValve() { -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::set_control -// Access: Published -// Description: Sets an overall Control on the indicated child node. -// The nth child of this node, zero-based, will receive -// data only while the indicated Control is on. This -// affects all types of data that is not specifically -// mentioned by set_fine_control(). -//////////////////////////////////////////////////////////////////// -void DataValve:: -set_control(int child_index, Control *control) { - ensure_child_index(child_index); - nassertv(child_index >= 0 && child_index < (int)_controls.size()); - _controls[child_index]._control = control; -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::clear_control -// Access: Published -// Description: Removes the overall Control, as well as all fine -// controls, from the indicated child node. The -// indicated child will now be affected only by the -// default control. See set_control() and -// set_fine_control(). -//////////////////////////////////////////////////////////////////// -void DataValve:: -clear_control(int child_index) { - nassertv(child_index >= 0); - if (child_index < (int)_controls.size()) { - _controls[child_index]._control.clear(); - _controls[child_index]._fine_controls.clear(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::has_control -// Access: Published -// Description: Returns true if the indicated child has a particular -// Control set, or if it has *any* fine controls set. -// If this returns false, the child is controlled only -// by the default control. See set_control() and -// set_fine_control(). -//////////////////////////////////////////////////////////////////// -bool DataValve:: -has_control(int child_index) const { - nassertr(child_index >= 0, false); - if (child_index < (int)_controls.size()) { - return - !_controls[child_index]._control.is_null() || - !_controls[child_index]._fine_controls.empty(); - } - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::get_control -// Access: Published -// Description: Returns the control that has been set for the -// indicated child, or NULL if no control has been set -// (which implies the default control is in affect for -// the indicated child). Note that it is possible for -// this function to return NULL even if has_control(), -// above, returned true, since a fine control may have -// been set without setting a particular general -// control. -//////////////////////////////////////////////////////////////////// -DataValve::Control *DataValve:: -get_control(int child_index) const { - nassertr(child_index >= 0, NULL); - if (child_index < (int)_controls.size()) { - return _controls[child_index]._control; - } - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::set_fine_control -// Access: Published -// Description: Sets the "fine" control for the indicated child index -// and the indicated data type. This overrides the -// control set by set_control() for this child, but only -// for data of this type. This can be used to send -// data of different types to different children. -//////////////////////////////////////////////////////////////////// -void DataValve:: -set_fine_control(int child_index, TypeHandle data_type, Control *control) { - ensure_child_index(child_index); - nassertv(child_index >= 0 && child_index < (int)_controls.size()); - _controls[child_index]._fine_controls[data_type] = control; -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::clear_fine_control -// Access: Published -// Description: Removes the particular fine control set by -// set_fine_control() for the indicated child index and -// data type. Data of this type will now be controlled -// by the Control indicated by set_control() for this -// child, or by set_default_control() if nothing is -// indicated by set_control(). -//////////////////////////////////////////////////////////////////// -void DataValve:: -clear_fine_control(int child_index, TypeHandle data_type) { - nassertv(child_index >= 0); - if (child_index < (int)_controls.size()) { - _controls[child_index]._fine_controls.erase(data_type); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::has_fine_control -// Access: Published -// Description: Returns true if the indicated child has a particular -// fine control set for the indicated data type, or -// false otherwise. -//////////////////////////////////////////////////////////////////// -bool DataValve:: -has_fine_control(int child_index, TypeHandle data_type) const { - nassertr(child_index >= 0, false); - if (child_index < (int)_controls.size()) { - return _controls[child_index]._fine_controls.count(data_type) != 0; - } - return false; -} - - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::get_fine_control -// Access: Published -// Description: Returns the fine control that has been set for the -// indicated child and data type, or NULL if no such -// fine control has been set. -//////////////////////////////////////////////////////////////////// -DataValve::Control *DataValve:: -get_fine_control(int child_index, TypeHandle data_type) const { - nassertr(child_index >= 0, NULL); - if (child_index < (int)_controls.size()) { - FineControls::const_iterator fci = - _controls[child_index]._fine_controls.find(data_type); - if (fci != _controls[child_index]._fine_controls.end()) { - return (*fci).second; - } - } - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void DataValve:: -write(ostream &out, int indent_level) const { - indent(out, indent_level) - << "DataValve " << get_name() << ": (default control is " - << *_default_control << ")\n"; - - size_t i; - for (i = 0; i < _controls.size(); i++) { - if (has_control(i)) { - const Child &child = _controls[i]; - indent(out, indent_level + 2) - << "Child " << i << ": "; - - if (child._control.is_null()) { - out << "(default)"; - } else { - out << *child._control; - } - out << "\n"; - - FineControls::const_iterator fci; - for (fci = child._fine_controls.begin(); - fci != child._fine_controls.end(); - ++fci) { - indent(out, indent_level + 4) - << (*fci).first << " " << *(*fci).second; - } - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::ensure_child_index -// Access: Private -// Description: Guarantees that we have at least enough children in -// the _control vector to describe the indicated -// child_index. -//////////////////////////////////////////////////////////////////// -void DataValve:: -ensure_child_index(int child_index) { - _controls.reserve(child_index + 1); - while ((int)_controls.size() <= child_index) { - _controls.push_back(Child()); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::transmit_data -// Access: Public, Virtual -// Description: Called once before transmit_data_per_child() is -// called for each child, this gives the node a chance -// to process its inputs. -//////////////////////////////////////////////////////////////////// -void DataValve:: -transmit_data(AllTransitionsWrapper &data) { - // Update our modifier buttons during the overall pass. - const ButtonEventDataTransition *b; - if (get_transition_into(b, data, _button_events_type)) { - b->update_mods(_mods); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::transmit_data_per_child -// Access: Public, Virtual -// Description: Should be overridden in a derived class that wants to -// send a different data stream to each child. -// Normally, a node only overrides transmit_data(), -// which takes a set of input data transitions and -// generates a set of output data transitions. A node -// may also override transmit_data_per_child(), which is -// called after transmit_data(), once per child; this -// function may be used to send individual data -// transitions to each child. -//////////////////////////////////////////////////////////////////// -void DataValve:: -transmit_data_per_child(AllTransitionsWrapper &data, int child_index) { - // Consider which data this child wants to see. - static const FineControls empty_controls; - - Control *control = _default_control; - const FineControls *fine_controls = &empty_controls; - - if (child_index < (int)_controls.size()) { - if (!_controls[child_index]._control.is_null()) { - control = _controls[child_index]._control; - } - fine_controls = &_controls[child_index]._fine_controls; - } - - if (control->is_on(*this)) { - if (fine_controls->empty()) { - // The control is on, and we have no further fine-tuning. All - // data goes to the indicated node. - return; - - } else { - // The control is on, and we have some fine-tuning. Any data - // type explicitly "off" should be yanked. - FineControls::const_iterator fci; - for (fci = fine_controls->begin(); fci != fine_controls->end(); ++fci) { - TypeHandle data_type = (*fci).first; - Control *fcontrol = (*fci).second; - - if (!fcontrol->is_on(*this)) { - data.clear_transition(data_type); - } - } - } - - } else { - if (fine_controls->empty()) { - // The control is off, and we have no further fine-tuning. All - // data gets eliminated. - data.clear(); - - } else { - // The control is off, and we have some fine-tuning. Any data - // type explicitly "on" should be preserved. - AllTransitionsWrapper temp; - - FineControls::const_iterator fci; - for (fci = fine_controls->begin(); fci != fine_controls->end(); ++fci) { - TypeHandle data_type = (*fci).first; - Control *fcontrol = (*fci).second; - - if (fcontrol->is_on(*this)) { - NodeTransition *attrib = data.get_transition(data_type); - if (attrib != (NodeTransition *)NULL) { - temp.set_transition(data_type, attrib); - } - } - } - - data = temp; - } - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: DataValve::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -void DataValve:: -init_type() { - DataNode::init_type(); - register_type(_type_handle, "DataValve", - DataNode::get_class_type()); - - ButtonEventDataTransition::init_type(); - register_data_transition(_button_events_type, "ButtonEvents", - ButtonEventDataTransition::get_class_type()); -} diff --git a/panda/src/tform/dataValve.h b/panda/src/tform/dataValve.h deleted file mode 100644 index 81ce51318d..0000000000 --- a/panda/src/tform/dataValve.h +++ /dev/null @@ -1,144 +0,0 @@ -// Filename: dataValve.h -// Created by: drose (05Feb01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DATAVALVE_H -#define DATAVALVE_H - -#include "pandabase.h" - -#include "dataNode.h" -#include "modifierButtons.h" -#include "referenceCount.h" -#include "pointerTo.h" - -//////////////////////////////////////////////////////////////////// -// Class : DataValve -// Description : This DataNode can be used to selectively control -// which child node or nodes receive certain data graph -// events, based on the type of data and possibly on the -// combination of modifier buttons being held down by -// the user. -// -// It's particularly useful when used in conjunction -// with one or more Trackball interfaces, for instance, -// to move around various different objects according to -// the key combination being held down. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA DataValve : public DataNode { -PUBLISHED: - DataValve(const string &name = ""); - virtual ~DataValve(); - - // The Control is used extensively within the DataValve class to - // manage the data flow; see the comments on the Control - // constructor. - class EXPCL_PANDA Control : public ReferenceCount { - PUBLISHED: - INLINE Control(); - - INLINE void set_on(); - INLINE void set_off(); - INLINE void set_buttons(const ModifierButtons &mods); - - bool is_on(const DataValve &valve) const; - - void output(ostream &out) const; - - private: - enum State { - S_on, - S_off, - S_buttons - }; - State _state; - ModifierButtons _mods; - }; - - INLINE void set_default_control(Control *control); - INLINE Control *get_default_control() const; - - void set_control(int child_index, Control *control); - void clear_control(int child_index); - bool has_control(int child_index) const; - Control *get_control(int child_index) const; - - void set_fine_control(int child_index, TypeHandle data_type, Control *control); - void clear_fine_control(int child_index, TypeHandle data_type); - bool has_fine_control(int child_index, TypeHandle data_type) const; - Control *get_fine_control(int child_index, TypeHandle data_type) const; - - INLINE void set_modifier_buttons(const ModifierButtons &mods); - INLINE const ModifierButtons &get_modifier_buttons() const; - -public: - virtual void write(ostream &out, int indent_level = 0) const; - -private: - void ensure_child_index(int child_index); - - ModifierButtons _mods; - PT(Control) _default_control; - - typedef pmap FineControls; - - class Child { - public: - PT(Control) _control; - FineControls _fine_controls; - }; - - typedef pvector Controls; - Controls _controls; - - -//////////////////////////////////////////////////////////////////// -// From parent class DataNode -//////////////////////////////////////////////////////////////////// -public: - virtual void - transmit_data(AllTransitionsWrapper &data); - - virtual void - transmit_data_per_child(AllTransitionsWrapper &data, int child_index); - - // inputs - static TypeHandle _button_events_type; - - -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(); - -private: - static TypeHandle _type_handle; -}; - -INLINE ostream &operator << (ostream &out, const DataValve::Control &control) { - control.output(out); - return out; -} - -#include "dataValve.I" - -#endif diff --git a/panda/src/tform/driveInterface.I b/panda/src/tform/driveInterface.I deleted file mode 100644 index 2ab0a03d3b..0000000000 --- a/panda/src/tform/driveInterface.I +++ /dev/null @@ -1,526 +0,0 @@ -// Filename: driveInterface.I -// Created by: drose (12Feb01) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::set_forward_speed -// Access: Published -// Description: Sets the speed of full forward motion, when the mouse -// is at the very top of the window. This is in units -// (e.g. feet) per second. -//////////////////////////////////////////////////////////////////// -INLINE void DriveInterface:: -set_forward_speed(float speed) { - _forward_speed = speed; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::get_forward_speed -// Access: Published -// Description: Returns the speed of full forward motion, when the -// mouse is at the very top of the window. This is in -// units (e.g. feet) per second. -//////////////////////////////////////////////////////////////////// -INLINE float DriveInterface:: -get_forward_speed() const { - return _forward_speed; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::set_reverse_speed -// Access: Published -// Description: Sets the speed of full reverse motion, when the mouse -// is at the very bottom of the window. This is in -// units (e.g. feet) per second. -//////////////////////////////////////////////////////////////////// -INLINE void DriveInterface:: -set_reverse_speed(float speed) { - _reverse_speed = speed; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::get_reverse_speed -// Access: Published -// Description: Returns the speed of full reverse motion, when the -// mouse is at the very bottom of the window. This is -// in units (e.g. feet) per second. -//////////////////////////////////////////////////////////////////// -INLINE float DriveInterface:: -get_reverse_speed() const { - return _reverse_speed; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::set_rotate_speed -// Access: Published -// Description: Sets the maximum rate at which the user can rotate -// left or right, when the mouse is at the very edge of -// the window. This is in degrees per second. -//////////////////////////////////////////////////////////////////// -INLINE void DriveInterface:: -set_rotate_speed(float speed) { - _rotate_speed = speed; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::get_rotate_speed -// Access: Published -// Description: Returns the maximum rate at which the user can rotate -// left or right, when the mouse is at the very edge of -// the window. This is in degrees per second. -//////////////////////////////////////////////////////////////////// -INLINE float DriveInterface:: -get_rotate_speed() const { - return _rotate_speed; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::set_vertical_dead_zone -// Access: Published -// Description: Sets the size of the horizontal bar in the center of -// the screen that represents the "dead zone" of -// vertical motion: the region in which the mouse does -// not report vertical motion. This is in a fraction of -// the window height, so 0.5 will set a dead zone as -// large as half the screen. -//////////////////////////////////////////////////////////////////// -INLINE void DriveInterface:: -set_vertical_dead_zone(float speed) { - _vertical_dead_zone = speed; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::get_vertical_dead_zone -// Access: Published -// Description: Returns the size of the horizontal bar in the center -// of the screen that represents the "dead zone" of -// vertical motion: the region in which the mouse does -// not report vertical motion. This is in a fraction of -// the window height, so 0.5 will set a dead zone as -// large as half the screen. -//////////////////////////////////////////////////////////////////// -INLINE float DriveInterface:: -get_vertical_dead_zone() const { - return _vertical_dead_zone; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::set_horizontal_dead_zone -// Access: Published -// Description: Sets the size of the vertical bar in the center of -// the screen that represents the "dead zone" of -// horizontal motion: the region in which the mouse does -// not report horizontal motion. This is in a fraction of -// the window width, so 0.5 will set a dead zone as -// large as half the screen. -//////////////////////////////////////////////////////////////////// -INLINE void DriveInterface:: -set_horizontal_dead_zone(float speed) { - _horizontal_dead_zone = speed; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::get_horizontal_dead_zone -// Access: Published -// Description: Returns the size of the vertical bar in the center -// of the screen that represents the "dead zone" of -// horizontal motion: the region in which the mouse does -// not report horizontal motion. This is in a fraction of -// the window width, so 0.5 will set a dead zone as -// large as half the screen. -//////////////////////////////////////////////////////////////////// -INLINE float DriveInterface:: -get_horizontal_dead_zone() const { - return _horizontal_dead_zone; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::set_vertical_ramp_up_time -// Access: Published -// Description: Sets the amount of time, in seconds, it takes between -// the time an up or down arrow key is pressed and the -// time it registers full forward or backward motion. -//////////////////////////////////////////////////////////////////// -INLINE void DriveInterface:: -set_vertical_ramp_up_time(float ramp_up_time) { - _vertical_ramp_up_time = ramp_up_time; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::get_vertical_ramp_up_time -// Access: Published -// Description: Returns the amount of time, in seconds, it takes -// between the time an up or down arrow key is pressed -// and the time it registers full forward or backward -// motion. -//////////////////////////////////////////////////////////////////// -INLINE float DriveInterface:: -get_vertical_ramp_up_time() const { - return _vertical_ramp_up_time; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::set_vertical_ramp_down_time -// Access: Published -// Description: Sets the amount of time, in seconds, it takes between -// the time an up or down arrow key is released and the -// time it registers no motion. -//////////////////////////////////////////////////////////////////// -INLINE void DriveInterface:: -set_vertical_ramp_down_time(float ramp_down_time) { - _vertical_ramp_down_time = ramp_down_time; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::get_vertical_ramp_down_time -// Access: Published -// Description: Returns the amount of time, in seconds, it takes -// between the time an up or down arrow key is released -// and the time it registers no motion. -//////////////////////////////////////////////////////////////////// -INLINE float DriveInterface:: -get_vertical_ramp_down_time() const { - return _vertical_ramp_down_time; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::set_horizontal_ramp_up_time -// Access: Published -// Description: Sets the amount of time, in seconds, it takes between -// the time a left or right arrow key is pressed and the -// time it registers full rotation. -//////////////////////////////////////////////////////////////////// -INLINE void DriveInterface:: -set_horizontal_ramp_up_time(float ramp_up_time) { - _horizontal_ramp_up_time = ramp_up_time; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::get_horizontal_ramp_up_time -// Access: Published -// Description: Returns the amount of time, in seconds, it takes -// between the time a left or right arrow key is pressed -// and the time it registers full rotation. -//////////////////////////////////////////////////////////////////// -INLINE float DriveInterface:: -get_horizontal_ramp_up_time() const { - return _horizontal_ramp_up_time; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::set_horizontal_ramp_down_time -// Access: Published -// Description: Sets the amount of time, in seconds, it takes between -// the time a left or right arrow key is released and the -// time it registers no motion. -//////////////////////////////////////////////////////////////////// -INLINE void DriveInterface:: -set_horizontal_ramp_down_time(float ramp_down_time) { - _horizontal_ramp_down_time = ramp_down_time; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::get_horizontal_ramp_down_time -// Access: Published -// Description: Returns the amount of time, in seconds, it takes -// between the time a left or right arrow key is released -// and the time it registers no motion. -//////////////////////////////////////////////////////////////////// -INLINE float DriveInterface:: -get_horizontal_ramp_down_time() const { - return _horizontal_ramp_down_time; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::get_speed -// Access: Published -// Description: Returns the speed of the previous update in units/sec -//////////////////////////////////////////////////////////////////// -INLINE float DriveInterface:: -get_speed() const { - return _speed; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::get_rot_speed -// Access: Published -// Description: Returns the rot_speed of the previous update in units/sec -//////////////////////////////////////////////////////////////////// -INLINE float DriveInterface:: -get_rot_speed() const { - return _rot_speed; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::get_pos -// Access: Published -// Description: Returns the driver's position. -//////////////////////////////////////////////////////////////////// -INLINE const LPoint3f &DriveInterface:: -get_pos() const { - return _xyz; -} - -INLINE float DriveInterface:: -get_x() const { - return _xyz[0]; -} - -INLINE float DriveInterface:: -get_y() const { - return _xyz[1]; -} - -INLINE float DriveInterface:: -get_z() const { - return _xyz[2]; -} - - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::set_pos -// Access: Published -// Description: Directly sets the driver's position. -//////////////////////////////////////////////////////////////////// -INLINE void DriveInterface:: -set_pos(const LVecBase3f &vec) { - _xyz = vec; - recompute(); -} - -INLINE void DriveInterface:: -set_pos(float x, float y, float z) { - _xyz.set(x, y, z); - recompute(); -} - -INLINE void DriveInterface:: -set_x(float x) { - _xyz[0] = x; - recompute(); -} - -INLINE void DriveInterface:: -set_y(float y) { - _xyz[1] = y; - recompute(); -} - -INLINE void DriveInterface:: -set_z(float z) { - _xyz[2] = z; - recompute(); -} - - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::get_hpr -// Access: Published -// Description: Returns the driver's orientation. -//////////////////////////////////////////////////////////////////// -INLINE const LVecBase3f &DriveInterface:: -get_hpr() const { - return _hpr; -} - -INLINE float DriveInterface:: -get_h() const { - return _hpr[0]; -} - -INLINE float DriveInterface:: -get_p() const { - return _hpr[1]; -} - -INLINE float DriveInterface:: -get_r() const { - return _hpr[2]; -} - - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::set_hpr -// Access: Published -// Description: Directly sets the driver's orientation. -//////////////////////////////////////////////////////////////////// -INLINE void DriveInterface:: -set_hpr(const LVecBase3f &hpr) { - _hpr = hpr; - recompute(); -} - -INLINE void DriveInterface:: -set_hpr(float h, float p, float r) { - _hpr.set(h, p, r); - recompute(); - - if (_is_force_roll && r != _force_roll) { - reextract(); - } -} - -INLINE void DriveInterface:: -set_h(float h) { - _hpr[0] = h; - recompute(); -} - -INLINE void DriveInterface:: -set_p(float p) { - _hpr[1] = p; - recompute(); -} - -INLINE void DriveInterface:: -set_r(float r) { - _hpr[2] = r; - recompute(); - - if (_is_force_roll && r != _force_roll) { - reextract(); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::is_force_roll -// Access: Published -// Description: Returns true if the force_roll state is in effect, -// e.g. because of a previous call to set_force_roll(). -// In this state, the roll cannot be set to any value -// other than what the force_roll value indicates. -//////////////////////////////////////////////////////////////////// -INLINE bool DriveInterface:: -is_force_roll() const { - return _is_force_roll; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::clear_force_roll -// Access: Published -// Description: Disables the force_roll state. See set_force_roll(). -//////////////////////////////////////////////////////////////////// -INLINE void DriveInterface:: -clear_force_roll() { - _is_force_roll = false; -} - - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::set_coordinate_system -// Access: Published -// Description: Sets the coordinate system of the DriveInterface. -// Normally, this is the default coordinate system. -// This changes the plane the user drives around in; -// it's normally the horizontal plane (e.g. the X-Y -// plane in a Z-up coordinate system, or the X-Z plane -// in a Y-up coordinate system). -//////////////////////////////////////////////////////////////////// -INLINE void DriveInterface:: -set_coordinate_system(CoordinateSystem cs) { - _cs = cs; - recompute(); -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::get_coordinate_system -// Access: Published -// Description: Returns the coordinate system of the DriveInterface. -// See set_coordinate_system(). -//////////////////////////////////////////////////////////////////// -INLINE CoordinateSystem DriveInterface:: -get_coordinate_system() const { - return _cs; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::set_ignore_mouse -// Access: Published -// Description: Changes the state of the ignore_mouse flag. If this -// flag is true, the DriveInterface will ignore mouse -// down button events (but still recognize mouse up -// button events); the user will not be able to start -// the DriveInterface going again if it is stopped, but -// if the user is currently holding down a mouse button -// it will not stop immediately until the user -// eventually releases the button. -//////////////////////////////////////////////////////////////////// -INLINE void DriveInterface:: -set_ignore_mouse(bool ignore_mouse) { - _ignore_mouse = ignore_mouse; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::get_ignore_mouse -// Access: Published -// Description: Returns the current setting of the ignore_mouse flag. -// See set_ignore_mouse(). -//////////////////////////////////////////////////////////////////// -INLINE bool DriveInterface:: -get_ignore_mouse() const { - return _ignore_mouse; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::set_force_mouse -// Access: Published -// Description: Changes the state of the force_mouse flag. If this -// flag is true, the mouse button need not be held down -// in order to drive the avatar around. -//////////////////////////////////////////////////////////////////// -INLINE void DriveInterface:: -set_force_mouse(bool force_mouse) { - _force_mouse = force_mouse; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::get_force_mouse -// Access: Published -// Description: Returns the current setting of the force_mouse flag. -// See set_force_mouse(). -//////////////////////////////////////////////////////////////////// -INLINE bool DriveInterface:: -get_force_mouse() const { - return _force_mouse; -} - - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::set_mat -// Access: Published -// Description: Stores the indicated transform in the driveInterface. -// This is a transform in global space, regardless of -// the rel_to node. -//////////////////////////////////////////////////////////////////// -INLINE void DriveInterface:: -set_mat(const LMatrix4f &mat) { - _mat = mat; - reextract(); -} - - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::get_mat -// Access: Published -// Description: Fills mat with the net transformation applied by the -// current state. -//////////////////////////////////////////////////////////////////// -INLINE const LMatrix4f &DriveInterface:: -get_mat() const { - return _mat; -} diff --git a/panda/src/tform/driveInterface.cxx b/panda/src/tform/driveInterface.cxx deleted file mode 100644 index 7e5ebc4459..0000000000 --- a/panda/src/tform/driveInterface.cxx +++ /dev/null @@ -1,495 +0,0 @@ -// Filename: driveInterface.cxx -// Created by: drose (17Feb00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "driveInterface.h" -#include "config_tform.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -TypeHandle DriveInterface::_type_handle; - -TypeHandle DriveInterface::_xyz_type; -TypeHandle DriveInterface::_button_events_type; -TypeHandle DriveInterface::_transform_type; - - -DriveInterface::KeyHeld:: -KeyHeld() { - _down = false; - _changed_time = 0.0f; - _effect = 0.0f; - _effect_at_change = 0.0f; -} - -float DriveInterface::KeyHeld:: -get_effect(float ramp_up_time, float ramp_down_time) { - double elapsed = ClockObject::get_global_clock()->get_frame_time() - _changed_time; - - if (_down) { - // We are currently holding down the key. That means we base our - // effect on the ramp_up_time. - if (ramp_up_time == 0.0f) { - _effect = 1.0f; - - } else { - float change = elapsed / ramp_up_time; - _effect = min(_effect_at_change + change, 1.0f); - } - - } else { - // We are *not* currently holding down the key. That means we - // base our effect on the ramp_down_time. - if (ramp_down_time == 0.0f) { - _effect = 0.0f; - - } else { - float change = elapsed / ramp_down_time; - _effect = max(_effect_at_change - change, 0.0f); - } - } - - return _effect; -} - -void DriveInterface::KeyHeld:: -set_key(bool down) { - if (_down != down) { - _down = down; - _changed_time = ClockObject::get_global_clock()->get_frame_time(); - _effect_at_change = _effect; - } -} - -void DriveInterface::KeyHeld:: -clear() { - _down = false; - _changed_time = 0.0f; - _effect = 0.0f; - _effect_at_change = 0.0f; -} - -bool DriveInterface::KeyHeld:: -operator < (const DriveInterface::KeyHeld &other) const { - if (_down != other._down) { - // If one has the key held down and the other doesn't, the down - // key wins. - return _down; - } - - // Otherwise, the most-recently changed key wins. - return _changed_time > other._changed_time; -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -DriveInterface:: -DriveInterface(const string &name) : DataNode(name) { - _forward_speed = drive_forward_speed; - _reverse_speed = drive_reverse_speed; - _rotate_speed = drive_rotate_speed; - _vertical_dead_zone = drive_vertical_dead_zone; - _horizontal_dead_zone = drive_horizontal_dead_zone; - _vertical_center = drive_vertical_center; - _horizontal_center = drive_horizontal_center; - - _vertical_ramp_up_time = drive_vertical_ramp_up_time; - _vertical_ramp_down_time = drive_vertical_ramp_down_time; - _horizontal_ramp_up_time = drive_horizontal_ramp_up_time; - _horizontal_ramp_down_time = drive_horizontal_ramp_down_time; - - _speed = 0.0f; - _rot_speed = 0.0f; - - _xyz.set(0.0f, 0.0f, 0.0f); - _hpr.set(0.0f, 0.0f, 0.0f); - _mat = LMatrix4f::ident_mat(); - _force_roll = 0.0f; - _is_force_roll = true; - - _cs = default_coordinate_system; - _ignore_mouse = false; - _force_mouse = false; - - _mods.add_button(MouseButton::one()); - _mods.add_button(MouseButton::two()); - _mods.add_button(MouseButton::three()); - - _transform = new MatrixDataTransition; - _transform->set_value(_mat); - _attrib.set_transition(_transform_type, _transform); -} - - - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::Destructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -DriveInterface:: -~DriveInterface() { -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::reset -// Access: Published -// Description: Reinitializes the driver to the origin and resets any -// knowledge about buttons being held down. -//////////////////////////////////////////////////////////////////// -void DriveInterface:: -reset() { - _xyz.set(0.0f, 0.0f, 0.0f); - _hpr.set(0.0f, 0.0f, 0.0f); - _force_roll = 0.0f; - _mat = LMatrix4f::ident_mat(); - _up_arrow.clear(); - _down_arrow.clear(); - _left_arrow.clear(); - _right_arrow.clear(); - - _mods.all_buttons_up(); -} - - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::set_force_roll -// Access: Published -// Description: Sets the force_roll state. In this state, roll is -// always fixed to a particular value (typically zero), -// regardless of what it is explicitly set to via -// set_hpr(). -//////////////////////////////////////////////////////////////////// -void DriveInterface:: -set_force_roll(float force_roll) { - if (_is_force_roll) { - // If we already had force_roll() in effect, we have to - // recompensate for it. - if (_force_roll != force_roll) { - _force_roll = force_roll; - reextract(); - } - - } else { - _force_roll = force_roll; - _is_force_roll = true; - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::force_dgraph -// Access: Public -// Description: This is a special kludge for DriveInterface to allow -// us to avoid the one-frame latency after a collision. -// It forces an immediate partial data flow for all data -// graph nodes below this node, causing all data nodes -// that depend on this matrix to be updated immediately. -//////////////////////////////////////////////////////////////////// -void DriveInterface:: -force_dgraph() { - _transform->set_value(_mat); - - DataGraphTraverser dgt; - dgt.traverse_below(this, _attrib); -} - - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::apply -// Access: Private -// Description: Applies the operation indicated by the user's mouse -// motion to the current state. Returns the matrix -// indicating the new state. -//////////////////////////////////////////////////////////////////// -void DriveInterface:: -apply(double x, double y, bool any_button) { - - // First reset the speeds - _speed = 0.0f; - _rot_speed = 0.0f; - - if (any_button || _force_mouse) { - // If we're holding down any of the mouse buttons, do this - // computation based on the mouse position. - - // Determine, based on the mouse's position and the amount of time - // elapsed since last frame, how far forward/backward we should - // move and how much we should rotate. - - // First, how fast are we moving? This is based on the mouse's - // vertical position. - - float dead_zone_top = _vertical_center + _vertical_dead_zone; - float dead_zone_bottom = _vertical_center - _vertical_dead_zone; - - if (y >= dead_zone_top) { - // Motion is forward. Compute the throttle value: the ratio of - // the mouse pointer within the range of vertical movement. - float throttle = - // double 1.0, not 1.0f, is required here to satisfy min() - (min(y, 1.0) - dead_zone_top) / - (1.0f - dead_zone_top); - _speed = throttle * _forward_speed; - - } else if (y <= dead_zone_bottom) { - // Motion is backward. - float throttle = - (max(y, -1.0) - dead_zone_bottom) / - (-1.0f - dead_zone_bottom); - _speed = -throttle * _reverse_speed; - } - - // Now, what's our rotational velocity? This is based on the - // mouse's horizontal position. - - float dead_zone_right = _horizontal_center + _horizontal_dead_zone; - float dead_zone_left = _horizontal_center - _horizontal_dead_zone; - - if (x >= dead_zone_right) { - // Rotation is to the right. Compute the throttle value: the - // ratio of the mouse pointer within the range of horizontal - // movement. - float throttle = - (min(x, 1.0) - dead_zone_right) / - (1.0f - dead_zone_right); - _rot_speed = throttle * _rotate_speed; - - } else if (x <= dead_zone_left) { - // Rotation is to the left. - float throttle = - (max(x, -1.0) - dead_zone_left) / - (-1.0f - dead_zone_left); - _rot_speed = -throttle * _rotate_speed; - } - - } else { - // If we're not holding down any of the mouse buttons, do this - // computation based on the arrow keys. - - // Which vertical arrow key changed state more recently? - float throttle; - - if (_up_arrow < _down_arrow) { - throttle = _up_arrow.get_effect(_vertical_ramp_up_time, - _vertical_ramp_down_time); - _speed = throttle * _forward_speed; - _down_arrow._effect = 0.0f; - - } else { - throttle = _down_arrow.get_effect(_vertical_ramp_up_time, - _vertical_ramp_down_time); - _speed = -throttle * _reverse_speed; - _up_arrow._effect = 0.0f; - } - - // Which horizontal arrow key changed state more recently? - if (_right_arrow < _left_arrow) { - throttle = _right_arrow.get_effect(_horizontal_ramp_up_time, - _horizontal_ramp_down_time); - _rot_speed = throttle * _rotate_speed; - _left_arrow._effect = 0.0f; - - } else { - throttle = _left_arrow.get_effect(_horizontal_ramp_up_time, - _horizontal_ramp_down_time); - _rot_speed = -throttle * _rotate_speed; - _right_arrow._effect = 0.0f; - } - _right_arrow._effect = throttle; - _left_arrow._effect = throttle; - } - - if (_speed == 0.0f && _rot_speed == 0.0f) { - return; - } - - // Now how far did we move based on the amount of time elapsed? - float distance = ClockObject::get_global_clock()->get_dt() * _speed; - float rotation = ClockObject::get_global_clock()->get_dt() * _rot_speed; - - // Now apply the vectors. - - // rot_mat is the rotation matrix corresponding to our previous - // heading. - LMatrix3f rot_mat = - LMatrix3f::rotate_mat_normaxis(_hpr[0], LVector3f::up(_cs), _cs); - - // Take a step in the direction of our previous heading. - LVector3f step = distance * (LVector3f::forward(_cs) * rot_mat); - - // To prevent upward drift due to numerical errors, force the - // vertical component of our step to zero (it should be pretty near - // zero anyway). - switch (_cs) { - case CS_zup_right: - case CS_zup_left: - step[2] = 0.0f; - break; - - case CS_yup_right: - case CS_yup_left: - step[1] = 0.0f; - break; - - default: - break; - } - - _xyz += step; - _hpr[0] -= rotation; - - recompute(); -} - - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::reextract -// Access: Private -// Description: Given a correctly computed _mat matrix, rederive the -// translation and rotation elements. -//////////////////////////////////////////////////////////////////// -void DriveInterface:: -reextract() { - LVecBase3f scale; - - if (_is_force_roll) { - // We strongly discourage a roll other than _force_roll. - decompose_matrix(_mat, scale, _hpr, _xyz, _force_roll); - } else { - decompose_matrix(_mat, scale, _hpr, _xyz); - } - - if (tform_cat.is_debug()) { - tform_cat.debug() - << "Reextract " << _hpr << ", " << _xyz << " from:\n"; - _mat.write(tform_cat.debug(false), 2); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::recompute -// Access: Private -// Description: Rebuilds the matrix according to the stored rotation -// and translation components. -//////////////////////////////////////////////////////////////////// -void DriveInterface:: -recompute() { - compose_matrix(_mat, LVecBase3f(1.0f, 1.0f, 1.0f), _hpr, _xyz, _cs); -} - - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::transmit_data -// Access: Public -// Description: Convert mouse data into a driveInterface matrix -//////////////////////////////////////////////////////////////////// -void DriveInterface:: -transmit_data(AllTransitionsWrapper &data) { - - // Look for mouse activity. - double x = 0.0f; - double y = 0.0f; - - bool got_mouse = false; - - const Vec3DataTransition *xyz; - if (get_transition_into(xyz, data, _xyz_type)) { - LVecBase3f p = xyz->get_value(); - x = p[0]; - y = p[1]; - - got_mouse = true; - } - - // Look for keyboard events. - const ButtonEventDataTransition *b; - if (get_transition_into(b, data, _button_events_type)) { - ButtonEventDataTransition::const_iterator bi; - for (bi = b->begin(); bi != b->end(); ++bi) { - const ButtonEvent &be = (*bi); - if (be._type != ButtonEvent::T_keystroke) { - bool down = (be._type == ButtonEvent::T_down); - - if (down) { - // We only trap button down events if (a) the mouse is in the - // window, and (b) we aren't set to ignore the mouse. - if (got_mouse && !_ignore_mouse) { - _mods.add_event(be); - } - } else { - // However, we always trap button up events, so we don't get - // confused and believe a button is still being held down when - // it is not. - _mods.add_event(be); - } - - if (be._button == KeyboardButton::up()) { - _up_arrow.set_key(down); - } else if (be._button == KeyboardButton::down()) { - _down_arrow.set_key(down); - } else if (be._button == KeyboardButton::left()) { - _left_arrow.set_key(down); - } else if (be._button == KeyboardButton::right()) { - _right_arrow.set_key(down); - } - } - } - } - - apply(x, y, _mods.is_any_down()); - _transform->set_value(_mat); - - // Now send our matrix down the pipe. - data = _attrib; -} - - -//////////////////////////////////////////////////////////////////// -// Function: DriveInterface::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -void DriveInterface:: -init_type() { - DataNode::init_type(); - register_type(_type_handle, "DriveInterface", - DataNode::get_class_type()); - - Vec3DataTransition::init_type(); - register_data_transition(_xyz_type, "XYZ", - Vec3DataTransition::get_class_type()); - MatrixDataTransition::init_type(); - register_data_transition(_transform_type, "Transform", - MatrixDataTransition::get_class_type()); - ButtonEventDataTransition::init_type(); - register_data_transition(_button_events_type, "ButtonEvents", - ButtonEventDataTransition::get_class_type()); -} diff --git a/panda/src/tform/driveInterface.h b/panda/src/tform/driveInterface.h deleted file mode 100644 index 61348e161f..0000000000 --- a/panda/src/tform/driveInterface.h +++ /dev/null @@ -1,203 +0,0 @@ -// Filename: driveInterface.h -// Created by: drose (17Feb00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef DRIVEINTERFACE_H -#define DRIVEINTERFACE_H - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -//////////////////////////////////////////////////////////////////// -// Class : DriveInterface -// Description : This is a TFormer, similar to Trackball, that moves -// around a transform matrix in response to mouse input. -// The basic motion is on a horizontal plane, as if -// driving a vehicle. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA DriveInterface : public DataNode { -PUBLISHED: - DriveInterface(const string &name = ""); - ~DriveInterface(); - - INLINE void set_forward_speed(float speed); - INLINE float get_forward_speed() const; - INLINE void set_reverse_speed(float speed); - INLINE float get_reverse_speed() const; - INLINE void set_rotate_speed(float speed); - INLINE float get_rotate_speed() const; - INLINE void set_vertical_dead_zone(float zone); - INLINE float get_vertical_dead_zone() const; - INLINE void set_horizontal_dead_zone(float zone); - INLINE float get_horizontal_dead_zone() const; - - INLINE void set_vertical_ramp_up_time(float ramp_up_time); - INLINE float get_vertical_ramp_up_time() const; - INLINE void set_vertical_ramp_down_time(float ramp_down_time); - INLINE float get_vertical_ramp_down_time() const; - INLINE void set_horizontal_ramp_up_time(float ramp_up_time); - INLINE float get_horizontal_ramp_up_time() const; - INLINE void set_horizontal_ramp_down_time(float ramp_down_time); - INLINE float get_horizontal_ramp_down_time() const; - - INLINE float get_speed() const; - INLINE float get_rot_speed() const; - - void reset(); - - /// **** Translation **** - - INLINE const LPoint3f &get_pos() const; - INLINE float get_x() const; - INLINE float get_y() const; - INLINE float get_z() const; - INLINE void set_pos(const LVecBase3f &vec); - INLINE void set_pos(float x, float y, float z); - INLINE void set_x(float x); - INLINE void set_y(float y); - INLINE void set_z(float z); - - /// **** Rotation **** - - INLINE const LVecBase3f &get_hpr() const; - INLINE float get_h() const; - INLINE float get_p() const; - INLINE float get_r() const; - INLINE void set_hpr(const LVecBase3f &hpr); - INLINE void set_hpr(float h, float p, float r); - INLINE void set_h(float h); - INLINE void set_p(float p); - INLINE void set_r(float r); - - void set_force_roll(float force_roll); - INLINE bool is_force_roll() const; - INLINE void clear_force_roll(); - - INLINE void set_coordinate_system(CoordinateSystem cs); - INLINE CoordinateSystem get_coordinate_system() const; - - INLINE void set_ignore_mouse(bool ignore_mouse); - INLINE bool get_ignore_mouse() const; - - INLINE void set_force_mouse(bool force_mouse); - INLINE bool get_force_mouse() const; - - void set_mat(const LMatrix4f &mat); - const LMatrix4f &get_mat() const; - - void force_dgraph(); - -private: - void apply(double x, double y, bool any_button); - - void reextract(); - void recompute(); - - float _forward_speed; // units / sec, mouse all the way up - float _reverse_speed; // units / sec, mouse all the way down - float _rotate_speed; // degrees / sec, mouse all the way over - float _vertical_dead_zone; // fraction of window size - float _horizontal_dead_zone; // fraction of window size - float _vertical_center; // window units, 0 = center, -1 = bottom, 1 = top - float _horizontal_center; // window units, 0 = center, -1 = left, 1 = right - - // The time it takes to ramp up to full speed from a stop (or return - // to a stop from full speed) when using the keyboard. - float _vertical_ramp_up_time; - float _vertical_ramp_down_time; - float _horizontal_ramp_up_time; - float _horizontal_ramp_down_time; - - float _speed; // instantaneous units / sec - float _rot_speed; // instantaneous rotational units / sec - - LPoint3f _xyz; - LVecBase3f _hpr; - LMatrix4f _mat; - float _force_roll; - bool _is_force_roll; - CoordinateSystem _cs; - bool _ignore_mouse; - bool _force_mouse; - - // Remember which mouse buttons are being held down. - ModifierButtons _mods; - - // Remember which arrow keys are being held down and which aren't, - // and at what point they last changed state. - class KeyHeld { - public: - KeyHeld(); - float get_effect(float ramp_up_time, float ramp_down_time); - void set_key(bool down); - void clear(); - bool operator < (const KeyHeld &other) const; - - float _effect; - bool _down; - double _changed_time; - float _effect_at_change; - }; - KeyHeld _up_arrow, _down_arrow; - KeyHeld _left_arrow, _right_arrow; - -//////////////////////////////////////////////////////////////////// -// From parent class DataNode -//////////////////////////////////////////////////////////////////// -public: - - virtual void - transmit_data(AllTransitionsWrapper &data); - - AllTransitionsWrapper _attrib; - PT(MatrixDataTransition) _transform; - - // inputs - static TypeHandle _xyz_type; - static TypeHandle _button_events_type; - - // outputs - static TypeHandle _transform_type; - - -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(); - -private: - static TypeHandle _type_handle; -}; - -#include "driveInterface.I" - -#endif diff --git a/panda/src/tform/mouseWatcher.I b/panda/src/tform/mouseWatcher.I deleted file mode 100644 index 6f9747b1ff..0000000000 --- a/panda/src/tform/mouseWatcher.I +++ /dev/null @@ -1,437 +0,0 @@ -// Filename: mouseWatcher.I -// Created by: drose (13Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::has_mouse -// Access: Published -// Description: Returns true if the mouse is anywhere within the -// window, false otherwise. Also see is_mouse_open(). -//////////////////////////////////////////////////////////////////// -INLINE bool MouseWatcher:: -has_mouse() const { - return _has_mouse; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::is_mouse_open -// Access: Published -// Description: Returns true if the mouse is within the window and -// not over some particular MouseWatcherRegion that is -// marked to suppress mouse events; that is, that the -// mouse is in open space within the window. -//////////////////////////////////////////////////////////////////// -INLINE bool MouseWatcher:: -is_mouse_open() const { - return _has_mouse && (_suppress_flags & MouseWatcherRegion::SF_mouse_position) == 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::get_mouse -// Access: Published -// Description: It is only valid to call this if has_mouse() returns -// true. If so, this returns the current position of -// the mouse within the window. -//////////////////////////////////////////////////////////////////// -INLINE const LPoint2f &MouseWatcher:: -get_mouse() const { -#ifndef NDEBUG - static LPoint2f bogus_mouse(0.0f, 0.0f); - nassertr(_has_mouse, bogus_mouse); -#endif - return _mouse; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::get_mouse_x -// Access: Published -// Description: It is only valid to call this if has_mouse() returns -// true. If so, this returns the current X position of -// the mouse within the window. -//////////////////////////////////////////////////////////////////// -INLINE float MouseWatcher:: -get_mouse_x() const { - nassertr(_has_mouse, 0.0f); - return _mouse[0]; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::get_mouse_y -// Access: Published -// Description: It is only valid to call this if has_mouse() returns -// true. If so, this returns the current Y position of -// the mouse within the window. -//////////////////////////////////////////////////////////////////// -INLINE float MouseWatcher:: -get_mouse_y() const { - nassertr(_has_mouse, 0.0f); - return _mouse[1]; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::is_over_region -// Access: Published -// Description: Returns true if the mouse is over any rectangular -// region, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool MouseWatcher:: -is_over_region() const { - return get_over_region() != (MouseWatcherRegion *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::is_over_region -// Access: Published -// Description: Returns true if the mouse is over any rectangular -// region, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool MouseWatcher:: -is_over_region(float x, float y) const { - return get_over_region(x, y) != (MouseWatcherRegion *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::is_over_region -// Access: Published -// Description: Returns true if the mouse is over any rectangular -// region, false otherwise. -//////////////////////////////////////////////////////////////////// -INLINE bool MouseWatcher:: -is_over_region(const LPoint2f &pos) const { - return get_over_region(pos) != (MouseWatcherRegion *)NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::get_over_region -// Access: Published -// Description: Returns the smallest region the mouse is currently -// over, or NULL if it is over no region. -//////////////////////////////////////////////////////////////////// -INLINE MouseWatcherRegion *MouseWatcher:: -get_over_region() const { - return _preferred_region; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::get_over_region -// Access: Published -// Description: Returns the smallest region the indicated point is -// over, or NULL if it is over no region. -//////////////////////////////////////////////////////////////////// -INLINE MouseWatcherRegion *MouseWatcher:: -get_over_region(float x, float y) const { - return get_over_region(LPoint2f(x, y)); -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::set_button_down_pattern -// Access: Published -// Description: Sets the pattern string that indicates how the event -// names are generated when a button is depressed. This -// is a string that may contain any of the following: -// -// %r - the name of the region the mouse is over -// %b - the name of the button pressed. -// -// The event name will be based on the in_pattern -// string specified here, with all occurrences of the -// above strings replaced with the corresponding values. -//////////////////////////////////////////////////////////////////// -INLINE void MouseWatcher:: -set_button_down_pattern(const string &pattern) { - _button_down_pattern = pattern; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::get_button_down_pattern -// Access: Published -// Description: Returns the string that indicates how event names are -// generated when a button is depressed. See -// set_button_down_pattern(). -//////////////////////////////////////////////////////////////////// -INLINE const string &MouseWatcher:: -get_button_down_pattern() const { - return _button_down_pattern; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::set_button_up_pattern -// Access: Published -// Description: Sets the pattern string that indicates how the event -// names are generated when a button is released. See -// set_button_down_pattern(). -//////////////////////////////////////////////////////////////////// -INLINE void MouseWatcher:: -set_button_up_pattern(const string &pattern) { - _button_up_pattern = pattern; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::get_button_up_pattern -// Access: Published -// Description: Returns the string that indicates how event names are -// generated when a button is released. See -// set_button_down_pattern(). -//////////////////////////////////////////////////////////////////// -INLINE const string &MouseWatcher:: -get_button_up_pattern() const { - return _button_up_pattern; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::set_enter_pattern -// Access: Published -// Description: Sets the pattern string that indicates how the event -// names are generated when the mouse enters a region. -// This is different from within_pattern, in that a -// mouse is only "entered" in the topmost region at a -// given time, while it might be "within" multiple -// nested regions. -//////////////////////////////////////////////////////////////////// -INLINE void MouseWatcher:: -set_enter_pattern(const string &pattern) { - _enter_pattern = pattern; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::get_enter_pattern -// Access: Published -// Description: Returns the string that indicates how event names are -// generated when the mouse enters a region. This is -// different from within_pattern, in that a mouse is -// only "entered" in the topmost region at a given time, -// while it might be "within" multiple nested regions. -//////////////////////////////////////////////////////////////////// -INLINE const string &MouseWatcher:: -get_enter_pattern() const { - return _enter_pattern; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::set_leave_pattern -// Access: Published -// Description: Sets the pattern string that indicates how the event -// names are generated when the mouse leaves a region. -// This is different from without_pattern, in that a -// mouse is only "entered" in the topmost region at a -// given time, while it might be "within" multiple -// nested regions. -//////////////////////////////////////////////////////////////////// -INLINE void MouseWatcher:: -set_leave_pattern(const string &pattern) { - _leave_pattern = pattern; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::get_leave_pattern -// Access: Published -// Description: Returns the string that indicates how event names are -// generated when the mouse leaves a region. This is -// different from without_pattern, in that a mouse is -// only "entered" in the topmost region at a given time, -// while it might be "within" multiple nested regions. -//////////////////////////////////////////////////////////////////// -INLINE const string &MouseWatcher:: -get_leave_pattern() const { - return _leave_pattern; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::set_within_pattern -// Access: Published -// Description: Sets the pattern string that indicates how the event -// names are generated when the mouse wanders over a -// region. This is different from enter_pattern, in -// that a mouse is only "entered" in the topmost region -// at a given time, while it might be "within" multiple -// nested regions. -//////////////////////////////////////////////////////////////////// -INLINE void MouseWatcher:: -set_within_pattern(const string &pattern) { - _within_pattern = pattern; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::get_within_pattern -// Access: Published -// Description: Returns the string that indicates how event names are -// generated when the mouse wanders over a region. This -// is different from enter_pattern, in that a mouse is -// only "entered" in the topmost region at a given time, -// while it might be "within" multiple nested regions. -//////////////////////////////////////////////////////////////////// -INLINE const string &MouseWatcher:: -get_within_pattern() const { - return _within_pattern; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::set_without_pattern -// Access: Published -// Description: Sets the pattern string that indicates how the event -// names are generated when the mouse wanders out of a -// region. This is different from leave_pattern, in -// that a mouse is only "entered" in the topmost region -// at a given time, while it might be "within" multiple -// nested regions. -//////////////////////////////////////////////////////////////////// -INLINE void MouseWatcher:: -set_without_pattern(const string &pattern) { - _without_pattern = pattern; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::get_without_pattern -// Access: Published -// Description: Returns the string that indicates how event names are -// generated when the mouse wanders out of a region. -// This is different from leave_pattern, in that a mouse -// is only "entered" in the topmost region at a given -// time, while it might be "within" multiple nested -// regions. -//////////////////////////////////////////////////////////////////// -INLINE const string &MouseWatcher:: -get_without_pattern() const { - return _without_pattern; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::set_geometry -// Access: Published -// Description: Sets the arc that will be transformed each frame by -// the mouse's coordinates. It will also be hidden when -// the mouse goes outside the window. This can be used -// to implement a software mouse pointer for when a -// hardware (or system) mouse pointer is unavailable. -//////////////////////////////////////////////////////////////////// -INLINE void MouseWatcher:: -set_geometry(NodeRelation *arc) { - _geometry = arc; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::has_geometry -// Access: Published -// Description: Returns true if a software mouse pointer has been -// setup via set_geometry(), or false otherwise. See -// set_geometry(). -//////////////////////////////////////////////////////////////////// -INLINE bool MouseWatcher:: -has_geometry() const { - return !_geometry.is_null(); -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::get_geometry -// Access: Published -// Description: Returns the arc that has been set as the software -// mouse pointer, or NULL if no arc has been set. See -// has_geometry() and set_geometry(). -//////////////////////////////////////////////////////////////////// -INLINE NodeRelation *MouseWatcher:: -get_geometry() const { - return _geometry; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::clear_geometry -// Access: Published -// Description: Stops the use of the software cursor set up via -// set_geometry(). -//////////////////////////////////////////////////////////////////// -INLINE void MouseWatcher:: -clear_geometry() { - _geometry.clear(); -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::set_extra_handler -// Access: Published -// Description: As an optimization for the C++ Gui, an extra handler -// can be registered with a mouseWatcher so that events -// can be dealt with much sooner. -//////////////////////////////////////////////////////////////////// -INLINE void MouseWatcher:: -set_extra_handler(EventHandler *eh) { - _eh = eh; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::get_extra_handler -// Access: Published -// Description: As an optimization for the C++ Gui, an extra handler -// can be registered with a mouseWatcher so that events -// can be dealt with much sooner. -//////////////////////////////////////////////////////////////////// -INLINE EventHandler *MouseWatcher:: -get_extra_handler(void) const { - return _eh; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::set_modifier_buttons -// Access: Public -// Description: Sets the buttons that should be monitored as modifier -// buttons for generating events to the -// MouseWatcherRegions. -//////////////////////////////////////////////////////////////////// -INLINE void MouseWatcher:: -set_modifier_buttons(const ModifierButtons &mods) { - _mods = mods; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::get_modifier_buttons -// Access: Published -// Description: Returns the set of buttons that are being monitored -// as modifier buttons, as well as their current state. -//////////////////////////////////////////////////////////////////// -INLINE ModifierButtons MouseWatcher:: -get_modifier_buttons() const { - return _mods; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::within_region -// Access: Protected -// Description: Called internally to indicate the mouse pointer has -// moved within the indicated region's boundaries. -//////////////////////////////////////////////////////////////////// -INLINE void MouseWatcher:: -within_region(MouseWatcherRegion *region, const MouseWatcherParameter ¶m) { - region->within(param); - throw_event_pattern(_within_pattern, region, ButtonHandle::none()); - if (_enter_multiple) { - enter_region(region, param); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::without_region -// Access: Protected -// Description: Called internally to indicate the mouse pointer has -// moved outside of the indicated region's boundaries. -//////////////////////////////////////////////////////////////////// -INLINE void MouseWatcher:: -without_region(MouseWatcherRegion *region, const MouseWatcherParameter ¶m) { - if (_enter_multiple) { - exit_region(region, param); - } - region->without(param); - throw_event_pattern(_without_pattern, region, ButtonHandle::none()); -} diff --git a/panda/src/tform/mouseWatcher.cxx b/panda/src/tform/mouseWatcher.cxx deleted file mode 100644 index a9050ea530..0000000000 --- a/panda/src/tform/mouseWatcher.cxx +++ /dev/null @@ -1,963 +0,0 @@ -// Filename: mouseWatcher.cxx -// Created by: drose (13Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "mouseWatcher.h" -#include "config_tform.h" -#include "mouseWatcherParameter.h" - -#include "mouse.h" -#include "mouseData.h" -#include "buttonEventDataTransition.h" -#include "mouseButton.h" -#include "throw_event.h" -#include "eventParameter.h" -#include "pruneTransition.h" -#include "transformTransition.h" - -#include - -TypeHandle MouseWatcher::_type_handle; - -TypeHandle MouseWatcher::_xyz_type; -TypeHandle MouseWatcher::_pixel_xyz_type; -TypeHandle MouseWatcher::_button_events_type; - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::Constructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -MouseWatcher:: -MouseWatcher(const string &name) : DataNode(name) { - _has_mouse = false; - _suppress_flags = 0; - _preferred_region = (MouseWatcherRegion *)NULL; - _preferred_button_down_region = (MouseWatcherRegion *)NULL; - _button_down = false; - _eh = (EventHandler*)0L; - - // When this flag is true, the mouse pointer is allowed to be - // "entered" into multiple regions simultaneously; when false, it - // will only be "within" multiple regions, but "entered" into the - // topmost of those. - _enter_multiple = false; - - // When this flag is true, moving the pointer into a region is - // enough to click it. The click is simulated with mouse button - // one. - _implicit_click = false; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::Destructor -// Access: Published -// Description: -//////////////////////////////////////////////////////////////////// -MouseWatcher:: -~MouseWatcher() { -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::remove_region -// Access: Published -// Description: Removes the indicated region from the group. -// Returns true if it was successfully removed, or false -// if it wasn't there in the first place. -//////////////////////////////////////////////////////////////////// -bool MouseWatcher:: -remove_region(MouseWatcherRegion *region) { - remove_region_from(_current_regions, region); - if (region == _preferred_region) { - _preferred_region = (MouseWatcherRegion *)NULL; - } - if (region == _preferred_button_down_region) { - _preferred_button_down_region = (MouseWatcherRegion *)NULL; - } - - return MouseWatcherGroup::remove_region(region); -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::get_over_region -// Access: Published -// Description: Returns the preferred region the mouse is over. In -// the case of overlapping regions, the region with the -// largest sort order is preferred; if two regions have -// the same sort order, then the smaller region is -// preferred. -//////////////////////////////////////////////////////////////////// -MouseWatcherRegion *MouseWatcher:: -get_over_region(const LPoint2f &pos) const { - VRegions regions; - get_over_regions(regions, pos); - return get_preferred_region(regions); -} - - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::output -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void MouseWatcher:: -output(ostream &out) const { - DataNode::output(out); - - int count = _regions.size(); - Groups::const_iterator gi; - for (gi = _groups.begin(); gi != _groups.end(); ++gi) { - MouseWatcherGroup *group = (*gi); - count += group->_regions.size(); - } - - out << " (" << count << " regions)"; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::write -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -void MouseWatcher:: -write(ostream &out, int indent_level) const { - indent(out, indent_level) - << "MouseWatcher " << get_name() << ":\n"; - Regions::const_iterator ri; - for (ri = _regions.begin(); ri != _regions.end(); ++ri) { - MouseWatcherRegion *region = (*ri); - region->write(out, indent_level + 2); - } - - if (!_groups.empty()) { - Groups::const_iterator gi; - for (gi = _groups.begin(); gi != _groups.end(); ++gi) { - MouseWatcherGroup *group = (*gi); - indent(out, indent_level + 2) - << "Subgroup:\n"; - for (ri = group->_regions.begin(); ri != group->_regions.end(); ++ri) { - MouseWatcherRegion *region = (*ri); - region->write(out, indent_level + 4); - } - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::add_group -// Access: Public -// Description: Adds the indicated group of regions to the set of -// regions the MouseWatcher will monitor each frame. -// -// Since the MouseWatcher itself inherits from -// MouseWatcherGroup, this operation is normally not -// necessary--you can simply add the Regions you care -// about one at a time. Adding a complete group is -// useful when you may want to explicitly remove the -// regions as a group later. -// -// Returns true if the group was successfully added, or -// false if it was already on the list. -//////////////////////////////////////////////////////////////////// -bool MouseWatcher:: -add_group(MouseWatcherGroup *group) { - // return _groups.insert(group).second; - - // See if the group is in the set/vector already - PT(MouseWatcherGroup) pt = group; - Groups::const_iterator gi = - find(_groups.begin(), _groups.end(), pt); - if (gi != _groups.end()) { - // Already in the set, return false - return false; - } - - // Not in the set, add it and return true - _groups.push_back(pt); - return true; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::remove_group -// Access: Public -// Description: Removes the indicated group from the set of extra -// groups associated with the MouseWatcher. Returns -// true if successful, or false if the group was already -// removed or was never added via add_group(). -//////////////////////////////////////////////////////////////////// -bool MouseWatcher:: -remove_group(MouseWatcherGroup *group) { - remove_regions_from(_current_regions, group); - if (group->has_region(_preferred_region)) { - _preferred_region = (MouseWatcherRegion *)NULL; - } - if (group->has_region(_preferred_button_down_region)) { - _preferred_button_down_region = (MouseWatcherRegion *)NULL; - } - - // See if the group is in the set/vector - PT(MouseWatcherGroup) pt = group; - Groups::iterator gi = - find(_groups.begin(), _groups.end(), pt); - if (gi != _groups.end()) { - // Found it, now erase it - _groups.erase(gi); - return true; - } - - // Did not find the group to erase - return false; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::get_over_regions -// Access: Protected -// Description: Fills up the "regions" list with the set of regions -// that the indicated point is over, sorted in order by -// pointer. -//////////////////////////////////////////////////////////////////// -void MouseWatcher:: -get_over_regions(MouseWatcher::VRegions ®ions, const LPoint2f &pos) const { - // Ensure the vector is empty before we begin. - regions.clear(); - - Regions::const_iterator ri; - for (ri = _regions.begin(); ri != _regions.end(); ++ri) { - MouseWatcherRegion *region = (*ri); - const LVecBase4f &frame = region->get_frame(); - - if (region->get_active() && - pos[0] >= frame[0] && pos[0] <= frame[1] && - pos[1] >= frame[2] && pos[1] <= frame[3]) { - - regions.push_back(region); - } - } - - // Also check all of our sub-groups. - Groups::const_iterator gi; - for (gi = _groups.begin(); gi != _groups.end(); ++gi) { - MouseWatcherGroup *group = (*gi); - for (ri = group->_regions.begin(); ri != group->_regions.end(); ++ri) { - MouseWatcherRegion *region = (*ri); - const LVecBase4f &frame = region->get_frame(); - - if (region->get_active() && - pos[0] >= frame[0] && pos[0] <= frame[1] && - pos[1] >= frame[2] && pos[1] <= frame[3]) { - - regions.push_back(region); - } - } - } - - // Now sort the regions by pointer. By convention, the Regions - // vectors are always kept in order by pointer, so we can do easy - // linear comparison and intersection operations. - sort(regions.begin(), regions.end()); -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::get_preferred_region -// Access: Protected, Static -// Description: Returns the innermost region of all the regions -// indicated in the given vector (usually, the regions -// the mouse is over). This is the "preferred" region -// that gets some special treatment. -//////////////////////////////////////////////////////////////////// -MouseWatcherRegion *MouseWatcher:: -get_preferred_region(const MouseWatcher::VRegions ®ions) { - if (regions.empty()) { - return (MouseWatcherRegion *)NULL; - } - - VRegions::const_iterator ri; - ri = regions.begin(); - MouseWatcherRegion *preferred = *ri; - ++ri; - while (ri != regions.end()) { - MouseWatcherRegion *region = *ri; - - if (*region < *preferred) { - preferred = region; - } - ++ri; - } - - return preferred; -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::set_current_regions -// Access: Protected -// Description: Changes the "current" regions--the one we consider the -// mouse to be over--to the indicated list, and throws -// whatever events are appropriate because of that. -// -// The list passed in is destroyed. -//////////////////////////////////////////////////////////////////// -void MouseWatcher:: -set_current_regions(MouseWatcher::VRegions ®ions) { - // Set up a parameter for passing through any change events. - MouseWatcherParameter param; - param.set_modifier_buttons(_mods); - param.set_mouse(_mouse); - - // Now do a standard sorted comparison between the two vectors. - VRegions::const_iterator new_ri = regions.begin(); - VRegions::const_iterator old_ri = _current_regions.begin(); - - // Queue up all the new regions so we can send the within patterns - // all at once, after all of the without patterns have been thrown. - vector new_regions; - - bool any_changes = false; - while (new_ri != regions.end() && old_ri != _current_regions.end()) { - if ((*new_ri) < (*old_ri)) { - // Here's a new region that we didn't have last frame. - MouseWatcherRegion *new_region = (*new_ri); - new_regions.push_back(new_region); - any_changes = true; - ++new_ri; - - } else if ((*old_ri) < (*new_ri)) { - // Here's a region we don't have any more. - MouseWatcherRegion *old_region = (*old_ri); - without_region(old_region, param); - any_changes = true; - ++old_ri; - - } else { - // Here's a region that hasn't changed. - ++new_ri; - ++old_ri; - } - } - - while (new_ri != regions.end()) { - // Here's a new region that we didn't have last frame. - MouseWatcherRegion *new_region = (*new_ri); - new_regions.push_back(new_region); - any_changes = true; - ++new_ri; - } - - while (old_ri != _current_regions.end()) { - // Here's a region we don't have any more. - MouseWatcherRegion *old_region = (*old_ri); - without_region(old_region, param); - any_changes = true; - ++old_ri; - } - - if (any_changes) { - // Now that we've compared the two vectors, simply swap them to set - // the new vector. - _current_regions.swap(regions); - - // And don't forget to throw all of the new regions' "within" events. - vector::const_iterator ri; - for (ri = new_regions.begin(); ri != new_regions.end(); ++ri) { - MouseWatcherRegion *new_region = (*ri); - within_region(new_region, param); - } - } - - if (!_enter_multiple) { - // Determine which is the "preferred region", if any. This is the - // topmost region that the mouse cursor is over, and the one that - // we are considered "entered" into. - MouseWatcherRegion *new_preferred_region = - get_preferred_region(_current_regions); - - if (_button_down && new_preferred_region != _preferred_button_down_region) { - // If the button's being held down, we're only allowed to select - // the preferred button down region. - new_preferred_region = (MouseWatcherRegion *)NULL; - } - - if (new_preferred_region != _preferred_region) { - if (_preferred_region != (MouseWatcherRegion *)NULL) { - exit_region(_preferred_region, param); - } - _preferred_region = new_preferred_region; - if (_preferred_region != (MouseWatcherRegion *)NULL) { - enter_region(_preferred_region, param); - } - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::clear_current_regions -// Access: Protected -// Description: Empties the set of current regions. -//////////////////////////////////////////////////////////////////// -void MouseWatcher:: -clear_current_regions() { - if (!_current_regions.empty()) { - // Set up a parameter for passing through any change events. - MouseWatcherParameter param; - param.set_modifier_buttons(_mods); - param.set_mouse(_mouse); - - VRegions::const_iterator old_ri = _current_regions.begin(); - - while (old_ri != _current_regions.end()) { - // Here's a region we don't have any more. - MouseWatcherRegion *old_region = (*old_ri); - old_region->exit(param); - throw_event_pattern(_leave_pattern, old_region, ButtonHandle::none()); - ++old_ri; - } - - _current_regions.clear(); - - if (_preferred_region != (MouseWatcherRegion *)NULL) { - _preferred_region->exit(param); - throw_event_pattern(_leave_pattern, _preferred_region, ButtonHandle::none()); - _preferred_region = (MouseWatcherRegion *)NULL; - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::intersect_regions -// Access: Protected, Static -// Description: Sets result to be the intersection of the list of -// regions in regions_a and regions_b. It is assumed -// that both vectors are already sorted in pointer -// order. -//////////////////////////////////////////////////////////////////// -void MouseWatcher:: -intersect_regions(MouseWatcher::VRegions &result, - const MouseWatcher::VRegions ®ions_a, - const MouseWatcher::VRegions ®ions_b) { - // Get a temporary vector for storing the result in. We don't use - // result directly, because it might be the same vector as one of a - // or b. - VRegions temp; - - // Now do a standard sorted intersection between the two vectors. - VRegions::const_iterator a_ri = regions_a.begin(); - VRegions::const_iterator b_ri = regions_b.begin(); - - while (a_ri != regions_a.end() && b_ri != regions_b.end()) { - if ((*a_ri) < (*b_ri)) { - // Here's a region in a, not in b. - ++a_ri; - - } else if ((*b_ri) < (*a_ri)) { - // Here's a region in b, not in a. - ++b_ri; - - } else { - // Here's a region in both vectors. - temp.push_back(*a_ri); - ++a_ri; - ++b_ri; - } - } - - // Now store the result! - result.swap(temp); -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::remove_region_from -// Access: Protected, Static -// Description: Removes the indicated region from the given vector. -// Assumes the vector is sorted in pointer order. -//////////////////////////////////////////////////////////////////// -void MouseWatcher:: -remove_region_from(MouseWatcher::VRegions ®ions, - MouseWatcherRegion *region) { - VRegions::iterator ri = - lower_bound(regions.begin(), regions.end(), region); - if (ri != regions.end() && (*ri) == region) { - // The region is in the vector. Remove it. - regions.erase(ri); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::remove_regions_from -// Access: Protected, Static -// Description: Removes all the regions in the indicated group from -// the given vector. Assumes the vector is sorted in -// pointer order. -//////////////////////////////////////////////////////////////////// -void MouseWatcher:: -remove_regions_from(MouseWatcher::VRegions ®ions, - MouseWatcherGroup *group) { - // Since the group stores a set of regions, which are also sorted in - // pointer order, we can just do an intersection operation here. - VRegions temp; - - VRegions::const_iterator a_ri = regions.begin(); - MouseWatcherGroup::Regions::const_iterator b_ri = group->_regions.begin(); - - while (a_ri != regions.end() && b_ri != group->_regions.end()) { - if ((*a_ri) < (*b_ri)) { - // Here's a region in the group, not in regions. - ++a_ri; - - } else if ((*b_ri) < (*a_ri)) { - // Here's a region in regions, not in the group. - temp.push_back(*b_ri); - ++b_ri; - - } else { - // Here's a region in the group and in regions. - ++a_ri; - ++b_ri; - } - } - - // Now store the result! - regions.swap(temp); -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::throw_event_for -// Access: Protected -// Description: Throws an event associated with the indicated region, -// using the given pattern. -//////////////////////////////////////////////////////////////////// -void MouseWatcher:: -throw_event_pattern(const string &pattern, const MouseWatcherRegion *region, - const ButtonHandle &button) { - if (pattern.empty()) { - return; - } -#ifndef NDEBUG - if (region != (MouseWatcherRegion *)NULL) { - region->test_ref_count_integrity(); - } -#endif - - string button_name; - if (button != ButtonHandle::none()) { - if (!_mods.has_button(button)) { - // We only prepend modifier names for buttons which are not - // themselves modifiers. - button_name = _mods.get_prefix(); - } - button_name += button.get_name(); - } - - string event; - for (size_t p = 0; p < pattern.size(); ++p) { - if (pattern[p] == '%') { - string cmd = pattern.substr(p + 1, 1); - p++; - if (cmd == "r") { - if (region != (MouseWatcherRegion *)NULL) { - event += button_name; - } - - } else if (cmd == "b") { - event += button.get_name(); - - } else { - tform_cat.error() - << "Invalid symbol in event_pattern: %" << cmd << "\n"; - } - } else { - event += pattern[p]; - } - } - - if (!event.empty()) { - throw_event(event, EventParameter(region), EventParameter(button_name)); - if (_eh != (EventHandler*)0L) - throw_event_directly(*_eh, event, EventParameter(region), - EventParameter(button_name)); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::press -// Access: Protected -// Description: Records the indicated mouse or keyboard button as -// being depressed. -//////////////////////////////////////////////////////////////////// -void MouseWatcher:: -press(ButtonHandle button) { - MouseWatcherParameter param; - param.set_button(button); - param.set_modifier_buttons(_mods); - param.set_mouse(_mouse); - - if (MouseButton::is_mouse_button(button)) { - // Mouse buttons are inextricably linked to the mouse position. - - if (!_button_down) { - _preferred_button_down_region = _preferred_region; - } - _button_down = true; - - if (_preferred_button_down_region != (MouseWatcherRegion *)NULL) { - _preferred_button_down_region->press(param); - throw_event_pattern(_button_down_pattern, - _preferred_button_down_region, button); - } - - } else { - // It's a keyboard button; therefore, send the event to every - // region that wants keyboard buttons, regardless of the mouse - // position. - if (_preferred_region != (MouseWatcherRegion *)NULL) { - // Our current region, the one under the mouse, always get - // all the keyboard events, even if it doesn't set its - // keyboard flag. - _preferred_region->press(param); - } - - if ((_suppress_flags & MouseWatcherRegion::SF_other_button) == 0) { - // All the other regions only get the keyboard events if they - // set their global keyboard flag, *and* the current region does - // not suppress keyboard buttons. - param.set_outside(true); - global_keyboard_press(param); - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::release -// Access: Protected -// Description: Records the indicated mouse or keyboard button as -// being released. -//////////////////////////////////////////////////////////////////// -void MouseWatcher:: -release(ButtonHandle button) { - MouseWatcherParameter param; - param.set_button(button); - param.set_modifier_buttons(_mods); - param.set_mouse(_mouse); - - if (MouseButton::is_mouse_button(button)) { - // Button up. Send the up event associated with the region(s) we - // were over when the button went down. - - // There is some danger of losing button-up events here. If - // more than one button goes down together, we won't detect - // both of the button-up events properly. - if (_preferred_button_down_region != (MouseWatcherRegion *)NULL) { - param.set_outside(_preferred_button_down_region != _preferred_region); - _preferred_button_down_region->release(param); - throw_event_pattern(_button_up_pattern, - _preferred_button_down_region, button); - } - - _button_down = false; - _preferred_button_down_region = (MouseWatcherRegion *)NULL; - - } else { - // It's a keyboard button; therefore, send the event to every - // region that wants keyboard buttons, regardless of the mouse - // position. - if (_preferred_region != (MouseWatcherRegion *)NULL) { - _preferred_region->release(param); - } - - param.set_outside(true); - global_keyboard_release(param); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::keystroke -// Access: Protected -// Description: Records that the indicated keystroke has been -// generated. -//////////////////////////////////////////////////////////////////// -void MouseWatcher:: -keystroke(int keycode) { - MouseWatcherParameter param; - param.set_keycode(keycode); - param.set_modifier_buttons(_mods); - param.set_mouse(_mouse); - - // Keystrokes go to all those regions that want keyboard events, - // regardless of which is the "preferred" region (that is, without - // respect to the mouse position). However, we do set the outside - // flag according to whether the given region is preferred region or - // not. - - Regions::const_iterator ri; - for (ri = _regions.begin(); ri != _regions.end(); ++ri) { - MouseWatcherRegion *region = (*ri); - - if (region->get_keyboard()) { - param.set_outside(region != _preferred_region); - region->keystroke(param); - } - } - - // Also check all of our sub-groups. - Groups::const_iterator gi; - for (gi = _groups.begin(); gi != _groups.end(); ++gi) { - MouseWatcherGroup *group = (*gi); - for (ri = group->_regions.begin(); ri != group->_regions.end(); ++ri) { - MouseWatcherRegion *region = (*ri); - - if (region->get_keyboard()) { - param.set_outside(region != _preferred_region); - region->keystroke(param); - } - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::global_keyboard_press -// Access: Protected -// Description: Calls press() on all regions that are interested in -// receiving global keyboard events, except for the -// current region (which already received this one). -//////////////////////////////////////////////////////////////////// -void MouseWatcher:: -global_keyboard_press(const MouseWatcherParameter ¶m) { - Regions::const_iterator ri; - for (ri = _regions.begin(); ri != _regions.end(); ++ri) { - MouseWatcherRegion *region = (*ri); - - if (region != _preferred_region && region->get_keyboard()) { - region->press(param); - } - } - - // Also check all of our sub-groups. - Groups::const_iterator gi; - for (gi = _groups.begin(); gi != _groups.end(); ++gi) { - MouseWatcherGroup *group = (*gi); - for (ri = group->_regions.begin(); ri != group->_regions.end(); ++ri) { - MouseWatcherRegion *region = (*ri); - - if (region != _preferred_region && region->get_keyboard()) { - region->press(param); - } - } - } -} -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::global_keyboard_release -// Access: Protected -// Description: Calls release() on all regions that are interested in -// receiving global keyboard events, except for the -// current region (which already received this one). -//////////////////////////////////////////////////////////////////// -void MouseWatcher:: -global_keyboard_release(const MouseWatcherParameter ¶m) { - Regions::const_iterator ri; - for (ri = _regions.begin(); ri != _regions.end(); ++ri) { - MouseWatcherRegion *region = (*ri); - - if (region != _preferred_region && region->get_keyboard()) { - region->release(param); - } - } - - // Also check all of our sub-groups. - Groups::const_iterator gi; - for (gi = _groups.begin(); gi != _groups.end(); ++gi) { - MouseWatcherGroup *group = (*gi); - for (ri = group->_regions.begin(); ri != group->_regions.end(); ++ri) { - MouseWatcherRegion *region = (*ri); - - if (region != _preferred_region && region->get_keyboard()) { - region->release(param); - } - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::enter_region -// Access: Protected -// Description: Called internally to indicate the mouse pointer is no -// longer favoring the indicated region. -//////////////////////////////////////////////////////////////////// -void MouseWatcher:: -enter_region(MouseWatcherRegion *region, const MouseWatcherParameter ¶m) { - region->enter(param); - throw_event_pattern(_enter_pattern, region, ButtonHandle::none()); - if (_implicit_click) { - MouseWatcherParameter param1(param); - param1.set_button(MouseButton::one()); - region->press(param1); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::exit_region -// Access: Protected -// Description: Called internally to indicate the mouse pointer is no -// longer favoring the indicated region. -//////////////////////////////////////////////////////////////////// -void MouseWatcher:: -exit_region(MouseWatcherRegion *region, const MouseWatcherParameter ¶m) { - if (_implicit_click) { - MouseWatcherParameter param1(param); - param1.set_button(MouseButton::one()); - region->release(param1); - } - region->exit(param); - throw_event_pattern(_leave_pattern, region, ButtonHandle::none()); -} - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::transmit_data -// Access: Public -// Description: Convert mouse data into a mouseWatcher matrix -//////////////////////////////////////////////////////////////////// -void MouseWatcher:: -transmit_data(AllTransitionsWrapper &data) { - // Get the current mouse position. - const Vec3DataTransition *xyz; - if (!get_transition_into(xyz, data, _xyz_type)) { - if (_has_mouse) { - // Hide the mouse pointer. - if (!_geometry.is_null()) { - _geometry->set_transition(new PruneTransition); - } - } - - _has_mouse = false; - // If the mouse is outside the window, do nothing; let all the - // events continue down the pipe unmolested. - clear_current_regions(); - return; - } - - LVecBase3f p = xyz->get_value(); - _mouse.set(p[0], p[1]); - - if (!_geometry.is_null()) { - // Transform the mouse pointer. - LMatrix4f mat = LMatrix4f::translate_mat(p[0], 0, p[1]); - _geometry->set_transition(new TransformTransition(mat)); - if (!_has_mouse) { - // Show the mouse pointer. - _geometry->clear_transition(PruneTransition::get_class_type()); - } - } - - _has_mouse = true; - - VRegions regions; - get_over_regions(regions, _mouse); - set_current_regions(regions); - - _suppress_flags = 0; - if (_preferred_region != (MouseWatcherRegion *)NULL) { - _suppress_flags = _preferred_region->get_suppress_flags(); - } - - // Look for button events. - const ButtonEventDataTransition *b; - if (get_transition_into(b, data, _button_events_type)) { - ButtonEventDataTransition::const_iterator bi; - for (bi = b->begin(); bi != b->end(); ++bi) { - const ButtonEvent &be = (*bi); - _mods.add_event(be); - - switch (be._type) { - case ButtonEvent::T_down: - press(be._button); - break; - - case ButtonEvent::T_up: - release(be._button); - break; - - case ButtonEvent::T_keystroke: - keystroke(be._keycode); - break; - } - } - } - - if ((_suppress_flags & MouseWatcherRegion::SF_mouse_position) != 0) { - // Suppress the mouse position. - data.clear_transition(_xyz_type); - data.clear_transition(_pixel_xyz_type); - } - int suppress_buttons = (_suppress_flags & MouseWatcherRegion::SF_any_button); - if (suppress_buttons == MouseWatcherRegion::SF_any_button) { - // Suppress all buttons. - data.clear_transition(_button_events_type); - - } else if (suppress_buttons != 0) { - // Suppress some buttons. - const ButtonEventDataTransition *b; - ButtonEventDataTransition *new_b = (ButtonEventDataTransition *)NULL; - - if (get_transition_into(b, data, _button_events_type)) { - ButtonEventDataTransition::const_iterator bi; - for (bi = b->begin(); bi != b->end(); ++bi) { - const ButtonEvent &be = (*bi); - bool suppress = true; - - if (be._type != ButtonEvent::T_keystroke && - MouseButton::is_mouse_button(be._button)) { - suppress = ((suppress_buttons & MouseWatcherRegion::SF_mouse_button) != 0); - } else { - suppress = ((suppress_buttons & MouseWatcherRegion::SF_other_button) != 0); - } - - if (!suppress) { - // Don't suppress this button event; pass it through. - if (new_b == (ButtonEventDataTransition *)NULL) { - new_b = new ButtonEventDataTransition; - } - new_b->push_back(be); - } - } - } - - if (new_b == (ButtonEventDataTransition *)NULL) { - data.clear_transition(_button_events_type); - } else { - data.set_transition(_button_events_type, new_b); - } - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: MouseWatcher::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -void MouseWatcher:: -init_type() { - DataNode::init_type(); - register_type(_type_handle, "MouseWatcher", - DataNode::get_class_type()); - - Vec3DataTransition::init_type(); - register_data_transition(_xyz_type, "XYZ", - Vec3DataTransition::get_class_type()); - register_data_transition(_pixel_xyz_type, "PixelXYZ", - Vec3DataTransition::get_class_type()); - ButtonEventDataTransition::init_type(); - register_data_transition(_button_events_type, "ButtonEvents", - ButtonEventDataTransition::get_class_type()); -} diff --git a/panda/src/tform/mouseWatcher.h b/panda/src/tform/mouseWatcher.h deleted file mode 100644 index 1ad4b84312..0000000000 --- a/panda/src/tform/mouseWatcher.h +++ /dev/null @@ -1,207 +0,0 @@ -// Filename: mouseWatcher.h -// Created by: drose (13Jul00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef MOUSEWATCHER_H -#define MOUSEWATCHER_H - -#include - -#include "mouseWatcherRegion.h" -#include "mouseWatcherGroup.h" - -#include "dataNode.h" -#include "vec3DataTransition.h" -#include "luse.h" -#include "nodeRelation.h" -#include "pointerTo.h" -#include "eventHandler.h" -#include "pt_NodeRelation.h" -#include "modifierButtons.h" -#include "buttonHandle.h" - -#include "pvector.h" - -class MouseWatcherParameter; - -//////////////////////////////////////////////////////////////////// -// Class : MouseWatcher -// Description : This TFormer maintains a list of rectangular regions -// on the screen that are considered special mouse -// regions; typically these will be click buttons. When -// the mouse passes in or out of one of these regions, -// or when a button is clicked while the mouse is in one -// of these regions, an event is thrown. -// -// Mouse events may also be suppressed from the rest of -// the datagraph in these special regions. -// -// This class can also implement a software mouse -// pointer by automatically generating a transform to -// apply to a piece of geometry placed under the 2-d -// scene graph. It will move the geometry around -// according to the mouse's known position. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA MouseWatcher : public DataNode, public MouseWatcherGroup { -PUBLISHED: - MouseWatcher(const string &name = ""); - ~MouseWatcher(); - - bool remove_region(MouseWatcherRegion *region); - - INLINE bool has_mouse() const; - INLINE bool is_mouse_open() const; - INLINE const LPoint2f &get_mouse() const; - INLINE float get_mouse_x() const; - INLINE float get_mouse_y() const; - - INLINE bool is_over_region() const; - INLINE bool is_over_region(float x, float y) const; - INLINE bool is_over_region(const LPoint2f &pos) const; - - INLINE MouseWatcherRegion *get_over_region() const; - INLINE MouseWatcherRegion *get_over_region(float x, float y) const; - MouseWatcherRegion *get_over_region(const LPoint2f &pos) const; - - INLINE void set_button_down_pattern(const string &pattern); - INLINE const string &get_button_down_pattern() const; - - INLINE void set_button_up_pattern(const string &pattern); - INLINE const string &get_button_up_pattern() const; - - INLINE void set_enter_pattern(const string &pattern); - INLINE const string &get_enter_pattern() const; - - INLINE void set_leave_pattern(const string &pattern); - INLINE const string &get_leave_pattern() const; - - INLINE void set_within_pattern(const string &pattern); - INLINE const string &get_within_pattern() const; - - INLINE void set_without_pattern(const string &pattern); - INLINE const string &get_without_pattern() const; - - INLINE void set_geometry(NodeRelation *arc); - INLINE bool has_geometry() const; - INLINE NodeRelation *get_geometry() const; - INLINE void clear_geometry(); - - INLINE void set_extra_handler(EventHandler *eh); - INLINE EventHandler *get_extra_handler(void) const; - - INLINE void set_modifier_buttons(const ModifierButtons &mods); - INLINE ModifierButtons get_modifier_buttons() const; - -public: - virtual void output(ostream &out) const; - virtual void write(ostream &out, int indent_level = 0) const; - - bool add_group(MouseWatcherGroup *group); - bool remove_group(MouseWatcherGroup *group); - -protected: - typedef pvector< PT(MouseWatcherRegion) > VRegions; - void get_over_regions(VRegions ®ions, const LPoint2f &pos) const; - static MouseWatcherRegion *get_preferred_region(const VRegions ®ions); - - void set_current_regions(VRegions ®ions); - void clear_current_regions(); - static void intersect_regions(MouseWatcher::VRegions &result, - const MouseWatcher::VRegions ®ions_a, - const MouseWatcher::VRegions ®ions_b); - static void remove_region_from(MouseWatcher::VRegions ®ions, - MouseWatcherRegion *region); - static void remove_regions_from(MouseWatcher::VRegions ®ions, - MouseWatcherGroup *group); - - - void throw_event_pattern(const string &pattern, - const MouseWatcherRegion *region, - const ButtonHandle &button); - - void press(ButtonHandle button); - void release(ButtonHandle button); - void keystroke(int keycode); - void global_keyboard_press(const MouseWatcherParameter ¶m); - void global_keyboard_release(const MouseWatcherParameter ¶m); - - INLINE void within_region(MouseWatcherRegion *region, const MouseWatcherParameter ¶m); - INLINE void without_region(MouseWatcherRegion *region, const MouseWatcherParameter ¶m); - void enter_region(MouseWatcherRegion *region, const MouseWatcherParameter ¶m); - void exit_region(MouseWatcherRegion *region, const MouseWatcherParameter ¶m); - - // This wants to be a set, but because you cannot export sets across - // dlls in windows, we will make it a vector instead - typedef pvector< PT(MouseWatcherGroup) > Groups; - Groups _groups; - - bool _has_mouse; - int _suppress_flags; - LPoint2f _mouse; - - VRegions _current_regions; - PT(MouseWatcherRegion) _preferred_region; - PT(MouseWatcherRegion) _preferred_button_down_region; - bool _button_down; - - bool _enter_multiple; - bool _implicit_click; - - string _button_down_pattern; - string _button_up_pattern; - string _enter_pattern; - string _leave_pattern; - string _within_pattern; - string _without_pattern; - - PT_NodeRelation _geometry; - - EventHandler *_eh; - - ModifierButtons _mods; - -//////////////////////////////////////////////////////////////////// -// From parent class DataNode -//////////////////////////////////////////////////////////////////// -public: - - virtual void - transmit_data(AllTransitionsWrapper &data); - - // inputs & outputs - static TypeHandle _xyz_type; - static TypeHandle _pixel_xyz_type; - static TypeHandle _button_events_type; - - -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(); - -private: - static TypeHandle _type_handle; -}; - -#include "mouseWatcher.I" - -#endif diff --git a/panda/src/tform/planarSlider.cxx b/panda/src/tform/planarSlider.cxx deleted file mode 100644 index 623bce29b3..0000000000 --- a/panda/src/tform/planarSlider.cxx +++ /dev/null @@ -1,206 +0,0 @@ -// Filename: planarSlider.cxx -// Created by: drose (10Jan00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "planarSlider.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -TypeHandle PlanarSlider::_type_handle; - -TypeHandle PlanarSlider::_xyz_type; -TypeHandle PlanarSlider::_button_events_type; -TypeHandle PlanarSlider::_transform_type; - - -//////////////////////////////////////////////////////////////////// -// Function: PlanarSlider::Constructor -// Access: Public, Scheme -// Description: -//////////////////////////////////////////////////////////////////// -PlanarSlider:: -PlanarSlider(const string &name) : DataNode(name) { - _cs = default_coordinate_system; - - _mouse_pos.set(0.0f, 0.0f); - _transform_mat = LMatrix4f::ident_mat(); - - _transform = new MatrixDataTransition; - _attrib.set_transition(_transform_type, _transform); - - _mods.add_button(MouseButton::one()); -} - - - -//////////////////////////////////////////////////////////////////// -// Function: PlanarSlider::Destructor -// Access: Public, Scheme -// Description: -//////////////////////////////////////////////////////////////////// -PlanarSlider:: -~PlanarSlider() { -} - - - - -//////////////////////////////////////////////////////////////////// -// Function: PlanarSlider::set_coordinate_system -// Access: Public, Scheme -// Description: Sets the coordinate system of the PlanarSlider. -// Normally, this is the default coordinate system. -// This changes the definition of the ground plane. -//////////////////////////////////////////////////////////////////// -void PlanarSlider:: -set_coordinate_system(CoordinateSystem cs) { - _cs = cs; -} - -//////////////////////////////////////////////////////////////////// -// Function: PlanarSlider::get_coordinate_system -// Access: Public, Scheme -// Description: Returns the coordinate system of the PlanarSlider. -// See set_coordinate_system(). -//////////////////////////////////////////////////////////////////// -CoordinateSystem PlanarSlider:: -get_coordinate_system() const { - return _cs; -} - -//////////////////////////////////////////////////////////////////// -// Function: PlanarSlider::set_transform -// Access: Public, Scheme -// Description: Defines the plane in which the TForm operates by -// specifying a transform. By default (with an identity -// transform), the plane is the ground plane, at the -// scale -1 to 1 around the origin. This function may -// specify a rotate, translate, or scale (or any -// arbitrary transform) to reposition the plane. -//////////////////////////////////////////////////////////////////// -void PlanarSlider:: -set_transform(const LMatrix4f &trans) { - _transform_mat = trans; - _inverse_mat = invert(trans); - _inverse_mat.set_row(3, LVector3f(0.0f, 0.0f, 0.0f)); - set_mouse_pos(_mouse_pos); -} - -//////////////////////////////////////////////////////////////////// -// Function: PlanarSlider::get_transform -// Access: Public, Scheme -// Description: Returns the matrix that transforms the plane in which -// the TForm operates. See set_transform(). -//////////////////////////////////////////////////////////////////// -LMatrix4f PlanarSlider:: -get_transform() const { - return _transform_mat; -} - -//////////////////////////////////////////////////////////////////// -// Function: PlanarSlider::set_mouse_pos -// Access: Public, Scheme -// Description: Directly sets the reported position of the mouse. In -// general, this function should not be used unless the -// data graph is disconnected for some reason; normally, -// the PlanarSlider reads the reported mouse position -// directly from the data graph. The mouse position -// ranges from -1 to 1 in both axes. -//////////////////////////////////////////////////////////////////// -void PlanarSlider:: -set_mouse_pos(const LPoint2f &mouse_pos) { - _mouse_pos.set(max(min(mouse_pos[0], 1.0f), -1.0f), - max(min(mouse_pos[1], 1.0f), -1.0f)); - - LMatrix4f mat = - _inverse_mat * - LMatrix4f::translate_mat(LVector3f::rfu(_mouse_pos[0], - _mouse_pos[1], - 0.0f, - _cs)) * - _transform_mat; - - _transform->set_value(mat); -} - -//////////////////////////////////////////////////////////////////// -// Function: PlanarSlider::get_mouse_pos -// Access: Public, Scheme -// Description: Returns the last known position of the mouse, in the -// range -1 to 1 in both axes. -//////////////////////////////////////////////////////////////////// -LPoint2f PlanarSlider:: -get_mouse_pos() const { - return _mouse_pos; -} - -//////////////////////////////////////////////////////////////////// -// Function: PlanarSlider::transmit_data -// Access: Public -// Description: Convert mouse data into a planarSlider matrix -//////////////////////////////////////////////////////////////////// -void PlanarSlider:: -transmit_data(AllTransitionsWrapper &data) { - // First, update our modifier buttons. - const ButtonEventDataTransition *b; - if (get_transition_into(b, data, _button_events_type)) { - b->update_mods(_mods); - } - - // Now look for a mouse position. - const NodeTransition *xyz = data.get_transition(_xyz_type); - - if (xyz != (NodeTransition *)NULL) { - if (_mods.is_any_down()) { - LVecBase3f p = DCAST(Vec3DataTransition, xyz)->get_value(); - set_mouse_pos(LPoint2f(p[0], p[1])); - } - } - - // Now send our matrix down the pipe. - data = _attrib; -} - - -//////////////////////////////////////////////////////////////////// -// Function: PlanarSlider::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -void PlanarSlider:: -init_type() { - DataNode::init_type(); - register_type(_type_handle, "PlanarSlider", - DataNode::get_class_type()); - - Vec3DataTransition::init_type(); - register_data_transition(_xyz_type, "XYZ", - Vec3DataTransition::get_class_type()); - MatrixDataTransition::init_type(); - register_data_transition(_transform_type, "Transform", - MatrixDataTransition::get_class_type()); - ButtonEventDataTransition::init_type(); - register_data_transition(_button_events_type, "ButtonEvents", - ButtonEventDataTransition::get_class_type()); -} diff --git a/panda/src/tform/planarSlider.h b/panda/src/tform/planarSlider.h deleted file mode 100644 index b702c23c68..0000000000 --- a/panda/src/tform/planarSlider.h +++ /dev/null @@ -1,96 +0,0 @@ -// Filename: planarSlider.h -// Created by: drose (10Jan00) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef PLANARSLIDER_H -#define PLANARSLIDER_H - -#include - -#include -#include -#include -#include -#include -#include -#include - - -//////////////////////////////////////////////////////////////////// -// Class : PlanarSlider -// Description : A PlanarSlider TFormer can be connected to a DCS. It -// accepts mouse input from the data graph and uses it -// to slide the DCS around within a specified plane. By -// default, this is the ground plane in the range -1,1. -// This can be scaled or rotated using the -// set_transform() method. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA PlanarSlider : public DataNode { -public: - - PlanarSlider(const string &name = ""); - ~PlanarSlider(); - - void set_coordinate_system(CoordinateSystem cs); - CoordinateSystem get_coordinate_system() const; - - void set_transform(const LMatrix4f &trans); - LMatrix4f get_transform() const; - - void set_mouse_pos(const LPoint2f &mouse_pos); - LPoint2f get_mouse_pos() const; - -private: - CoordinateSystem _cs; - LMatrix4f _transform_mat, _inverse_mat; - LPoint2f _mouse_pos; - ModifierButtons _mods; - -//////////////////////////////////////////////////////////////////// -// From parent class DataNode -//////////////////////////////////////////////////////////////////// -public: - - virtual void - transmit_data(AllTransitionsWrapper &data); - - AllTransitionsWrapper _attrib; - PT(MatrixDataTransition) _transform; - - // inputs - static TypeHandle _xyz_type; - static TypeHandle _button_events_type; - - // outputs - static TypeHandle _transform_type; - - -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(); - -private: - static TypeHandle _type_handle; -}; - -#endif diff --git a/panda/src/tform/qpbuttonThrower.cxx b/panda/src/tform/qpbuttonThrower.cxx index 832e695e14..dd3b97ed7f 100644 --- a/panda/src/tform/qpbuttonThrower.cxx +++ b/panda/src/tform/qpbuttonThrower.cxx @@ -23,6 +23,7 @@ #include "dataNodeTransmit.h" #include "throw_event.h" #include "indent.h" +#include "dcast.h" TypeHandle qpButtonThrower::_type_handle; diff --git a/panda/src/tform/qpdriveInterface.cxx b/panda/src/tform/qpdriveInterface.cxx index d54d745160..3a8061943f 100644 --- a/panda/src/tform/qpdriveInterface.cxx +++ b/panda/src/tform/qpdriveInterface.cxx @@ -16,11 +16,11 @@ // //////////////////////////////////////////////////////////////////// -#include "driveInterface.h" +#include "qpdriveInterface.h" #include "config_tform.h" #include "compose_matrix.h" -#include "mouse.h" +#include "mouseAndKeyboard.h" #include "mouseData.h" #include "clockObject.h" #include "modifierButtons.h" diff --git a/panda/src/tform/qpmouseWatcher.I b/panda/src/tform/qpmouseWatcher.I index cf7af02aa1..8d6481d6ea 100644 --- a/panda/src/tform/qpmouseWatcher.I +++ b/panda/src/tform/qpmouseWatcher.I @@ -313,15 +313,15 @@ get_without_pattern() const { //////////////////////////////////////////////////////////////////// // Function: qpMouseWatcher::set_geometry // Access: Published -// Description: Sets the arc that will be transformed each frame by +// Description: Sets the node that will be transformed each frame by // the mouse's coordinates. It will also be hidden when // the mouse goes outside the window. This can be used // to implement a software mouse pointer for when a // hardware (or system) mouse pointer is unavailable. //////////////////////////////////////////////////////////////////// INLINE void qpMouseWatcher:: -set_geometry(NodeRelation *arc) { - _geometry = arc; +set_geometry(PandaNode *node) { + _geometry = node; } //////////////////////////////////////////////////////////////////// @@ -339,11 +339,11 @@ has_geometry() const { //////////////////////////////////////////////////////////////////// // Function: qpMouseWatcher::get_geometry // Access: Published -// Description: Returns the arc that has been set as the software -// mouse pointer, or NULL if no arc has been set. See +// Description: Returns the node that has been set as the software +// mouse pointer, or NULL if no node has been set. See // has_geometry() and set_geometry(). //////////////////////////////////////////////////////////////////// -INLINE NodeRelation *qpMouseWatcher:: +INLINE PandaNode *qpMouseWatcher:: get_geometry() const { return _geometry; } diff --git a/panda/src/tform/qpmouseWatcher.cxx b/panda/src/tform/qpmouseWatcher.cxx index a9f00034e0..32e352716f 100644 --- a/panda/src/tform/qpmouseWatcher.cxx +++ b/panda/src/tform/qpmouseWatcher.cxx @@ -19,13 +19,15 @@ #include "qpmouseWatcher.h" #include "config_tform.h" #include "mouseWatcherParameter.h" -#include "mouse.h" +#include "mouseAndKeyboard.h" #include "mouseData.h" #include "buttonEventList.h" #include "mouseButton.h" #include "throw_event.h" #include "eventParameter.h" #include "dataNodeTransmit.h" +#include "transformState.h" +#include "dcast.h" #include @@ -851,7 +853,7 @@ do_transmit_data(const DataNodeTransmit &input, DataNodeTransmit &output) { if (_has_mouse) { // Hide the mouse pointer. if (!_geometry.is_null()) { - _geometry->set_transition(new PruneTransition); + _geometry->set_draw_mask(DrawMask::all_off()); } } @@ -870,11 +872,10 @@ do_transmit_data(const DataNodeTransmit &input, DataNodeTransmit &output) { if (!_geometry.is_null()) { // Transform the mouse pointer. - LMatrix4f mat = LMatrix4f::translate_mat(p[0], 0, p[1]); - _geometry->set_transition(new TransformTransition(mat)); + _geometry->set_transform(TransformState::make_pos(LVecBase3f(p[0], 0, p[1]))); if (!_has_mouse) { // Show the mouse pointer. - _geometry->clear_transition(PruneTransition::get_class_type()); + _geometry->set_draw_mask(DrawMask::all_on()); } } diff --git a/panda/src/tform/qpmouseWatcher.h b/panda/src/tform/qpmouseWatcher.h index 9bdfcdd4ba..20f1429fd3 100644 --- a/panda/src/tform/qpmouseWatcher.h +++ b/panda/src/tform/qpmouseWatcher.h @@ -92,9 +92,9 @@ PUBLISHED: INLINE void set_without_pattern(const string &pattern); INLINE const string &get_without_pattern() const; - INLINE void set_geometry(NodeRelation *arc); + INLINE void set_geometry(PandaNode *node); INLINE bool has_geometry() const; - INLINE NodeRelation *get_geometry() const; + INLINE PandaNode *get_geometry() const; INLINE void clear_geometry(); INLINE void set_extra_handler(EventHandler *eh); @@ -165,7 +165,7 @@ protected: string _within_pattern; string _without_pattern; - PT_NodeRelation _geometry; + PT(PandaNode) _geometry; EventHandler *_eh; diff --git a/panda/src/tform/tform_composite1.cxx b/panda/src/tform/tform_composite1.cxx index e548461c74..75c049aeb7 100644 --- a/panda/src/tform/tform_composite1.cxx +++ b/panda/src/tform/tform_composite1.cxx @@ -1,9 +1,5 @@ -#include "buttonThrower.cxx" #include "qpbuttonThrower.cxx" #include "config_tform.cxx" -#include "dataValve.cxx" -#include "driveInterface.cxx" #include "qpdriveInterface.cxx" -#include "planarSlider.cxx" diff --git a/panda/src/tform/tform_composite2.cxx b/panda/src/tform/tform_composite2.cxx index b699580892..e09a19fbb5 100644 --- a/panda/src/tform/tform_composite2.cxx +++ b/panda/src/tform/tform_composite2.cxx @@ -1,11 +1,8 @@ -#include "mouseWatcher.cxx" #include "qpmouseWatcher.cxx" #include "mouseWatcherGroup.cxx" #include "mouseWatcherParameter.cxx" #include "mouseWatcherRegion.cxx" -#include "trackball.cxx" #include "qptrackball.cxx" -#include "transform2sg.cxx" #include "qptransform2sg.cxx" diff --git a/panda/src/tform/trackball.cxx b/panda/src/tform/trackball.cxx deleted file mode 100644 index 32e6292358..0000000000 --- a/panda/src/tform/trackball.cxx +++ /dev/null @@ -1,545 +0,0 @@ -// Filename: trackball.cxx -// Created by: drose (27Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "trackball.h" - -#include "compose_matrix.h" -#include "mouse.h" -#include "mouseData.h" -#include "modifierButtons.h" -#include "buttonEventDataTransition.h" -#include "mouseButton.h" -#include "get_rel_pos.h" - -TypeHandle Trackball::_type_handle; - -TypeHandle Trackball::_pixel_xyz_type; -TypeHandle Trackball::_button_events_type; -TypeHandle Trackball::_transform_type; - -#define B1_MASK 0x1 -#define B2_MASK 0x2 -#define B3_MASK 0x4 - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::Constructor -// Access: Public, Scheme -// Description: Trackball uses the mouse input to spin around a DCS -// similarly to Performer's trackball mode. -//////////////////////////////////////////////////////////////////// -Trackball:: -Trackball(const string &name) : DataNode(name) { - _rotscale = 0.3f; - _fwdscale = 0.3f; - - _lastx = _lasty = 0.5f; - - _rotation = LMatrix4f::ident_mat(); - _translation.set(0.0f, 0.0f, 0.0f); - _mat = LMatrix4f::ident_mat(); - _orig = LMatrix4f::ident_mat(); - _invert = true; - _rel_to = NULL; - _cs = default_coordinate_system; - - _mods.add_button(MouseButton::one()); - _mods.add_button(MouseButton::two()); - _mods.add_button(MouseButton::three()); - - _transform = new MatrixDataTransition; - _transform->set_value(LMatrix4f::ident_mat()); - _attrib.set_transition(_transform_type, _transform); -} - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::Destructor -// Access: Public, Scheme -// Description: -//////////////////////////////////////////////////////////////////// -Trackball:: -~Trackball() { -} - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::reset -// Access: Public, Scheme -// Description: Reinitializes all transforms to identity. -//////////////////////////////////////////////////////////////////// -void Trackball:: -reset() { - _rotation = LMatrix4f::ident_mat(); - _translation.set(0.0f, 0.0f, 0.0f); - _orig = LMatrix4f::ident_mat(); - _mat = LMatrix4f::ident_mat(); -} - - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::get_pos -// Access: Public, Scheme -// Description: Return the offset from the center of rotation. -//////////////////////////////////////////////////////////////////// -const LPoint3f &Trackball:: -get_pos() const { - return _translation; -} - -float Trackball:: -get_x() const { - return _translation[0]; -} - -float Trackball:: -get_y() const { - return _translation[1]; -} - -float Trackball:: -get_z() const { - return _translation[2]; -} - - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::set_pos -// Access: Public, Scheme -// Description: Directly set the offset from the rotational origin. -//////////////////////////////////////////////////////////////////// -void Trackball:: -set_pos(const LVecBase3f &vec) { - _translation = vec; - recompute(); -} - -void Trackball:: -set_pos(float x, float y, float z) { - _translation.set(x, y, z); - recompute(); -} - -void Trackball:: -set_x(float x) { - _translation[0] = x; - recompute(); -} - -void Trackball:: -set_y(float y) { - _translation[1] = y; - recompute(); -} - -void Trackball:: -set_z(float z) { - _translation[2] = z; - recompute(); -} - - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::get_hpr -// Access: Public, Scheme -// Description: Return the trackball's orientation. -//////////////////////////////////////////////////////////////////// -LVecBase3f Trackball:: -get_hpr() const { - LVecBase3f scale, hpr, translate; - decompose_matrix(_rotation, scale, hpr, translate); - return hpr; -} - -float Trackball:: -get_h() const { - LVecBase3f scale, hpr, translate; - decompose_matrix(_rotation, scale, hpr, translate); - return hpr[0]; -} - -float Trackball:: -get_p() const { - LVecBase3f scale, hpr, translate; - decompose_matrix(_rotation, scale, hpr, translate); - return hpr[1]; -} - -float Trackball:: -get_r() const { - LVecBase3f scale, hpr, translate; - decompose_matrix(_rotation, scale, hpr, translate); - return hpr[2]; -} - - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::set_hpr -// Access: Public, Scheme -// Description: Directly set the mover's orientation. -//////////////////////////////////////////////////////////////////// -void Trackball:: -set_hpr(const LVecBase3f &hpr) { - LVecBase3f scale, old_hpr, translate; - decompose_matrix(_rotation, scale, old_hpr, translate); - compose_matrix(_rotation, scale, hpr, translate); - recompute(); -} - -void Trackball:: -set_hpr(float h, float p, float r) { - LVecBase3f scale, hpr, translate; - decompose_matrix(_rotation, scale, hpr, translate); - hpr.set(h, p, r); - compose_matrix(_rotation, scale, hpr, translate); - recompute(); -} - -void Trackball:: -set_h(float h) { - LVecBase3f scale, hpr, translate; - decompose_matrix(_rotation, scale, hpr, translate); - hpr[0] = h; - compose_matrix(_rotation, scale, hpr, translate); - recompute(); -} - -void Trackball:: -set_p(float p) { - LVecBase3f scale, hpr, translate; - decompose_matrix(_rotation, scale, hpr, translate); - hpr[1] = p; - compose_matrix(_rotation, scale, hpr, translate); - recompute(); -} - -void Trackball:: -set_r(float r) { - LVecBase3f scale, hpr, translate; - decompose_matrix(_rotation, scale, hpr, translate); - hpr[2] = r; - compose_matrix(_rotation, scale, hpr, translate); - recompute(); -} - - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::reset_origin_here -// Access: Public, Scheme -// Description: Reposition the center of rotation to coincide with -// the current translation offset. Future rotations -// will be about the current origin. -//////////////////////////////////////////////////////////////////// -void Trackball:: -reset_origin_here() { - recompute(); - _rotation = _orig; - _translation.set(0.0f, 0.0f, 0.0f); -} - - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::move_origin -// Access: Public, Scheme -// Description: Moves the center of rotation by the given amount. -//////////////////////////////////////////////////////////////////// -void Trackball:: -move_origin(float x, float y, float z) { - _rotation = LMatrix4f::translate_mat(LVecBase3f(x, y, z)) * _rotation; -} - - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::set_invert -// Access: Public, Scheme -// Description: Sets the invert flag. When this is set, the inverse -// matrix is generated, suitable for joining to a -// camera, instead of parenting the scene under it. -//////////////////////////////////////////////////////////////////// -void Trackball:: -set_invert(bool flag) { - _invert = flag; -} - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::get_invert -// Access: Public, Scheme -// Description: Returns the invert flag. When this is set, the -// inverse matrix is generated, suitable for joining to -// a camera, instead of parenting the scene under it. -//////////////////////////////////////////////////////////////////// -bool Trackball:: -get_invert() const { - return _invert; -} - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::set_rel_to -// Access: Public, Scheme -// Description: Sets the node that all trackball manipulations are to -// be assumed to be relative to. For instance, set your -// camera node here to make the trackball motion camera -// relative. The default is NULL, which means trackball -// motion is in global space. -//////////////////////////////////////////////////////////////////// -void Trackball:: -set_rel_to(const Node *rel_to) { - _rel_to = rel_to; -} - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::get_rel_to -// Access: Public, Scheme -// Description: Returns the node that all trackball manipulations are -// relative to, or NULL. -//////////////////////////////////////////////////////////////////// -const Node *Trackball:: -get_rel_to() const { - return _rel_to; -} - - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::set_coordinate_system -// Access: Public, Scheme -// Description: Sets the coordinate system of the Trackball. -// Normally, this is the default coordinate system. -// This changes the axes the Trackball manipulates so -// that the user interface remains consistent across -// different coordinate systems. -//////////////////////////////////////////////////////////////////// -void Trackball:: -set_coordinate_system(CoordinateSystem cs) { - _cs = cs; -} - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::get_coordinate_system -// Access: Public, Scheme -// Description: Returns the coordinate system of the Trackball. -// See set_coordinate_system(). -//////////////////////////////////////////////////////////////////// -CoordinateSystem Trackball:: -get_coordinate_system() const { - return _cs; -} - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::set_mat -// Access: Public, Scheme -// Description: Stores the indicated transform in the trackball. -// This is a transform in global space, regardless of -// the rel_to node. -//////////////////////////////////////////////////////////////////// -void Trackball:: -set_mat(const LMatrix4f &mat) { - _orig = mat; - if (_invert) { - _mat = invert(_orig); - } else { - _mat = _orig; - } - - reextract(); -} - - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::get_mat -// Access: Public, Scheme -// Description: Returns the matrix represented by the trackball -// rotation. -//////////////////////////////////////////////////////////////////// -const LMatrix4f &Trackball:: -get_mat() const { - return _orig; -} - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::get_trans_mat -// Access: Public, Scheme -// Description: Returns the actual transform that will be applied to -// the scene graph. This is the same as get_mat(), -// unless invert is in effect. -//////////////////////////////////////////////////////////////////// -const LMatrix4f &Trackball:: -get_trans_mat() const { - return _mat; -} - - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::apply -// Access: Private -// Description: Applies the operation indicated by the user's mouse -// motion to the current state. Returns the matrix -// indicating the new state. -//////////////////////////////////////////////////////////////////// -void Trackball:: -apply(double x, double y, int button) { - if (button && _rel_to != NULL) { - // If we have a rel_to node, we must first adjust our rotation and - // translation to be in those local coordinates. - reextract(); - } - if (button == B1_MASK) { - // Button 1: translate in plane parallel to screen. - - _translation += - x * _fwdscale * LVector3f::right(_cs) + - y * _fwdscale * LVector3f::down(_cs); - - } else if (button == (B2_MASK | B3_MASK)) { - // Buttons 2 + 3: rotate about the vector perpendicular to the - // screen. - - _rotation *= - LMatrix4f::rotate_mat_normaxis((x - y) * _rotscale, - LVector3f::forward(_cs), _cs); - - } else if ((button == B2_MASK) || (button == (B1_MASK | B3_MASK))) { - // Button 2, or buttons 1 + 3: rotate about the right and up - // vectors. (We alternately define this as buttons 1 + 3, to - // support two-button mice.) - - _rotation *= - LMatrix4f::rotate_mat_normaxis(x * _rotscale, LVector3f::up(_cs), _cs) * - LMatrix4f::rotate_mat_normaxis(y * _rotscale, LVector3f::right(_cs), _cs); - - } else if ((button == B3_MASK) || (button == (B1_MASK | B2_MASK))) { - // Button 3, or buttons 1 + 2: dolly in and out along the forward - // vector. (We alternately define this as buttons 1 + 2, to - // support two-button mice.) - _translation -= y * _fwdscale * LVector3f::forward(_cs); - } - - if (button) { - recompute(); - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::reextract -// Access: Private -// Description: Given a correctly computed _orig matrix, rederive the -// translation and rotation elements. -//////////////////////////////////////////////////////////////////// -void Trackball:: -reextract() { - LMatrix4f m = _orig; - if (_rel_to != NULL) { - LMatrix4f rel_mat; - ::get_rel_mat(NULL, _rel_to, rel_mat); - m = _orig * rel_mat; - } - - m.get_row3(_translation,3); - _rotation = m; - _rotation.set_row(3, LVecBase3f(0.0f, 0.0f, 0.0f)); -} - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::recompute -// Access: Private -// Description: Rebuilds the matrix according to the stored rotation -// and translation components. -//////////////////////////////////////////////////////////////////// -void Trackball:: -recompute() { - _orig = _rotation * LMatrix4f::translate_mat(_translation); - - if (_rel_to != NULL) { - LMatrix4f rel_mat; - ::get_rel_mat(_rel_to, NULL, rel_mat); - _orig = _orig * rel_mat; - } - - if (_invert) { - _mat = invert(_orig); - } else { - _mat = _orig; - } -} - - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::transmit_data -// Access: Public -// Description: Convert mouse data into a trackball matrix -//////////////////////////////////////////////////////////////////// -void Trackball:: -transmit_data(AllTransitionsWrapper &data) { - // First, update our modifier buttons. - const ButtonEventDataTransition *b; - if (get_transition_into(b, data, _button_events_type)) { - b->update_mods(_mods); - } - - // Now, check for mouse motion. - const NodeTransition *pixel_xyz = data.get_transition(_pixel_xyz_type); - - if (pixel_xyz != (NodeTransition *)NULL) { - LVecBase3f p = DCAST(Vec3DataTransition, pixel_xyz)->get_value(); - float this_x = p[0]; - float this_y = p[1]; - int this_button = 0; - - if (_mods.is_down(MouseButton::one())) { - this_button |= B1_MASK; - } - if (_mods.is_down(MouseButton::two())) { - this_button |= B2_MASK; - } - if (_mods.is_down(MouseButton::three())) { - this_button |= B3_MASK; - } - - float x = this_x - _lastx; - float y = this_y - _lasty; - - apply(x, y, this_button); - - _lastx = this_x; - _lasty = this_y; - } - - // Now send our matrix down the pipe. - _transform->set_value(_mat); - data = _attrib; -} - - -//////////////////////////////////////////////////////////////////// -// Function: Trackball::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -void Trackball:: -init_type() { - DataNode::init_type(); - register_type(_type_handle, "Trackball", - DataNode::get_class_type()); - - Vec3DataTransition::init_type(); - register_data_transition(_pixel_xyz_type, "PixelXYZ", - Vec3DataTransition::get_class_type()); - ButtonEventDataTransition::init_type(); - register_data_transition(_button_events_type, "ButtonEvents", - ButtonEventDataTransition::get_class_type()); - MatrixDataTransition::init_type(); - register_data_transition(_transform_type, "Transform", - MatrixDataTransition::get_class_type()); -} diff --git a/panda/src/tform/trackball.h b/panda/src/tform/trackball.h deleted file mode 100644 index 0da056ec64..0000000000 --- a/panda/src/tform/trackball.h +++ /dev/null @@ -1,155 +0,0 @@ -// Filename: trackball.h -// Created by: drose (27Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef TRACKBALL_H -#define TRACKBALL_H - -#include "pandabase.h" - -#include "dataNode.h" -#include "vec3DataTransition.h" -#include "matrixDataTransition.h" -#include "allTransitionsWrapper.h" -#include "modifierButtons.h" -#include "luse.h" -#include "lmatrix.h" - - -//////////////////////////////////////////////////////////////////// -// Class : Trackball -// Description : Trackball acts like Performer in trackball mode. It -// can either spin around a piece of geometry directly, -// or it can spin around a camera with the inverse -// transform to make it appear that the whole world is -// spinning. -// -// The Trackball object actually just places a transform -// in the data graph; parent a Transform2SG node under -// it to actually transform objects (or cameras) in the -// world. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA Trackball : public DataNode { -PUBLISHED: - - Trackball(const string &name = ""); - ~Trackball(); - - void reset(); - - /// **** Translation **** - - const LPoint3f &get_pos() const; - float get_x() const; - float get_y() const; - float get_z() const; - void set_pos(const LVecBase3f &vec); - void set_pos(float x, float y, float z); - void set_x(float x); - void set_y(float y); - void set_z(float z); - - /// **** Rotation **** - - LVecBase3f get_hpr() const; - float get_h() const; - float get_p() const; - float get_r() const; - void set_hpr(const LVecBase3f &hpr); - void set_hpr(float h, float p, float r); - void set_h(float h); - void set_p(float p); - void set_r(float r); - - /// **** Origin of Rotation **** - - void reset_origin_here(); - void move_origin(float x, float y, float z); - - /// **** Misc **** - - void set_invert(bool flag); - bool get_invert() const; - - void set_rel_to(const Node *_rel_to); - const Node *get_rel_to() const; - - void set_coordinate_system(CoordinateSystem cs); - CoordinateSystem get_coordinate_system() const; - - void set_mat(const LMatrix4f &mat); - const LMatrix4f &get_mat() const; - const LMatrix4f &get_trans_mat() const; - - -private: - void apply(double x, double y, int button); - - void reextract(); - void recompute(); - - - float _lastx, _lasty; - - float _rotscale; - float _fwdscale; - - LMatrix4f _rotation; - LPoint3f _translation; - LMatrix4f _mat, _orig; - bool _invert; - const Node *_rel_to; - CoordinateSystem _cs; - - // Remember which mouse buttons are being held down. - ModifierButtons _mods; - - -//////////////////////////////////////////////////////////////////// -// From parent class DataNode -//////////////////////////////////////////////////////////////////// -public: - - virtual void - transmit_data(AllTransitionsWrapper &data); - - AllTransitionsWrapper _attrib; - PT(MatrixDataTransition) _transform; - - // inputs - static TypeHandle _pixel_xyz_type; - static TypeHandle _button_events_type; - - // outputs - static TypeHandle _transform_type; - - -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(); - -private: - static TypeHandle _type_handle; -}; - -#endif diff --git a/panda/src/tform/transform2sg.cxx b/panda/src/tform/transform2sg.cxx deleted file mode 100644 index 53b5645d46..0000000000 --- a/panda/src/tform/transform2sg.cxx +++ /dev/null @@ -1,125 +0,0 @@ -// Filename: transform2sg.cxx -// Created by: drose (27Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#include "transform2sg.h" - -#include "nodeRelation.h" -#include "transformTransition.h" -#include "transformState.h" -#include "matrixDataTransition.h" -#include "allTransitionsWrapper.h" - - -TypeHandle Transform2SG::_type_handle; - -TypeHandle Transform2SG::_transform_type; - -//////////////////////////////////////////////////////////////////// -// Function: Transform2SG::Constructor -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -Transform2SG:: -Transform2SG(const string &name) : DataNode(name) { - _arc = NULL; - _node = NULL; -} - - -//////////////////////////////////////////////////////////////////// -// Function: Transform2SG::set_arc -// Access: Public -// Description: Sets the arc that this node will adjust. -//////////////////////////////////////////////////////////////////// -void Transform2SG:: -set_arc(NodeRelation *arc) { - _arc = arc; -} - -//////////////////////////////////////////////////////////////////// -// Function: Transform2SG::get_arc -// Access: Public -// Description: Returns the arc that this node will adjust, or NULL -// if the arc has not yet been set. -//////////////////////////////////////////////////////////////////// -NodeRelation *Transform2SG:: -get_arc() const { - return _arc; -} - -//////////////////////////////////////////////////////////////////// -// Function: Transform2SG::set_node -// Access: Public -// Description: Sets the node that this node will adjust. -//////////////////////////////////////////////////////////////////// -void Transform2SG:: -set_node(PandaNode *node) { - _node = node; -} - -//////////////////////////////////////////////////////////////////// -// Function: Transform2SG::get_node -// Access: Public -// Description: Returns the node that this node will adjust, or NULL -// if the node has not yet been set. -//////////////////////////////////////////////////////////////////// -PandaNode *Transform2SG:: -get_node() const { - return _node; -} - - -//////////////////////////////////////////////////////////////////// -// Function: Transform2SG::transmit_data -// Access: Public -// Description: -//////////////////////////////////////////////////////////////////// -void Transform2SG:: -transmit_data(AllTransitionsWrapper &data) { - const NodeTransition *transform = data.get_transition(_transform_type); - - if (transform != (NodeTransition *)NULL) { - const LMatrix4f &mat = DCAST(MatrixDataTransition, transform)->get_value(); - if (_arc != (NodeRelation *)NULL) { - _arc->set_transition(new TransformTransition(mat)); - } - if (_node != (PandaNode *)NULL) { - _node->set_transform(TransformState::make_mat(mat)); - } - } - - // Clear the data below us. - data.clear(); -} - - -//////////////////////////////////////////////////////////////////// -// Function: Transform2SG::init_type -// Access: Public, Static -// Description: -//////////////////////////////////////////////////////////////////// -void Transform2SG:: -init_type() { - DataNode::init_type(); - register_type(_type_handle, "Transform2SG", - DataNode::get_class_type()); - - MatrixDataTransition::init_type(); - register_data_transition(_transform_type, "Transform", - MatrixDataTransition::get_class_type()); -} diff --git a/panda/src/tform/transform2sg.h b/panda/src/tform/transform2sg.h deleted file mode 100644 index fdeef9c119..0000000000 --- a/panda/src/tform/transform2sg.h +++ /dev/null @@ -1,77 +0,0 @@ -// Filename: transform2sg.h -// Created by: drose (27Jan99) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved -// -// All use of this software is subject to the terms of the Panda 3d -// Software license. You should have received a copy of this license -// along with this source code; you will also find a current copy of -// the license at http://www.panda3d.org/license.txt . -// -// To contact the maintainers of this program write to -// panda3d@yahoogroups.com . -// -//////////////////////////////////////////////////////////////////// - -#ifndef TRANSFORM2SG_H -#define TRANSFORM2SG_H - -#include "pandabase.h" - -#include "dataNode.h" -#include "pandaNode.h" - -class NodeRelation; - -//////////////////////////////////////////////////////////////////// -// Class : Transform2SG -// Description : input: Transform (matrix) -// -// output: none, but applies the matrix as the transform -// transition for a given arc of the scene graph. -//////////////////////////////////////////////////////////////////// -class EXPCL_PANDA Transform2SG : public DataNode { -PUBLISHED: - Transform2SG(const string &name = ""); - - void set_arc(NodeRelation *arc); - NodeRelation *get_arc() const; - - void set_node(PandaNode *node); - PandaNode *get_node() const; - -private: - NodeRelation *_arc; - PandaNode *_node; - -//////////////////////////////////////////////////////////////////// -// From parent class DataNode -//////////////////////////////////////////////////////////////////// -public: - - virtual void - transmit_data(AllTransitionsWrapper &data); - - // inputs - static TypeHandle _transform_type; - - -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(); - -private: - static TypeHandle _type_handle; -}; - -#endif - diff --git a/pandatool/src/bam/Sources.pp b/pandatool/src/bam/Sources.pp index 6cb0354615..0a74b37998 100644 --- a/pandatool/src/bam/Sources.pp +++ b/pandatool/src/bam/Sources.pp @@ -3,10 +3,9 @@ #define LOCAL_LIBS \ progbase #define OTHER_LIBS \ - parametrics:c collide:c chan:c char:c switchnode:c \ - cull:c loader:c egg:c sgraphutil:c sgattrib:c \ - sgraph:c pnmimagetypes:c \ - graph:c putil:c linmath:c express:c panda:m pandaexpress:m \ + parametrics:c collide:c chan:c char:c \ + loader:c egg:c pnmimagetypes:c \ + putil:c linmath:c express:c panda:m pandaexpress:m \ interrogatedb:c dtoolutil:c dtoolbase:c dconfig:c dtoolconfig:m dtool:m pystub #define UNIX_SYS_LIBS \ m @@ -23,9 +22,9 @@ #define LOCAL_LIBS \ eggbase progbase #define OTHER_LIBS \ - sgmanip:c cull:c sgattrib:c sgraph:c dgraph:c \ - loader:c egg2sg:c builder:c egg:c pnmimagetypes:c gobj:c \ - chan:c graph:c putil:c linmath:c \ + dgraph:c \ + loader:c egg2pg:c builder:c egg:c pnmimagetypes:c gobj:c \ + chan:c putil:c linmath:c \ express:c pandaegg:m panda:m pandaexpress:m \ interrogatedb:c dtoolutil:c dtoolbase:c dconfig:c dtoolconfig:m dtool:m pystub #define UNIX_SYS_LIBS \ @@ -37,16 +36,16 @@ #end bin_target +#if // Temporarily broken until we can bring it into the new scene graph. #begin bin_target #define TARGET bam2egg #define LOCAL_LIBS \ converter eggbase progbase #define OTHER_LIBS \ egg:c pandaegg:m \ - parametrics:c collide:c chan:c char:c switchnode:c \ - cull:c loader:c gobj:c sgraphutil:c sgattrib:c \ - sgraph:c pnmimagetypes:c pstatclient:c \ - graph:c putil:c linmath:c express:c panda:m pandaexpress:m \ + parametrics:c collide:c chan:c char:c \ + loader:c gobj:c pnmimagetypes:c pstatclient:c \ + putil:c linmath:c express:c panda:m pandaexpress:m \ interrogatedb:c dtoolutil:c dtoolbase:c dconfig:c dtoolconfig:m dtool:m pystub #define UNIX_SYS_LIBS \ @@ -56,4 +55,4 @@ bamToEgg.cxx bamToEgg.h #end bin_target - +#endif // Temporarily broken until we can bring it into the new scene graph. diff --git a/pandatool/src/bam/bamInfo.cxx b/pandatool/src/bam/bamInfo.cxx index 4e8694dd22..54a17a2b04 100644 --- a/pandatool/src/bam/bamInfo.cxx +++ b/pandatool/src/bam/bamInfo.cxx @@ -18,11 +18,10 @@ #include "bamInfo.h" -#include -#include -#include -#include - +#include "bamFile.h" +#include "pandaNode.h" +#include "qpgeomNode.h" +#include "dcast.h" #include "pvector.h" //////////////////////////////////////////////////////////////////// @@ -138,8 +137,9 @@ get_info(const Filename &filename) { bam_file.resolve(); bam_file.close(); - if (objects.size() == 1 && objects[0]->is_of_type(Node::get_class_type())) { - describe_scene_graph(DCAST(Node, objects[0])); + if (objects.size() == 1 && + objects[0]->is_of_type(PandaNode::get_class_type())) { + describe_scene_graph(DCAST(PandaNode, objects[0])); } else { for (int i = 0; i < (int)objects.size(); i++) { @@ -159,15 +159,15 @@ get_info(const Filename &filename) { // that scene graph in some meaningful way. //////////////////////////////////////////////////////////////////// void BamInfo:: -describe_scene_graph(Node *node) { +describe_scene_graph(PandaNode *node) { // Parent the node to our own scene graph root, so we can (a) // guarantee it won't accidentally be deleted before we're done, (b) // easily determine the bounding volume of the scene, and (c) report // statistics on all the bam file's scene graphs together when we've // finished. - PT_Node root = new Node; - NodeRelation *arc = new RenderRelation(root, node); + PT(PandaNode) root = new PandaNode("root"); + root->add_child(node); _num_scene_graphs++; int num_nodes = _analyzer._num_nodes; @@ -175,7 +175,7 @@ describe_scene_graph(Node *node) { num_nodes = _analyzer._num_nodes - num_nodes; nout << " " << num_nodes << " nodes, bounding volume is " - << arc->get_bound() << "\n"; + << root->get_bound() << "\n"; if (_ls || _verbose_geoms || _verbose_transitions) { list_hierarchy(node, 0); @@ -201,31 +201,44 @@ describe_general_object(TypedWritable *object) { // information. //////////////////////////////////////////////////////////////////// void BamInfo:: -list_hierarchy(Node *node, int indent_level) { - indent(nout, indent_level) << *node << "\n"; +list_hierarchy(PandaNode *node, int indent_level) { + indent(nout, indent_level) << *node; - if (_verbose_geoms && node->is_of_type(GeomNode::get_class_type())) { - GeomNode *geom_node; + if (_verbose_transitions) { + nout << "\n"; + if (!node->get_transform()->is_identity()) { + node->get_transform()->write(nout, indent_level); + } + if (!node->get_state()->is_empty()) { + node->get_state()->write(nout, indent_level); + } + if (!node->get_effects()->is_empty()) { + node->get_effects()->write(nout, indent_level); + } + + } else { + if (!node->get_transform()->is_identity()) { + nout << " " << *node->get_transform(); + } + if (!node->get_state()->is_empty()) { + nout << " " << *node->get_state(); + } + if (!node->get_effects()->is_empty()) { + nout << " " << *node->get_effects(); + } + nout << "\n"; + } + + if (_verbose_geoms && node->is_geom_node()) { + qpGeomNode *geom_node; DCAST_INTO_V(geom_node, node); geom_node->write_verbose(nout, indent_level); } - int num_children = node->get_num_children(RenderRelation::get_class_type()); + int num_children = node->get_num_children(); for (int i = 0; i < num_children; i++) { - int next_indent = indent_level + 2; - - NodeRelation *arc = node->get_child(RenderRelation::get_class_type(), i); - if (_verbose_transitions) { - nout << "\n"; - indent(nout, next_indent) << *arc << "\n"; - - arc->write_transitions(nout, next_indent); - nout << "\n"; - - next_indent += 2; - } - - list_hierarchy(arc->get_child(), next_indent); + PandaNode *child = node->get_child(i); + list_hierarchy(child, indent_level + 2); } } diff --git a/pandatool/src/bam/bamInfo.h b/pandatool/src/bam/bamInfo.h index 8c2c96e6db..3c42024bbd 100644 --- a/pandatool/src/bam/bamInfo.h +++ b/pandatool/src/bam/bamInfo.h @@ -19,12 +19,11 @@ #ifndef BAMINFO_H #define BAMINFO_H -#include +#include "pandatoolbase.h" -#include -#include -#include -#include +#include "programBase.h" +#include "filename.h" +#include "sceneGraphAnalyzer.h" #include "pvector.h" @@ -45,9 +44,9 @@ protected: private: bool get_info(const Filename &filename); - void describe_scene_graph(Node *node); + void describe_scene_graph(PandaNode *node); void describe_general_object(TypedWritable *object); - void list_hierarchy(Node *node, int indent_level); + void list_hierarchy(PandaNode *node, int indent_level); typedef pvector Filenames; Filenames _filenames; diff --git a/pandatool/src/bam/bamToEgg.cxx b/pandatool/src/bam/bamToEgg.cxx index 4188036868..3774300f4b 100644 --- a/pandatool/src/bam/bamToEgg.cxx +++ b/pandatool/src/bam/bamToEgg.cxx @@ -19,11 +19,10 @@ #include "bamToEgg.h" #include "node.h" -#include "LODNode.h" -#include "geomNode.h" +#include "qpLODNode.h" +#include "qpgeomNode.h" #include "geom.h" #include "geomTri.h" -#include "renderRelation.h" #include "string_utils.h" #include "bamFile.h" #include "eggGroup.h" @@ -33,18 +32,6 @@ #include "eggPolygon.h" #include "eggTexture.h" #include "eggMaterial.h" -#include "arcChain.h" -#include "allTransitionsWrapper.h" -#include "wrt.h" -#include "transformTransition.h" -#include "texMatrixTransition.h" -#include "colorMatrixTransition.h" -#include "alphaTransformTransition.h" -#include "textureTransition.h" -#include "cullFaceTransition.h" -#include "cullFaceProperty.h" -#include "billboardTransition.h" -#include "decalTransition.h" #include "somethingToEggConverter.h" diff --git a/pandatool/src/bam/eggToBam.cxx b/pandatool/src/bam/eggToBam.cxx index 813a17fffe..91d8271106 100644 --- a/pandatool/src/bam/eggToBam.cxx +++ b/pandatool/src/bam/eggToBam.cxx @@ -20,10 +20,8 @@ #include "config_util.h" #include "bamFile.h" -#include "nodePath.h" -#include "load_egg_file.h" #include "qpload_egg_file.h" -#include "config_egg2sg.h" +#include "config_egg2pg.h" #include "config_gobj.h" #include "config_chan.h" @@ -44,13 +42,6 @@ EggToBam() : // provide it as an option to the user. remove_option("f"); - add_option - ("s", "", 0, - "Writes an old-style bam file, with the old scene graph code, " - "suitable for loading in demo (but won't work in pview). This is " - "a temporary hack.", - &EggToBam::dispatch_none, &_pgraph_style); - add_option ("tp", "path", 0, "Add the indicated colon-delimited paths to the texture-path. This " @@ -145,69 +136,32 @@ run() { _data.set_coordinate_system(CS_zup_right); } - if (!_pgraph_style) { - // New style scene graph. - - PT(PandaNode) root = qpload_egg_data(_data); - if (root == (PandaNode *)NULL) { - nout << "Unable to build scene graph from egg file.\n"; + PT(PandaNode) root = qpload_egg_data(_data); + if (root == (PandaNode *)NULL) { + nout << "Unable to build scene graph from egg file.\n"; + exit(1); + } + + if (_ls) { + root->ls(nout, 0); + } + + // This should be guaranteed because we pass false to the + // constructor, above. + nassertv(has_output_filename()); + + Filename filename = get_output_filename(); + filename.make_dir(); + nout << "Writing " << filename << "\n"; + BamFile bam_file; + if (!bam_file.open_write(filename)) { + nout << "Error in writing.\n"; + exit(1); + } + + if (!bam_file.write_object(root)) { + nout << "Error in writing.\n"; exit(1); - } - - if (_ls) { - root->ls(nout, 0); - } - - // This should be guaranteed because we pass false to the - // constructor, above. - nassertv(has_output_filename()); - - Filename filename = get_output_filename(); - filename.make_dir(); - nout << "Writing " << filename << "\n"; - BamFile bam_file; - if (!bam_file.open_write(filename)) { - nout << "Error in writing.\n"; - exit(1); - } - - if (!bam_file.write_object(root)) { - nout << "Error in writing.\n"; - exit(1); - } - - } else { - // Old style scene graph. - - PT_NamedNode root = load_egg_data(_data); - if (root == (NamedNode *)NULL) { - nout << "Unable to build scene graph from egg file.\n"; - exit(1); - } - - if (_ls) { - // If we wanted to list the contents, we need a NodePath. - NodePath np(root); - np.ls(); - } - - // This should be guaranteed because we pass false to the - // constructor, above. - nassertv(has_output_filename()); - - Filename filename = get_output_filename(); - filename.make_dir(); - nout << "Writing " << filename << "\n"; - BamFile bam_file; - if (!bam_file.open_write(filename)) { - nout << "Error in writing.\n"; - exit(1); - } - - if (!bam_file.write_object(root)) { - nout << "Error in writing.\n"; - exit(1); - } } } diff --git a/pandatool/src/bam/eggToBam.h b/pandatool/src/bam/eggToBam.h index 98c35eef08..0f6b18fbef 100644 --- a/pandatool/src/bam/eggToBam.h +++ b/pandatool/src/bam/eggToBam.h @@ -33,7 +33,6 @@ public: void run(); - bool _pgraph_style; bool _keep_paths; bool _has_egg_flatten; int _egg_flatten; diff --git a/pandatool/src/ptloader/Sources.pp b/pandatool/src/ptloader/Sources.pp index 36e2203197..dbd8fbaca5 100644 --- a/pandatool/src/ptloader/Sources.pp +++ b/pandatool/src/ptloader/Sources.pp @@ -3,7 +3,7 @@ #define BUILDING_DLL BUILDING_PTLOADER #define LOCAL_LIBS xfile fltegg flt lwoegg lwo converter pandatoolbase #define OTHER_LIBS \ - egg2sg:c builder:c egg:c pandaegg:m \ + egg2pg:c builder:c egg:c pandaegg:m \ mathutil:c linmath:c putil:c panda:m \ express:c pandaexpress:m \ dtoolconfig dtool diff --git a/pandatool/src/ptloader/loaderFileTypePandatool.cxx b/pandatool/src/ptloader/loaderFileTypePandatool.cxx index 3d1edacf9b..759c861444 100644 --- a/pandatool/src/ptloader/loaderFileTypePandatool.cxx +++ b/pandatool/src/ptloader/loaderFileTypePandatool.cxx @@ -18,10 +18,10 @@ #include "loaderFileTypePandatool.h" -#include -#include -#include -#include +#include "somethingToEggConverter.h" +#include "config_util.h" +#include "qpload_egg_file.h" +#include "eggData.h" TypeHandle LoaderFileTypePandatool::_type_handle; @@ -83,15 +83,15 @@ resolve_filename(Filename &path) const { // Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// -PT_Node LoaderFileTypePandatool:: -load_file(const Filename &path, bool) const { - PT_NamedNode result; +PT(PandaNode) LoaderFileTypePandatool:: +qpload_file(const Filename &path, bool) const { + PT(PandaNode) result; EggData egg_data; _converter->set_egg_data(&egg_data, false); if (_converter->convert_file(path)) { egg_data.set_coordinate_system(CS_default); - result = load_egg_data(egg_data); + result = qpload_egg_data(egg_data); } _converter->clear_egg_data(); return result.p(); diff --git a/pandatool/src/ptloader/loaderFileTypePandatool.h b/pandatool/src/ptloader/loaderFileTypePandatool.h index 43e2046b21..a76ab0e8be 100644 --- a/pandatool/src/ptloader/loaderFileTypePandatool.h +++ b/pandatool/src/ptloader/loaderFileTypePandatool.h @@ -19,9 +19,9 @@ #ifndef LOADERFILETYPEPANDATOOL_H #define LOADERFILETYPEPANDATOOL_H -#include +#include "pandatoolbase.h" -#include +#include "loaderFileType.h" class SomethingToEggConverter; @@ -41,7 +41,7 @@ public: virtual string get_extension() const; virtual void resolve_filename(Filename &path) const; - virtual PT_Node load_file(const Filename &path, bool report_errors) const; + virtual PT(PandaNode) qpload_file(const Filename &path, bool report_errors) const; private: SomethingToEggConverter *_converter;