stg_time.cc
Go to the documentation of this file.
00001 /*
00002  *  Player - One Hell of a Robot Server
00003  *     Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  *
00019  */
00021 //
00022 // Desc: Stage (simulator) time
00023 // Author: Richard Vaughan
00024 // Date: 7 May 2003
00025 // CVS: $Id$
00026 //
00028 
00029 #include <math.h>
00030 
00031 #include "p_driver.h"
00032 using namespace Stg;
00033 
00034 // Constructor
00035 StTime::StTime( StgDriver* driver )
00036 {
00037   assert(driver);
00038   this->driver = driver;
00039   return;
00040 }
00041 
00042 // Destructor
00043 StTime::~StTime()
00044 {
00045   return;
00046 }
00047 
00048 // Get the simulator time
00049 int StTime::GetTime(struct timeval* time)
00050 {
00051   PRINT_DEBUG( "get time" );
00052 
00053   assert( this->driver );
00054 
00055   World* world = driver->world;
00056 
00057   usec_t usec = world->SimTimeNow();
00058   time->tv_sec  = (int)floor(usec/million);
00059   time->tv_usec = (int)rint(fmod(usec,million) * million);
00060 
00061   PRINT_DEBUG2( "time now %ld sec %ld usec", time->tv_sec, time->tv_usec );
00062 
00063   return 0;
00064 }
00065 
00066 int StTime::GetTimeDouble(double* time)
00067 {
00068   PRINT_DEBUG( "get time (double)" );
00069 
00070   assert( this->driver );
00071 
00072   World* world = driver->world;
00073 
00074   *time = world->SimTimeNow() / million;
00075 
00076   PRINT_DEBUG1( "time now %f sec ", *time);
00077 
00078   return 0;
00079 }


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Thu Aug 27 2015 15:20:57