// ${AOs::Table::SM::active::paused} QP::QState Table::paused(Table * const me, QP::QEvt const * const e) { QP::QState status_; switch (e->sig) { // ${AOs::Table::SM::active::paused::PAUSE} case PAUSE_SIG: { static struct { QP::QMState const *target; QP::QActionHandler act[3]; } const tatbl_ = { // transition-action table &serving_s, { Q_ACTION_CAST(&paused_x), // exit Q_ACTION_CAST(&serving_e), // entry Q_ACTION_CAST(0) // zero terminator } }; status_ = QM_TRAN(&tatbl_); break; } // ${AOs::Table::SM::active::paused::HUNGRY} case HUNGRY_SIG: { uint8_t n = Q_EVT_CAST(TableEvt)->philoNum; // philo ID must be in range and he must be not hungry Q_ASSERT((n < N_PHILO) && (!me->m_isHungry[n])); me->m_isHungry[n] = true; BSP_displayPhilStat(n, HUNGRY); status_ = QM_HANDLED(); break; } // ${AOs::Table::SM::active::paused::DONE} case DONE_SIG: { uint8_t n = Q_EVT_CAST(TableEvt)->philoNum; // phil ID must be in range and he must be not hungry Q_ASSERT((n < N_PHILO) && (!me->m_isHungry[n])); BSP_displayPhilStat(n, THINKING); uint8_t m = LEFT(n); /* both forks of Phil[n] must be used */ Q_ASSERT((me->m_fork[n] == USED) && (me->m_fork[m] == USED)); me->m_fork[m] = FREE; me->m_fork[n] = FREE; status_ = QM_HANDLED(); break; } default: { status_ = QM_SUPER(); break; } } return status_; }
QP::QState Philo::hungry(Philo * const me, QP::QEvt const * const e) { QP::QState status_; switch (e->sig) { // @(/3/0/2/2/0) case EAT_SIG: { // @(/3/0/2/2/0/0) if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) { static QP::QActionHandler const act_[] = { Q_ACTION_CAST(&Philo::eating_e), Q_ACTION_CAST(0) }; status_ = QM_TRAN(&eating_s, act_); } else { status_ = QM_UNHANDLED(); } break; } // @(/3/0/2/2/1) case DONE_SIG: { /* DONE must be for other Philos than this one */ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me)); status_ = QM_HANDLED(); break; } default: { status_ = QM_SUPER(); break; } } return status_; }
QP::QState Mine1::exploding(Mine1 * const me, QP::QEvt const * const e) { QP::QState status_; switch (e->sig) { // @(/2/3/4/2/1/0) case TIME_TICK_SIG: { // @(/2/3/4/2/1/0/0) if ((me->m_x >= GAME_SPEED_X) && (me->m_exp_ctr < 15)) { ++me->m_exp_ctr; // advance the explosion counter me->m_x -= GAME_SPEED_X; // move explosion by 1 step // tell the Game to render the current stage of Explosion ObjectImageEvt *oie = Q_NEW(ObjectImageEvt, EXPLOSION_SIG); oie->x = me->m_x + 1U; // x of explosion oie->y = (int8_t)((int)me->m_y - 4 + 2); // y of explosion oie->bmp = EXPLOSION0_BMP + (me->m_exp_ctr >> 2); AO_Tunnel->POST(oie, me); status_ = QM_HANDLED(); } // @(/2/3/4/2/1/0/1) else { static QP::QActionHandler const act_[] = { Q_ACTION_CAST(&Mine1::used_x), Q_ACTION_CAST(0) }; status_ = QM_TRAN(&unused_s, &act_[0]); } break; }
/* ${SMs::Calc::SM::on::ready::begin} */ static QState Calc_begin(Calc * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* ${SMs::Calc::SM::on::ready::begin::OPER} */ case OPER_SIG: { /* ${SMs::Calc::SM::on::ready::begin::OPER::[e->key=='-']} */ if (Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS) { static struct { QMState const *target; QActionHandler act[4]; } const tatbl_ = { /* transition-action table */ &Calc_negated1_s, /* target state */ { Q_ACTION_CAST(&Calc_begin_x), /* exit */ Q_ACTION_CAST(&Calc_ready_x), /* exit */ Q_ACTION_CAST(&Calc_negated1_e), /* entry */ Q_ACTION_CAST(0) /* zero terminator */ } }; status_ = QM_TRAN(&tatbl_); } /* ${SMs::Calc::SM::on::ready::begin::OPER::[else]} */ else { status_ = QM_HANDLED(); } break; } default: { status_ = QM_SUPER(); break; } } (void)me; /* avoid compiler warning in case 'me' is not used */ return status_; }
QP::QState Philo::eating(Philo * const me, QP::QEvt const * const e) { QP::QState status_; switch (e->sig) { // @(/3/0/2/3/0) case TIMEOUT_SIG: { static QP::QActionHandler const act_[] = { Q_ACTION_CAST(&Philo::eating_x), Q_ACTION_CAST(&Philo::thinking_e), Q_ACTION_CAST(0) }; status_ = QM_TRAN(&thinking_s, act_); break; } // @(/3/0/2/3/1) case EAT_SIG: /* intentionally fall through */ case DONE_SIG: { /* EAT or DONE must be for other Philos than this one */ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me)); status_ = QM_HANDLED(); break; } default: { status_ = QM_SUPER(); break; } } return status_; }
/* ${AOs::Missile::SM::exploding} */ static QState Missile_exploding(Missile * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* ${AOs::Missile::SM::exploding::TIME_TICK} */ case TIME_TICK_SIG: { /* ${AOs::Missile::SM::exploding::TIME_TICK::[(me->x>=GAME_SPEED_X)&&(me->exp~} */ if ((me->x >= GAME_SPEED_X) && (me->exp_ctr < 15U)) { ObjectImageEvt *oie; ++me->exp_ctr; /* advance the explosion counter */ me->x -= GAME_SPEED_X; /* move the explosion by one step */ /* tell the Tunnel to render the current stage of Explosion */ oie = Q_NEW(ObjectImageEvt, EXPLOSION_SIG); oie->x = me->x + 3U; /* x-pos of explosion */ oie->y = (int8_t)((int)me->y - 4U); /* y-pos */ oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2); QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me); status_ = QM_HANDLED(); } /* ${AOs::Missile::SM::exploding::TIME_TICK::[else]} */ else { static QMTranActTable const tatbl_ = { /* transition-action table */ &Missile_armed_s, { Q_ACTION_CAST(0) /* zero terminator */ } }; status_ = QM_TRAN(&tatbl_); } break; }
/* ${AOs::Philo::SM::eating} */ static QState Philo_eating(Philo * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* ${AOs::Philo::SM::eating::TIMEOUT} */ case TIMEOUT_SIG: { static struct { QMState const *target; QActionHandler act[3]; } const tatbl_ = { /* transition-action table */ &Philo_thinking_s, /* target state */ { Q_ACTION_CAST(&Philo_eating_x), /* exit */ Q_ACTION_CAST(&Philo_thinking_e), /* entry */ Q_ACTION_CAST(0) /* zero terminator */ } }; status_ = QM_TRAN(&tatbl_); break; } /* ${AOs::Philo::SM::eating::EAT, DONE} */ case EAT_SIG: /* intentionally fall through */ case DONE_SIG: { /* EAT or DONE must be for other Philos than this one */ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me)); status_ = QM_HANDLED(); break; } default: { status_ = QM_SUPER(); break; } } return status_; }
// ${AOs::Mine2::SM::used::exploding} QP::QState Mine2::exploding(Mine2 * const me, QP::QEvt const * const e) { QP::QState status_; switch (e->sig) { // ${AOs::Mine2::SM::used::exploding::TIME_TICK} case TIME_TICK_SIG: { // ${AOs::Mine2::SM::used::exploding::TIME_TICK::[stillonscreen?]} if ((me->m_x >= GAME_SPEED_X) && (me->m_exp_ctr < 15)) { ++me->m_exp_ctr; // advance the explosion counter me->m_x -= GAME_SPEED_X; // move explosion by 1 step // tell the Game to render the current stage of Explosion ObjectImageEvt *oie = Q_NEW(ObjectImageEvt, EXPLOSION_SIG); oie->x = me->m_x + 1U; // x of explosion oie->y = (int8_t)((int)me->m_y - 4 + 2); // y of explosion oie->bmp = EXPLOSION0_BMP + (me->m_exp_ctr >> 2); AO_Tunnel->POST(oie, me); status_ = QM_HANDLED(); } // ${AOs::Mine2::SM::used::exploding::TIME_TICK::[else]} else { static struct { QP::QMState const *target; QP::QActionHandler act[2]; } const tatbl_ = { // transition-action table &unused_s, { Q_ACTION_CAST(&used_x), // exit Q_ACTION_CAST(0) // zero terminator } }; status_ = QM_TRAN(&tatbl_); } break; }
/* ${SMs::Calc::SM::on::operand1::int1} */ static QState Calc_int1(Calc * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* ${SMs::Calc::SM::on::operand1::int1::POINT} */ case POINT_SIG: { static struct { QMState const *target; QActionHandler act[3]; } const tatbl_ = { /* transition-action table */ &Calc_frac1_s, /* target state */ { Q_ACTION_CAST(&Calc_int1_x), /* exit */ Q_ACTION_CAST(&Calc_frac1_e), /* entry */ Q_ACTION_CAST(0) /* zero terminator */ } }; BSP_insert((int)'.'); status_ = QM_TRAN(&tatbl_); break; } /* ${SMs::Calc::SM::on::operand1::int1::DIGIT_0, DIGIT_1_9} */ case DIGIT_0_SIG: /* intentionally fall through */ case DIGIT_1_9_SIG: { BSP_insert(Q_EVT_CAST(CalcEvt)->key_code); status_ = QM_HANDLED(); break; } default: { status_ = QM_SUPER(); break; } } (void)me; /* avoid compiler warning in case 'me' is not used */ return status_; }
static QState Mine2_exploding(Mine2 * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* @(/2/4/3/2/2/0) */ case TIME_TICK_SIG: { /* @(/2/4/3/2/2/0/0) */ if ((me->x >= GAME_SPEED_X) && (me->exp_ctr < 15U)) { ObjectImageEvt *oie; ++me->exp_ctr; /* advance the explosion counter */ me->x -= GAME_SPEED_X; /* move explosion by 1 step */ /* tell the Game to render the current stage of Explosion */ oie = Q_NEW(ObjectImageEvt, EXPLOSION_SIG); oie->x = me->x + 1U; /* x of explosion */ oie->y = (int8_t)((int)me->y - 4 + 2); /* y of explosion */ oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2); QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me); status_ = QM_HANDLED(); } /* @(/2/4/3/2/2/0/1) */ else { static QActionHandler const act_[] = { Q_ACTION_CAST(&Mine2_used_x), Q_ACTION_CAST(0) }; status_ = QM_TRAN(&Mine2_unused_s, &act_[0]); } break; }
static QState Philo_eating(Philo * const me) { QState status_; switch (Q_SIG(me)) { /* @(/1/0/0/3/0) */ case Q_TIMEOUT_SIG: { static QActionHandler const act_[] = { Q_ACTION_CAST(&Philo_eating_x), Q_ACTION_CAST(&Philo_thinking_e), Q_ACTION_CAST(0) }; status_ = QM_TRAN(&Philo_thinking_s, &act_[0]); break; } /* @(/1/0/0/3/1) */ case EAT_SIG: /* intentionally fall through */ case DONE_SIG: { Q_ERROR(); /* these events should never arrive in this state */ status_ = QM_HANDLED(); break; } default: { status_ = QM_SUPER(); break; } } return status_; }
static QState Philo_hungry(Philo * const me) { QState status_; switch (Q_SIG(me)) { /* @(/1/0/0/2/0) */ case EAT_SIG: { static QActionHandler const act_[] = { Q_ACTION_CAST(&Philo_eating_e), Q_ACTION_CAST(0) }; status_ = QM_TRAN(&Philo_eating_s, &act_[0]); break; } /* @(/1/0/0/2/1) */ case DONE_SIG: { Q_ERROR(); /* this event should never arrive in this state */ status_ = QM_HANDLED(); break; } default: { status_ = QM_SUPER(); break; } } return status_; }
static QState Ped_wait(Ped * const me) { QState status_; switch (Q_SIG(me)) { /* @(/1/1/1/1/0) */ case Q_TIMEOUT_SIG: { --me->retryCtr; /* @(/1/1/1/1/0/0) */ if (me->retryCtr != 0U) { QActive_armX((QActive *)me, 0U, WAIT_TOUT); QACTIVE_POST((QActive *)&AO_Pelican, PEDS_WAITING_SIG); status_ = QM_HANDLED(); } /* @(/1/1/1/1/0/1) */ else { static QActionHandler const act_[] = { Q_ACTION_CAST(&Ped_off_e), Q_ACTION_CAST(0) }; status_ = QM_TRAN(&Ped_off_s, &act_[0]); } break; } default: { status_ = QM_SUPER(); break; } } return status_; }
/* ${AOs::Ship::SM::active::exploding} */ static QState Ship_exploding(Ship * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* ${AOs::Ship::SM::active::exploding::TIME_TICK} */ case TIME_TICK_SIG: { /* ${AOs::Ship::SM::active::exploding::TIME_TICK::[me->exp_ctr<1~]} */ if (me->exp_ctr < 15U) { ObjectImageEvt *oie; ++me->exp_ctr; /* tell the Tunnel to draw the current stage of Explosion */ oie = Q_NEW(ObjectImageEvt, EXPLOSION_SIG); oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2); oie->x = me->x; /* x of explosion */ oie->y = (int8_t)((int)me->y - 4U + SHIP_HEIGHT); QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me); status_ = QM_HANDLED(); } /* ${AOs::Ship::SM::active::exploding::TIME_TICK::[else]} */ else { static QMTranActTable const tatbl_ = { /* transition-action table */ &Ship_parked_s, { Q_ACTION_CAST(0) /* zero terminator */ } }; ScoreEvt *gameOver = Q_NEW(ScoreEvt, GAME_OVER_SIG); gameOver->score = me->score; QACTIVE_POST(AO_Tunnel, (QEvt *)gameOver, me); status_ = QM_TRAN(&tatbl_); } break; }
/* ${AOs::Mine2::SM::used::exploding} */ static QState Mine2_exploding(Mine2 * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* ${AOs::Mine2::SM::used::exploding::TIME_TICK} */ case TIME_TICK_SIG: { /* ${AOs::Mine2::SM::used::exploding::TIME_TICK::[stillonscreen?]} */ if ((me->x >= GAME_SPEED_X) && (me->exp_ctr < 15U)) { ObjectImageEvt *oie; ++me->exp_ctr; /* advance the explosion counter */ me->x -= GAME_SPEED_X; /* move explosion by 1 step */ /* tell the Game to render the current stage of Explosion */ oie = Q_NEW(ObjectImageEvt, EXPLOSION_SIG); oie->x = me->x + 1U; /* x of explosion */ oie->y = (int8_t)((int)me->y - 4 + 2); /* y of explosion */ oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2); QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me); status_ = QM_HANDLED(); } /* ${AOs::Mine2::SM::used::exploding::TIME_TICK::[else]} */ else { static struct { QMState const *target; QActionHandler act[2]; } const tatbl_ = { /* transition-action table */ &Mine2_unused_s, /* target state */ { Q_ACTION_CAST(&Mine2_used_x), /* exit */ Q_ACTION_CAST(0) /* zero terminator */ } }; status_ = QM_TRAN(&tatbl_); } break; }
static QState Ship_exploding(Ship * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* @(/2/1/4/1/4/0) */ case TIME_TICK_SIG: { /* @(/2/1/4/1/4/0/0) */ if (me->exp_ctr < 15U) { ObjectImageEvt *oie; ++me->exp_ctr; /* tell the Tunnel to draw the current stage of Explosion */ oie = Q_NEW(ObjectImageEvt, EXPLOSION_SIG); oie->bmp = EXPLOSION0_BMP + (me->exp_ctr >> 2); oie->x = me->x; /* x of explosion */ oie->y = (int8_t)((int)me->y - 4U + SHIP_HEIGHT); QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me); status_ = QM_HANDLED(); } /* @(/2/1/4/1/4/0/1) */ else { ScoreEvt *gameOver = Q_NEW(ScoreEvt, GAME_OVER_SIG); gameOver->score = me->score; QACTIVE_POST(AO_Tunnel, (QEvt *)gameOver, me); status_ = QM_TRAN(&Ship_parked_s, &QMsm_emptyAction_[0]); } break; }
static QState QMsmTst_s(QMsmTst * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* @(/1/0/1/1/1) */ case I_SIG: { /* @(/1/0/1/1/1/0) */ if (me->foo) { me->foo = 0U; BSP_display("s-I;"); status_ = QM_HANDLED(); } else { status_ = QM_UNHANDLED(); } break; } /* @(/1/0/1/1/2) */ case E_SIG: { static QActionHandler const act_[] = { Q_ACTION_CAST(&QMsmTst_s1_e), Q_ACTION_CAST(&QMsmTst_s11_e), Q_ACTION_CAST(0) }; BSP_display("s-E;"); status_ = QM_TRAN(&QMsmTst_s11_s, &act_[0]); break; } /* @(/1/0/1/1/3) */ case TERMINATE_SIG: { BSP_exit(); status_ = QM_HANDLED(); break; } default: { status_ = QM_SUPER(); break; } } return status_; }
/* ${SMs::Calc::SM::on::operand1::zero1} */ static QState Calc_zero1(Calc * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* ${SMs::Calc::SM::on::operand1::zero1::DIGIT_0} */ case DIGIT_0_SIG: { ; status_ = QM_HANDLED(); break; } /* ${SMs::Calc::SM::on::operand1::zero1::DIGIT_1_9} */ case DIGIT_1_9_SIG: { static struct { QMState const *target; QActionHandler act[3]; } const tatbl_ = { /* transition-action table */ &Calc_int1_s, /* target state */ { Q_ACTION_CAST(&Calc_zero1_x), /* exit */ Q_ACTION_CAST(&Calc_int1_e), /* entry */ Q_ACTION_CAST(0) /* zero terminator */ } }; BSP_insert(Q_EVT_CAST(CalcEvt)->key_code); status_ = QM_TRAN(&tatbl_); break; } /* ${SMs::Calc::SM::on::operand1::zero1::POINT} */ case POINT_SIG: { static struct { QMState const *target; QActionHandler act[3]; } const tatbl_ = { /* transition-action table */ &Calc_frac1_s, /* target state */ { Q_ACTION_CAST(&Calc_zero1_x), /* exit */ Q_ACTION_CAST(&Calc_frac1_e), /* entry */ Q_ACTION_CAST(0) /* zero terminator */ } }; BSP_insert((int)'0'); BSP_insert((int)'.'); status_ = QM_TRAN(&tatbl_); break; } default: { status_ = QM_SUPER(); break; } } return status_; }
static QState Pelican_offline(Pelican * const me) { QState status_; switch (Q_SIG(me)) { /* @(/1/0/1/2/0) */ case Q_TIMEOUT_SIG: { QActive_armX(&me->super, 0U, OFF_FLASH_TOUT); me->flashCtr ^= 1U; /* @(/1/0/1/2/0/0) */ if ((me->flashCtr & 1U) == 0U) { BSP_signalCars(CARS_RED); BSP_signalPeds(PEDS_DONT_WALK); status_ = QM_HANDLED(); } /* @(/1/0/1/2/0/1) */ else { BSP_signalCars(CARS_BLANK); BSP_signalPeds(PEDS_BLANK); status_ = QM_HANDLED(); } break; } /* @(/1/0/1/2/1) */ case ON_SIG: { static QActionHandler const act_[] = { Q_ACTION_CAST(&Pelican_operational_e), Q_ACTION_CAST(&Pelican_operational_i), Q_ACTION_CAST(0) }; status_ = QM_TRAN(&Pelican_operational_s, &act_[0]); break; } default: { status_ = QM_SUPER(); break; } } return status_; }
static QState Pelican_pedsFlash(Pelican * const me) { QState status_; switch (Q_SIG(me)) { /* @(/1/0/1/1/3/2/0) */ case Q_TIMEOUT_SIG: { /* @(/1/0/1/1/3/2/0/0) */ if (me->flashCtr != 0U) { --me->flashCtr; QActive_armX(&me->super, 0U, PEDS_FLASH_TOUT); /* @(/1/0/1/1/3/2/0/0/0) */ if ((me->flashCtr & 1U) == 0U) { BSP_signalPeds(PEDS_DONT_WALK); status_ = QM_HANDLED(); } /* @(/1/0/1/1/3/2/0/0/1) */ else { BSP_signalPeds(PEDS_BLANK); status_ = QM_HANDLED(); } } /* @(/1/0/1/1/3/2/0/1) */ else { static QActionHandler const act_[] = { Q_ACTION_CAST(&Pelican_pedsEnabled_x), Q_ACTION_CAST(&Pelican_carsEnabled_i), Q_ACTION_CAST(0) }; status_ = QM_TRAN(&Pelican_carsEnabled_s, &act_[0]); } break; } default: { status_ = QM_SUPER(); break; } } return status_; }
// ${AOs::Table::SM::active} QP::QState Table::active(Table * const me, QP::QEvt const * const e) { QP::QState status_; switch (e->sig) { // ${AOs::Table::SM::active::TERMINATE} case TERMINATE_SIG: { BSP_terminate(0); status_ = QM_HANDLED(); break; } // ${AOs::Table::SM::active::EAT} case EAT_SIG: { Q_ERROR(); status_ = QM_HANDLED(); break; } default: { status_ = QM_SUPER(); break; } } (void)me; // avoid compiler warning in case 'me' is not used return status_; }
/* ${SMs::Calc::SM::on::operand1::frac1} */ static QState Calc_frac1(Calc * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* ${SMs::Calc::SM::on::operand1::frac1::POINT} */ case POINT_SIG: { ; status_ = QM_HANDLED(); break; } /* ${SMs::Calc::SM::on::operand1::frac1::DIGIT_0, DIGIT_1_9} */ case DIGIT_0_SIG: /* intentionally fall through */ case DIGIT_1_9_SIG: { BSP_insert(Q_EVT_CAST(CalcEvt)->key_code); status_ = QM_HANDLED(); break; } default: { status_ = QM_SUPER(); break; } } (void)me; /* avoid compiler warning in case 'me' is not used */ return status_; }
static QState QMsmTst_s2(QMsmTst * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* @(/1/0/1/1/5/1) */ case I_SIG: { /* @(/1/0/1/1/5/1/0) */ if (!me->foo) { me->foo = 1U; BSP_display("s2-I;"); status_ = QM_HANDLED(); } else { status_ = QM_UNHANDLED(); } break; } /* @(/1/0/1/1/5/2) */ case F_SIG: { static QActionHandler const act_[] = { Q_ACTION_CAST(&QMsmTst_s2_x), Q_ACTION_CAST(&QMsmTst_s1_e), Q_ACTION_CAST(&QMsmTst_s11_e), Q_ACTION_CAST(0) }; BSP_display("s2-F;"); status_ = QM_TRAN(&QMsmTst_s11_s, &act_[0]); break; } /* @(/1/0/1/1/5/3) */ case C_SIG: { static QActionHandler const act_[] = { Q_ACTION_CAST(&QMsmTst_s2_x), Q_ACTION_CAST(&QMsmTst_s1_e), Q_ACTION_CAST(&QMsmTst_s1_i), Q_ACTION_CAST(0) }; BSP_display("s2-C;"); status_ = QM_TRAN(&QMsmTst_s1_s, &act_[0]); break; } default: { status_ = QM_SUPER(); break; } } return status_; }
static QState Ship_active(Ship * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* @(/2/1/4/1/1) */ case PLAYER_SHIP_MOVE_SIG: { me->x = Q_EVT_CAST(ObjectPosEvt)->x; me->y = Q_EVT_CAST(ObjectPosEvt)->y; status_ = QM_HANDLED(); break; } default: { status_ = QM_SUPER(); break; } } return status_; }
QP::QState Missile::flying(Missile * const me, QP::QEvt const * const e) { QP::QState status_; switch (e->sig) { // @(/3/2/4/2/0) case TIME_TICK_SIG: { // @(/3/2/4/2/0/0) if (me->m_x + GAME_MISSILE_SPEED_X < GAME_SCREEN_WIDTH) { me->m_x += GAME_MISSILE_SPEED_X; // tell the Tunnel to draw the Missile and test for wall hits ObjectImageEvt *oie = Q_NEW(ObjectImageEvt, MISSILE_IMG_SIG); oie->x = me->m_x; oie->y = me->m_y; oie->bmp = MISSILE_BMP; AO_Tunnel->POST(oie, me); status_ = QM_HANDLED(); } // @(/3/2/4/2/0/1) else { status_ = QM_TRAN(&armed_s, QP::QMsm::s_emptyAction_); } break; } // @(/3/2/4/2/1) case HIT_WALL_SIG: { static QP::QActionHandler const act_[] = { Q_ACTION_CAST(&Missile::exploding_e), Q_ACTION_CAST(0) }; status_ = QM_TRAN(&exploding_s, act_); break; } // @(/3/2/4/2/2) case DESTROYED_MINE_SIG: { AO_Ship->POST(e, me); status_ = QM_TRAN(&armed_s, QP::QMsm::s_emptyAction_); break; } default: { status_ = QM_SUPER(); break; } } return status_; }
/* ${AOs::Philo::SM::hungry} */ static QState Philo_hungry(Philo * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* ${AOs::Philo::SM::hungry::EAT} */ case EAT_SIG: { /* ${AOs::Philo::SM::hungry::EAT::[Q_EVT_CAST(Tabl~} */ if (Q_EVT_CAST(TableEvt)->philoNum == PHILO_ID(me)) { static struct { QMState const *target; QActionHandler act[2]; } const tatbl_ = { /* transition-action table */ &Philo_eating_s, /* target state */ { Q_ACTION_CAST(&Philo_eating_e), /* entry */ Q_ACTION_CAST(0) /* zero terminator */ } }; status_ = QM_TRAN(&tatbl_); } else { status_ = QM_UNHANDLED(); } break; } /* ${AOs::Philo::SM::hungry::DONE} */ case DONE_SIG: { /* DONE must be for other Philos than this one */ Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me)); status_ = QM_HANDLED(); break; } default: { status_ = QM_SUPER(); break; } } return status_; }
QP::QState Missile::exploding(Missile * const me, QP::QEvt const * const e) { QP::QState status_; switch (e->sig) { // @(/3/2/4/3/0) case TIME_TICK_SIG: { // @(/3/2/4/3/0/0) if ((me->m_x >= GAME_SPEED_X) && (me->m_exp_ctr < 15U)) { ++me->m_exp_ctr; // advance the explosion counter me->m_x -= GAME_SPEED_X; // move the explosion by one step // tell the Tunnel to render the current stage of Explosion ObjectImageEvt *oie = Q_NEW(ObjectImageEvt, EXPLOSION_SIG); oie->x = me->m_x + 3U; // x-pos of explosion oie->y = (int8_t)((int)me->m_y - 4U); // y-pos oie->bmp = EXPLOSION0_BMP + (me->m_exp_ctr >> 2); AO_Tunnel->POST(oie, me); status_ = QM_HANDLED(); } // @(/3/2/4/3/0/1) else { status_ = QM_TRAN(&armed_s, QP::QMsm::s_emptyAction_); } break; }
static QState Ship_flying(Ship * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* @(/2/1/4/1/3/0) */ case TIME_TICK_SIG: { /* tell the Tunnel to draw the Ship and test for hits */ ObjectImageEvt *oie = Q_NEW(ObjectImageEvt, SHIP_IMG_SIG); oie->x = me->x; oie->y = me->y; oie->bmp = SHIP_BMP; QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me); ++me->score; /* increment the score for surviving another tick */ if ((me->score % 10U) == 0U) { /* is the score "round"? */ ScoreEvt *sev = Q_NEW(ScoreEvt, SCORE_SIG); sev->score = me->score; QACTIVE_POST(AO_Tunnel, (QEvt *)sev, me); } status_ = QM_HANDLED(); break; } /* @(/2/1/4/1/3/1) */ case PLAYER_TRIGGER_SIG: { ObjectPosEvt *ope = Q_NEW(ObjectPosEvt, MISSILE_FIRE_SIG); ope->x = me->x; ope->y = me->y + SHIP_HEIGHT - 1U; QACTIVE_POST(AO_Missile, (QEvt *)ope, me); status_ = QM_HANDLED(); break; } /* @(/2/1/4/1/3/2) */ case DESTROYED_MINE_SIG: { me->score += Q_EVT_CAST(ScoreEvt)->score; /* the score will be sent to the Tunnel by the next TIME_TICK */ status_ = QM_HANDLED(); break; } /* @(/2/1/4/1/3/3) */ case HIT_WALL_SIG: { static QActionHandler const act_[] = { Q_ACTION_CAST(&Ship_exploding_e), Q_ACTION_CAST(0) }; status_ = QM_TRAN(&Ship_exploding_s, &act_[0]); break; } /* @(/2/1/4/1/3/4) */ case HIT_MINE_SIG: { static QActionHandler const act_[] = { Q_ACTION_CAST(&Ship_exploding_e), Q_ACTION_CAST(0) }; status_ = QM_TRAN(&Ship_exploding_s, &act_[0]); break; } default: { status_ = QM_SUPER(); break; } } return status_; }
static QState QMsmTst_s1(QMsmTst * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* @(/1/0/1/1/4/1) */ case I_SIG: { BSP_display("s1-I;"); status_ = QM_HANDLED(); break; } /* @(/1/0/1/1/4/2) */ case D_SIG: { /* @(/1/0/1/1/4/2/0) */ if (!me->foo) { static QActionHandler const act_[] = { Q_ACTION_CAST(&QMsmTst_s1_x), Q_ACTION_CAST(&QMsmTst_s_i), Q_ACTION_CAST(0) }; me->foo = 1U; BSP_display("s1-D;"); status_ = QM_TRAN(&QMsmTst_s_s, &act_[0]); } else { status_ = QM_UNHANDLED(); } break; } /* @(/1/0/1/1/4/3) */ case A_SIG: { static QActionHandler const act_[] = { Q_ACTION_CAST(&QMsmTst_s1_x), Q_ACTION_CAST(&QMsmTst_s1_e), Q_ACTION_CAST(&QMsmTst_s1_i), Q_ACTION_CAST(0) }; BSP_display("s1-A;"); status_ = QM_TRAN(&QMsmTst_s1_s, &act_[0]); break; } /* @(/1/0/1/1/4/4) */ case B_SIG: { static QActionHandler const act_[] = { Q_ACTION_CAST(&QMsmTst_s11_e), Q_ACTION_CAST(0) }; BSP_display("s1-B;"); status_ = QM_TRAN(&QMsmTst_s11_s, &act_[0]); break; } /* @(/1/0/1/1/4/5) */ case F_SIG: { static QActionHandler const act_[] = { Q_ACTION_CAST(&QMsmTst_s1_x), Q_ACTION_CAST(&QMsmTst_s2_e), Q_ACTION_CAST(&QMsmTst_s21_e), Q_ACTION_CAST(&QMsmTst_s211_e), Q_ACTION_CAST(0) }; BSP_display("s1-F;"); status_ = QM_TRAN(&QMsmTst_s211_s, &act_[0]); break; } /* @(/1/0/1/1/4/6) */ case C_SIG: { static QActionHandler const act_[] = { Q_ACTION_CAST(&QMsmTst_s1_x), Q_ACTION_CAST(&QMsmTst_s2_e), Q_ACTION_CAST(&QMsmTst_s2_i), Q_ACTION_CAST(0) }; BSP_display("s1-C;"); status_ = QM_TRAN(&QMsmTst_s2_s, &act_[0]); break; } default: { status_ = QM_SUPER(); break; } } return status_; }
/* @(/2/4/3/2/1) ...........................................................*/ static QState Mine2_planted(Mine2 * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* @(/2/4/3/2/1/0) */ case TIME_TICK_SIG: { /* @(/2/4/3/2/1/0/0) */ if (me->x >= GAME_SPEED_X) { ObjectImageEvt *oie; me->x -= GAME_SPEED_X; /* move the mine 1 step */ /* tell the Tunnel to draw the Mine */ oie = Q_NEW(ObjectImageEvt, MINE_IMG_SIG); oie->x = me->x; oie->y = me->y; oie->bmp = MINE2_BMP; QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me); status_ = QM_HANDLED(); } /* @(/2/4/3/2/1/0/1) */ else { static QActionHandler const act_[] = { Q_ACTION_CAST(&Mine2_used_x), Q_ACTION_CAST(0) }; status_ = QM_TRAN(&Mine2_unused_s, &act_[0]); } break; } /* @(/2/4/3/2/1/1) */ case SHIP_IMG_SIG: { uint8_t x = Q_EVT_CAST(ObjectImageEvt)->x; uint8_t y = Q_EVT_CAST(ObjectImageEvt)->y; uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp; /* @(/2/4/3/2/1/1/0) */ if (do_bitmaps_overlap(MINE2_BMP, me->x, me->y, bmp, x, y)) { static QActionHandler const act_[] = { Q_ACTION_CAST(&Mine2_used_x), Q_ACTION_CAST(0) }; static MineEvt const mine1_hit = { { HIT_MINE_SIG, 0U, 0U }, /* the QEvt base instance */ 2U /* type of the mine (2 for Mine type-2) */ }; QACTIVE_POST(AO_Ship, (QEvt *)&mine1_hit, me); /* go straight to 'disabled' and let the Ship do * the exploding */ status_ = QM_TRAN(&Mine2_unused_s, &act_[0]); } else { status_ = QM_UNHANDLED(); } break; } /* @(/2/4/3/2/1/2) */ case MISSILE_IMG_SIG: { uint8_t x = Q_EVT_CAST(ObjectImageEvt)->x; uint8_t y = Q_EVT_CAST(ObjectImageEvt)->y; uint8_t bmp = Q_EVT_CAST(ObjectImageEvt)->bmp; /* @(/2/4/3/2/1/2/0) */ if (do_bitmaps_overlap(MINE2_MISSILE_BMP, me->x, me->y, bmp, x, y)) { static QActionHandler const act_[] = { Q_ACTION_CAST(&Mine2_exploding_e), Q_ACTION_CAST(0) }; /* NOTE: Mine type-2 is nastier than Mine type-1. * The type-2 mine can hit the Ship with any of its * "tentacles". However, it can be destroyed by the * Missile only by hitting its center, defined as * a smaller bitmap MINE2_MISSILE_BMP. */ static ScoreEvt const mine2_destroyed = { { DESTROYED_MINE_SIG, 0U, 0U }, /* the QEvt base instance */ 45U /* score for destroying Mine type-2 */ }; QACTIVE_POST(AO_Missile, (QEvt *)&mine2_destroyed, me); status_ = QM_TRAN(&Mine2_exploding_s, &act_[0]); } else { status_ = QM_UNHANDLED(); } break; } default: { status_ = QM_SUPER(); break; } } return status_; }