MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); sr = new SimRunner(); connect(this, SIGNAL(runSim()), sr, SLOT(runSim())); connect(this, SIGNAL(stopSim()), sr, SLOT(stopSim())); connect(sr, SIGNAL(newDataPoints(QVector<double>*,QVector<QVector<double> *>*)), ui->signalPlot, SLOT(onNewDataPoints(QVector<double>*,QVector<QVector<double> *>*))); ui->PWMDutySpinBox->setValue(sr->getPWMDuty()*100); }
MThreadRetVal tProgressBar(void *data) { MStatus status=MS::kSuccess; if(!MProgressWindow::reserve()) { MGlobal::displayError("Progress window already in use"); stopSim(); return (MThreadRetVal)-1; } // Set up and print progress window state MProgressWindow::setProgressRange(PROGRESSBARMINVALUE, PROGRESSBARMAXVALUE); MProgressWindow::setTitle("Boids Progress"); MProgressWindow::setInterruptable(true); MProgressWindow::setProgressStatus("Simulation Progress"); MProgressWindow::setProgress(PROGRESSBARMINVALUE); MProgressWindow::startProgress(); while((MProgressWindow::progress()<PROGRESSBARMAXVALUE)&&(!MProgressWindow::isCancelled())) { int prog=getProgression(); int progV=MProgressWindow::progress(); while(prog>=progV+PROGRESSBARADVANCEVALUE) { MProgressWindow::advanceProgress(PROGRESSBARADVANCEVALUE); progV+=PROGRESSBARADVANCEVALUE; } if(progV>=PROGRESSBARMAXVALUE) MProgressWindow::setProgress(PROGRESSBARMAXVALUE); Sleep(PROGRESSBARSLEEPTIME); } if (MProgressWindow::isCancelled()) { MGlobal::displayInfo("Progress interrupted!"); stopSim(); } return (MThreadRetVal)0; }
void Physics::deleteBody(int index) { stopSim(); if(bodyList.size() > index && index >= 0) { bodyList[index].destroyNodes(); bodyList.removeAt(index); } emit objectListUpdated(bodyList); startSim(); }
// this function is working fine void *enterPhyData(void *in) { event_queue *physicque; event e; runphytrd = 0; while(1) { runphy =1; while(runphytrd == 0) { } physicsque = startSim(coins,wall,pocket); while(runphytrd == 1) { while(!isEmpty(physicsque) && runphy == 1) { phydone=0; e = top(physicsque); if(e.time < gameclock) { gameclock = e.time; } while(e.time > gameclock) { phydone = 1; } while(isFull(queue)) { } dequeue(physicsque, arrmutex); enqueue(queue ,e,queue_mutex); } if(runphy == 1) { phydone =1; } else { stopSim(); } } } }
void update2(int value) { int i; BALL b; event e; ball_event be; vector v1; char c = 0; if(chance == 0 && gamepause == 0) { runphytrd = 1; gameclock+=GAMETICK; while(!isEmpty(queue) && phydone == 1) {// do something e = dequeue(queue, queue_mutex); if(e.label == 1) {//pocketin enqueue(rulesque,e,rules_mutex); } if(e.label == 0) { // command to sinc ballques be = dequeue_ball(ballque,ballmutex); for(i=0;i<10;i++) { coins[i]=be.arr[i]; } } if(e.label==6) { runphy =0; runphytrd = 0; stopSim(); clearQueue(queue); chance = 2; gameclock =0; runphy = 1; gameRules(); coins[0].pos = relocateStriker(); } } } glutPostRedisplay(); glutTimerFunc(GAMETICK , update2 , 0); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), d_numViewPorts(0) { d_qSimTimer = new QTimer(this); connect(d_qSimTimer, SIGNAL(timeout()), this, SLOT(updateSim())); d_qDrawTimer = new QTimer(this); connect(d_qDrawTimer, SIGNAL(timeout()), this, SLOT(drawViewPorts())); d_qDrawTimer->start(30); QDockWidget *dock = new QDockWidget("Simulation Commands", this); QGridLayout *mainLayout = new QGridLayout; mainLayout->setSizeConstraint(QLayout::SetFixedSize); // Create the simulation control buttons Button *startButton = createButton(tr("Start"), SLOT(startSim())); Button *stopButton = createButton(tr("Stop"), SLOT(stopSim())); Button *initButton = createButton(tr("Initialize"), SLOT(initializeSim())); QGroupBox *controlGroupBox = new QGroupBox(tr("Simulation Control")); QVBoxLayout *vControlBox = new QVBoxLayout; vControlBox->addWidget(startButton); vControlBox->addWidget(stopButton); vControlBox->addWidget(initButton); vControlBox->addStretch(1); controlGroupBox->setLayout(vControlBox); mainLayout->addWidget(controlGroupBox, 0, 0); // Add other buttons here // Add the mainlayout to the dock widget QWidget *wi = new QWidget; wi->setLayout(mainLayout); dock->setWidget(wi); addDockWidget(Qt::LeftDockWidgetArea, dock); setWindowTitle("Cloth Simulation"); d_cloth = new C_Cloth(); d_cloth->initialize(10.0f, 10.0f, 30, 30, 200, 550.0, 400.0, 0.005, ZAXIS); d_cloth->lockParticle(0, 0); d_cloth->lockParticle(0, 19); d_cloth->setGravity(vector3f(0.0, -32.0, 0)); }
/** * Callback function for all GLUI controls. */ void control(int key) { static bool paused = false; switch (key) { case START: if (startEnabled) { glutSetWindow(modelWindow); if (model.init(ctlGeneBankName->get_text())) { glutIdleFunc(idle); startEnabled = false; ctlStart->disable(); ctlStop->enable(); ctlPause->enable(); std::cout << "Model Initialized!" << std::endl; } else std::cout << "Cannot initialize!" << std::endl; } break; case PREY_SIZE: std::cout << "Sim Time = " << model.getSimTime() << ". Prey size changed to " << System::PREY_SIZE << std::endl; break; case PREY_REPRODUCTION_AGE_LIMIT: std::cout << "Sim Time = " << model.getSimTime() << ". Prey reproduction age limit changed to " << System::PREY_REPRODUCTION_AGE_LIMIT << std::endl; break; case PREY_REPRODUCTION_INTERVAL: std::cout << "Sim Time = " << model.getSimTime() << ". Prey reproduction interval changed to " << System::PREY_REPRODUCTION_INTERVAL << std::endl; break; case PREY_DEMISE_AGE: std::cout << "Sim Time = " << model.getSimTime() << ". Prey demise age changed to " << System::PREY_REPRODUCTION_INTERVAL << std::endl; break; case PATTERN_MUTATION_RATE: std::cout << "Sim Time = " << model.getSimTime() << ". Pattern mutation rate changed to " << System::PATTERN_MUTATION_RATE << std::endl; break; case PREY_GENOME_MUTATION_RATE: std::cout << "Sim Time = " << model.getSimTime() << ". Prey genome mutation rate changed to " << System::PREY_GENOME_MUTATION_RATE << std::endl; break; case PREDATOR_REPRODUCTION_AGE_LIMIT: std::cout << "Sim Time = " << model.getSimTime() << ". Predator reproduction age limit changed to " << System::PREDATOR_REPRODUCTION_AGE_LIMIT << std::endl; break; case PREDATOR_REPRODUCTION_INTERVAL: std::cout << "Sim Time = " << model.getSimTime() << ". Predator reproduction interval changed to " << System::PREDATOR_REPRODUCTION_INTERVAL << std::endl; break; case PREDATOR_DEMISE_AGE: std::cout << "Sim Time = " << model.getSimTime() << ". Predator demise age changed to " << System::PREDATOR_REPRODUCTION_INTERVAL << std::endl; break; case PREDATOR_GENOME_MUTATION_RATE: std::cout << "Sim Time = " << model.getSimTime() << ". Predator genome mutation rate changed to " << System::PREDATOR_GENOME_MUTATION_RATE << std::endl; break; case MIN_MEMORY_SIZE: std::cout << "Sim Time = " << model.getSimTime() << ". Predator minimum memory changed to " << System::MIN_MEMORY_SIZE << std::endl; break; case MAX_MEMORY_SIZE: std::cout << "Sim Time = " << model.getSimTime() << ". Predator maximum memory changed to " << System::MAX_MEMORY_SIZE << std::endl; break; case ZOOM: viewingAngle = (180 / PI) * atan(gluiPosition[2]) + 90; setProjection(); break; case RESET: ctlRot->reset(); gluiPosition[0] = initX; gluiPosition[1] = initY; viewingAngle = initialViewingAngle; gluiPosition[2] = tan((PI/180) * (viewingAngle - 90)); setProjection(); break; case STOP: stopSim(); break; case PAUSE: if (paused) { glutSetWindow(modelWindow); glutIdleFunc(idle); } else { glutSetWindow(modelWindow); glutIdleFunc(0); } paused = !paused; break; case RING_REPORT: model.ringReport(); break; } }