Revision: 7811
http://playerstage.svn.sourceforge.net/playerstage/?rev=7811&view=rev
Author: rtv
Date: 2009-06-07 18:24:41 +0000 (Sun, 07 Jun 2009)
Log Message:
-----------
added single-step simulation - press the '.' key
Modified Paths:
--------------
code/stage/trunk/libstage/stage.hh
code/stage/trunk/libstage/worldgui.cc
code/stage/trunk/worlds/fasr_plan.world
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2009-06-07 09:44:32 UTC (rev 7810)
+++ code/stage/trunk/libstage/stage.hh 2009-06-07 18:24:41 UTC (rev 7811)
@@ -1474,6 +1474,7 @@
stg_usec_t interval_real; ///< real-time interval between updates - set
this to zero for 'as fast as possible
Fl_Menu_Bar* mbar;
OptionsDlg* oDlg;
+ unsigned int steps;
bool pause_time;
bool paused; ///< the world only updates when this is false
stg_usec_t real_time_of_last_update;
@@ -1490,6 +1491,7 @@
static void optionsDlgCb( OptionsDlg* oDlg, WorldGui* worldGui );
static void helpAboutCb( Fl_Widget* w, void* p );
static void pauseCb( Fl_Widget* w, WorldGui* worldGui );
+ static void onceCb( Fl_Widget* w, WorldGui* worldGui );
static void fasterCb( Fl_Widget* w, WorldGui* worldGui );
static void slowerCb( Fl_Widget* w, WorldGui* worldGui );
static void realtimeCb( Fl_Widget* w, WorldGui* worldGui );
Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc 2009-06-07 09:44:32 UTC (rev
7810)
+++ code/stage/trunk/libstage/worldgui.cc 2009-06-07 18:24:41 UTC (rev
7811)
@@ -216,7 +216,8 @@
canvas->createMenuItems( mbar, "View" );
mbar->add( "Run", 0,0,0, FL_SUBMENU );
- mbar->add( "Run/Pause", 'p', (Fl_Callback*) WorldGui::pauseCb, this,
FL_MENU_DIVIDER );
+ mbar->add( "Run/Pause", 'p', (Fl_Callback*) WorldGui::pauseCb, this );
+ mbar->add( "Run/One step", '.', (Fl_Callback*) WorldGui::onceCb, this,
FL_MENU_DIVIDER );
mbar->add( "Run/Faster", ']', (Fl_Callback*) WorldGui::fasterCb, this );
mbar->add( "Run/Slower", '[', (Fl_Callback*) WorldGui::slowerCb, this );
mbar->add( "Run/Realtime", '{', (Fl_Callback*) WorldGui::realtimeCb, this,
FL_MENU_DIVIDER );
@@ -325,9 +326,20 @@
TogglePause();
pause_time = true;
}
-
- bool val = paused ? true : World::Update();
+
+ bool val = true;
+ if( paused )
+ {
+ if( steps > 0 )
+ {
+ val = World::Update();
+ --steps;
+ }
+ }
+ else
+ val = World::Update();
+
stg_usec_t interval;
stg_usec_t timenow;
@@ -336,34 +348,24 @@
Fl::check();
timenow = RealTimeNow();
-
- // if we're attempting to match some real time interval
- //if( interval_real > 0 )
- {
- interval = timenow - real_time_of_last_update; // guaranteed
to be >= 0
-
- double sleeptime = (double)interval_real - (double)interval;
-
- if( paused ) sleeptime = 20000; // spare the CPU if we're
paused
-
- // printf( "real %.2f interval %.2f sleeptime %.2f\n",
- // (double)interval_real,
- // (double)interval,
- // sleeptime );
-
- if( sleeptime > 0 )
- usleep( (stg_usec_t)MIN(sleeptime,20000) ); // check
the GUI at 10Hz min
- }
+
+ // do
+ {
+ interval = timenow - real_time_of_last_update; // guaranteed to
be >= 0
+
+ double sleeptime = (double)interval_real - (double)interval;
+
+ if( paused ) sleeptime = 20000; // spare the CPU if we're paused
+
+ // printf( "real %.2f interval %.2f sleeptime %.2f\n",
+ // (double)interval_real,
+ // (double)interval,
+ // sleeptime );
+
+ if( (sleeptime > 0) || paused )
+ usleep( (stg_usec_t)MIN(sleeptime,20000) ); // check the GUI
at 10Hz min
+ }
} while( interval < interval_real );
-
-// if( !IsGUI() )
-// printf( "[Stage: %s\n", ClockString().cstr()
-
- //printf( "\r \t\t timenow %lu", timenow );
- //printf( "interval_real %.20f\n", interval_real );
-
- // if( paused ) // gentle on the CPU when paused
- //usleep( 10000 );
interval_log[updates%INTERVAL_LOG_LEN] = timenow - real_time_of_last_update;
@@ -615,6 +617,12 @@
// drawn 'cos we cancelled the timeout
}
+void WorldGui::onceCb( Fl_Widget* w, WorldGui* worldGui )
+{
+ worldGui->paused = true;
+ worldGui->steps = 1; // number of steps to run
+}
+
void WorldGui::viewOptionsCb( OptionsDlg* oDlg, WorldGui* worldGui )
{
// the options dialog expects a std::vector of options (annoyingly)
Modified: code/stage/trunk/worlds/fasr_plan.world
===================================================================
--- code/stage/trunk/worlds/fasr_plan.world 2009-06-07 09:44:32 UTC (rev
7810)
+++ code/stage/trunk/worlds/fasr_plan.world 2009-06-07 18:24:41 UTC (rev
7811)
@@ -14,7 +14,7 @@
# threads may speed things up here depending on available CPU cores & workload
# threadpool 8
- threadpool 16
+ threadpool 0
# configure the GUI window
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit