QVariantMap ReceiptsPlugin::readCardTablesData(int card_id) { qfLogFuncFrame() << card_id; QVariantMap ret; CardReader::ReadCard read_card = cardReaderPlugin()->readCard(card_id); { qfu::TreeTable tt; tt.appendColumn("position", QVariant::Int); tt.appendColumn("code", QVariant::Int); tt.appendColumn("punchTimeMs", QVariant::Int); tt.appendColumn("stpTimeMs", QVariant::Int); tt.appendColumn("lapTimeMs", QVariant::Int); QMapIterator<QString, QVariant> it(read_card); while(it.hasNext()) { it.next(); if(it.key() != QLatin1String("punches")) tt.setValue(it.key(), it.value()); } int position = 0; int start_time_ms = read_card.startTime(); if(start_time_ms == 0xeeee) start_time_ms = read_card.checkTime(); start_time_ms *= 1000; int prev_stp_time_ms = 0; for(auto v : read_card.punches()) { CardReader::ReadPunch punch(v.toMap()); int punch_time_ms = punch.time() * 1000 + punch.msec(); int stp_time_ms = quickevent::og::TimeMs::msecIntervalAM(start_time_ms, punch_time_ms); qfu::TreeTableRow ttr = tt.appendRow(); ++position; int code = punch.code(); ttr.setValue("position", position); ttr.setValue("code", code); ttr.setValue("punchTimeMs", punch_time_ms); ttr.setValue("stpTimeMs", stp_time_ms); ttr.setValue("lapTimeMs", stp_time_ms - prev_stp_time_ms); prev_stp_time_ms = stp_time_ms; } { qf::core::sql::QueryBuilder qb; qb.select2("config", "ckey, cvalue, ctype") .from("config") .where("ckey LIKE 'event.%'"); qf::core::sql::Query q; q.exec(qb.toString()); while(q.next()) { QVariant v = qf::core::Utils::retypeStringValue(q.value("cvalue").toString(), q.value("ctype").toString()); tt.setValue(q.value("ckey").toString(), v); } } tt.setValue("stageCount", eventPlugin()->stageCount()); tt.setValue("currentStageId", eventPlugin()->currentStageId()); qfDebug() << "card:\n" << tt.toString(); ret["card"] = tt.toVariant(); } return ret; }
static void anim_edit_loop() { #define BLINK_PERIOD 30 int loop = BLINK_PERIOD; while (1) { unsigned long now = clock(); while (now == clock()) {} if (kbhit()) { handle_anim_edit_key(cgetc()); loop = 0; } if (loop-- == 0) { // Blink. punch(screen_char() ^ 0x80, color); loop = BLINK_PERIOD; } } }
void Elodie::handleEvent(const EventHandler& event, EntityMap& entities, Collide collideTiles) { if (event.keyIsPressed(sf::Keyboard::Space) && (state == Elodie::State::WALKING || state == Elodie::State::STANDING || (state == Elodie::State::PUNCHING && collideTiles.bottom["surface"]))) { changeState(Elodie::State::JUMPING); speed.y = jumpSpeed; spriteCast->changeStance(animations.at(state), sf::seconds(0.1f)); } else if (event.keyIsPressed(sf::Keyboard::A) && (attackTimer > attackCD)) { attackTimer = 0; changeState(Elodie::State::PUNCHING); } else if (state == Elodie::State::PUNCHING) { punch(entities); } }
void Enemy1::punch_players() { bool hitPlayer = false; for (auto player : players) { GameCharacter *player_ = std::get<TARGET>(player); if ((characterInLeft(player_) || characterInRigh(player_)) && !player_punching() && (player_->getCondition() != MOVING && player_->getCondition() != JUMPING) && abs(player_->getRow() - Row_) <= 2 && abs(player_->getCol() - Col_)>3) { synchroniseFlip(player_); if (frame / FRAMES_DELIMITOR == 3) { player_->editHealth(DAMAGE); playSound(punchSound); } hitPlayer = true; } } if (hitPlayer) punch(); }
void Shooter::update() { double bobX = bobTheAccelerometer->GetAcceleration(ADXL345_I2C::kAxis_X); double bobY = bobTheAccelerometer->GetAcceleration(ADXL345_I2C::kAxis_Y); double bobZ = bobTheAccelerometer->GetAcceleration(ADXL345_I2C::kAxis_Z); currentPitch = (atan2(bobX, sqrt(bobY*bobY + bobZ*bobZ))*180.0)/PI; // manual controls if(shooterJoy -> IsAxisZero(TILT)) { pitchStop(); } else if(shooterJoy -> GetRawAxis(TILT) < 0) // push up = negative values = tilt down { pitchDown(); } else { pitchUp(); } if(shooterJoy -> GetSmoothButton(ROLLERS)) { pull(); } else { pullStop(); } if(shooterJoy -> GetTriggerState() == LOCKANDLOAD) { autoPulling = true; wormPull(); } else if(autoPulling) { autoPulling = false; wormStop(); punch(); } // auto pitch angle if (isPitchingUp) { if (currentPitch <= destinationPitch || !(axis->GetForwardLimitOK())) { pitchStop(); isPitchingUp = false; } } if (isPitchingDown) { if (currentPitch >= destinationPitch || !(axis->GetReverseLimitOK())) { pitchStop(); isPitchingDown = false; } } // smart pickup control // sequence: // clamp up, tilt down // when tilt at pickup position, clamp down, rollers pull // when let go, tilt up // when tilt at shoot position, clamp up, rollers stop if(shooterJoy -> GetSmoothButton(PICKUP)) // holding down button { if (!isPickingUp) // hasn't started sequence yet { isPickingUp = true; pitchAngle(PICKUP_POSITION); clampUp(); } if(!isPitchingDown) // tilt at pickup position { clampDown(); pull(); } } else // let go of button { if(isPickingUp) // was picking up, so now should stop picking up { pitchAngle(SHOOTING_POSITION); isPickingUp = false; isPickingUpStopping = true; } if (!isPitchingUp && isPickingUpStopping) // tilt at shooting position { clampUp(); pullStop(); isPickingUpStopping = false; } } // increasing worm drive speed if(wormIsPulling) { if(currentSpeed <= WORM_LIMIT) { currentSpeed += INCREMENT; wormGear->Set(currentSpeed); } else if(currentSpeed > WORM_LIMIT || !(wormGear->GetForwardLimitOK())) { wormStop(); } } }
QVariantMap ReceiptsPlugin::receiptTablesData(int card_id) { qfLogFuncFrame() << card_id; QF_TIME_SCOPE("receiptTablesData()"); QVariantMap ret; CardReader::ReadCard read_card = cardReaderPlugin()->readCard(card_id); CardReader::CheckedCard checked_card = cardReaderPlugin()->checkCard(read_card); int current_stage_id = eventPlugin()->currentStageId(); int run_id = checked_card.runId(); int course_id = checked_card.courseId(); int current_standings = 0; int competitors_finished = 0; QMap<int, int> best_laps; //< position->time ///QMap<int, int> missing_codes; //< pos->code ///QSet<int> out_of_order_codes; { qf::core::model::SqlTableModel model; qf::core::sql::QueryBuilder qb; qb.select2("competitors", "*") .select2("runs", "*") .select2("classes", "name") .select("COALESCE(competitors.lastName, '') || ' ' || COALESCE(competitors.firstName, '') AS competitorName") .from("runs") .join("runs.competitorId", "competitors.id") .join("competitors.classId", "classes.id") .where("runs.id=" QF_IARG(run_id)); model.setQuery(qb.toString()); model.reload(); if(model.rowCount() == 1) { int class_id = model.value(0, "competitors.classId").toInt(); { // find best laps for competitors class qf::core::sql::QueryBuilder qb_minlaps; // TODO: remove position field from DB in 0.1.5 qb_minlaps.select("runlaps.position, MIN(runlaps.lapTimeMs) AS minLapTimeMs") .from("competitors") .joinRestricted("competitors.id", "runs.competitorId", "runs.stageId=" QF_IARG(current_stage_id) " AND competitors.classId=" QF_IARG(class_id), "JOIN") .joinRestricted("runs.id", "runlaps.runId", "runlaps.position > 0 AND runlaps.lapTimeMs > 0", "JOIN") .groupBy("runlaps.position"); QString qs = qb_minlaps.toString(); //qfInfo() << qs; qf::core::sql::Query q; q.exec(qs); while(q.next()) { int position = q.value("position").toInt(); if(position == 0) { qfWarning() << "position == 0 in best runlaps"; continue; } int lap = q.value("minLapTimeMs").toInt(); if(lap == 0) { qfWarning() << "minLapTimeMs == 0 in best runlaps"; continue; } best_laps[position] = lap; //qfInfo() << "bestlaps[" << pos << "] =" << lap; } } if(checked_card.isOk()) { // find current standings qf::core::sql::QueryBuilder qb; qb.select2("runs", "timeMs") .select("runs.disqualified OR NOT runs.isRunning OR runs.isRunning IS NULL OR runs.misPunch AS dis") .from("competitors") .joinRestricted("competitors.id", "runs.competitorId", "runs.stageId=" QF_IARG(current_stage_id) " AND competitors.classId=" QF_IARG(class_id)) .where("runs.finishTimeMs > 0") .orderBy("misPunch, disqualified, isRunning, runs.timeMs"); //qfInfo() << qb.toString(); qf::core::sql::Query q; q.exec(qb.toString(), qf::core::Exception::Throw); while (q.next()) { bool dis = q.value("dis").toBool(); int time = q.value("timeMs").toInt(); if(!dis) { if(time <= checked_card.timeMs()) current_standings++; } competitors_finished++; } } } qfu::TreeTable tt = model.toTreeTable(); { qf::core::sql::QueryBuilder qb; qb.select2("courses", "length, climb") .select("(SELECT COUNT(*) FROM coursecodes WHERE courseId=courses.id) AS controlCount") .from("courses") .where("courses.id=" QF_IARG(course_id)); qf::core::sql::Query q; q.exec(qb.toString()); if(q.next()) { QSqlRecord rec = q.record(); for (int i = 0; i < rec.count(); ++i) { QString fld_name = rec.fieldName(i); tt.setValue(fld_name, rec.value(i)); } } } { qf::core::sql::QueryBuilder qb; qb.select2("config", "ckey, cvalue, ctype") .from("config") .where("ckey LIKE 'event.%'"); qf::core::sql::Query q; q.exec(qb.toString()); while(q.next()) { QVariant v = qf::core::Utils::retypeStringValue(q.value("cvalue").toString(), q.value("ctype").toString()); tt.setValue(q.value("ckey").toString(), v); } } tt.setValue("stageCount", eventPlugin()->stageCount()); tt.setValue("currentStageId", eventPlugin()->currentStageId()); qfDebug() << "competitor:\n" << tt.toString(); ret["competitor"] = tt.toVariant(); } { qfu::TreeTable tt; tt.appendColumn("position", QVariant::Int); tt.appendColumn("code", QVariant::Int); tt.appendColumn("stpTimeMs", QVariant::Int); tt.appendColumn("lapTimeMs", QVariant::Int); tt.appendColumn("lossMs", QVariant::Int); QMapIterator<QString, QVariant> it(checked_card); while(it.hasNext()) { it.next(); if(it.key() != QLatin1String("punches")) tt.setValue(it.key(), it.value()); } tt.setValue("isOk", checked_card.isOk()); int position = 0; for(auto v : checked_card.punches()) { CardReader::CheckedPunch punch(v.toMap()); qfu::TreeTableRow ttr = tt.appendRow(); ++position; int code = punch.code(); ttr.setValue("position", position); ttr.setValue("code", code); ttr.setValue("stpTimeMs", punch.stpTimeMs()); int lap = punch.lapTimeMs(); ttr.setValue("lapTimeMs", lap); int best_lap = best_laps.value(position); if(lap > 0 && best_lap > 0) { int loss = lap - best_lap; ttr.setValue("lossMs", loss); } } /* { // runlaps table contains also finish time entry, it is under FINISH_PUNCH_POS // currently best_laps[999] contains best finish lap time for this class int loss = 0; int best_lap = best_laps.value(CardReader::CardReaderPlugin::FINISH_PUNCH_POS); if(best_lap > 0) loss = checked_card.finishLapTimeMs() - best_lap; //qfInfo() << "control_count:" << control_count << "finishLapTimeMs:" << checked_card.finishLapTimeMs() << "- best_lap:" << best_lap << "=" << loss; tt.setValue("finishLossMs", loss); } */ { QSet<int> correct_codes; for (int i = 0; i < checked_card.punchCount(); ++i) { correct_codes << checked_card.punchAt(i).code(); } QVariantList xc; for (int i = 0; i < read_card.punchCount(); ++i) { int code = read_card.punchAt(i).code(); if(!correct_codes.contains(code)) { xc.insert(xc.count(), QVariantList() << (i+1) << code); } } tt.setValue("extraCodes", xc); } tt.setValue("currentStandings", current_standings); tt.setValue("competitorsFinished", competitors_finished); tt.setValue("timeMs", checked_card.timeMs()); qfDebug() << "card:\n" << tt.toString(); ret["card"] = tt.toVariant(); } return ret; }
static void punch_paint() { punch(paint_char, color); }
void switch_color(char c) { color = c; hidden_color = c; punch(hidden_screen_char, c); }
static void hide_cursor() { punch(hidden_screen_char, hidden_color); }
rtems_task Task2(rtems_task_argument ignored) { rtems_status_code status; rtems_id period_id; rtems_interval ticks; status = rtems_rate_monotonic_create( rtems_build_name( 'P', 'E', 'R', '2' ), &period_id ); ticks = get_ticks_for_period(50); // the punching will start with the first hole int hole_to_punch = 0; // we are about to punch holes_total_count holes int holes_total_count = 4; int error = 0; int done = 0; while(1) { status = rtems_rate_monotonic_period( period_id, ticks ); if(status == RTEMS_TIMEOUT) { break; // this is the end. the system missed a deadline, which is fatal. } int state = read_punchpress_state(); if (state < STATE_INITIAL) break; switch (state) { case STATE_READY: plan_movement(hole_to_punch, holes_total_count); break; case STATE_PUNCH_READY: punch(hole_to_punch, holes_total_count); break; case STATE_PUNCHING: control_punch(&hole_to_punch); break; case STATE_RETRACT: control_retract(); break; case STATE_NAVIGATING: break; case STATE_DONE: done = 1; break; default: error = 1; break; } if ((error + done) > 0){ break; } } if (error > 0) { printf("ERROR! SOMETHING WENT WRONG (UNEXPECTED STATE OR DEADLINE MISSED) IN TASK CONTROLLING PUNCHING!\n"); exit(1); } outport_byte(OUT_PUNCH_IRQ, 0); rtems_rate_monotonic_delete(period_id); rtems_semaphore_delete(state_semaphore_id); rtems_interrupt_handler_remove(5, isr, NULL); /** * The only way to shutdown the app is to invoke exit() before deleting the "last" task. * Since it is not very nice and it is not used in example apps, just delete the task. **/ rtems_task_delete(RTEMS_SELF); }
int main (int argc, char **argv) { struct event_base *base; struct uhp_info *ui; char *port; char *msg; char *address; int c; struct input_p *ip; struct output_p *op; printf("INITIALIZATION\n"); ip = malloc(sizeof(*ip)); if (ip == NULL){ perror("malloc"); exit(-1); } while ((c = getopt(argc, argv, "a:m:p:")) != -1) { switch (c) { case 'a': printf("Setting a \n"); address = optarg; break; case 'p': printf("Setting p \n"); port = optarg; break; case 'm': printf("Setting m \n"); msg = optarg; break; default: printf("Usage: "); printf("test -a 192.168.0.1 -p 54321 -m message\n"); exit(-1); } } ip->address = strdup(address); if (ip->address == NULL){ perror("strdup failed"); exit(-1); } printf("INITIALIZATION: ADDRESS: %s\n",ip->address); ip->port = strdup(port); if (ip->port == NULL){ perror("strdup failed"); exit(-1); } printf("INITIALIZATION: PORT: %s\n", ip->port); ip->msg = strdup(msg); if (ip->msg == NULL){ perror("strdup failed"); exit(-1); } printf("INITIALIZATION: MSG: %s\n", ip->msg); ip->base = event_base_new(); if (ip->base == NULL) { perror("Couldn't open event base"); exit(-1); } op = malloc(sizeof(*op)); if (op == NULL){ perror("malloc"); exit(-1); } op->uhp_cb = p_cb; op->metadata = NULL; printf("CALL PUNCH\n"); punch(ip,op); printf("DISPATCH\n"); event_base_dispatch(ip->base); return 0; }
/** * Updates the melee enemy * @param of this game is host or not */ void MeleeEnemy::update(bool pHost) { b2Vec2 target = mPlayer->getBody()->GetPosition(); if(abs(target.x - mBody->GetPosition().x) <= 35 && abs(target.y - mBody->GetPosition().y) <= 5) { mState = ATTACK; } else { mState = IDLE; } if(mCanMove == true) { if(mPunchTimer > 0) { mPunchTimer -= 0.1f; } if(mState == ATTACK) { // Move towards the player if(target.x >= mBody->GetPosition().x) { mDirection = 1; mDrawDirection = mDirection; if(abs((target - mBody->GetPosition()).Length() <= mAttackRange)) { mDirection = 0; //setAttack(); if(punching == false) { if(mPunchTimer <= 0.0f) { punch(); } } } } if(target.x < mBody->GetPosition().x) { mDirection = -1; mDrawDirection = mDirection; if(abs((target - mBody->GetPosition()).Length() <= mAttackRange)) { mDirection = 0; //setAttack(); if(punching == false) { if(mPunchTimer <= 0.0f) { punch(); } } } } if(mFrame == mFrameWidth*8 && abs((target - mBody->GetPosition()).Length() <= mAttackRange)) { if(punching) { // hurt player mPlayer->applyDamage(mStrength); punching = false; } } //if(abs(mTarget.x - mBody->GetPosition().x >= mAttackRange*10)) { //mState = IDLE; //} } else if(mState == IDLE && mAlive) { if(mBody->GetPosition().x >= mPatrolPointB) { mDirection = -1; mDrawDirection = mDirection; } else if(mBody->GetPosition().x <= mPatrolPointA) { mDirection = 1; mDrawDirection = mDirection; } } b2Vec2 force = b2Vec2(150000*mDirection, 0); mBody->ApplyForce(force, mBody->GetWorldCenter()); if(abs(mBody->GetLinearVelocity().x) > 7) { mBody->SetLinearVelocity(b2Vec2(6*mDirection, mBody->GetLinearVelocity().y)); } } else { mStunTimer -= 0.1; if(mStunTimer <= 0.0f) { mCanMove = true; } } if(pHost) { if(mHealth <= 0) { mAlive = false; mDeathSoundSpec->Play(); } } draw(); }