Commit ab3ceb2a authored by Jan Möbius's avatar Jan Möbius

Dennis : Check Scenegraph for dirty flag in core and control number of redraws

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@4326 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 06defb14
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include "Core.hh" #include "Core.hh"
// -------------------- ACG // -------------------- ACG
#include <ACG/Scenegraph/DrawModes.hh> #include <ACG/Scenegraph/DrawModes.hh>
#include <ACG/Scenegraph/SceneGraph.hh>
#include <ACG/QtWidgets/QtFileDialog.hh> #include <ACG/QtWidgets/QtFileDialog.hh>
// -------------------- Qt // -------------------- Qt
...@@ -157,6 +158,14 @@ Core::init() { ...@@ -157,6 +158,14 @@ Core::init() {
redrawTimer_->setSingleShot(true); redrawTimer_->setSingleShot(true);
connect(redrawTimer_, SIGNAL(timeout()), this, SLOT(updateView()),Qt::DirectConnection); connect(redrawTimer_, SIGNAL(timeout()), this, SLOT(updateView()),Qt::DirectConnection);
// Initialice scenegraph check timer. Will be used to check for changes in the scenegraph
scenegraphCheckTimer_ = new QTimer();
scenegraphCheckTimer_->setSingleShot(false);
connect(scenegraphCheckTimer_, SIGNAL(timeout()), this, SLOT(checkScenegraphDirty()),Qt::DirectConnection);
// Will measure the time between redraws
redrawTime_ = new QTime();
redrawTime_->start ();
if ( OpenFlipper::Options::splash() ) { if ( OpenFlipper::Options::splash() ) {
QPixmap splashPixmap(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "splash.png"); QPixmap splashPixmap(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "splash.png");
...@@ -452,6 +461,9 @@ Core::init() { ...@@ -452,6 +461,9 @@ Core::init() {
splash_->finish(coreWidget_); splash_->finish(coreWidget_);
} }
// start checking for scenegraph changes
scenegraphCheckTimer_->setInterval (1000 / OpenFlipper::Options::maxFrameRate());
scenegraphCheckTimer_->start ();
} }
} }
...@@ -601,22 +613,27 @@ void Core::updateView() { ...@@ -601,22 +613,27 @@ void Core::updateView() {
if ( OpenFlipper::Options::restrictFrameRate() ) { if ( OpenFlipper::Options::restrictFrameRate() ) {
// redraw time not reached ... waiting for timer event for next redraw int elapsed = redrawTime_->elapsed ();
if ( redrawTimer_->isActive() ) {
if ( OpenFlipper::Options::doSlotDebugging() )
emit log(LOGINFO,"Too early for redraw! Delaying request from " + QString( sender()->metaObject()->className() ) );
return;
}
// std::cerr << "Redraw" << std::endl;
// Start the timer if we are not called by the timer if ( elapsed < 1000 / OpenFlipper::Options::maxFrameRate() )
if ( sender() != redrawTimer_ ) { {
redrawTimer_->start( 1000 / OpenFlipper::Options::maxFrameRate() ); // redraw time not reached ... waiting for timer event for next redraw
if ( redrawTimer_->isActive() ) {
if ( OpenFlipper::Options::doSlotDebugging() )
emit log(LOGINFO,"Too early for redraw! Delaying request from " + QString( sender()->metaObject()->className() ) );
return;
}
// Start the timer
redrawTimer_->start( (1000 / OpenFlipper::Options::maxFrameRate()) - elapsed);
return;
} }
else if ( redrawTimer_->isActive() )
redrawTimer_->stop ();
} }
redrawTime_->restart ();
if ( OpenFlipper::Options::gui() && !OpenFlipper::Options::loadingSettings() && !OpenFlipper::Options::redrawDisabled() ) { if ( OpenFlipper::Options::gui() && !OpenFlipper::Options::loadingSettings() && !OpenFlipper::Options::redrawDisabled() ) {
...@@ -628,6 +645,20 @@ void Core::updateView() { ...@@ -628,6 +645,20 @@ void Core::updateView() {
} }
} }
//-----------------------------------------------------------------------------
/** Check if scenegraph is dirty and initiate redraw
*/
void Core::checkScenegraphDirty() {
if ( true )
{
ACG::SceneGraph::CheckDirtyAction action;
ACG::SceneGraph::traverse( root_node_scenegraph_, action );
if ( action.isDirty () )
emit updateView ();
}
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Core::restrictFrameRate( bool _enable ) { void Core::restrictFrameRate( bool _enable ) {
...@@ -639,6 +670,9 @@ void Core::restrictFrameRate( bool _enable ) { ...@@ -639,6 +670,9 @@ void Core::restrictFrameRate( bool _enable ) {
void Core::setMaxFrameRate( int _rate ) { void Core::setMaxFrameRate( int _rate ) {
OpenFlipper::Options::maxFrameRate( _rate ); OpenFlipper::Options::maxFrameRate( _rate );
OpenFlipper::Options::restrictFrameRate( true ); OpenFlipper::Options::restrictFrameRate( true );
// update Timer to new framerate
scenegraphCheckTimer_->setInterval (1000 / OpenFlipper::Options::maxFrameRate());
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
......
...@@ -674,6 +674,26 @@ private: ...@@ -674,6 +674,26 @@ private:
/** @} */ /** @} */
//===========================================================================
/** @name Scenegraph redraw handling
* @{ */
//===========================================================================
private slots:
/// Called to check if the scenegraph needs to be redrawn
void checkScenegraphDirty();
private:
/// Timer that starts scenegraph check
QTimer *scenegraphCheckTimer_;
/// Holds the time since last redraw
QTime *redrawTime_;
/** @} */
private : private :
/// Id for the next backup /// Id for the next backup
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment