hydrax setVisible() small patch

tdev

27-12-2008 15:30:24

since i needed it, i thought it might be useful to others as well:

Index: Hydrax/Hydrax.cpp
===================================================================
--- Hydrax/Hydrax.cpp (revision 1669)
+++ Hydrax/Hydrax.cpp (working copy)
@@ -657,6 +657,12 @@
setSunPosition(mSunPosition);
}

+ void Hydrax::setVisible(const bool visible)
+ {
+ if(mMesh)
+ mMesh->getSceneNode()->setVisible(visible);
+ }
+
void Hydrax::rotate(const Ogre::Quaternion &q)
{
if (!mCreated)
Index: Hydrax/Hydrax.h
===================================================================
--- Hydrax/Hydrax.h (revision 1669)
+++ Hydrax/Hydrax.h (working copy)
@@ -109,6 +109,11 @@
*/
void setPosition(const Ogre::Vector3 &Position);

+ /** shows or hides the mesh
+ @param visible mesh visibility
+ */
+ void setVisible(const bool visible);
+
/** Rotate water and planes
@param q const Ogre::Quaternion&
*/

Xavyiy

30-12-2008 18:55:01

Main problem of this setVisible() patch is that update() method is performed when the mesh is not visible, using a lot of CPU.
I suggest yo doing something like:

inline void setVisible(const bool& Visible, const bool& ForceToUpdate = false)

and check in Hydrax::update() ForceToUpdate, with something like:
if(!mMesh->getSceneNode()->isVisible() && !mForceToUpdate) return;

Xavi

tdev

15-01-2009 17:44:24

Main problem of this setVisible() patch is that update() method is performed when the mesh is not visible, using a lot of CPU.
I suggest yo doing something like:

inline void setVisible(const bool& Visible, const bool& ForceToUpdate = false)

and check in Hydrax::update() ForceToUpdate, with something like:
if(!mMesh->getSceneNode()->isVisible() && !mForceToUpdate) return;

Xavi

thats correct, i forgot about that completely. (hydrax is just hidden for me once at application startup in order to take a picture of the map as overview)