Browse Source

fix MouseWatcherRegion update and show_regions

David Rose 19 years ago
parent
commit
1ee0741221

+ 18 - 0
panda/src/pgui/pgTop.cxx

@@ -137,6 +137,24 @@ cull_callback(CullTraverser *trav, CullTraverserData &data) {
   return false;
   return false;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: PGTop::is_renderable
+//       Access: Public, Virtual
+//  Description: Returns true if there is some value to visiting this
+//               particular node during the cull traversal for any
+//               camera, false otherwise.  This will be used to
+//               optimize the result of get_net_draw_show_mask(), so
+//               that any subtrees that contain only nodes for which
+//               is_renderable() is false need not be visited.
+////////////////////////////////////////////////////////////////////
+bool PGTop::
+is_renderable() const {
+  // We flag the PGTop as renderable, even though it technically
+  // doesn't have anything to render, but we do need the traverser to
+  // visit it every frame.
+  return true;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: PGTop::set_mouse_watcher
 //     Function: PGTop::set_mouse_watcher
 //       Access: Published
 //       Access: Published

+ 1 - 0
panda/src/pgui/pgTop.h

@@ -56,6 +56,7 @@ public:
   virtual PandaNode *make_copy() const;
   virtual PandaNode *make_copy() const;
   virtual bool has_cull_callback() const;
   virtual bool has_cull_callback() const;
   virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
   virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
+  virtual bool is_renderable() const;
 
 
 PUBLISHED:
 PUBLISHED:
   void set_mouse_watcher(MouseWatcher *watcher);
   void set_mouse_watcher(MouseWatcher *watcher);

+ 23 - 5
panda/src/tform/mouseWatcher.cxx

@@ -158,6 +158,12 @@ add_group(MouseWatcherGroup *group) {
     return false;
     return false;
   }
   }
 
 
+#ifndef NDEBUG
+  if (!_show_regions_render2d.is_empty()) {
+    group->show_regions(_show_regions_render2d);
+  }
+#endif  // NDEBUG
+
   // Not in the set, add it and return true
   // Not in the set, add it and return true
   _groups.push_back(pt);
   _groups.push_back(pt);
   return true;
   return true;
@@ -188,6 +194,12 @@ remove_group(MouseWatcherGroup *group) {
     _preferred_button_down_region = (MouseWatcherRegion *)NULL;
     _preferred_button_down_region = (MouseWatcherRegion *)NULL;
   }
   }
 
 
+#ifndef NDEBUG
+  if (!_show_regions_render2d.is_empty()) {
+    group->do_hide_regions();
+  }
+#endif  // NDEBUG
+
   // See if the group is in the set/vector
   // See if the group is in the set/vector
   PT(MouseWatcherGroup) pt = group;
   PT(MouseWatcherGroup) pt = group;
   Groups::iterator gi = 
   Groups::iterator gi = 
