int main(int argc, char **argv) { ROBOT_SPECIFICATIONS robot_specifications_data; PROGRAM_STATE program_state_data; ROBOT_STATE robot_state_data; ACTION action_data; SENSATION sensation_data; ROBOT_SPECIFICATIONS_PTR robot_specifications = &robot_specifications_data; PROGRAM_STATE_PTR program_state = &program_state_data; ROBOT_STATE_PTR robot_state = &robot_state_data; ACTION_PTR action = &action_data; SENSATION_PTR sensation = &sensation_data; struct timeval TCX_waiting_time = {0, 0}; robot_specifications->is_initialized = 0; program_state->is_initialized = 0; robot_state->is_initialized = 0; action->is_initialized = 0; sensation->is_initialized = 0; allGlobal.is_initialized = 0; signal(SIGTERM, &interrupt_handler); /* kill interupt handler */ signal(SIGINT, &interrupt_handler); /* control-C interupt handler */ #if 0 signal(SIGALRM, &alarm_handler); /* handler for regular interrupts */ #endif bParamList = bParametersAddEntry(bParamList, "robot", "name", "B21"); bParamList = bParametersAddEntry(bParamList, "", "TCXHOST", "localhost"); bParamList = bParametersAddEntry(bParamList, "", "fork", "yes"); /* add some parameter files */ bParamList = bParametersAddFile (bParamList, "etc/beeSoft.ini"); /* add some enviroment variables */ bParamList = bParametersAddEnv(bParamList, "", "TCXHOST"); bParamList = bParametersAddArray(bParamList, "", argc, argv); bParametersFillParams(bParamList); check_commandline_parameters(argc, argv, ALL); init_program(ALL); if (!load_parameters(RHINO_INIT_NAME, ALL)) exit(-1); allocate_memory(ALL); /*save_parameters(RHINO_INIT_NAME, ALL);*/ init_graphics(ALL); connect_to_tcx(ALL); G_display_switch(TITLE_BUTTON, 1); #if 0 alarm((unsigned) robot_specifications->alarm_interval); /* set up alarm */ #endif tcx_reset_joystick(ALL); for (;!program_state->quit;){ program_state->something_happened = 0; if (program_state->tcx_autoconnect) connect_to_tcx(ALL); if (test_mouse(ALL)) program_state->something_happened = 1; if (refresh_action(ALL)) program_state->something_happened = 1; if (initiate_action(ALL)) program_state->something_happened = 1; /* if (terminate_action(ALL)) program_state->something_happened = 1; */ if (program_state->tcx_initialized){ TCX_waiting_time.tv_sec = 0; TCX_waiting_time.tv_usec = 0; tcxRecvLoop((void *) &TCX_waiting_time); } if (!program_state->something_happened){ block_waiting_time.tv_sec = 1; block_waiting_time.tv_usec = 0; block_wait(&block_waiting_time, program_state->tcx_initialized, program_state->graphics_initialized); } #ifdef TOURGUIDE_VERSION tourguide_check_for_timeout(ALL); #endif /* TOURGUIDE_VERSION */ } /* close_log_file(ALL);*/ /* if (program_state->tcx_initialized) tcxCloseAll();*/ G_display_switch(TITLE_BUTTON, 2); fprintf(stderr, "\nGood-bye.\n"); sleep(1); exit(0); }
uint32 parse_keymap(void) { uint32 flags = 0; if(get_keyboard_controller_status()) { Uint8 *key_map; if (Console::instance()->input_active()) { static Uint8 chat_input_mode_keymap[SDLK_LAST]; memset(&chat_input_mode_keymap, 0, sizeof(chat_input_mode_keymap)); key_map = chat_input_mode_keymap; } else { key_map = SDL_GetKeyState(NULL); } // ZZZ: let mouse code simulate keypresses mouse_buttons_become_keypresses(key_map); joystick_buttons_become_keypresses(key_map); // Parse the keymap key_definition *key = current_key_definitions; for (unsigned i=0; i<NUMBER_OF_STANDARD_KEY_DEFINITIONS; i++, key++) if (key_map[key->offset]) flags |= key->action_flag; // Post-process the keymap struct special_flag_data *special = special_flags; for (unsigned i=0; i<NUMBER_OF_SPECIAL_FLAGS; i++, special++) { if (flags & special->flag) { switch (special->type) { case _double_flag: // If this flag has a double-click flag and has been hit within // DOUBLE_CLICK_PERSISTENCE (but not at MAXIMUM_FLAG_PERSISTENCE), // mask on the double-click flag */ if (special->persistence < MAXIMUM_FLAG_PERSISTENCE && special->persistence > MAXIMUM_FLAG_PERSISTENCE - DOUBLE_CLICK_PERSISTENCE) flags |= special->alternate_flag; break; case _latched_flag: // If this flag is latched and still being held down, mask it out if (special->persistence == MAXIMUM_FLAG_PERSISTENCE) flags &= ~special->flag; break; default: assert(false); break; } special->persistence = MAXIMUM_FLAG_PERSISTENCE; } else special->persistence = FLOOR(special->persistence-1, 0); } bool do_interchange = (local_player->variables.flags & _HEAD_BELOW_MEDIA_BIT) ? (input_preferences->modifiers & _inputmod_interchange_swim_sink) != 0: (input_preferences->modifiers & _inputmod_interchange_run_walk) != 0; // Handle the selected input controller if (input_preferences->input_device != _keyboard_or_game_pad) { _fixed delta_yaw, delta_pitch, delta_velocity; test_mouse(input_preferences->input_device, &flags, &delta_yaw, &delta_pitch, &delta_velocity); flags = mask_in_absolute_positioning_information(flags, delta_yaw, delta_pitch, delta_velocity); if (do_interchange) flags ^= _run_dont_walk; } else { int joyflags = process_joystick_axes(flags, heartbeat_count); if (joyflags != flags) { flags = joyflags; } else { // Modify flags with run/walk and swim/sink if we're using the keyboard if (do_interchange) flags ^= _run_dont_walk; } } if (player_in_terminal_mode(local_player_index)) flags = build_terminal_action_flags((char *)key_map); } // if(get_keyboard_controller_status()) return flags; }