static int blob_process(uint8_t* frame, int width, int height, int size) { init_display(width, height); if (!initialized || process_changed) { blob.setGraphics(true); blob.setGraphicsThickness(2); initialized = true; process_changed = false; } prepare_display(frame, width, height, size); //compute blob if (!init_track) { blob.initTracking(*grey_img, germ); init_track = true; } else { blob.track(*grey_img); } int bat = jakopter_com_read_int(com_in, 0); std::ostringstream bat_str; bat_str << bat; vpDisplay::displayText(*display_img, (int)display_img->getHeight()-25, 10, "Battery : " + bat_str.str() + " %%", vpColor::red); vpDisplay::flush(*display_img); return 0; }
static int qrcode_process(uint8_t* frame, int width, int height, int size) { init_display(width, height); if (!initialized || process_changed) { initialized = true; process_changed = false; } prepare_display(frame, width, height, size); if (qr_detector.detect(*grey_img)) { std::vector<vpImagePoint> pol = qr_detector.getPolygon(0); vpRect bbox = qr_detector.getBBox(0); vpDisplay::displayRectangle(*display_img, bbox, vpColor::green); vpDisplay::displayText(*display_img, (int)(bbox.getTop()-10), (int)bbox.getLeft(), "Message: \"" + qr_detector.getMessage(0) + "\"", vpColor::red); for (size_t j = 0; j < pol.size(); j++) { vpDisplay::displayCross(*display_img, pol[j], 14, vpColor::red, 3); std::ostringstream number; number << j; vpDisplay::displayText(*display_img, pol[j]+vpImagePoint(10,0), number.str(), vpColor::blue); } double x = 0; double y = 0; bbox.getCenter(x, y); std::string msg = qr_detector.getMessage(0); char cstr[SIZE_MESSAGE]; strncpy(cstr, msg.c_str(),SIZE_MESSAGE); jakopter_com_write_float(com_out, 0, (float)bbox.getSize()); jakopter_com_write_float(com_out, 4, (float)x); jakopter_com_write_float(com_out, 8, (float)y); jakopter_com_write_int(com_out, 12, strlen(cstr)+1); jakopter_com_write_buf(com_out, 16, cstr, SIZE_MESSAGE); } int bat = jakopter_com_read_int(com_in, 0); std::ostringstream bat_str; bat_str << bat; vpDisplay::displayText(*display_img, (int)display_img->getHeight()-25, 10, "Battery : " + bat_str.str() + " %", vpColor::red); vpDisplay::flush(*display_img); return 0; }
static int face_process(uint8_t* frame, int width, int height, int size) { //alt_tree, lbpcascade std::string face_cascade_script = "/usr/share/opencv/lbpcascades/lbpcascade_frontalface.xml"; init_display(width, height); if (!initialized || process_changed) { face_detector.setCascadeClassifierFile(face_cascade_script); initialized = true; process_changed = false; } prepare_display(frame, width, height, size); //compute face detection bool face_found = face_detector.detect(*grey_img); if (face_found) { std::ostringstream text; text << "Found " << face_detector.getNbObjects() << " face(s)"; vpDisplay::displayText(*display_img, 10, 10, text.str(), vpColor::red); //we get the first face in the list, which is also the biggest std::vector<vpImagePoint> p = face_detector.getPolygon(0); vpRect bbox = face_detector.getBBox(0); vpDisplay::displayRectangle(*display_img, bbox, vpColor::green, false, 4); vpDisplay::displayText(*display_img, (int)bbox.getTop()-10, (int)bbox.getLeft(), "Message: \"" + face_detector.getMessage(0) + "\"", vpColor::red); double x = 0; double y = 0; bbox.getCenter(x, y); jakopter_com_write_float(com_out, 0, (float)bbox.getSize()); jakopter_com_write_float(com_out, 4, (float)x); jakopter_com_write_float(com_out, 8, (float)y); } int bat = jakopter_com_read_int(com_in, 0); std::ostringstream bat_str; bat_str << bat; vpDisplay::displayText(*display_img, (int)display_img->getHeight()-25, 10, "Battery : " + bat_str.str() + " %", vpColor::red); vpDisplay::flush(*display_img); return 0; }
/* Self-explanatory. */ void init_at_startup(void) { LOCK_FUNCTION (framecount); LOCK_FUNCTION (tickover); LOCK_VARIABLE (ticked); LOCK_VARIABLE (frames_per_second); LOCK_VARIABLE (framecounter); LOCK_VARIABLE (turns_per_second); LOCK_VARIABLE (turncounter); install_int (framecount, 1000); install_int (tickover, 20); set_color_depth(8); int randseed = get_config_int("Misc", "Seed", 0); srand(randseed); options.windowed = get_config_int("Misc", "Windowed", 0); int windowed; switch(options.windowed) { default: case 1: windowed = GFX_AUTODETECT_WINDOWED; break; case 0: windowed = GFX_AUTODETECT_FULLSCREEN; break; } // windowed = GFX_AUTODETECT_WINDOWED; // windowed = GFX_AUTODETECT_FULLSCREEN; // if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0) // if (set_gfx_mode(windowed, 640, 480, 0, 0) != 0) if (set_gfx_mode(windowed, 800, 600, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set 800x600 256 colour display mode. Sorry!\n%s\n", allegro_error); exit(1); } init_trig(); prepare_display(); init_sound(); /* PP.ckey [CKEY_UP] = KEY_UP; PP.ckey [CKEY_DOWN] = KEY_DOWN; PP.ckey [CKEY_LEFT] = KEY_LEFT; PP.ckey [CKEY_RIGHT] = KEY_RIGHT; PP.ckey [CKEY_FIRE1] = KEY_Z; PP.ckey [CKEY_FIRE2] = KEY_X; PP.ckey [CKEY_FIRE3] = KEY_C; */ int p = 0; init_joystick(); player[0].control = get_config_int("misc", "player1_control", CONTROL_KEY_A); player[1].control = get_config_int("misc", "player2_control", CONTROL_KEY_B); // if a particular joystick isn't available, default to keyboard controls. // note that this doesn't set the config values for (p = 0; p < 2; p ++) { if (options.joystick_available [0] == 0 && PP.control == CONTROL_JOY_A) { PP.control = CONTROL_KEY_A; if (PP.control == CONTROL_KEY_A) PP.control = CONTROL_KEY_B; } if (options.joystick_available [1] == 0 && PP.control == CONTROL_JOY_B) { PP.control = CONTROL_KEY_A; if (PP.control == CONTROL_KEY_A) PP.control = CONTROL_KEY_B; } } options.ckey [0] [CKEY_UP] = get_config_int("Misc", "key1_up", KEY_8_PAD); options.ckey [0] [CKEY_DOWN] = get_config_int("Misc", "key1_down", KEY_2_PAD); options.ckey [0] [CKEY_LEFT] = get_config_int("Misc", "key1_left", KEY_4_PAD); options.ckey [0] [CKEY_RIGHT] = get_config_int("Misc", "key1_right", KEY_6_PAD); options.ckey [0] [CKEY_LEFT2] = get_config_int("Misc", "key1_left2", KEY_1_PAD); options.ckey [0] [CKEY_RIGHT2] = get_config_int("Misc", "key1_right2", KEY_3_PAD); options.ckey [0] [CKEY_FIRE1] = get_config_int("Misc", "key1_fire1", KEY_Z); options.ckey [0] [CKEY_FIRE2] = get_config_int("Misc", "key1_fire2", KEY_X); options.ckey [0] [CKEY_FIRE3] = get_config_int("Misc", "key1_fire3", KEY_C); options.ckey [0] [CKEY_FIRE4] = get_config_int("Misc", "key1_fire4", KEY_V); options.ckey [0] [CKEY_COMMAND] = get_config_int("Misc", "key1_command", KEY_A); options.ckey [1] [CKEY_UP] = get_config_int("Misc", "key2_up", KEY_UP); options.ckey [1] [CKEY_DOWN] = get_config_int("Misc", "key2_down", KEY_DOWN); options.ckey [1] [CKEY_LEFT] = get_config_int("Misc", "key2_left", KEY_LEFT); options.ckey [1] [CKEY_RIGHT] = get_config_int("Misc", "key2_right", KEY_RIGHT); options.ckey [1] [CKEY_LEFT2] = get_config_int("Misc", "key2_left2", KEY_J); options.ckey [1] [CKEY_RIGHT2] = get_config_int("Misc", "key2_right2", KEY_K); options.ckey [1] [CKEY_FIRE1] = get_config_int("Misc", "key2_fire1", KEY_T); options.ckey [1] [CKEY_FIRE2] = get_config_int("Misc", "key2_fire2", KEY_Y); options.ckey [1] [CKEY_FIRE3] = get_config_int("Misc", "key2_fire3", KEY_U); options.ckey [1] [CKEY_FIRE4] = get_config_int("Misc", "key2_fire4", KEY_I); options.ckey [1] [CKEY_COMMAND] = get_config_int("Misc", "key2_command", KEY_O); /* PP.ckey [CKEY_UP] = get_config_int("Misc", "key_up", KEY_UP); PP.ckey [CKEY_DOWN] = get_config_int("Misc", "key_down", KEY_DOWN); PP.ckey [CKEY_LEFT] = get_config_int("Misc", "key_left", KEY_LEFT); PP.ckey [CKEY_RIGHT] = get_config_int("Misc", "key_right", KEY_RIGHT); PP.ckey [CKEY_FIRE1] = get_config_int("Misc", "key_fire1", KEY_Z); PP.ckey [CKEY_FIRE2] = get_config_int("Misc", "key_fire2", KEY_X); PP.ckey [CKEY_FIRE3] = get_config_int("Misc", "key_fire3", KEY_C); PP.ckey [CKEY_FIRE4] = get_config_int("Misc", "key_fire4", KEY_V); */ /* player[1].ckey [CKEY_UP] = get_config_int("MiscP2", "key_up", KEY_UP); player[1].ckey [CKEY_DOWN] = get_config_int("MiscP2", "key_down", KEY_DOWN); player[1].ckey [CKEY_LEFT] = get_config_int("MiscP2", "key_left", KEY_LEFT); player[1].ckey [CKEY_RIGHT] = get_config_int("MiscP2", "key_right", KEY_RIGHT); player[1].ckey [CKEY_LEFT2] = get_config_int("MiscP2", "key_left2", KEY_K); player[1].ckey [CKEY_RIGHT2] = get_config_int("MiscP2", "key_right2", KEY_L); player[1].ckey [CKEY_FIRE1] = get_config_int("MiscP2", "key_fire1", KEY_0_PAD); player[1].ckey [CKEY_FIRE2] = get_config_int("MiscP2", "key_fire2", KEY_P); player[1].ckey [CKEY_FIRE3] = get_config_int("MiscP2", "key_fire3", KEY_O); player[1].ckey [CKEY_FIRE4] = get_config_int("MiscP2", "key_fire4", KEY_I); options.joy_stick = get_config_int("Misc", "joy_stick", 0); options.joy_sensitivity = get_config_int("Misc", "joy_sensitivity", 70); options.init_joystick = get_config_int("Misc", "joy_init", 1);*/ // options.joystick = 0; // options.key_or_joy = 0; // don't put in initfile! options.sfx_volume = get_config_int("Misc", "sfx_volume", 70); options.ambience_volume = get_config_int("Misc", "ambience_volume", 100); options.run_vsync = get_config_int("Misc", "run_vsync", 0); options.fix_camera_angle = get_config_int("Misc", "fix_camera_angle", 0); options.joystick_dual = get_config_int("Misc", "joystick_dual", 1); // set_config_int("Misc", "Tourist", 3); // set_config_int("Misc", "joy_stick", 0); // if (options.init_joystick) // if (options.joystick == 1) // set in init_joystick { options.joy_button [0] [0] = get_config_int("Misc", "joy1_button_1", 0); if (options.joy_button [0] [0] > joy[0].num_buttons) options.joy_button [0] [0] = joy[0].num_buttons - 1; options.joy_button [0] [1] = get_config_int("Misc", "joy1_button_2", 1); if (options.joy_button [0] [1] > joy[0].num_buttons) options.joy_button [0] [1] = joy[0].num_buttons - 1; options.joy_button [0] [2] = get_config_int("Misc", "joy1_button_3", 2); if (options.joy_button [0] [2] > joy[0].num_buttons) options.joy_button [0] [2] = joy[0].num_buttons - 1; options.joy_button [0] [3] = get_config_int("Misc", "joy1_button_4", 4); if (options.joy_button [0] [3] > joy[0].num_buttons) options.joy_button [0] [3] = joy[0].num_buttons - 1; options.joy_button [0] [4] = get_config_int("Misc", "joy1_button_5", 5); if (options.joy_button [0] [4] > joy[0].num_buttons) options.joy_button [0] [4] = joy[0].num_buttons - 1; options.joy_button [0] [5] = get_config_int("Misc", "joy1_button_6", 6); if (options.joy_button [0] [5] > joy[0].num_buttons) options.joy_button [0] [5] = joy[0].num_buttons - 1; options.joy_button [1] [0] = get_config_int("Misc", "joy2_button_1", 0); if (options.joy_button [1] [0] > joy[0].num_buttons) options.joy_button [1] [0] = joy[0].num_buttons - 1; options.joy_button [1] [1] = get_config_int("Misc", "joy2_button_2", 1); if (options.joy_button [1] [1] > joy[0].num_buttons) options.joy_button [1] [1] = joy[0].num_buttons - 1; options.joy_button [1] [2] = get_config_int("Misc", "joy2_button_3", 2); if (options.joy_button [1] [2] > joy[0].num_buttons) options.joy_button [1] [2] = joy[0].num_buttons - 1; options.joy_button [1] [3] = get_config_int("Misc", "joy2_button_4", 4); if (options.joy_button [1] [3] > joy[0].num_buttons) options.joy_button [1] [3] = joy[0].num_buttons - 1; options.joy_button [1] [4] = get_config_int("Misc", "joy2_button_5", 5); if (options.joy_button [1] [4] > joy[0].num_buttons) options.joy_button [1] [4] = joy[0].num_buttons - 1; options.joy_button [1] [5] = get_config_int("Misc", "joy2_button_6", 6); if (options.joy_button [1] [5] > joy[0].num_buttons) options.joy_button [1] [5] = joy[0].num_buttons - 1; } ticked = 0; arena.players = 1; // NOTE: it's assumed in a few places that if there's just one player, it's player[0]. }
void begin_game(void) { int i; counter = 0; init_structs_etc(); for (i = 0; i < NO_ACTORS; i ++) { actor[i].in_play = 0; } player[0].score = 0; player[1].score = 0; if (game.type == GAME_SINGLE || game.type == GAME_TIME_ATTACK) { game.users = 1; actor[0].in_play = 0; player[game.single_player].actor_controlled = 0; // player[0].ships_left = 3; game.ships_left = 3; actor[0].controller = game.single_player; init_actor(0, player[game.single_player].ship); //ACTORTYPE_SHIP); } if (game.type == GAME_COOP || game.type == GAME_DUEL || game.type == GAME_TIME_ATTACK_COOP) { game.users = 2; actor[0].in_play = 0; player[0].actor_controlled = 0; // player[0].ships_left = 3; actor[0].controller = 0; init_actor(0, player[0].ship); //ACTORTYPE_SHIP); actor[1].in_play = 0; player[1].actor_controlled = 1; // player[1].ships_left = 3; actor[1].controller = 1; init_actor(1, player[1].ship); //ACTORTYPE_SHIP); game.ships_left = 6; } init_bullets(); init_clouds(); // init_stars(); init_enemies(); prepare_display(); game.drag = 0.013;//955;//9999; /* arena.max_x = 894000; arena.max_y = 895000; */ arena.level = 0; game.symbols_given = 0; init_level(); long_slacktime = 0; arena.waver_on_level = 0; }
int hslink_input(user_data_rec *udta, /* current user data record */ int argc, /* argument count */ char *argv[]) /* argument values */ { /* allocate application workspace if needed */ if (udta->substt == 0) { udta->appws = (workspace_rec*)mem_alloc(sizeof(workspace_rec)); if (udta->appws == 0) { cprintf("Cannot allocate workspace for user %d!\r\n",usrnum); return 0; } } /* current workspace to application workspace for this user */ current_hsws = udta->appws; /* process current substate */ switch (udta->substt) { case 0: if (top_init()) { udta->substt = 0; break; } set_defaults(); if (argc == 1) { usage("No command line given\r\n",""); udta->substt = 0; break; } if (process_options(argc,argv)) { usage("No command line given\r\n",""); udta->substt = 0; break; } ComOpen(); WS.Option.ComSpeed = ComGetSpeed(); if (!WS.Option.EffSpeed) WS.Option.EffSpeed = WS.Option.ComSpeed; /* we're now ready for SlowHandshake to work */ WS.IoLevel = 0; /* allocate up to 10k for file buffers, but no more */ WS.buffer_sizes = mem_avail()-1000>10240: 10240:mem_avail()-1000; /* display opening screen */ prepare_display(); process_filespecs(argc,argv); /* verify hardware handshake status */ if (!ComGetCts() && !WS.Option.ForceCts) { cprintf("CTS signal missing! Please use -HC or -FC option.\r\n"); WS.Option.CtsHandshake = 0; } udta->substt = 1; break; case 1: /* wait for ready handshake with remote */ service_receive(); udta->substt = wait_for_ready()? 1:2; break; case 2: /* select first file in batch and begin transmit */ udta->curnode = WS.first_send; udta->substt = 3; break; case 3: /* end of batch? change to state 4 */ if (udta->curnode == NULL) { udta->substt = 4; PSEND("%d file%s transmitted.\r\n",WS.files_sent, WS.files_sent==1?"":"s"); break; } service_receive(); if (transmit_file(udta->curnode->name)) break; /* remain in state 3 */ /* advance to next file in the batch */ udta->curnode = udta->curnode->next; break; case 4: /* wait for remaining receive activity to terminate */ service_receive(); udta->substt = finish_receive()? 4:5; break; case 5: /* close down link */ udta->substt = terminate_link()? 5:6; break; case 6: /* process exit codes */ if (ComCarrierLost()) set_cancel_link(CANCEL_CARRIER_LOST); if ((WS.files_received+WS.files_sent) ==0) set_cancel_link(CANCEL_NO_FILES); ComClose(); close_display(); cprintf("HS/Link finished! (t:%d r:%d)",WS.files_sent,WS.files_received); cprintf(" Exit code = %d\r\n",(int)WS.cancel_link); udta->substt = 0; break; } /* if substt is 0 we are done and need to free the workspace */ if (udta->substt == 0) { current_hsws = 0; mem_free(udta->appws); udta->appws = 0; } /* otherwise we need more calls- return non 0 */ return udta->substt; }
/* Self-explanatory. */ void init_at_startup(void) { LOCK_FUNCTION (framecount); LOCK_FUNCTION (tickover); LOCK_VARIABLE (ticked); LOCK_VARIABLE (frames_per_second); LOCK_VARIABLE (framecounter); LOCK_VARIABLE (turns_per_second); LOCK_VARIABLE (turncounter); install_int (framecount, 1000); install_int (tickover, 20); set_color_depth(8); int randseed = get_config_int("Misc", "Seed", 0); srand(randseed); options.windowed = get_config_int("Misc", "Windowed", 0); int windowed; switch(options.windowed) { default: case 1: windowed = GFX_AUTODETECT_WINDOWED; break; case 0: windowed = GFX_AUTODETECT_FULLSCREEN; break; } // windowed = GFX_AUTODETECT_WINDOWED; // windowed = GFX_AUTODETECT_FULLSCREEN; // if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0) if (set_gfx_mode(windowed, 640, 480, 0, 0) != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Unable to set 640x480 display mode\n%s\n", allegro_error); exit(1); } init_trig(); prepare_display(); init_sound(); /* player[0].ckey [CKEY_UP] = KEY_UP; player[0].ckey [CKEY_DOWN] = KEY_DOWN; player[0].ckey [CKEY_LEFT] = KEY_LEFT; player[0].ckey [CKEY_RIGHT] = KEY_RIGHT; player[0].ckey [CKEY_FIRE1] = KEY_Z; player[0].ckey [CKEY_FIRE2] = KEY_X; player[0].ckey [CKEY_FIRE3] = KEY_C; */ player[0].ckey [CKEY_UP] = get_config_int("Misc", "key_up", KEY_UP); player[0].ckey [CKEY_DOWN] = get_config_int("Misc", "key_down", KEY_DOWN); player[0].ckey [CKEY_LEFT] = get_config_int("Misc", "key_left", KEY_LEFT); player[0].ckey [CKEY_RIGHT] = get_config_int("Misc", "key_right", KEY_RIGHT); player[0].ckey [CKEY_FIRE1] = get_config_int("Misc", "key_fire1", KEY_Z); player[0].ckey [CKEY_FIRE2] = get_config_int("Misc", "key_fire2", KEY_X); options.joy_stick = get_config_int("Misc", "joy_stick", 0); options.joy_sensitivity = get_config_int("Misc", "joy_sensitivity", 70); options.init_joystick = get_config_int("Misc", "joy_init", 1); options.joystick = 0; options.key_or_joy = 0; // don't put in initfile! options.sfx_volume = get_config_int("Misc", "sfx_volume", 70); options.ambience_volume = get_config_int("Misc", "ambience_volume", 100); options.run_vsync = get_config_int("Misc", "run_vsync", 0); // set_config_int("Misc", "Tourist", 3); // set_config_int("Misc", "joy_stick", 0); if (options.init_joystick) init_joystick(); if (options.joystick == 1) // set in init_joystick { options.joy_button [0] = get_config_int("Misc", "joy_button_1", 0); if (options.joy_button [0] > joy[0].num_buttons) options.joy_button [0] = joy[0].num_buttons - 1; options.joy_button [1] = get_config_int("Misc", "joy_button_2", 1); if (options.joy_button [1] > joy[0].num_buttons) options.joy_button [1] = joy[0].num_buttons - 1; options.joy_button [2] = get_config_int("Misc", "joy_button_engine", 3); if (options.joy_button [2] > joy[0].num_buttons) options.joy_button [2] = joy[0].num_buttons - 1; options.joy_button [3] = get_config_int("Misc", "joy_button_brake", 2); if (options.joy_button [3] > joy[0].num_buttons) options.joy_button [3] = joy[0].num_buttons - 1; } ticked = 0; }
void begin_game(void) { int i; counter = 0; init_structs_etc(); for (i = 0; i < NO_ACTORS; i ++) { actor[i].in_play = 0; } player[0].score = 0; player[1].score = 0; if (game.type == GAME_SINGLE) { game.users = 1; actor[0].in_play = 0; player[game.single_player].actor_controlled = 0; // player[0].ships_left = 3; game.ships_left = 3; actor[0].controller = game.single_player; init_actor(0, player[game.single_player].ship); //ACTORTYPE_SHIP); } else { game.users = 2; actor[0].in_play = 0; player[0].actor_controlled = 0; // player[0].ships_left = 3; actor[0].controller = 0; init_actor(0, player[0].ship); //ACTORTYPE_SHIP); actor[1].in_play = 0; player[1].actor_controlled = 1; // player[1].ships_left = 3; actor[1].controller = 1; init_actor(1, player[1].ship); //ACTORTYPE_SHIP); game.ships_left = 6; } init_bullets(); init_clouds(); init_enemies(); prepare_display(); game.drag = 0.013;//955;//9999; /* arena.max_x = 894000; arena.max_y = 895000; */ arena.level = 0; init_level(); }