@@ -223,16 +235,16 @@ replace_group(MouseWatcherGroup *old_group, MouseWatcherGroup *new_group) {
 
 
   MutexHolder holder(_lock);
   MutexHolder holder(_lock);
 
 
+  MutexHolder holder2(old_group->_lock);
+  MutexHolder holder3(new_group->_lock);
+
 #ifndef NDEBUG
 #ifndef NDEBUG
   if (!_show_regions_render2d.is_empty()) {
   if (!_show_regions_render2d.is_empty()) {
-    old_group->hide_regions();
-    new_group->show_regions(_show_regions_render2d);
+    old_group->do_hide_regions();
+    new_group->do_show_regions(_show_regions_render2d);
   }
   }
 #endif  // NDEBUG
 #endif  // NDEBUG
 
 
-  MutexHolder holder2(old_group->_lock);
-  MutexHolder holder3(new_group->_lock);
-
   // Figure out the list of regions that change
   // Figure out the list of regions that change
   Regions remove, add, keep;
   Regions remove, add, keep;
   intersect_regions(remove, add, keep,
   intersect_regions(remove, add, keep,
@@ -268,6 +280,12 @@ replace_group(MouseWatcherGroup *old_group, MouseWatcherGroup *new_group) {
   if (gi == _groups.end()) {
   if (gi == _groups.end()) {
     _groups.push_back(new_group);
     _groups.push_back(new_group);
   }
   }
+
+#ifndef NDEBUG
+  if (!_show_regions_render2d.is_empty()) {
+    new_group->do_update_regions();
+  }
+#endif  // NDEBUG
     
     
   // Remove the old group, if it is already there.
   // Remove the old group, if it is already there.
   pt = old_group;
   pt = old_group;

+ 31 - 13
panda/src/tform/mouseWatcherGroup.cxx

@@ -239,14 +239,14 @@ set_color(const Colorf &color) {
   MutexHolder holder(_lock);
   MutexHolder holder(_lock);
 
 
   _color = color;
   _color = color;
-  update_regions();
+  do_update_regions();
 }
 }
 #endif  // NDEBUG
 #endif  // NDEBUG
 
 
 #ifndef NDEBUG
 #ifndef NDEBUG
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: MouseWatcherGroup::hide_regions
 //     Function: MouseWatcherGroup::hide_regions
-//       Access: Published, Virtual
+//       Access: Published
 //  Description: Stops the visualization created by a previous call to
 //  Description: Stops the visualization created by a previous call to
 //               show_regions().
 //               show_regions().
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -257,6 +257,20 @@ hide_regions() {
 }
 }
 #endif  // NDEBUG
 #endif  // NDEBUG
 
 
+#ifndef NDEBUG
+////////////////////////////////////////////////////////////////////
+//     Function: MouseWatcherGroup::update_regions
+//       Access: Published
+//  Description: Refreshes the visualization created by
+//               show_regions().
+////////////////////////////////////////////////////////////////////
+void MouseWatcherGroup::
+update_regions() {
+  MutexHolder holder(_lock);
+  do_update_regions();
+}
+#endif  // NDEBUG
+
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: MouseWatcherGroup::do_remove_region
 //     Function: MouseWatcherGroup::do_remove_region
@@ -300,10 +314,11 @@ do_remove_region(MouseWatcherRegion *region) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void MouseWatcherGroup::
 void MouseWatcherGroup::
 do_show_regions(const NodePath &render2d) {
 do_show_regions(const NodePath &render2d) {
+  do_hide_regions();
   _show_regions = true;
   _show_regions = true;
   _show_regions_root = render2d.attach_new_node("show_regions");
   _show_regions_root = render2d.attach_new_node("show_regions");
   _show_regions_root.set_bin("unsorted", 0);
   _show_regions_root.set_bin("unsorted", 0);
-  update_regions();
+  do_update_regions();
 }
 }
 #endif  // NDEBUG
 #endif  // NDEBUG
 
 
@@ -325,26 +340,29 @@ do_hide_regions() {
 
 
 #ifndef NDEBUG
 #ifndef NDEBUG
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
-//     Function: MouseWatcherGroup::update_regions
-//       Access: Private
+//     Function: MouseWatcherGroup::do_update_regions
+//       Access: Protected
 //  Description: Internally regenerates the show_regions()
 //  Description: Internally regenerates the show_regions()
 //               visualization.  Assumes the lock is already held.
 //               visualization.  Assumes the lock is already held.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void MouseWatcherGroup::
 void MouseWatcherGroup::
-update_regions() {
+do_update_regions() {
   nassertv(_lock.debug_is_locked());
   nassertv(_lock.debug_is_locked());
 
 
-  _show_regions_root.node()->remove_all_children();
-  _vizzes.clear();
-  _vizzes.reserve(_regions.size());
-
-  Regions::const_iterator ri;
-  for (ri = _regions.begin(); ri != _regions.end(); ++ri) {
-    _vizzes.push_back(make_viz_region(*ri));
+  if (_show_regions) {
+    _show_regions_root.node()->remove_all_children();
+    _vizzes.clear();
+    _vizzes.reserve(_regions.size());
+    
+    Regions::const_iterator ri;
+    for (ri = _regions.begin(); ri != _regions.end(); ++ri) {
+      _vizzes.push_back(make_viz_region(*ri));
+    }
   }
   }
 }
 }
 #endif  // NDEBUG
 #endif  // NDEBUG
 
 
+
 #ifndef NDEBUG
 #ifndef NDEBUG
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: MouseWatcherGroup::make_viz_region
 //     Function: MouseWatcherGroup::make_viz_region

+ 3 - 1
panda/src/tform/mouseWatcherGroup.h

@@ -55,6 +55,8 @@ PUBLISHED:
   void show_regions(const NodePath &render2d);
   void show_regions(const NodePath &render2d);
   void set_color(const Colorf &color);
   void set_color(const Colorf &color);
   void hide_regions();
   void hide_regions();
+
+  void update_regions();
 #endif  // NDEBUG
 #endif  // NDEBUG
 
 
 protected:
 protected:
@@ -63,6 +65,7 @@ protected:
 #ifndef NDEBUG
 #ifndef NDEBUG
   virtual void do_show_regions(const NodePath &render2d);
   virtual void do_show_regions(const NodePath &render2d);
   virtual void do_hide_regions();
   virtual void do_hide_regions();
+  void do_update_regions();
 #endif  // NDEBUG
 #endif  // NDEBUG
 
 
 protected:
 protected:
@@ -76,7 +79,6 @@ protected:
 
 
 private:
 private:
 #ifndef NDEBUG
 #ifndef NDEBUG
-  void update_regions();
   PandaNode *make_viz_region(MouseWatcherRegion *region);
   PandaNode *make_viz_region(MouseWatcherRegion *region);
 
 
   typedef pvector< PT(PandaNode) > Vizzes;
   typedef pvector< PT(PandaNode) > Vizzes;