void GLFW3Context::mainLoop(void (*updateLoop)()) { while (glfwWindowShouldClose(window_) == false) { if (glfwGetKey(window_, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window_, true); glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); updateLoop(); Engine::update(); Engine::render(); } glfwTerminate(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { lastAve = 10000; sum = 0; count = 0; inmin = 0; inmax = 1; outmin = 0; outmax = 1; stop = true; controller = new PIDcontroller(-1000, 1000); pathFunction = 'f'; ui->setupUi(this); ui->lineTrackerWidget->window = this; ui->lineTrackerWidget->drawPath(); speed = 1; robot = new Robot(0, -10); updater = new QTimer(this); // connect events connect(updater, SIGNAL(timeout()), this, SLOT(updateLoop())); connect(ui->radioButton_3, SIGNAL( clicked() ), this, SLOT( on_radioButton_3_clicked() )); connect(ui->radioButton_4, SIGNAL( clicked() ), this, SLOT( on_radioButton_4_clicked() )); connect(ui->radioButton_5, SIGNAL( clicked() ), this, SLOT( on_radioButton_5_clicked() )); connect(ui->pushButton_2, SIGNAL( clicked() ), this, SLOT( on_pushButton_2_clicked() )); connect(ui->pushButton, SIGNAL( clicked() ), this, SLOT( on_pushButton_clicked() )); connect(ui->pushButton_3, SIGNAL( clicked() ), this, SLOT( on_pushButton_3_clicked() )); }
void PlayerWidget::_setupSource() { setUpdatesEnabled( false ); const bool hasAudioSource = audioSource_ != 0; setEnabled( hasAudioSource ); // inititialized-invariant values ui_.labelFileName->setText( hasAudioSource ? QFileInfo( playerInfo_->filePath ).fileName() : QString() ); ui_.buttonDestroy->setEnabled( hasAudioSource ); _updateStateLabels(); updateLoop(); updateGain(); updatePitch(); // initialized-depended values _updateSourceInitialization(); setUpdatesEnabled( true ); }
/** * @brief MainWindow::MainWindow Initialize the main window and everything else * @param parent */ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { // Initialize the interface ui->setupUi(this); ui->glWidget->addAction(ui->actionFullscreen); ui->glWidget->addAction(ui->actionExit); connect(ui->actionExit,SIGNAL(triggered()),this,SLOT(close())); connect(ui->actionFullscreen,SIGNAL(triggered()),this,SLOT(toggleFullscreenSlot())); // The test script runs a simple experiment experimentScript = new TestScript(this,this); // Add a cosmetic line to the splitter handle // so that it's easier to grab with the mouse QSplitterHandle *handle = ui->splitter->handle(1); QVBoxLayout *layout = new QVBoxLayout(handle); layout->setSpacing(0); layout->setMargin(0); QFrame *line = new QFrame(handle); line->setFrameShape(QFrame::VLine); line->setFrameShadow(QFrame::Sunken); layout->addWidget(line); // In a future revision, we'll move the SimWorld // to a more intelligent place. It doesn't // belong as a child to the graphics widget. SimWorld* world = ui->glWidget->getWorld(); CapBody* capBody = world->getBody(); #if defined( BOARD_DATA ) BoardMarkerData* md = ui->glWidget->getWorld()->getMarkerData(); #elif defined( POKE_DATA ) PokeMarkerData* md = ui->glWidget->getWorld()->getMarkerData(); #else MarkerData* md = world->getMarkerData(); #endif // We populate a ScrollArea with the same number of // MarkerWidgets as there are markers in the data file. QScrollArea* sa = new QScrollArea; QWidget* wid = new QWidget; layout = new QVBoxLayout; layout->setContentsMargins(0,0,0,0); // This part needs to become part of a function // that is called everytime a new data file is // loaded. int markCnt = md->marker_count; ui->markerCountLineEdit->setText(QString::number(markCnt)); ui->frameCountLineEdit->setText(QString::number(md->size())); ui->markerFileLineEdit->setText("data.c3d"); ui->markerFrameStartBox->setValue(0); setDataRange(md->size()); QHBoxLayout* innerLayout = new QHBoxLayout; QPushButton* connectButton = new QPushButton("Connect"); QPushButton* releaseButton = new QPushButton("Release"); QPushButton* updateButton = new QPushButton("Update Anchors"); innerLayout->addWidget(connectButton); innerLayout->addWidget(releaseButton); innerLayout->addWidget(updateButton); connect(connectButton,SIGNAL(clicked()),this,SLOT(connectMarkers())); connect(releaseButton,SIGNAL(clicked()),this,SLOT(releaseMarkers())); connect(updateButton,SIGNAL(clicked()),this,SLOT(updateMarkerAnchors())); layout->addLayout(innerLayout); markerWidgetArray.resize(markCnt); for (int ii=0;ii<markCnt;++ii) { markerWidgetArray[ii] = new MarkerWidget(ii,0); layout->addWidget(markerWidgetArray[ii]); } wid->setLayout(layout); sa->setWidget(wid); ui->controlTabWidget->addTab(sa,"Markers"); // Joint control tab sa = new QScrollArea; wid = new QWidget; layout = new QVBoxLayout; layout->setContentsMargins(0,0,0,0); // A couple buttons at the top of the joint tab make it possible // to rapidly change all the force limits innerLayout = new QHBoxLayout; QPushButton* zeroButton = new QPushButton("Zero"); QPushButton* lightButton = new QPushButton("Light"); QPushButton* resetButton = new QPushButton("Strong"); innerLayout->addWidget(zeroButton); innerLayout->addWidget(lightButton); innerLayout->addWidget(resetButton); layout->addLayout(innerLayout); connect(zeroButton,SIGNAL(clicked()),this,SLOT(zeroForces())); connect(lightButton,SIGNAL(clicked()),this,SLOT(lightForces())); connect(resetButton,SIGNAL(clicked()),this,SLOT(strongForces())); // Fill the tab with hard-coded data about the model... populateJointTab(capBody,layout); wid->setLayout(layout); sa->setWidget(wid); ui->controlTabWidget->addTab(sa,"Joints"); // Body dimensions widget sa = new QScrollArea; wid = new QWidget; layout = new QVBoxLayout; layout->setContentsMargins(0,0,0,0); QCheckBox* keepBodyRel = new QCheckBox("Body Rel"); layout->addWidget(keepBodyRel); // Fill the tab with model-specific widgets populateBodyTab(capBody,layout); wid->setLayout(layout); sa->setWidget(wid); ui->controlTabWidget->addTab(sa,"Model dimensions"); // Hook up the interface elements to their respecitve functionality connect(ui->saveButton,SIGNAL(clicked()),capBody,SLOT(saveBody())); connect(ui->loadButton,SIGNAL(clicked()),capBody,SLOT(loadBody())); connect(ui->testButton,SIGNAL(clicked()),this,SLOT(experimentSlot())); // When a the CapBody loads the marker map, tell the interface // how and where the markers are connected. connect(capBody,SIGNAL(markMap(int,int)),this,SLOT(setMarkMap(int,int))); connect(capBody,SIGNAL(markPoint(int,double,double,double)), this,SLOT(setMarkPoint(int,double,double,double))); // ***** // (Each MarkerWidget informs the capBody when the interface // changes). for (int ii=0;ii<markCnt;++ii) { connect(markerWidgetArray[ii],SIGNAL(markBodySet(int,int)),md,SLOT(changeBodyConnect(int,int))); connect(markerWidgetArray[ii],SIGNAL(markConnect(int,bool)),md,SLOT(changeBodyLink(int,bool))); connect(markerWidgetArray[ii],SIGNAL(markPosSet(int,double,double,double)), md,SLOT(changeLinkPos(int,double,double,double))); connect(markerWidgetArray[ii],SIGNAL(markGrab(int)),this, SLOT(grabMarkPos(int))); } connect(ui->clearPlotButton,SIGNAL(clicked()),this,SLOT(clearData())); connect(ui->glWidget->getWorld(),SIGNAL(useMarkers(bool)),this,SLOT(usingMarkers(bool))); connect(ui->frictionSpinBox,SIGNAL(valueChanged(double)),world,SLOT(setGroundFriction(double))); connect(ui->terrainSpinBox,SIGNAL(valueChanged(double)),world,SLOT(setTerrainSoftness(double))); connect(ui->zBox,SIGNAL(valueChanged(double)),ui->glWidget->getWorld(),SLOT(setTerrainZ(double))); connect(ui->forceLinesCheckBox,SIGNAL(clicked(bool)),ui->glWidget,SLOT(setDrawLines(bool))); connect(ui->camFollowCheckBox,SIGNAL(clicked(bool)),ui->glWidget,SLOT(setFollowCamera(bool))); connect(ui->timeSlider,SIGNAL(valueChanged(int)),world->getMarkerData(),SLOT(setFrame(int))); connect(ui->glWidget->getWorld()->getMarkerData(),SIGNAL(frameChanged(int)),ui->timeSlider,SLOT(setValue(int))); connect(ui->bodyAlpha,SIGNAL(valueChanged(double)),ui->glWidget,SLOT(setBodyAlpha(double))); connect(ui->showMarkBox,SIGNAL(toggled(bool)),ui->glWidget,SLOT(setShowMarkers(bool))); connect(ui->selfCollideBox,SIGNAL(toggled(bool)),world,SLOT(setSelfCollide(bool))); connect(ui->saveStateButton,SIGNAL(clicked()),this,SLOT(saveModel())); connect(ui->restoreButton,SIGNAL(clicked()),this,SLOT(restoreModel())); connect(ui->markerRadio,SIGNAL(toggled(bool)),this,SLOT(useMarkers(bool))); connect(ui->torqueRadio,SIGNAL(toggled(bool)),this,SLOT(useTorques(bool))); connect(ui->altRadio,SIGNAL(toggled(bool)),this,SLOT(useAltForces(bool))); connect(ui->playAllButton,SIGNAL(clicked(bool)),this,SLOT(playPauseAll(bool))); connect(ui->playPauseDataButton,SIGNAL(clicked(bool)),this,SLOT(playPauseData(bool))); connect(ui->playPauseSimButton,SIGNAL(clicked(bool)),this,SLOT(playPauseSim(bool))); connect(ui->stepAllButton,SIGNAL(clicked()),this,SLOT(stepAll())); connect(ui->stepDataButton,SIGNAL(clicked()),this,SLOT(stepData())); connect(ui->stepSimButton,SIGNAL(clicked()),this,SLOT(stepSim())); connect(ui->selectFileToolButton,SIGNAL(clicked()),this,SLOT(markerFileDialog())); connect(ui->dataStepBox,SIGNAL(valueChanged(int)),this,SLOT(setDataStep(int))); connect(ui->dataFrameBox,SIGNAL(valueChanged(int)),this,SLOT(setDataFrame(int))); connect(ui->timeSlider,SIGNAL(valueChanged(int)),ui->dataFrameBox,SLOT(setValue(int))); // ***** // Need to dynamically change this ui->timeSlider->setRange(0,world->getMarkerData()->size()-1); connect(ui->globalBox,SIGNAL(toggled(bool)),this,SLOT(useGlobalForces(bool))); #if defined( BOARD_DATA ) bd = new BoardData(this); bd->loadData("boardData.dat"); ui->glWidget->setBoardData(bd); #endif // Start the timer for updating the data, sim, and graphics updateTimer.setSingleShot(false); connect(&updateTimer,SIGNAL(timeout()),this,SLOT(updateLoop())); connect(ui->frameTimeBox,SIGNAL(valueChanged(double)),this,SLOT(setFrameTime(double))); ui->frameTimeBox->setValue(1/60.0); ui->dataStepBox->setValue(2); capBody->loadBody(); useMarkers(true); saveModel(); }
void Voice::process(int frames, float* p) { float modlfo_to_fc = 0.0; float modenv_to_fc = 0.0; float _fres = _zerberus->ct2hz(fres + modlfo_val * modlfo_to_fc + modenv_val * modenv_to_fc); int sr = _zerberus->sampleRate(); if (_fres > 0.45f * sr) _fres = 0.45f * sr; else if (_fres < 5.f) _fres = 5.f; if ((fabs(_fres - last_fres) > 0.01f)) { updateFilter(_fres); last_fres = _fres; } if (audioChan == 1) { while (frames--) { updateLoop(); int idx = phase.index(); if (idx >= eidx) { off(); break; } const float* coeffs = interpCoeff[phase.fract()]; float f; f = (coeffs[0] * getData(idx-1) + coeffs[1] * getData(idx+0) + coeffs[2] * getData(idx+1) + coeffs[3] * getData(idx+2)) * gain - a1 * hist1l - a2 * hist2l; float v = b02 * (f + hist2l) + b1 * hist1l; hist2l = hist1l; hist1l = f; if (filter_coeff_incr_count) { --filter_coeff_incr_count; a1 += a1_incr; a2 += a2_incr; b02 += b02_incr; b1 += b1_incr; } updateEnvelopes(); if (_state == VoiceState::OFF) break; v *= envelopes[currentEnvelope].val; *p++ += v * _channel->panLeftGain(); *p++ += v * _channel->panRightGain(); phase += phaseIncr; _samplesSinceStart++; } } else { // // handle interleaved stereo samples // while (frames--) { updateLoop(); int idx = phase.index() * 2; if (idx >= eidx) { off(); // printf("end of sample\n"); break; } const float* coeffs = interpCoeff[phase.fract()]; float f1, f2; f1 = (coeffs[0] * getData(idx-2) + coeffs[1] * getData(idx) + coeffs[2] * getData(idx+2) + coeffs[3] * getData(idx+4)) * gain * _channel->panLeftGain(); f2 = (coeffs[0] * getData(idx-1) + coeffs[1] * getData(idx+1) + coeffs[2] * getData(idx+3) + coeffs[3] * getData(idx+5)) * gain * _channel->panRightGain(); updateEnvelopes(); if (_state == VoiceState::OFF) break; f1 *= envelopes[currentEnvelope].val; f2 *= envelopes[currentEnvelope].val; f1 += -a1 * hist1l - a2 * hist2l; float vl = b02 * (f1 + hist2l) + b1 * hist1l; hist2l = hist1l; hist1l = f1; f2 += -a1 * hist1r - a2 * hist2r; float vr = b02 * (f2 + hist2r) + b1 * hist1r; hist2r = hist1r; hist1r = f2; if (filter_coeff_incr_count) { --filter_coeff_incr_count; a1 += a1_incr; a2 += a2_incr; b02 += b02_incr; b1 += b1_incr; } *p++ += vl; *p++ += vr; phase += phaseIncr; _samplesSinceStart++; } } }
void CCEngine::updateEngineThread() { // Update our system time updateTime(); time.lifetime += time.real; #if LOG_FPS static uint loggedUpdates = 0; static float loggedDelta = 0.0f; loggedUpdates++; loggedDelta += time.real; if( loggedDelta > 1.0f ) { #if !defined WP8 && !defined WIN8 const float averageFPS = 1.0f / ( loggedDelta / loggedUpdates ); DEBUGLOG( "Average FPS: %f \n", averageFPS ); #endif loggedUpdates = 0; loggedDelta = 0.0f; } #endif if( backButtonPressed ) { backButtonPressed = false; handleBackButton(); } // Run callbacks if( engineThreadCallbacks.length > 0 ) { CCNativeThreadLock(); CCJobsThreadLock(); while( engineThreadCallbacks.length > 0 ) { CCLambdaCallback *callback = engineThreadCallbacks.pop(); if( callback != NULL ) { callback->safeRun(); delete callback; } } CCNativeThreadUnlock(); CCJobsThreadUnlock(); } finishJobs(); updateLoop(); if( paused == false && pauseRendering == false ) { CCAppManager::UpdateOrientation( time.delta ); renderLoop(); } #if defined DEBUGON && TARGET_IPHONE_SIMULATOR // 66 frames a second in debug //usleep( 15000 ); usleep( 0 ); #endif }
void Grid::runLoops() { updateLoop(); actionLoop(); }
void CCEngine::updateEngineThread() { // Update our system time updateTime(); time.lifetime += time.real; #if LOG_FPS static uint loggedUpdates = 0; static float loggedDelta = 0.0f; loggedUpdates++; loggedDelta += time.real; if( loggedDelta > 1.0f ) { #if !defined WP8 && !defined WIN8 const float averageFPS = 1.0f / ( loggedDelta / loggedUpdates ); DEBUGLOG( "Average FPS: %f \n", averageFPS ); #endif loggedUpdates = 0; loggedDelta = 0.0f; } #endif if( backButtonActionPending ) { backButtonActionPending = false; handleBackButton(); } // Run callbacks if( engineThreadCallbacks.length > 0 ) { int jobsProcessed = 0; const double startTime = CCEngine::GetSystemTime(); const double finishTime = startTime + 0.002f; // Spend a max of 2ms on this task double currentTime = startTime; while( engineThreadCallbacks.length > 0 ) { CCNativeThreadLock(); CCJobsThreadLock(); CCLambdaCallback *callback = engineThreadCallbacks.pop(); if( callback != NULL ) { callback->safeRun(); } CCNativeThreadUnlock(); CCJobsThreadUnlock(); if( callback != NULL ) { delete callback; } jobsProcessed++; if( textureManager != NULL && textureManager->isReady() ) { currentTime = CCEngine::GetSystemTime(); if( currentTime > finishTime ) { DEBUGLOG( "Max engineThreadCallbacks processed in time %i, %i\n", jobsProcessed, engineThreadCallbacks.length ); break; } } } } finishJobs(); updateLoop(); if( paused == false ) { CCAppManager::UpdateOrientation( time.delta ); } renderLoop(); #if defined DEBUGON && TARGET_IPHONE_SIMULATOR // 66 frames a second in debug //usleep( 15000 ); usleep( 0 ); #endif }
void CCEngine::updateEngineThread() { // Update our system time if( updateTime() == false ) { #ifdef ANDROID // FIXME: Android needs to always redraw the scene // We currently never return false, so perhaps remove this.. renderer->clear(); renderLoop(); #endif return; } time.lifetime += time.real; #if LOG_FPS static uint loggedUpdates = 0; static float loggedDelta = 0.0f; loggedUpdates++; loggedDelta += time.real; if( loggedDelta > 1.0f ) { const float averageFPS = 1.0f / ( loggedDelta / loggedUpdates ); DEBUGLOG( "Average FPS: %f \n", averageFPS ); loggedUpdates = 0; loggedDelta = 0.0f; } #endif // Run callbacks if( engineThreadCallbacks.length > 0 ) { CCNativeThreadLock(); CCJobsThreadLock(); CCLambdaCallback *callback = engineThreadCallbacks.pop(); CCNativeThreadUnlock(); CCJobsThreadUnlock(); callback->run(); delete callback; // for( int i=0; i<engineThreadCallbacks.length; ++i ) // { // engineThreadCallbacks.list[i]->run(); // delete engineThreadCallbacks.list[i]; // } // engineThreadCallbacks.length = 0; } finishJobs(); updateLoop(); CCViewManager::UpdateOrientation( time.delta ); renderer->clear(); renderLoop(); renderer->resolve(); #if defined DEBUGON && TARGET_IPHONE_SIMULATOR // 66 frames a second in debug //usleep( 15000 ); usleep( 0 ); #endif }