void Enemy::moveUp(int px) { Action GoUp; GoUp.is_blocking = true; GoUp.thread_id = 1; Action AnimReset; AnimReset.is_blocking = true; AnimReset.thread_id = 1; GoUp.action = get_action([this, px](sf::Time dt) { if (getAnimationState() != static_cast<int>(Animations::GoUp)) { animation.play(); changeAnimation(static_cast<int>(Animations::GoUp)); getAnimation().play(); } return goUpUntil(px, dt); }); AnimReset.action = get_action([this](sf::Time dt) { animation.reset(); return false; }); action_tree.push(GoUp); action_tree.push(AnimReset); }
void test_action::test_dummy_action() { char buffer[100]; int total = 0; // get_action total = get_action( 1, 0, buffer, 0 ); total = get_action( 1, 0, buffer, static_cast<size_t>(total) ); eosio_assert( total > 0, "get_action failed" ); eosio::action act = eosio::get_action( 1, 0 ); eosio_assert( act.authorization.back().actor == N(testapi), "incorrect permission actor" ); eosio_assert( act.authorization.back().permission == N(active), "incorrect permission name" ); eosio_assert( eosio::pack_size(act) == static_cast<size_t>(total), "pack_size does not match get_action size" ); eosio_assert( act.account == N(testapi), "expected testapi account" ); dummy_action dum13 = act.data_as<dummy_action>(); if ( dum13.b == 200 ) { // attempt to access context free only api get_context_free_data( 0, nullptr, 0 ); eosio_assert(false, "get_context_free_data() not allowed in non-context free action"); } else { eosio_assert(dum13.a == DUMMY_ACTION_DEFAULT_A, "dum13.a == DUMMY_ACTION_DEFAULT_A"); eosio_assert(dum13.b == DUMMY_ACTION_DEFAULT_B, "dum13.b == DUMMY_ACTION_DEFAULT_B"); eosio_assert(dum13.c == DUMMY_ACTION_DEFAULT_C, "dum13.c == DUMMY_ACTION_DEFAULT_C"); } }
void Enemy::patrol() { std::discrete_distribution<int> dir_distribution({ 60, 10, 10, 10, 10 }); std::uniform_int_distribution<int> distance_distribution(50, 100); std::uniform_real_distribution<float> wait_time_distribution(1.f, 3.f); Direction dir = static_cast<Direction>(dir_distribution(mt)); int distance = distance_distribution(mt); stop_time = sf::seconds(wait_time_distribution(mt)); //Action selection Action patrol; patrol.thread_id = 1; patrol.action = get_action([this, dir, distance](sf::Time dt) { if (dir == Direction::Left) { moveLeft(distance); } else if (dir == Direction::Right) { moveRight(distance); } else if (dir == Direction::Up) { moveUp(distance); } else if (dir == Direction::Down) { moveDown(distance); } //else if (dir == Direction::None) { std::cout << "Stop time" << stop_time.asSeconds() << std::endl; wait(stop_time); } return false; }); //When we have 2 actions we stop action addition unsigned int max_actions = 2; if (action_tree.threadSize(patrol.thread_id) < max_actions) { pushAction(patrol); } //Action updating, each frame Action patrol_update; patrol_update.thread_id = 0; patrol_update.action = get_action([this](sf::Time dt) { if (getCurrentDirection() == Direction::Left) { goLeft(dt); } else if (getCurrentDirection() == Direction::Right) { goRight(dt); } else if (getCurrentDirection() == Direction::Up) { goUp(dt); } else if (getCurrentDirection() == Direction::Down) { goDown(dt); } return false; }); pushAction(patrol_update); }
//------- Begin of function Nation::get_action_based_on_id --------// // // Return ActionNode for the given actionId. // ActionNode* Nation::get_action_based_on_id(int actionId) { for( int i=action_count() ; i>0 ; i-- ) { if( is_action_deleted(i) ) continue; if( get_action(i)->action_id == actionId ) { return get_action(i); } } return 0; }
bool lcd_debug_screen(void) { lcd_setfont(FONT_SYSFIXED); while(1) { int button = get_action(CONTEXT_STD, HZ / 10); switch(button) { case ACTION_STD_NEXT: case ACTION_STD_PREV: case ACTION_STD_OK: case ACTION_STD_MENU: lcd_setfont(FONT_UI); return true; case ACTION_STD_CANCEL: lcd_setfont(FONT_UI); return false; } lcd_clear_display(); lcd_putsf(0, 0, "has power: %d", lcd_has_power); lcd_putsf(0, 1, "lcd kind: %d", lcd_kind); lcd_update(); yield(); } return true; }
/* * Load the actions attributes */ int gilP_load_att_actions(FILE * inFile, ABObj obj, ABObj module) { int return_value = 0; int rc = 0; /* r turn code */ ABObj action = NULL; if (!abio_get_list_begin(inFile)) return (abil_print_load_err(ERR_WANT_LIST), -1); while (!abio_get_list_end(inFile)) { action = obj_create(AB_TYPE_ACTION, NULL); if ((rc = get_action(inFile, obj, module, action)) < 0) { obj_destroy(action); return rc; } else { if (obj_get_when(action) == AB_WHEN_UNDEF) { /* unsupported :when value - ignore it and continue */ obj_destroy(action); } else { install_action(obj, module, action); } } } return return_value; }
//--------- Begin of function Nation::is_action_exist --------// // // Check if the an action of the specific mode and para // exists in the action_array. // // <int> actionMode - action mode // <int> actionPara - parameter of the action // [int] regionId - if this parameter is given, only // action with destination in this // region will be checked. // int Nation::is_action_exist(int actionMode, int actionPara, int regionId) { int i; ActionNode* actionNode; for( i=action_count() ; i>0 ; i-- ) { if( is_action_deleted(i) ) continue; actionNode = get_action(i); if( actionNode->action_mode == actionMode && actionNode->action_para == actionPara ) { if( !regionId ) return 1; err_when( actionNode->action_x_loc < 0 || actionNode->action_y_loc < 0 || actionNode->action_x_loc >= MAX_WORLD_X_LOC || actionNode->action_y_loc >= MAX_WORLD_Y_LOC ); if( world.get_region_id(actionNode->action_x_loc, actionNode->action_y_loc) == regionId ) { return 1; } } } return 0; }
//--------- Begin of function Nation::is_action_exist --------// // // Note: it only check either action?Loc or ref?Loc. If actionXLoc is -1 // it will check ref?Loc, otherwise it will check action?Loc. // // <short> actionXLoc, actionYLoc - action_?_loc in ActionNode to match with // <short> refXLoc, refYLoc - ref_?_loc in ActionNode to match with // <int> actionMode - action mode // <int> actionPara - parameter of the action // [int] unitRecno - unit recno to match with, only useful for actions under processing. // int Nation::is_action_exist(short actionXLoc, short actionYLoc, short refXLoc, short refYLoc, int actionMode, int actionPara, int unitRecno) { int i; ActionNode* actionNode; for( i=action_count() ; i>0 ; i-- ) { if( is_action_deleted(i) ) continue; actionNode = get_action(i); if( actionNode->action_mode == actionMode && actionNode->action_para == actionPara ) { if( unitRecno && unitRecno != actionNode->unit_recno ) // it requests to match the unit recno and it is not matched here continue; if( actionXLoc >= 0 ) { if( actionNode->action_x_loc==actionXLoc && actionNode->action_y_loc==actionYLoc ) return i; } else { if( actionNode->ref_x_loc==refXLoc && actionNode->ref_y_loc==refYLoc) return i; } } } return 0; }
//--------- Begin of function Nation::is_build_action_exist --------// // // Return 1 if there is already a firm queued for building with // a building location that is within the effective range // of the given position. // int Nation::is_build_action_exist(int firmId, int xLoc, int yLoc) { int i; ActionNode* actionNode; int effectiveDis = world.effective_distance(firmId, 0); for( i=action_count() ; i>0 ; i-- ) { if( is_action_deleted(i) ) continue; actionNode = get_action(i); if( actionNode->action_mode == ACTION_AI_BUILD_FIRM && actionNode->action_para == firmId ) { if( m.points_distance( actionNode->action_x_loc, actionNode->action_y_loc, xLoc, yLoc) <= effectiveDis ) { return 1; } } } return 0; }
int main() { int32_t s, tk; lexer_t lex; init_smt_stdin_lexer(&lex); /* * NOTE: Clang (version 3.2) gives the following warning for s<NSTATES: * * comparison of constant 64 with expression of type 'state_t' * (aka 'enum state_s') is always true. * * It gives no warning for tk<NUM_SMT_TOKENS. * * I've changed the declaration of s: it used to be 'state_t s' * instead of 'int32_t s' */ for (s=0; s<NSTATES; s++) { printf("Source state %s\n", state2string[s]); for (tk=SMT_TK_LP; tk<NUM_SMT_TOKENS; tk++) { printf(" %20s %s\n", smt_token_to_string(tk), action2string[get_action(s, tk)]); } printf("\n"); } close_lexer(&lex); return 0; }
bool dbg_hw_info_rtc(void) { lcd_setfont(FONT_SYSFIXED); while(1) { int button = get_action(CONTEXT_STD, HZ / 10); switch(button) { case ACTION_STD_NEXT: case ACTION_STD_PREV: case ACTION_STD_OK: case ACTION_STD_MENU: lcd_setfont(FONT_UI); return true; case ACTION_STD_CANCEL: lcd_setfont(FONT_UI); return false; } lcd_clear_display(); struct imx233_rtc_info_t info = imx233_rtc_get_info(); lcd_putsf(0, 0, "seconds: %lu", info.seconds); for(int i = 0; i < 6; i++) lcd_putsf(0, i + 1, "persistent%d: 0x%lx", i, info.persistent[i]); lcd_update(); yield(); } }
void Enemy::chase(sf::Vector2f pos) { action_tree.deleteThread(1); Action chase; chase.thread_id = 1; chase.action = get_action([this, pos](sf::Time dt) { sf::Vector2f normal = normalize(pos.x - getPosition().x, pos.y - getPosition().y); float x = normal.x; float y = normal.y; if ((isCollisionDirection(Direction::Left) && x < 0.f) || (isCollisionDirection(Direction::Right) && x > 0.f)) { x = 0.f; if (y > 0.f) y = 1.f; else if (y < 0.f) y = -1.f; } if ((isCollisionDirection(Direction::Up) && y < 0.f) || (isCollisionDirection(Direction::Down) && y > 0.f)) { y = 0.f; if (x > 0.f)x = 1.f; else if (x < 0.f) x = -1.f; } x = x * 100.f * dt.asSeconds(); y = y * 100.f * dt.asSeconds(); playAnimation(); if (x > 0 && abs(x) > abs(y)) { if (getCurrentDirection() != Direction::Right) { setCurrentDirection(Direction::Right); changeAnimation(static_cast<int>(Animations::GoRight)); } } if (x < 0 && abs(x) > abs(y)) { if (getCurrentDirection() != Direction::Left) { setCurrentDirection(Direction::Left); changeAnimation(static_cast<int>(Animations::GoLeft)); } } if (y > 0 && abs(x) < abs(y)) { if (getCurrentDirection() != Direction::Down) { setCurrentDirection(Direction::Down); changeAnimation(static_cast<int>(Animations::GoDown)); } } if (y < 0 && abs(x) < abs(y)) { if (getCurrentDirection() != Direction::Up) { setCurrentDirection(Direction::Up); changeAnimation(static_cast<int>(Animations::GoUp)); } } //std::cout <<x << " " << y << std::endl; //std::cout << this->isCollisionDirection(Direction::Left) << " " << this->isCollisionDirection(Direction::Right) << " " << isCollisionDirection(Direction::Down) << " " << isCollisionDirection(Direction::Up) << std::endl; move(sf::Vector2f(x, y)); return false; }); pushAction(chase); }
//bartender simulation void* bartender(){ void* ret_val = 0; int tid = thread_getId(); double amount =0; double buf_size =0; for(;;){ struct Action* bartender_action = get_action(); if(bartender_action->action_type == DRINK_ORDER){ struct Cup* current_cup = get_clean_cup(); //need to write to file intsead of screen TODO printf(1,"Bartender %d is making drink with cup %d\n",tid,current_cup->id); serve_drink(current_cup); } else if(bartender_action->action_type == RETURN_CUP){ struct Cup* current_cup = bartender_action->cup; return_cup(current_cup); //need to write to file intsead of screen TODO printf(1,"Bartender %d returned cup %d\n",tid,current_cup->id); amount = DBB->full->value; buf_size = DBB->buffer_size; if(amount/buf_size >= 0.6){ printf(1,"Go Clean Boy %d\n"); binary_semaphore_up(cup_boy_lock); } if(bartender_action->action_type == GO_HOME){ free(bartender_action); thread_exit(ret_val); } } free(bartender_action); } return 0; }
bool dbg_hw_info_adc(void) { lcd_setfont(FONT_SYSFIXED); while(1) { int button = get_action(CONTEXT_STD, HZ / 25); switch(button) { case ACTION_STD_NEXT: case ACTION_STD_PREV: case ACTION_STD_OK: case ACTION_STD_MENU: lcd_setfont(FONT_UI); return true; case ACTION_STD_CANCEL: lcd_setfont(FONT_UI); return false; } lcd_clear_display(); /* add battery readout in mV, this it is not the direct output of a channel */ lcd_putsf(0, 0, "Battery(mV) %d", _battery_voltage()); for(unsigned i = 0; i < NUM_ADC_CHANNELS; i++) { lcd_putsf(0, i + 1, "%s %d", imx233_adc_channel_name[i], adc_read(i)); } lcd_update(); yield(); } }
int handle_msg(char recvline[MAX_RX_BUF], int sockfd) { char sendline[MAX_TX_BUF]; int sent_bytes = -1; printf("first char is %c\n", recvline[0]); switch(recvline[0]) { case REQUEST_QUIT: // the server ask us to quit, just return return 1; case REQUEST_NAME: // server ask for our name // answer "n YOURNAME\" printf("Server ask for my name...\n"); strcpy(sendline, "n lorenzo"); // it give us the dimension of the arena expressed in number of tiles // of each edge of the square area. sscanf(&recvline[2], "%d", &arena_size); printf("Arena size is %d\n", arena_size); // arena is a square arena_size X arena_size break; case REQUEST_ACTION: printf("Server ask for action...\n"); printf("Received from server: %s\n", recvline); // for our convenience, the server send us the positions of other shuttles // in the list we are the first one // it send to us also the position of rockets sent by other spacecraft // the format is // CAN_FIRE NUMBER_OF_SPACESHIPS X1 Y1 X2 Y2 X3 Y3 ... NUMBER_OF_ROCKETS X1 Y1 A1 X2 Y2 A2 ... // e.g. 0 3 120 234 45 87 98 67 1 10 100 282.23 // You can not fire, there are three shuttles. We are at coords (120, 234), there is a rocket at (10, 100) // we can decide where to move // we can move up (u), down (d), left (l) or right (r) // just answer "m u" to go up or "m l" to go left // alternatively, we can also decide to fire // syntax is f ANGLE where angle is a float //sprintf(sendline, "f %f", 271.32); get_action(&recvline[2], sendline); break; } strcat(sendline, "\r\n"); //add endline sent_bytes = send(sockfd, sendline, strlen(sendline), 0); //send to the server printf("Sent %d bytes\n", sent_bytes); return 0; }
std::vector<std::string> genericFilechooserWindow::getPathToFiles ( void ) { return (get_action() != Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER) ? get_filenames() : genericFeatures::listFiles(get_filenames().at(0)); }
bool lr_parser::try_parse_ahead() { /* create a virtual stack from the real parse stack */ virtual_stack vstack(stack); /* parse until we fail or get past the lookahead input */ while (true) { /* look up the action from the current state (on top of stack) */ int act = get_action(vstack.top(), cur_err_token()->sym); /* if its an error, we fail */ if (act == 0) return false; /* > 0 encodes a shift */ if (act > 0) { /* push the new state on the stack */ vstack.push(act-1); DEBUG_LOG("# Parse-ahead shifts symbol #" << cur_err_token()->sym << " into state #" << (act-1)); /* advance simulated input, if we run off the end, we are done */ if (!advance_lookahead()) return true; } /* < 0 encodes a reduce */ else { /* if this is a reduce with the start production we are done */ if ((-act)-1 == start_production()) { DEBUG_LOG("# Parse-ahead accepts"); return true; } /* get the lhs symbol and the rhs size */ short lhs = production_tab[(-act)-1].lhs_sym; short rhs_size = production_tab[(-act)-1].rhs_size; /* pop handle off the stack */ for (int i = 0; i < rhs_size; i++) vstack.pop(); DEBUG_LOG("# Parse-ahead reduces: handle size = " << rhs_size << " lhs = #" << lhs << " from state #" << vstack.top()); /* look up goto and push it onto the stack */ vstack.push(get_reduce(vstack.top(), lhs)); DEBUG_LOG("# Goto state #" << vstack.top()); } } }
/* helper function to remove a non-empty directory */ static int remove_dir(char* dirname, int len) { int result = 0; DIR* dir; int dirlen = strlen(dirname); dir = opendir(dirname); if (!dir) return -1; /* open error */ while(true) { struct dirent* entry; /* walk through the directory content */ entry = readdir(dir); if (!entry) break; struct dirinfo info = dir_get_info(dir, entry); dirname[dirlen] ='\0'; /* inform the user which dir we're deleting */ splash(0, dirname); /* append name to current directory */ snprintf(dirname+dirlen, len-dirlen, "/%s", entry->d_name); if (info.attribute & ATTR_DIRECTORY) { /* remove a subdirectory */ if (!strcmp((char *)entry->d_name, ".") || !strcmp((char *)entry->d_name, "..")) continue; /* skip these */ result = remove_dir(dirname, len); /* recursion */ if (result) break; /* or better continue, delete what we can? */ } else { /* remove a file */ draw_slider(); result = remove(dirname); } if(ACTION_STD_CANCEL == get_action(CONTEXT_STD,TIMEOUT_NOBLOCK)) { splash(HZ, ID2P(LANG_CANCEL)); result = -1; break; } } closedir(dir); if (!result) { /* remove the now empty directory */ dirname[dirlen] = '\0'; /* terminate to original length */ result = rmdir(dirname); } return result; }
std::string item_action_generator::get_action_name( const item_action_id &id ) const { const auto &act = get_action( id ); if( !act.name.empty() ) { return _( act.name.c_str() ); } return id; }
bool dbg_hw_info_pinctrl(void) { lcd_setfont(FONT_SYSFIXED); #ifdef IMX233_PINCTRL_DEBUG unsigned top_user = 0; #endif while(1) { int button = get_action(CONTEXT_STD, HZ / 10); switch(button) { case ACTION_STD_NEXT: #ifdef IMX233_PINCTRL_DEBUG top_user++; break; #endif case ACTION_STD_PREV: #ifdef IMX233_PINCTRL_DEBUG if(top_user > 0) top_user--; break; #endif case ACTION_STD_OK: case ACTION_STD_MENU: lcd_setfont(FONT_UI); return true; case ACTION_STD_CANCEL: lcd_setfont(FONT_UI); return false; } lcd_clear_display(); for(int i = 0; i < 4; i++) lcd_putsf(0, i, "DIN%d = 0x%08x", i, imx233_get_gpio_input_mask(i, 0xffffffff)); #ifdef IMX233_PINCTRL_DEBUG unsigned cur_line = 6; unsigned last_line = lcd_getheight() / font_get(lcd_getfont())->height; unsigned cur_idx = 0; for(int bank = 0; bank < 4; bank++) for(int pin = 0; pin < 32; pin++) { const char *owner = imx233_pinctrl_get_pin_use(bank, pin); if(owner == NULL) continue; if(cur_idx++ >= top_user && cur_line < last_line) lcd_putsf(0, cur_line++, "B%dP%02d %s", bank, pin, owner); } if(cur_idx < top_user) top_user = cur_idx - 1; #endif lcd_update(); yield(); } }
bool dbg_hw_info_power(void) { lcd_setfont(FONT_SYSFIXED); while(1) { int button = get_action(CONTEXT_STD, HZ / 10); switch(button) { case ACTION_STD_NEXT: case ACTION_STD_PREV: case ACTION_STD_OK: case ACTION_STD_MENU: lcd_setfont(FONT_UI); return true; case ACTION_STD_CANCEL: lcd_setfont(FONT_UI); return false; } lcd_clear_display(); struct imx233_power_info_t info = imx233_power_get_info(POWER_INFO_ALL); int line = 0; unsigned trg, bo; bool en; int linreg; char buf[16]; lcd_putsf(0, line++, "name value bo linreg"); #define DISP_REGULATOR(name) \ imx233_power_get_regulator(REGULATOR_##name, &trg, &bo); \ imx233_power_get_regulator_linreg(REGULATOR_##name, &en, &linreg); \ if(en) snprintf(buf, sizeof(buf), "%d", linreg); \ else snprintf(buf, sizeof(buf), " "); \ lcd_putsf(0, line++, "%6s %4d %4d %s", #name, trg, bo, buf); \ DISP_REGULATOR(VDDD); DISP_REGULATOR(VDDA); DISP_REGULATOR(VDDIO); DISP_REGULATOR(VDDMEM); lcd_putsf(0, line++, "DC-DC: pll: %d freq: %d", info.dcdc_sel_pllclk, info.dcdc_freqsel); lcd_putsf(0, line++, "charge: %d mA stop: %d mA", info.charge_current, info.stop_current); lcd_putsf(0, line++, "charging: %d bat_adj: %d", info.charging, info.batt_adj); lcd_putsf(0, line++, "4.2: en: %d dcdc: %d", info._4p2_enable, info._4p2_dcdc); lcd_putsf(0, line++, "4.2: cmptrip: %d dropout: %d", info._4p2_cmptrip, info._4p2_dropout); lcd_putsf(0, line++, "5V: pwd_4.2_charge: %d", info._5v_pwd_charge_4p2); lcd_putsf(0, line++, "5V: chargelim: %d mA", info._5v_charge_4p2_limit); lcd_putsf(0, line++, "5V: dcdc: %d xfer: %d", info._5v_enable_dcdc, info._5v_dcdc_xfer); lcd_putsf(0, line++, "5V: thr: %d mV use: %d cmps: %d", info._5v_vbusvalid_thr, info._5v_vbusvalid_detect, info._5v_vbus_cmps); lcd_update(); yield(); } }
int main() { int i = 0; async_state_t state; async_init(&state); async_push(&state, get_action(h3)); async_loop(&state); return 0; }
struct options * options_alloc(int argc, char *argv[]) { struct options *options = calloc_or_die(1, sizeof(struct options)); options->command_name = strdup_or_die(basename(argv[0])); options->rnd = rnd_alloc(); int action_index = get_options(options, argc, argv); if (options->error) return options; get_action(options, argc, argv, action_index); return options; }
static bool show_credits(void) { char credits[MAX_PATH] = { '\0' }; snprintf(credits, MAX_PATH, "%s/credits.rock", VIEWERS_DIR); if (plugin_load(credits, NULL) != PLUGIN_OK) { /* show the rockbox logo and version untill a button is pressed */ show_logo(); while (IS_SYSEVENT(get_action(CONTEXT_STD, TIMEOUT_BLOCK))) ; } return false; }
int ptrace_sandbox_handle_event(struct pt_sandbox* p_sandbox, int status) { int sig; int action; if (WIFEXITED(status) || WIFSIGNALED(status)) { p_sandbox->pid = -1; return 1; } if (!WIFSTOPPED(status)) { warnx("weird status: %d\n", status); return PTRACE_SANDBOX_ERR_WAIT_STATUS; } sig = WSTOPSIG(status); if (sig >= 0 && sig < 0x80) { /* It's a normal signal; deliver it right on. SIGSTOP / SIGCONT handling * are buggy in the kernel and I'm not sure it's safe to pass either on, * so the signal becomes a little more... robust :) */ if (sig == SIGSTOP || sig == SIGCONT) { sig = SIGKILL; } return ptrace_sandbox_continue_process(p_sandbox, sig); } if (!(sig & 0x80)) { warnx("weird status: %d\n", status); return PTRACE_SANDBOX_ERR_WAIT_STATUS; } /* Syscall trap. */ if (p_sandbox->is_exit) { p_sandbox->is_exit = 0; } else { p_sandbox->is_exit = 1; action = get_action(p_sandbox); if (action != 0) { return action; } } return ptrace_sandbox_continue_process(p_sandbox, 0); }
int main(){ state = 1; food = 0; mail = 0; int action; printf("\n\nWelcome to Get Your Mail Simulator 2015!\n"); printf("Use north, east, south, west, or openmail to get around.\n\n\n"); printf("The mail came in today.\n"); while(1){ //Print location of where we are printf("%s",locations[state]); if (state == 5){ food = 1; } if (state == 6){ mail = 1; } action = get_action(); //win condition if (state == 1 && mail == 1 && action == 4){ printf("You open your mail at home. You win.\n"); exit(0); } //try to access win condition if (action == 4){ if (mail == 0){ printf("You don't even have your mail!\n"); }else{ printf("Wait until you're home to open it!\n"); } } //try to get to post office without food if (state == 4 && action == 2 && food == 0){ printf("You feel hungry and it's a long walk to the post office.\n"); printf("You should get food first.\n"); action = 4; } state = nextstate[5*state + action]; } }
//------- Begin of function Nation::process_action_id --------// // // Process a specific action. // int Nation::process_action_id(int actionId) { for( int i=action_count() ; i>0 ; i-- ) { if( is_action_deleted(i) ) continue; if( get_action(i)->action_id == actionId ) { process_action(i); return 1; } } return 0; }
void browse_cuesheet(struct cuesheet *cue) { struct gui_synclist lists; int action; bool done = false; int sel; char title[MAX_PATH]; char cuepath[MAX_PATH]; struct mp3entry *id3 = audio_current_track(); snprintf(title, MAX_PATH, "%s: %s", cue->performer, cue->title); gui_synclist_init(&lists, list_get_name_cb, cue, false, 2, NULL); gui_synclist_set_nb_items(&lists, 2*cue->track_count); gui_synclist_set_title(&lists, title, 0); if (id3) { gui_synclist_select_item(&lists, 2*cue_find_current_track(cue, id3->elapsed)); } while (!done) { gui_synclist_draw(&lists); action = get_action(CONTEXT_LIST,TIMEOUT_BLOCK); if (gui_synclist_do_button(&lists, &action, LIST_WRAP_UNLESS_HELD)) continue; switch (action) { case ACTION_STD_OK: id3 = audio_current_track(); if (id3 && *id3->path && strcmp(id3->path, "No file!")) { look_for_cuesheet_file(id3->path, cuepath); if (id3->cuesheet && !strcmp(cue->path, cuepath)) { sel = gui_synclist_get_sel_pos(&lists); seek(cue->tracks[sel/2].offset); } } break; case ACTION_STD_CANCEL: done = true; } } }
bool dbg_hw_info_ocotp(void) { lcd_setfont(FONT_SYSFIXED); unsigned top_user = 0; while(1) { int button = get_action(CONTEXT_STD, HZ / 10); switch(button) { case ACTION_STD_NEXT: top_user++; break; case ACTION_STD_PREV: if(top_user > 0) top_user--; break; case ACTION_STD_OK: case ACTION_STD_MENU: lcd_setfont(FONT_UI); return true; case ACTION_STD_CANCEL: lcd_setfont(FONT_UI); return false; } lcd_clear_display(); unsigned cur_line = 0; unsigned last_line = lcd_getheight() / font_get(lcd_getfont())->height; unsigned i = 0; for(i = 0; i < ARRAYLEN(dbg_ocotp); i++) { if(i >= top_user && cur_line < last_line) { lcd_putsf(0, cur_line, "%s", dbg_ocotp[i].name); lcd_putsf(8, cur_line++, "%x", imx233_ocotp_read(dbg_ocotp[i].addr)); } } if(i < top_user) top_user = i - 1; lcd_update(); yield(); } }
/* do the button loop as often as required for the peak meters to update * with a good refresh rate. */ int skin_wait_for_action(enum skinnable_screens skin, int context, int timeout) { (void)skin; /* silence charcell warning */ int button = ACTION_NONE; #ifdef HAVE_LCD_BITMAP int i; /* when the peak meter is enabled we want to have a few extra updates to make it look smooth. On the other hand we don't want to waste energy if it isn't displayed */ bool pm=false; FOR_NB_SCREENS(i) { if(skin_get_gwps(skin, i)->data->peak_meter_enabled) pm = true; } if (pm) { long next_refresh = current_tick; long next_big_refresh = current_tick + timeout; button = BUTTON_NONE; while (TIME_BEFORE(current_tick, next_big_refresh)) { button = get_action(context,TIMEOUT_NOBLOCK); if (button != ACTION_NONE) { break; } peak_meter_peek(); sleep(0); /* Sleep until end of current tick. */ if (TIME_AFTER(current_tick, next_refresh)) { FOR_NB_SCREENS(i) { if(skin_get_gwps(skin, i)->data->peak_meter_enabled) skin_update(skin, i, SKIN_REFRESH_PEAK_METER); next_refresh += HZ / PEAK_METER_FPS; } } } } /* The peak meter is disabled -> no additional screen updates needed */ else #endif {