int main(int argc, char const *argv[]) { // Check for argument unsigned int x = 0; if (argc >= 2) { x = atoi(argv[1]); } else { printf("Output of \"cat /proc/bus/input/devices | grep mouse\"\n"); system("cat /proc/bus/input/devices | grep mouse"); printf("\nEnter event file number: "); fflush(stdout); if (scanf("%u", &x) != 1) f**k("Invalid input"); } // Open the device char * path = (char *) malloc((strlen(dev_path_format) + 32)); sprintf(path, dev_path_format, x); fd = open(path, O_WRONLY); free(path); if (fd < 0) f**k("Failed to open device"); // Create mouse input events struct input_event ev; ev.type = EV_REL; // Relative movement struct input_event ev_syn; ev_syn.type = EV_SYN; // Sync event ev_syn.code = SYN_REPORT; // Report any changes ev_syn.value = 0; // Inject input events to create a circle double t = 0, dx, dy, A, T; while (t < 60) { T = 1; A = 10; dx = A * sin(t * 2 * PI / T); dy = A * cos(t * 2 * PI / T); ev.code = REL_X; // On the X axis ev.value = (int) dx; writeEvent(&ev); ev.code = REL_Y; // On the Y axis ev.value = (int) dy; writeEvent(&ev); writeEvent(&ev_syn); t += 0.01; usleep(10000); } return 0; }
bool MidiFile::writeTrack(const MidiTrack &t) { write("MTrk", 4); qint64 lenpos = fp->pos(); writeLong(0); // dummy len status = -1; int tick = 0; for (auto i : t.events()) { int ntick = i.first; putvl(ntick - tick); // write tick delta // // if track channel != -1, then use this // channel for all events in this track // if (t.outChannel() != -1) writeEvent(i.second); tick = ntick; } //--------------------------------------------------- // write "End Of Track" Meta // write Track Len // putvl(1); put(0xff); // Meta put(0x2f); // EOT putvl(0); // len 0 qint64 endpos = fp->pos(); fp->seek(lenpos); writeLong(endpos-lenpos-4); // tracklen fp->seek(endpos); return false; }
/*virtual*/ void InputEmulatorUInput::keySend(const uint32_t key, const uint32_t state) const { struct input_event event; memset(&event, 0, sizeof(event)); event.type = EV_KEY; event.code = key; event.value = state; writeEvent(&event); event.type = EV_SYN; event.code = SYN_REPORT; event.value = 0; writeEvent(&event); }
int processEvent(GameEvent* e) { int value = 0; Data *data; if(game2->mode == GAME_SINGLE_RECORD) { writeEvent(e); } switch(e->type) { case EVENT_TURN_LEFT: data = game->player[e->player].data; if(data->speed > 0) { data->iposx = e->x; data->iposy = e->y; data->turn = TURN_LEFT; doTurn(data, e->timestamp); } break; case EVENT_TURN_RIGHT: data = game->player[e->player].data; if(data->speed > 0) { data->iposx = e->x; data->iposy = e->y; data->turn = TURN_RIGHT; doTurn(data, e->timestamp); } break; case EVENT_CRASH: data = game->player[e->player].data; data->posx = data->iposx = e->x; data->posy = data->iposy = e->y; sprintf(messages, "player %d crashed", e->player + 1); fprintf(stderr, "%s\n", messages); consoleAddLine(messages); crashPlayer(e->player); break; case EVENT_STOP: fprintf(stderr, "game stopped\n"); if(game2->mode == GAME_SINGLE_RECORD) { stopRecording(); game2->mode = GAME_SINGLE; } else if(game2->mode == GAME_PLAY) { stopPlaying(); game2->mode = GAME_SINGLE; } game->winner = e->player; sprintf(messages, "winner: %d", game->winner + 1); printf("%s\n", messages); consoleAddLine(messages); switchCallbacks(&pauseCallbacks); /* screenSaverCheck(0); */ stoptime = SystemGetElapsedTime(); game->pauseflag = PAUSE_GAME_FINISHED; value = 1; break; } free(e); return value; }
static int thread_write( UThread* ut, UBuffer* port, const UCell* data ) { UBuffer* buf; ThreadExt* ext = (ThreadExt*) port->ptr.v; ThreadQueue* queue; int type = ur_type(data); if( ur_isSeriesType(type) && ! ur_isShared( data->series.buf ) ) { buf = ur_bufferSerM( data ); if( ! buf ) return UR_THROW; if( ur_isBlockType(type) ) { UCell* it = buf->ptr.cell; UCell* end = it + buf->used; while( it != end ) { type = ur_type(it); if( ur_isWordType(type) ) { if( ur_binding(it) == UR_BIND_THREAD ) ur_unbind(it); } else if( ur_isSeriesType(type) ) { return ur_error( ut, UR_ERR_INTERNAL, "Cannot write block containing series to thread port" ); } ++it; } } } else buf = 0; queue = (port->SIDE == SIDE_A) ? &ext->A : &ext->B; mutexLock( queue->mutex ); if( queue->END_OPEN ) { thread_queue( &queue->buf, data, buf ); condSignal( queue->cond ); writeEvent( queue ); } mutexUnlock( queue->mutex ); return UR_OK; }
/*virtual*/ void InputEmulatorUInput::movePointer(const int32_t x, const int32_t y) const { struct input_event event; int32_t gx(x), gy(y); toScreen(&gx, &gy); memset(&event, 0, sizeof(event)); event.type = EV_ABS; event.code = ABS_X; event.value = gx; writeEvent(&event); event.type = EV_ABS; event.code = ABS_Y; event.value = gy; writeEvent(&event); event.type = EV_SYN; event.code = SYN_REPORT; event.value = 0; writeEvent(&event); }
int processEvent(GameEvent* e) { int value = 0; #ifdef RECORD if(game2->mode == GAME_SINGLE_RECORD) { writeEvent(e); } #endif switch(e->type) { case EVENT_TURN_LEFT: doTurn(e, TURN_LEFT); break; case EVENT_TURN_RIGHT: doTurn(e, TURN_RIGHT); break; case EVENT_CRASH: displayMessage(TO_CONSOLE, "player %d crashed", e->player + 1); doCrashPlayer(e); break; case EVENT_STOP: // displayMessage(TO_STDOUT, "game stopped"); #ifdef RECORD if(game2->mode == GAME_SINGLE_RECORD) { stopRecording(); game2->mode = GAME_SINGLE; } else if(game2->mode == GAME_PLAY) { stopPlaying(); game2->mode = GAME_SINGLE; } #endif if(e->player<PLAYERS && game->player[e->player].ai->active != AI_NONE) { game->winner = e->player; displayMessage(TO_CONSOLE, "winner: %d", game->winner + 1); } else { game->winner = -2; displayMessage(TO_CONSOLE, "everyone died! no one wins!"); } SystemExitLoop(RETURN_GAME_END); game->pauseflag = PAUSE_GAME_FINISHED; value = 1; break; } free(e); return value; }
GameScreen::GameScreen(QWidget *parent) : QMainWindow(parent), ui(new Ui::GameScreen) { ui->setupUi(this); tmp = new QMainWindow(this); paddleIcon = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/paddle.png"); ballIcon = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/white_ball.png"); gameOverIcon = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/gameover.png"); gameOverlay = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/background.jpg"); gameWonIcon = new QPixmap("C:/Users/TAYLOR/Documents/C++ Files/BrickBreak/youwin.jpg"); overlayLbl = new QLabel(this); overlayLbl->setPixmap(*gameOverlay); overlayLbl->setGeometry(0, ui->menuBar->height(), this->width() - (this->width() - ui->rightLine->pos().x()), this->height() - (this->height() - ui->bottomLine->pos().y())); connect(this, SIGNAL(eventTriggered(QString)), this, SLOT(writeEvent(QString))); connect(this, SIGNAL(gameEnded()), this, SLOT(gameOver())); diff = EASY; level = 1; newLevel(level); createActions(); createMenus(); createPaddle(); createBall(); numLives = 3; time = new Timer(this, "time"); connect(time, SIGNAL(timeout()), this, SLOT(decrementTimer())); cheatModeActive = false; spacePressed = false; score = 0; createBlocks(); eventLogFullSizePos = new QPoint(310, 10); eventLogHalfSizePos = new QPoint(310, 200); hideCheatMode(); setLivesText(numLives); setTimeText(timeLeft); setLevelText(level); setScoreText(score); }
int main(){ std::cout<<"start processing"<<std::endl; auto store = podio::EventStore(); auto writer = podio::ASCIIWriter("example.txt", &store); auto& info = store.create<EventInfoCollection>("info"); auto& mcps = store.create<ExampleMCCollection>("mcparticles"); auto& hits = store.create<ExampleHitCollection>("hits"); auto& clusters = store.create<ExampleClusterCollection>("clusters"); auto& refs = store.create<ExampleReferencingTypeCollection>("refs"); auto& refs2 = store.create<ExampleReferencingTypeCollection>("refs2"); auto& comps = store.create<ExampleWithComponentCollection>("Component"); auto& oneRels = store.create<ExampleWithOneRelationCollection>("OneRelation"); auto& vecs = store.create<ExampleWithVectorMemberCollection>("WithVectorMember"); auto& namesps = store.create<ex::ExampleWithNamespaceCollection>("WithNamespaceMember"); auto& namesprels = store.create<ex::ExampleWithARelationCollection>("WithNamespaceRelation"); auto& strings = store.create<ExampleWithStringCollection>("strings"); writer.registerForWrite<EventInfoCollection>("info"); writer.registerForWrite<ExampleMCCollection>("mcparticles"); writer.registerForWrite<ExampleHitCollection>("hits"); writer.registerForWrite<ExampleClusterCollection>("clusters"); writer.registerForWrite<ExampleReferencingTypeCollection>("refs"); writer.registerForWrite<ExampleReferencingTypeCollection>("refs2"); writer.registerForWrite<ExampleWithComponentCollection>("Component"); writer.registerForWrite<ExampleWithOneRelationCollection>("OneRelation"); writer.registerForWrite<ExampleWithVectorMemberCollection>("WithVectorMember"); writer.registerForWrite<ex::ExampleWithNamespaceCollection>("WithNamespaceMember"); writer.registerForWrite<ex::ExampleWithARelationCollection>("WithNamespaceRelation"); writer.registerForWrite<ExampleWithStringCollection>("strings"); unsigned nevents=1;//2000; for(unsigned i=0; i<nevents; ++i) { if(i % 1000 == 0) { std::cout << "processing event " << i << std::endl; } auto item1 = EventInfo(); item1.Number(i); info.push_back(item1); auto hit1 = ExampleHit(0.,0.,0.,23.+i); auto hit2 = ExampleHit(1.,0.,0.,12.+i); hits.push_back(hit1); hits.push_back(hit2); // ---- add some MC particles ---- auto mcp0 = ExampleMC(); auto mcp1 = ExampleMC(); auto mcp2 = ExampleMC(); auto mcp3 = ExampleMC(); auto mcp4 = ExampleMC(); auto mcp5 = ExampleMC(); auto mcp6 = ExampleMC(); auto mcp7 = ExampleMC(); auto mcp8 = ExampleMC(); auto mcp9 = ExampleMC(); mcps.push_back( mcp0 ) ; mcps.push_back( mcp1 ) ; mcps.push_back( mcp2 ) ; mcps.push_back( mcp3 ) ; mcps.push_back( mcp4 ) ; mcps.push_back( mcp5 ) ; mcps.push_back( mcp6 ) ; mcps.push_back( mcp7 ) ; mcps.push_back( mcp8 ) ; mcps.push_back( mcp9 ) ; // --- add some daughter relations auto p = ExampleMC(); auto d = ExampleMC(); p = mcps[0] ; p.adddaughters( mcps[2] ) ; p.adddaughters( mcps[3] ) ; p.adddaughters( mcps[4] ) ; p.adddaughters( mcps[5] ) ; p = mcps[1] ; p.adddaughters( mcps[2] ) ; p.adddaughters( mcps[3] ) ; p.adddaughters( mcps[4] ) ; p.adddaughters( mcps[5] ) ; p = mcps[2] ; p.adddaughters( mcps[6] ) ; p.adddaughters( mcps[7] ) ; p.adddaughters( mcps[8] ) ; p.adddaughters( mcps[9] ) ; p = mcps[3] ; p.adddaughters( mcps[6] ) ; p.adddaughters( mcps[7] ) ; p.adddaughters( mcps[8] ) ; p.adddaughters( mcps[9] ) ; //--- now fix the parent relations for( unsigned j=0,N=mcps.size();j<N;++j){ p = mcps[j] ; for(auto it = p.daughters_begin(), end = p.daughters_end() ; it!=end ; ++it ){ int dIndex = it->getObjectID().index ; d = mcps[ dIndex ] ; d.addparents( p ) ; } } //-------- print relations for debugging: for( auto p : mcps ){ std::cout << " particle " << p.getObjectID().index << " has daughters: " ; for(auto it = p.daughters_begin(), end = p.daughters_end() ; it!=end ; ++it ){ std::cout << " " << it->getObjectID().index ; } std::cout << " and parents: " ; for(auto it = p.parents_begin(), end = p.parents_end() ; it!=end ; ++it ){ std::cout << " " << it->getObjectID().index ; } std::cout << std::endl ; } //------------------------------- auto cluster = ExampleCluster(); auto clu0 = ExampleCluster(); auto clu1 = ExampleCluster(); clu0.addHits(hit1); clu0.energy(hit1.energy()); clu1.addHits(hit2); clu1.energy(hit2.energy()); cluster.addHits(hit1); cluster.addHits(hit2); cluster.energy(hit1.energy()+hit2.energy()); cluster.addClusters( clu0 ) ; cluster.addClusters( clu1 ) ; clusters.push_back(clu0); clusters.push_back(clu1); clusters.push_back(cluster); auto ref = ExampleReferencingType(); refs.push_back(ref); auto ref2 = ExampleReferencingType(); refs2.push_back(ref2); ref.addClusters(cluster); ref.addRefs(ref2); auto comp = ExampleWithComponent(); comp.component().data.x = 0; comp.component().data.y = 1; comp.component().data.z = i; comps.push_back(comp); auto cyclic = ExampleReferencingType(); cyclic.addRefs(cyclic); refs.push_back(cyclic); auto oneRel = ExampleWithOneRelation(); oneRel.cluster(cluster); oneRels.push_back(oneRel); // write non-filled relation auto oneRelEmpty = ExampleWithOneRelation(); oneRels.push_back(oneRelEmpty); auto vec = ExampleWithVectorMember(); vec.addcount(23); vec.addcount(24); vecs.push_back(vec); auto namesp = ex::ExampleWithNamespace(); namesp.data().x = 1; namesp.data().y = i; namesps.push_back(namesp); auto rel = ex::ExampleWithARelation(); rel.ref(namesp); namesprels.push_back(rel); auto string = ExampleWithString("SomeString"); strings.push_back(string); writer.writeEvent(); store.clearCollections(); } writer.finish(); }
void write(std::string outfilename) { std::cout<<"start processing"<<std::endl; auto store = podio::EventStore(); auto writer = podio::ROOTWriter(outfilename, &store); auto& info = store.create<EventInfoCollection>("info"); auto& mcps = store.create<ExampleMCCollection>("mcparticles"); auto& hits = store.create<ExampleHitCollection>("hits"); auto& clusters = store.create<ExampleClusterCollection>("clusters"); auto& refs = store.create<ExampleReferencingTypeCollection>("refs"); auto& refs2 = store.create<ExampleReferencingTypeCollection>("refs2"); auto& comps = store.create<ExampleWithComponentCollection>("Component"); auto& oneRels = store.create<ExampleWithOneRelationCollection>("OneRelation"); auto& vecs = store.create<ExampleWithVectorMemberCollection>("WithVectorMember"); auto& namesps = store.create<ex::ExampleWithNamespaceCollection>("WithNamespaceMember"); auto& namesprels = store.create<ex::ExampleWithARelationCollection>("WithNamespaceRelation"); auto& cpytest = store.create<ex::ExampleWithARelationCollection>("WithNamespaceRelationCopy"); auto& strings = store.create<ExampleWithStringCollection>("strings"); auto& arrays = store.create<ExampleWithArrayCollection>("arrays"); writer.registerForWrite("info"); writer.registerForWrite("mcparticles"); writer.registerForWrite("hits"); writer.registerForWrite("clusters"); writer.registerForWrite("refs"); writer.registerForWrite("refs2"); writer.registerForWrite("Component"); writer.registerForWrite("OneRelation"); writer.registerForWrite("WithVectorMember"); writer.registerForWrite("WithNamespaceMember"); writer.registerForWrite("WithNamespaceRelation"); writer.registerForWrite("WithNamespaceRelationCopy"); writer.registerForWrite("strings"); writer.registerForWrite("arrays"); unsigned nevents = 2000; for(unsigned i=0; i<nevents; ++i) { if(i % 1000 == 0) { std::cout << "processing event " << i << std::endl; } auto item1 = EventInfo(); item1.Number(i); info.push_back(item1); auto hit1 = ExampleHit(0.,0.,0.,23.+i); auto hit2 = ExampleHit(1.,0.,0.,12.+i); hits.push_back(hit1); hits.push_back(hit2); // ---- add some MC particles ---- auto mcp0 = ExampleMC(); auto mcp1 = ExampleMC(); auto mcp2 = ExampleMC(); auto mcp3 = ExampleMC(); auto mcp4 = ExampleMC(); auto mcp5 = ExampleMC(); auto mcp6 = ExampleMC(); auto mcp7 = ExampleMC(); auto mcp8 = ExampleMC(); auto mcp9 = ExampleMC(); mcps.push_back( mcp0 ) ; mcps.push_back( mcp1 ) ; mcps.push_back( mcp2 ) ; mcps.push_back( mcp3 ) ; mcps.push_back( mcp4 ) ; mcps.push_back( mcp5 ) ; mcps.push_back( mcp6 ) ; mcps.push_back( mcp7 ) ; mcps.push_back( mcp8 ) ; mcps.push_back( mcp9 ) ; // --- add some daughter relations auto p = ExampleMC(); auto d = ExampleMC(); p = mcps[0] ; p.adddaughters( mcps[2] ) ; p.adddaughters( mcps[3] ) ; p.adddaughters( mcps[4] ) ; p.adddaughters( mcps[5] ) ; p = mcps[1] ; p.adddaughters( mcps[2] ) ; p.adddaughters( mcps[3] ) ; p.adddaughters( mcps[4] ) ; p.adddaughters( mcps[5] ) ; p = mcps[2] ; p.adddaughters( mcps[6] ) ; p.adddaughters( mcps[7] ) ; p.adddaughters( mcps[8] ) ; p.adddaughters( mcps[9] ) ; p = mcps[3] ; p.adddaughters( mcps[6] ) ; p.adddaughters( mcps[7] ) ; p.adddaughters( mcps[8] ) ; p.adddaughters( mcps[9] ) ; //--- now fix the parent relations for( unsigned j=0,N=mcps.size();j<N;++j){ p = mcps[j] ; for(auto it = p.daughters_begin(), end = p.daughters_end() ; it!=end ; ++it ){ int dIndex = it->getObjectID().index ; d = mcps[ dIndex ] ; d.addparents( p ) ; } } //-------- print relations for debugging: for( auto p : mcps ){ std::cout << " particle " << p.getObjectID().index << " has daughters: " ; for(auto it = p.daughters_begin(), end = p.daughters_end() ; it!=end ; ++it ){ std::cout << " " << it->getObjectID().index ; } std::cout << " and parents: " ; for(auto it = p.parents_begin(), end = p.parents_end() ; it!=end ; ++it ){ std::cout << " " << it->getObjectID().index ; } std::cout << std::endl ; } //------------------------------- auto cluster = ExampleCluster(); auto clu0 = ExampleCluster(); auto clu1 = ExampleCluster(); clu0.addHits(hit1); clu0.energy(hit1.energy()); clu1.addHits(hit2); clu1.energy(hit2.energy()); cluster.addHits(hit1); cluster.addHits(hit2); cluster.energy(hit1.energy()+hit2.energy()); cluster.addClusters( clu0 ) ; cluster.addClusters( clu1 ) ; clusters.push_back(clu0); clusters.push_back(clu1); clusters.push_back(cluster); auto ref = ExampleReferencingType(); refs.push_back(ref); auto ref2 = ExampleReferencingType(); refs2.push_back(ref2); ref.addClusters(cluster); ref.addRefs(ref2); auto comp = ExampleWithComponent(); comp.component().data.x = 0; comp.component().data.y = 1; comp.component().data.z = i; comps.push_back(comp); auto cyclic = ExampleReferencingType(); cyclic.addRefs(cyclic); refs.push_back(cyclic); auto oneRel = ExampleWithOneRelation(); oneRel.cluster(cluster); oneRels.push_back(oneRel); // write non-filled relation auto oneRelEmpty = ExampleWithOneRelation(); oneRels.push_back(oneRelEmpty); auto vec = ExampleWithVectorMember(); vec.addcount(i); vec.addcount(i+10); vecs.push_back(vec); auto vec1 = ExampleWithVectorMember(); vec1.addcount(i+1); vec1.addcount(i+11); vecs.push_back(vec1); for (int j = 0; j < 5; j++) { auto rel = ex::ExampleWithARelation(); rel.number(0.5*j); auto exWithNamesp = ex::ExampleWithNamespace(); exWithNamesp.data().x = i; exWithNamesp.data().y = 1000*i; namesps.push_back(exWithNamesp); if (j != 3) { // also check for empty relations rel.ref(exWithNamesp); for (int k = 0; k < 5; k++) { auto namesp = ex::ExampleWithNamespace(); namesp.x(3*k); namesp.data().y = k; namesps.push_back(namesp); rel.addrefs(namesp); } } namesprels.push_back(rel); } for (int j = 0; j < namesprels.size(); ++j) { cpytest.push_back(namesprels.at(j).clone()); } auto string = ExampleWithString("SomeString"); strings.push_back(string); std::array<int, 4> arrayTest = {0, 0, 2, 3}; std::array<int, 4> arrayTest2 = {4, 4, 2 * static_cast<int>(i)}; NotSoSimpleStruct a; a.data.p = arrayTest2; ex2::NamespaceStruct nstruct; nstruct.x = static_cast<int>(i); std::array<ex2::NamespaceStruct, 4> structArrayTest = {nstruct, nstruct, nstruct, nstruct}; auto array = ExampleWithArray(a, arrayTest, arrayTest, arrayTest, arrayTest, structArrayTest); array.myArray(1, i); array.arrayStruct(a); arrays.push_back(array); writer.writeEvent(); store.clearCollections(); } writer.finish(); }
void ScenarioEvent::fire() { cerr << "Fire !" << endl; string descr = writeEvent(); }