int ReUpdate(void) { double t; tRmMovieCapture *capture; START_PROFILE("ReUpdate"); ReInfo->_refreshDisplay = 0; switch (ReInfo->_displayMode) { case RM_DISP_MODE_NORMAL: t = GfTimeClock(); START_PROFILE("ReOneStep*"); while (ReInfo->_reRunning && ((t - ReInfo->_reCurTime) > RCM_MAX_DT_SIMU)) { ReOneStep(RCM_MAX_DT_SIMU); } STOP_PROFILE("ReOneStep*"); GfuiDisplay(); ReInfo->_reGraphicItf.refresh(ReInfo->s); glutPostRedisplay(); /* Callback -> reDisplay */ break; case RM_DISP_MODE_NONE: ReOneStep(RCM_MAX_DT_SIMU); if (ReInfo->_refreshDisplay) { GfuiDisplay(); } glutPostRedisplay(); /* Callback -> reDisplay */ break; case RM_DISP_MODE_CAPTURE: capture = &(ReInfo->movieCapture); while ((ReInfo->_reCurTime - capture->lastFrame) < capture->deltaFrame) { ReOneStep(capture->deltaSimu); } capture->lastFrame = ReInfo->_reCurTime; GfuiDisplay(); ReInfo->_reGraphicItf.refresh(ReInfo->s); reCapture(); glutPostRedisplay(); /* Callback -> reDisplay */ break; } STOP_PROFILE("ReUpdate"); return RM_ASYNC; }
static void ReOneStep(double deltaTimeIncrement) { int i; tRobotItf *robot; tSituation *s = ReInfo->s; if (floor(s->currentTime) == -2.0) { ReRaceBigMsgSet("Ready", 1.0); } else if (floor(s->currentTime) == -1.0) { ReRaceBigMsgSet("Set", 1.0); } else if (floor(s->currentTime) == 0.0) { ReRaceBigMsgSet("Go", 1.0); } ReInfo->_reCurTime += deltaTimeIncrement * ReInfo->_reTimeMult; /* "Real" time */ s->currentTime += deltaTimeIncrement; /* Simulated time */ if (s->currentTime < 0) { /* no simu yet */ ReInfo->s->_raceState = RM_RACE_PRESTART; } else if (ReInfo->s->_raceState == RM_RACE_PRESTART) { ReInfo->s->_raceState = RM_RACE_RUNNING; s->currentTime = 0.0; /* resynchronize */ ReInfo->_reLastTime = 0.0; } START_PROFILE("rbDrive*"); if ((s->currentTime - ReInfo->_reLastTime) >= RCM_MAX_DT_ROBOTS) { s->deltaTime = s->currentTime - ReInfo->_reLastTime; for (i = 0; i < s->_ncars; i++) { if ((s->cars[i]->_state & RM_CAR_STATE_NO_SIMU) == 0) { robot = s->cars[i]->robot; robot->rbDrive(robot->index, s->cars[i], s); } } ReInfo->_reLastTime = s->currentTime; } STOP_PROFILE("rbDrive*"); START_PROFILE("_reSimItf.update*"); ReInfo->_reSimItf.update(s, deltaTimeIncrement, -1); for (i = 0; i < s->_ncars; i++) { ReManage(s->cars[i]); } STOP_PROFILE("_reSimItf.update*"); ReRaceMsgUpdate(); ReSortCars(); }
int refresh(tSituation *s) { int i; START_PROFILE("refresh"); nFrame++; grCurTime = GfTimeClock(); grDeltaTime = grCurTime - OldTime; if ((grCurTime - OldTime) > 1.0) { /* The Frames Per Second (FPS) display is refreshed every second */ grFps = (tdble)nFrame / (grCurTime - OldTime); nFrame = 0; OldTime = grCurTime; } TRACE_GL("refresh: start"); START_PROFILE("grRefreshSound*"); grRefreshSound(s, grScreens[0]->getCurCamera()); STOP_PROFILE("grRefreshSound*"); START_PROFILE("grDrawBackground/glClear"); glDepthFunc(GL_LEQUAL); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); STOP_PROFILE("grDrawBackground/glClear"); for (i = 0; i < GR_NB_MAX_SCREEN; i++) { grScreens[i]->update(s, grFps); } grUpdateSmoke(s->currentTime); STOP_PROFILE("refresh"); return 0; }
/****************************************************************************//** * Video capture thread main entry point. * @param arg Optional thread parameter, this is unused. * @return Always null ****************************************************************************/ static void *videocapThread( void *arg ) { PongInstance_t* pongInstance = (PongInstance_t *) arg; int vIndex = -1; int result; while ( keepWorking ) { // 1. Get an empty vframe buffer, // only if we sucessfully sent the previous one if ( vIndex == -1 ) { result = mq_read( pongInstance->mqVideoEmpty, &vIndex, sizeof(int), 100000 ); if ( result!=OK ) { if ( result == ERROR ) loge("mq_read failed - %s", strerror(errno) ); continue; } /*if*/ log("Got empty video frame index %d ", vIndex ); //usleep(1000000); }/*if*/ #ifdef PROFILING_ON START_PROFILE(); #endif // 2. fill vframe buffer with data from camera // copy data to 'pongInstance.videoFrames[vIndex]' getFrame((unsigned char *) &pongInstance->videoFrames[vIndex], &pongInstance->cameraInfo); #ifdef PROFILING_ON STOP_PROFILE(); GET_PROFILE("getFrame"); #endif // 3. Send vframe to the color filters threads result = mq_write( pongInstance->mqVideoFull, &vIndex, sizeof(int), 100000 ); if ( result!=OK ) { if ( result == ERROR ) loge("mq_write failed - %s", strerror(errno) ); continue; } /*if*/ log("Sent full video frame index %d ", vIndex ); //usleep(1000000); vIndex = -1; //allow another receive to happen in the next iteration }/*while*/ log( FG13 " *** VideoCap exited..."); return NULL; }