← Back to team overview

yade-dev team mailing list archive

[svn] r1635 - in trunk: gui/qt3 pkg/common/Engine/StandAloneEngine pkg/dem/Engine/StandAloneEngine

 

Author: eudoxos
Date: 2009-01-24 01:25:04 +0100 (Sat, 24 Jan 2009)
New Revision: 1635

Modified:
   trunk/gui/qt3/GLSimulationPlayerViewer.cpp
   trunk/gui/qt3/GLSimulationPlayerViewer.hpp
   trunk/gui/qt3/QtSimulationPlayer.cpp
   trunk/pkg/common/Engine/StandAloneEngine/PeriodicEngines.hpp
   trunk/pkg/dem/Engine/StandAloneEngine/SQLiteRecorder.hpp
Log:
1. Make player reuse existing renderer if there is one (allows setting Draw_mask etc before running player)
2. Add initRun parameter to PeriodicEngine (false by default), to run at the very fist run.


Modified: trunk/gui/qt3/GLSimulationPlayerViewer.cpp
===================================================================
--- trunk/gui/qt3/GLSimulationPlayerViewer.cpp	2009-01-23 23:06:59 UTC (rev 1634)
+++ trunk/gui/qt3/GLSimulationPlayerViewer.cpp	2009-01-24 00:25:04 UTC (rev 1635)
@@ -45,7 +45,7 @@
 	else GLViewer::keyPressEvent(e);
 }
 
-GLSimulationPlayerViewer::GLSimulationPlayerViewer(QWidget* parent): GLViewer(/*special value meaning player*/ -1,shared_ptr<OpenGLRenderingEngine>(new OpenGLRenderingEngine),parent,NULL) {
+GLSimulationPlayerViewer::GLSimulationPlayerViewer(QWidget* parent,shared_ptr<OpenGLRenderingEngine> renderer): GLViewer(/*special value meaning player*/ -1,renderer,parent,NULL) {
 	setSceneRadius(2);
 	showEntireScene();
 	resize(550, 550);

Modified: trunk/gui/qt3/GLSimulationPlayerViewer.hpp
===================================================================
--- trunk/gui/qt3/GLSimulationPlayerViewer.hpp	2009-01-23 23:06:59 UTC (rev 1634)
+++ trunk/gui/qt3/GLSimulationPlayerViewer.hpp	2009-01-24 00:25:04 UTC (rev 1635)
@@ -47,7 +47,7 @@
  		list<string>::iterator xyzNamesIter;
 		vector< shared_ptr< FilterEngine > > filters;
 	public :
-		GLSimulationPlayerViewer(QWidget* parent);
+		GLSimulationPlayerViewer(QWidget* parent,shared_ptr<OpenGLRenderingEngine> renderer);
 		virtual ~GLSimulationPlayerViewer(){};
 		void setRootBody(shared_ptr<MetaBody> rb) { rootBody = rb;};
 		void load(const string& fileName, bool fromFile=true);

Modified: trunk/gui/qt3/QtSimulationPlayer.cpp
===================================================================
--- trunk/gui/qt3/QtSimulationPlayer.cpp	2009-01-23 23:06:59 UTC (rev 1634)
+++ trunk/gui/qt3/QtSimulationPlayer.cpp	2009-01-24 00:25:04 UTC (rev 1635)
@@ -16,6 +16,8 @@
 #include <qspinbox.h>
 #include<qlabel.h>
 #include<qstring.h>
+
+#include<yade/gui-qt3/YadeQtMainWindow.hpp>
 CREATE_LOGGER(QtSimulationPlayer);
 
 void QtSimulationPlayer::keyPressEvent(QKeyEvent* e){
@@ -25,7 +27,8 @@
 }
 
 QtSimulationPlayer::QtSimulationPlayer() : QtGeneratedSimulationPlayer(){
-	glSimulationPlayerViewer=new GLSimulationPlayerViewer(NULL);
+	YadeQtMainWindow::self->ensureRenderer();
+	glSimulationPlayerViewer=new GLSimulationPlayerViewer(NULL,YadeQtMainWindow::self->renderer);
 	glSimulationPlayerViewer->simPlayer=this;
 	leInputConfigFile->setText(Omega::instance().getSimulationFileName());
 	enableControls(false);

Modified: trunk/pkg/common/Engine/StandAloneEngine/PeriodicEngines.hpp
===================================================================
--- trunk/pkg/common/Engine/StandAloneEngine/PeriodicEngines.hpp	2009-01-23 23:06:59 UTC (rev 1634)
+++ trunk/pkg/common/Engine/StandAloneEngine/PeriodicEngines.hpp	2009-01-24 00:25:04 UTC (rev 1635)
@@ -9,12 +9,16 @@
  *
  * The number of times this engine is activated can be limited by setting nDo>0. In the contrary case, or if
  * the number of activations was already reached, no action will be called even if any of active period has elapsed.
+ *
+ * If initRun is set, the engine will run when called for the first time; otherwise it will only set *Last and will be
+ * called after desired period elapses for the first time.
  */
 class PeriodicEngine:  public StandAloneEngine {
 	public:
 		static Real getClock(){ timeval tp; gettimeofday(&tp,NULL); return tp.tv_sec+tp.tv_usec/1e6; }
 		Real virtPeriod, virtLast, realPeriod, realLast; long iterPeriod,iterLast,nDo,nDone;
-		PeriodicEngine(): virtPeriod(0),virtLast(0),realPeriod(0),realLast(0),iterPeriod(0),iterLast(0),nDo(-1),nDone(0) { realLast=getClock(); }
+		bool initRun;
+		PeriodicEngine(): virtPeriod(0),virtLast(0),realPeriod(0),realLast(0),iterPeriod(0),iterLast(0),nDo(-1),nDone(0),initRun(false) { realLast=getClock(); }
 		virtual bool isActivated(){
 			Real virtNow=Omega::instance().getSimulationTime();
 			Real realNow=getClock();
@@ -26,6 +30,11 @@
 				realLast=realNow; virtLast=virtNow; iterLast=iterNow; nDone++;
 				return true;
 			}
+			if(nDone==0){
+				realLast=realNow; virtLast=virtNow; iterLast=iterNow; nDone++;
+				if(initRun) return true;
+				return false;
+			}
 			return false;
 		}
 	protected:

Modified: trunk/pkg/dem/Engine/StandAloneEngine/SQLiteRecorder.hpp
===================================================================
--- trunk/pkg/dem/Engine/StandAloneEngine/SQLiteRecorder.hpp	2009-01-23 23:06:59 UTC (rev 1634)
+++ trunk/pkg/dem/Engine/StandAloneEngine/SQLiteRecorder.hpp	2009-01-24 00:25:04 UTC (rev 1635)
@@ -41,7 +41,7 @@
 		enum {REC_SE3=0,REC_RGB,REC_SENTINEL};
 		vector<string> recorders;
 		string dbFile;
-		SQLiteRecorder() {};
+		SQLiteRecorder() { /* we always want to save the first state as well */ initRun=true; };
 		~SQLiteRecorder(){ if(con) con->close(); }
 		void init(MetaBody*);
 		virtual void registerAttributes(){