static int8 check_admin_pswd() { CLEAR_SCREEN; int ret; char admin_pswd[64] = {0}; ret = SAFE_GET_CONFIG("sys.password", admin_pswd); if (ret) { disp_msg("不能获取管理密码", 5); return -1; } input_dst* pswd_input; pswd_input = input_init(PASSWORD_MOD); input_props_set(pswd_input, input_one_property); input_property_set(pswd_input, INPUT_HIND, "密码"); input_property_set(pswd_input, INPUT_MAX_LEN, 8); input_dis(MAIN_DISP, pswd_input); printf_str(MAIN_DISP, DISP_X_COOR, DISP_Y_COOR, "请输入管理员密码", 1); lcd_160_upd(); ret = input_key_manege(MAIN_DISP, pswd_input , lcd_160_upd); if (ret >= 0) { char pswd[9] = {0}; input_str_get(pswd_input, pswd); if (strcmp(pswd, admin_pswd) == 0) ret = 0; else { disp_msg("密码错误", 10); ret = -1; } } input_destory(pswd_input); return ret; }
static bool process(int argc,char **argv,int start) { int i; bool success; char *filename; input_init(start,argc,argv); input_read_all_files(); numfiles = input_get_file_count(); if (numfiles < 2) st_help("need two or more files to process"); if (NULL == (files = malloc((numfiles + 1) * sizeof(wave_info *)))) st_error("could not allocate memory for file info array"); for (i=0;i<numfiles;i++) { filename = input_get_filename(); if (NULL == (files[i] = new_wave_info(filename))) { st_error("could not open file: [%s]",filename); } } files[numfiles] = NULL; check_headers(); reorder_files(files,numfiles); success = do_join(); for (i=0;i<numfiles;i++) st_free(files[i]); st_free(files); return success; }
void osd_interface::init_subsystems() { if (!video_init()) { video_exit(); osd_printf_error("video_init: Initialization failed!\n\n\n"); fflush(stderr); fflush(stdout); exit(-1); } sound_init(); input_init(); // we need pause callbacks machine().add_notifier(MACHINE_NOTIFY_PAUSE, machine_notify_delegate(FUNC(osd_interface::input_pause), this)); machine().add_notifier(MACHINE_NOTIFY_RESUME, machine_notify_delegate(FUNC(osd_interface::input_resume), this)); output_init(); #ifdef USE_NETWORK network_init(); #endif midi_init(); }
void init_visual_search_thin (INPUT_DESC *input) { int x,y; make_input_image_visual_search_thin (input, IMAGE_WIDTH, IMAGE_HEIGHT); glutInitWindowSize (input->ww, input->wh); if (read_window_position (input->name, &x, &y)) glutInitWindowPosition (x, y); else glutInitWindowPosition (-1, -1); input->win = glutCreateWindow (input->name); glGenTextures (1, (GLuint *)(&(input->tex))); input_init (input); glutReshapeFunc (input_reshape); glutDisplayFunc (input_display); glutKeyboardFunc (keyboard); glutPassiveMotionFunc (input_passive_motion); glutMouseFunc (input_mouse); glutTimerFunc(10, ipc_timer_function, 1); }
int main(void) { int vmode = -1; exception_init(); dsp_reset(); irq_initialize(); irq_bw_enable(BW_PI_IRQ_RESET); irq_bw_enable(BW_PI_IRQ_HW); //hollywood pic /* external ohci */ irq_hw_enable(IRQ_OHCI0); /* internal ohci */ //irq_hw_enable(IRQ_OHCI1); ipc_initialize(); ipc_slowping(); gecko_init(); input_init(); init_fb(vmode); VIDEO_Init(vmode); VIDEO_SetFrameBuffer(get_xfb()); VISetupEncoder(); u32 version = ipc_getvers(); u16 mini_version_major = version >> 16 & 0xFFFF; u16 mini_version_minor = version & 0xFFFF; printf("Mini version: %d.%0d\n", mini_version_major, mini_version_minor); if (version < MINIMUM_MINI_VERSION) { printf("Sorry, this version of MINI (armboot.bin)\n" "is too old, please update to at least %d.%0d.\n", (MINIMUM_MINI_VERSION >> 16), (MINIMUM_MINI_VERSION & 0xFFFF)); for (;;) ; // better ideas welcome! }
void init_class_cnae(INPUT_DESC *input) { int x, y; char strFileName[128]; g_nDocNumber = DOC_MIN; g_nTotalTested = 0; g_nCorrect = 0; g_nStatus = TRAINING_PHASE; make_input_image_class_cnae (input, IMAGE_WIDTH, IMAGE_HEIGHT); // Le a primeira imagem if (!GetNextFileName(strFileName, NO_DIRECTION)) { ReadDocumentInput(input, strFileName); } input->up2date = 0; glutInitWindowSize (input->ww, input->wh); if (read_window_position (input->name, &x, &y)) glutInitWindowPosition (x, y); else glutInitWindowPosition (-1, -1); input->win = glutCreateWindow (input->name); glGenTextures (1, (GLuint *)(&(input->tex))); input_init (input); glutReshapeFunc (input_reshape); glutDisplayFunc (input_display); glutKeyboardFunc (keyboard); glutPassiveMotionFunc (input_passive_motion); glutMouseFunc (input_mouse); }
void osd_common_t::init_subsystems() { if (!video_init()) { video_exit(); osd_printf_error("video_init: Initialization failed!\n\n\n"); fflush(stderr); fflush(stdout); exit(-1); } m_keyboard_input = select_module_options<input_module *>(options(), OSD_KEYBOARDINPUT_PROVIDER); m_mouse_input = select_module_options<input_module *>(options(), OSD_MOUSEINPUT_PROVIDER); m_lightgun_input = select_module_options<input_module *>(options(), OSD_LIGHTGUNINPUT_PROVIDER); m_joystick_input = select_module_options<input_module *>(options(), OSD_JOYSTICKINPUT_PROVIDER); m_font_module = select_module_options<font_module *>(options(), OSD_FONT_PROVIDER); m_sound = select_module_options<sound_module *>(options(), OSD_SOUND_PROVIDER); m_sound->m_sample_rate = options().sample_rate(); m_sound->m_audio_latency = options().audio_latency(); m_debugger = select_module_options<debug_module *>(options(), OSD_DEBUG_PROVIDER); select_module_options<netdev_module *>(options(), OSD_NETDEV_PROVIDER); m_midi = select_module_options<midi_module *>(options(), OSD_MIDI_PROVIDER); m_output = select_module_options<output_module *>(options(), OSD_OUTPUT_PROVIDER); machine().output().set_notifier(nullptr, output_notifier_callback, this); m_mod_man.init(options()); input_init(); // we need pause callbacks machine().add_notifier(MACHINE_NOTIFY_PAUSE, machine_notify_delegate(FUNC(osd_common_t::input_pause), this)); machine().add_notifier(MACHINE_NOTIFY_RESUME, machine_notify_delegate(FUNC(osd_common_t::input_resume), this)); }
int main(void) { physics_init(LCD_WIDTH, LCD_HEIGHT); input_init(); display_init(); segment_init(); players_init(); playerA = players_get(0); playerB = players_get(1); ball = physics_create(LCD_WIDTH / 2, LCD_HEIGHT / 2, BALL_RADIUS, BALL_MASS); for (;;) { input_update(); players_update(0.01f); physics_update(0.01f); game_update(); game_draw(); } return 0; }
void input_generator (INPUT_DESC *input, int status) { if ((input->win != 0) && (status == MOVE)) { update_input_neurons (input); check_input_bounds (input, input->wxd, input->wyd); glutSetWindow(input->win); input_display (); all_filters_update (); all_outputs_update (); } if (input->win == 0) { int x, y; make_input_image (input); init (input); glutInitWindowSize (input->ww, input->wh); if (read_window_position (input->name, &x, &y)) glutInitWindowPosition (x, y); else glutInitWindowPosition (-1, -1); input->win = glutCreateWindow (input->name); glGenTextures (1, (GLuint *)(&(input->tex))); input_init (input); glutReshapeFunc (input_reshape); glutDisplayFunc (input_display); glutKeyboardFunc (keyboard); glutPassiveMotionFunc (input_passive_motion); glutMouseFunc (input_mouse); } }
/// Setup our environment (e.g., tty modes), process key strokes, then reset the environment. static void setup_and_process_keys(bool continuous_mode) { is_interactive_session = 1; // by definition this program is interactive set_main_thread(); setup_fork_guards(); env_init(); reader_init(); input_init(); proc_push_interactive(1); signal_set_handlers(); install_our_signal_handlers(); if (continuous_mode) { fprintf(stderr, "\n"); fprintf(stderr, "To terminate this program type \"exit\" or \"quit\" in this window,\n"); fprintf(stderr, "or press [ctrl-C] or [ctrl-D] twice in a row.\n"); fprintf(stderr, "\n"); } process_input(continuous_mode); restore_term_mode(); restore_term_foreground_process_group(); input_destroy(); reader_destroy(); }
int main(int argc, char **argv) { int ch; const char *conffile; conffile = CONFFILE; while ((ch = getopt(argc, argv, "f:v")) != -1) { switch (ch) { case 'f': conffile = optarg; break; case 'v': verbose++; break; default: usage(); /* NOTREACHED */ } } bzero(&config, sizeof(config)); config.print.feedlines = -1; config.print.cchide_customer = 1; config.print.ccsig_customer = 1; bzero(&header, sizeof(header)); if (parse_config(conffile)) exit(1); /* set database files */ if (config.database.custdb == NULL) if ((config.database.custdb = strdup(config.database.alldb ? config.database.alldb : CUSTDBFILE)) == NULL) err(1, "cannot set customer database file"); if (config.database.menudb == NULL) if ((config.database.menudb = strdup(config.database.alldb ? config.database.alldb : MENUDBFILE)) == NULL) err(1, "cannot set menu database file"); if (config.database.orderdb == NULL) if ((config.database.orderdb = strdup(config.database.alldb ? config.database.alldb : ORDERDBFILE)) == NULL) err(1, "cannot set order database file"); if (config.print.feedlines < 0) config.print.feedlines = PRINT_FEED_LINES; if (licence_init() == -1) errx(1, "cannot proceed without licence"); event_init(); module_init(); rule_init(); input_init(); print_init(); form_init(); display_init(); status_init(); menu_init(); customer_init(); special_init(); payment_init(); window_init(); order_init(); display_refresh(); signal(SIGPIPE, SIG_IGN); if (event_dispatch() == -1) err(1, "terminated abnormally"); if (exitcode != 0 && exitmsg == NULL) exitmsg = strdup(status.status); order_exit(); window_exit(); payment_exit(); special_exit(); customer_exit(); menu_exit(); status_exit(); display_exit(); form_exit(); print_exit(); input_exit(); rule_exit(); module_exit(); if (exitcode && exitmsg != NULL) errx(exitcode, "%s", exitmsg); else fprintf(stdout, "exiting normally\n"); exit(0); }
void running_machine::start() { // initialize basic can't-fail systems here fileio_init(this); config_init(this); input_init(this); output_init(this); state_init(this); state_save_allow_registration(this, true); palette_init(this); render_init(this); ui_init(this); generic_machine_init(this); generic_video_init(this); generic_sound_init(this); // initialize the timers and allocate a soft_reset timer // this must be done before cpu_init so that CPU's can allocate timers timer_init(this); m_soft_reset_timer = timer_alloc(this, static_soft_reset, NULL); // init the osd layer osd_init(this); // initialize the base time (needed for doing record/playback) time(&m_base_time); // initialize the input system and input ports for the game // this must be done before memory_init in order to allow specifying // callbacks based on input port tags time_t newbase = input_port_init(this, m_game.ipt); if (newbase != 0) m_base_time = newbase; // intialize UI input ui_input_init(this); // initialize the streams engine before the sound devices start streams_init(this); // first load ROMs, then populate memory, and finally initialize CPUs // these operations must proceed in this order rom_init(this); memory_init(this); watchdog_init(this); // allocate the gfx elements prior to device initialization gfx_init(this); // initialize natural keyboard support inputx_init(this); // initialize image devices image_init(this); // start up the devices m_devicelist.start_all(); // call the game driver's init function // this is where decryption is done and memory maps are altered // so this location in the init order is important ui_set_startup_text(this, "Initializing...", true); if (m_game.driver_init != NULL) (*m_game.driver_init)(this); // finish image devices init process image_postdevice_init(this); // start the video and audio hardware video_init(this); tilemap_init(this); crosshair_init(this); sound_init(this); // initialize the debugger if ((debug_flags & DEBUG_FLAG_ENABLED) != 0) debugger_init(this); // call the driver's _START callbacks if (m_config.m_machine_start != NULL) (*m_config.m_machine_start)(this); if (m_config.m_sound_start != NULL) (*m_config.m_sound_start)(this); if (m_config.m_video_start != NULL) (*m_config.m_video_start)(this); // if we're coming in with a savegame request, process it now const char *savegame = options_get_string(&m_options, OPTION_STATE); if (savegame[0] != 0) schedule_load(savegame); // if we're in autosave mode, schedule a load else if (options_get_bool(&m_options, OPTION_AUTOSAVE) && (m_game.flags & GAME_SUPPORTS_SAVE) != 0) schedule_load("auto"); // set up the cheat engine if (options_get_bool(&m_options, OPTION_CHEAT)) cheat_init(this); // disallow save state registrations starting here state_save_allow_registration(this, false); }
/***************************************************************************** * I/O chip functions * * * *****************************************************************************/ void io_init(void) { /* Initialize IO Ports handlers */ switch (input.system[0]) { case SYSTEM_GAMEPAD: port[0].data_w = gamepad_1_write; port[0].data_r = gamepad_1_read; break; case SYSTEM_MOUSE: port[0].data_w = mouse_write; port[0].data_r = mouse_read; break; case SYSTEM_WAYPLAY: port[0].data_w = wayplay_1_write; port[0].data_r = wayplay_1_read; break; case SYSTEM_TEAMPLAYER: port[0].data_w = teamplayer_1_write; port[0].data_r = teamplayer_1_read; break; default: port[0].data_w = dummy_write; port[0].data_r = dummy_read; break; } switch (input.system[1]) { case SYSTEM_GAMEPAD: port[1].data_w = gamepad_2_write; port[1].data_r = gamepad_2_read; break; case SYSTEM_MOUSE: port[1].data_w = mouse_write; port[1].data_r = mouse_read; break; case SYSTEM_MENACER: port[1].data_w = dummy_write; port[1].data_r = menacer_read; break; case SYSTEM_JUSTIFIER: port[1].data_w = dummy_write; port[1].data_r = justifier_read; break; case SYSTEM_WAYPLAY: port[1].data_w = wayplay_2_write; port[1].data_r = wayplay_2_read; break; case SYSTEM_TEAMPLAYER: port[1].data_w = teamplayer_2_write; port[1].data_r = teamplayer_2_read; break; default: port[1].data_w = dummy_write; port[1].data_r = dummy_read; break; } /* External Port (unconnected) */ port[2].data_w = dummy_write; port[2].data_r = dummy_read; /* Initialize connected input devices */ input_init(); }
int main(int argc, char **argv) { cf_t *input_buffer, *sf_symbols = NULL; int frame_cnt; ue_sync_t s; int pos; pss_synch_t pss; float peak; struct timeval t[3]; float mean_ce_time=0; bool signal_detected; lte_fft_t fft; lte_cell_t cell; bzero(&cell, sizeof(lte_cell_t)); parse_args(argc, argv); #ifndef DISABLE_GRAPHICS if (!disable_plots) { init_plots(); } #endif input_init(); if (ue_sync_init(&s, cuhd_set_rx_srate, cuhd_recv_wrapper, uhd)) { fprintf(stderr, "Error initiating UE sync module\n"); exit(-1); } ue_sync_pbch_enable(&s, true); signal_detected = true; frame_cnt = 0; mean_ce_time=0; uint32_t valid_frames=0; //uint32_t unaligned = 0; while (frame_cnt < nof_frames || nof_frames == -1) { int n = ue_sync_get_buffer(&s, &input_buffer); if (n < 0) { fprintf(stderr, "Error calling sync work()\n"); exit(-1); } if (n == 1 && ue_sync_get_sfidx(&s) == 0) { if (signal_detected) { cell = ue_sync_get_cell(&s); pss_synch_init_fft(&pss, SF_LEN(lte_symbol_sz(cell.nof_prb), cell.cp), lte_symbol_sz(cell.nof_prb)); pss_synch_set_N_id_2(&pss, cell.id%3); sf_symbols = vec_malloc(SLOT_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t)); if (!sf_symbols) { perror("malloc"); exit(-1); } lte_fft_init(&fft, cell.cp, cell.nof_prb); signal_detected = false; } mean_ce_time = (float) (mean_ce_time + (float) t[0].tv_usec * valid_frames) / (valid_frames+1); valid_frames++; #ifndef DISABLE_GRAPHICS if (!disable_plots && !(valid_frames % 5) && sf_symbols) { /* Run FFT for the second slot */ lte_fft_run_slot(&fft, input_buffer, sf_symbols); int i; int nof_re = SLOT_LEN_RE(cell.nof_prb, cell.cp); for (i = 0; i < nof_re; i++) { tmp_plot[i] = 10 * log10f(cabsf(sf_symbols[i])); if (isinf(tmp_plot[i])) { tmp_plot[i] = -80; } } plot_real_setNewData(&poutfft, tmp_plot, nof_re); } #endif pos = pss_synch_find_pss(&pss, input_buffer, &peak, NULL); /*if (pos > 962 || pos < 958) { unaligned++; } */ printf("CELL_ID: %3d CFO: %+.4f KHz, SFO: %+.4f Khz, TimeOffset: %4d, Exec: %3.2f\r", cell.id, ue_sync_get_cfo(&s)/1000, ue_sync_get_sfo(&s)/1000, pos, s.mean_exec_time); fflush(stdout); if (VERBOSE_ISINFO()) { printf("\n"); } } frame_cnt++; } printf("\nBye\n"); exit(0); }
int game_server_init(const char *file_name, int t, int e) { struct { int x, y; } version; int i; timer = (float) t / 100.f; timer_down = (t > 0); coins = 0; status = GAME_NONE; game_server_free(file_name); /* Load SOL data. */ if (!game_base_load(file_name)) return (server_state = 0); if (!sol_load_vary(&vary, &game_base)) { game_base_free(NULL); return (server_state = 0); } server_state = 1; /* Get SOL version. */ version.x = 0; version.y = 0; for (i = 0; i < vary.base->dc; i++) { char *k = vary.base->av + vary.base->dv[i].ai; char *v = vary.base->av + vary.base->dv[i].aj; if (strcmp(k, "version") == 0) sscanf(v, "%d.%d", &version.x, &version.y); } input_init(); game_tilt_init(&tilt); /* Initialize jump and goal states. */ jump_e = 1; jump_b = 0; goal_e = e ? 1 : 0; /* Initialize the view (and put it at the ball). */ game_view_fly(&view, &vary, 0.0f); view_k = 1.0f; view_time = 0.0f; view_fade = 0.0f; /* Initialize ball size tracking. */ got_orig = 0; grow = 0; /* Initialize simulation. */ sol_init_sim(&vary); sol_cmd_enq_func(game_proxy_enq); /* Send initial update. */ game_cmd_map(file_name, version.x, version.y); game_cmd_ups(); game_cmd_timer(); if (goal_e) game_cmd_goalopen(); game_cmd_init_balls(); game_cmd_init_items(); game_cmd_updview(); game_cmd_eou(); /* Reset lockstep state. */ lockstep_clr(&server_step); return server_state; }
int main(int argc, char **argv) { char *localip; int localport; char* remoteip; int remoteport; FILE* logfile; char* logfile_name; struct stat logfile_stats; long logfile_len; union pkt_any out; union pkt_any in; if (argc != 6) { printf("usage: dummysender <local ip> <local port> " "<remote ip> <remote port> <logfile name>\n"); return 0; } localip = argv[1]; localport = atoi(argv[2]); remoteip = argv[3]; remoteport = atoi(argv[4]); logfile_name = argv[5]; printf("using %s:%d -> %s:%d\n", localip, localport, remoteip, remoteport); printf("Sending logfile: %s\n", logfile_name); logfile = fopen(logfile_name, "r"); if(logfile == NULL){ perror("fopen"); fprintf(stderr, "Error opening log file for sending\n"); exit(1); } stat(logfile_name, &logfile_stats); logfile_len = logfile_stats.st_size; if (socket_init(localip, localport, remoteip, remoteport)) return -1; input_init(); output_init(); while(!feof(logfile)){ //int priority, node, channel;// value; //unsigned int timestamp; // unsigned long long otherstamp; uint32_t header; uint64_t payload; long double scanalysis_time; fscanf(logfile, "%x %Lx %Lf", &header, &payload, &scanalysis_time); out.sample.type = PKT_SAMPLE; out.sample.can.id = header; out.sample.can.data[0] = (payload >> 56) & 0xFF; out.sample.can.data[1] = (payload >> 48) & 0xFF; out.sample.can.data[2] = (payload >> 40 ) & 0xFF; out.sample.can.data[3] = (payload >> 32 ) & 0xFF; out.sample.can.data[4] = (payload >> 24) & 0xFF; out.sample.can.data[5] = (payload >> 16) & 0xFF; out.sample.can.data[6] = (payload >> 8 ) & 0xFF; out.sample.can.data[7] = (payload >> 0 ) & 0xFF; out.sample.can.length = 8; output_queue(&out); out.sample.type = PKT_SAMPLE; /* WHAT THE F**K IS THIS SHIT switch(node){ case 5: out.sample.can.id = fake_heartbeat_id(node, 28); break; case 26: out.sample.can.id = fake_heartbeat_id(node, 26); break; case 111: case 113: out.sample.can.id = fake_heartbeat_id(node, 25); break; case 40: out.sample.can.id = fake_heartbeat_id(node, 13); break; case 30: out.sample.can.id = fake_heartbeat_id(node, 23); break; case 155: case 160: case 165: case 170: case 175: case 180: case 185: out.sample.can.id = fake_heartbeat_id(node, 22); break; } */ /* again, wtf out.sample.can.data[0] = 0; out.sample.can.data[1] = 0; out.sample.can.data[2] = 0; out.sample.can.data[3] = 0; out.sample.can.data[4] = (timestamp >> 24) & 0xFF; out.sample.can.data[5] = (timestamp >> 16) & 0xFF; out.sample.can.data[6] = (timestamp >> 8 ) & 0xFF; out.sample.can.data[7] = (timestamp >> 0 ) & 0xFF; out.sample.can.length = 8; output_queue(&out); */ fprintf(stdout, "\r%d%%\r", (int)(100.0 * ((float)ftell(logfile)) / (float)logfile_len)); while(input_dequeue(&in)==0){ printf("Recieved " "packet_type=%d " "packet_id=%d " "can_id=%x " "can.data=[%x %x %x %x %x %x %x %x] " "can_length=%d\n", in.sample.type, in.sample.packet_id, in.sample.can.id & 0x1FFFFFFF, in.sample.can.data[0], in.sample.can.data[1], in.sample.can.data[2], in.sample.can.data[3], in.sample.can.data[4], in.sample.can.data[5], in.sample.can.data[6], in.sample.can.data[7], in.sample.can.length ); } output_send(); input_recv(); usleep(5000); } return 0; }
int main(int argc,char **argv) { static struct option longopts[] = { {"help",no_argument,NULL,'h'}, {"version",no_argument,NULL,'V'}, {"verbose",no_argument,NULL,'v'}, {"foreground",no_argument,NULL,'f'}, {"evmap",required_argument,NULL,'e'}, {"socket",required_argument,NULL,'s'}, {"mode",required_argument,NULL,'m'}, {"repeat-filter",no_argument,NULL,'R'}, {"release",required_argument,NULL,'r'}, {0, 0, 0, 0} }; const char *progname = NULL; int verbose = 0; bool foreground = false; const char *input_device_evmap_dir = EVMAP_DIR; const char *lircd_socket_path = LIRCD_SOCKET; mode_t lircd_socket_mode = S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH; bool input_repeat_filter = false; const char *lircd_release_suffix = NULL; int opt; for (progname = argv[0] ; strchr(progname, '/') != NULL ; progname = strchr(progname, '/') + 1); openlog(progname, LOG_CONS | LOG_PERROR | LOG_PID, LOG_DAEMON); while((opt = getopt_long(argc, argv, "hVvfe:s:m:Rr:", longopts, NULL)) != -1) { switch(opt) { case 'h': fprintf(stdout, "Usage: %s [options]\n", progname); fprintf(stdout, " -h --help print this help message and exit\n"); fprintf(stdout, " -V --version print the program version and exit\n"); fprintf(stdout, " -v --verbose increase the output message verbosity (-v, -vv or -vvv)\n"); fprintf(stdout, " -f --foreground run in the foreground\n"); fprintf(stdout, " -e --evmap=<dir> directory containing input device event map files (default is '%s')\n", input_device_evmap_dir); fprintf(stdout, " -s --socket=<socket> lircd socket (default is '%s')\n", lircd_socket_path); fprintf(stdout, " -m --mode=<mode> lircd socket mode (default is '%04o')\n", lircd_socket_mode); fprintf(stdout, " -R --repeat-filter enable repeat filtering (default is '%s')\n", input_repeat_filter ? "false" : "true"); fprintf(stdout, " -r --release=<suffix> generate key release events suffixed with <suffix>\n"); exit(EX_OK); break; case 'V': fprintf(stdout, PACKAGE_STRING "\n"); break; case 'v': if (verbose < 3) { verbose++; } else { syslog(LOG_WARNING, "the highest verbosity level is -vvv\n"); } case 'f': foreground = true; break; case 'e': input_device_evmap_dir = optarg; break; case 's': lircd_socket_path = optarg; break; case 'm': lircd_socket_mode = (mode_t)atol(optarg); break; case 'R': input_repeat_filter = true; break; case 'r': lircd_release_suffix = optarg; break; default: fprintf(stderr, "error: unknown option: %c\n", opt); exit(EX_USAGE); } } if (verbose == 0) { setlogmask(0 | LOG_DEBUG | LOG_INFO | LOG_NOTICE); } else if (verbose == 1) { setlogmask(0 | LOG_DEBUG | LOG_INFO); } else if (verbose == 2) { setlogmask(0 | LOG_DEBUG); } else { setlogmask(0); } signal(SIGPIPE, SIG_IGN); if (monitor_init() != 0) { exit(EXIT_FAILURE); } /* Initialize the lircd socket before daemonizing in order to ensure that programs started after it damonizes will have an lircd socket with which to connect. */ if (lircd_init(lircd_socket_path, lircd_socket_mode, lircd_release_suffix) != 0) { monitor_exit(); exit(EXIT_FAILURE); } if (foreground != true) { daemon(0, 0); } if (input_init(input_device_evmap_dir, input_repeat_filter) != 0) { monitor_exit(); lircd_exit(); exit(EXIT_FAILURE); } monitor_run(); if (input_exit() != 0) { monitor_exit(); lircd_exit(); exit(EXIT_FAILURE); } if (lircd_exit() != 0) { monitor_exit(); exit(EXIT_FAILURE); } if (monitor_exit() != 0) { exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); }
int main(int argc, char* args[]) { setlocale(LC_ALL, "de_DE.UTF-8"); if (init() == FALSE) return 1; Uint32 frameStart = 0; espeak_set_run(TRUE); int valid_input = -1; int do_input_name = FALSE; int do_input_continue = FALSE; int input_move_y = 0; while (quit == FALSE) { if (do_input_name == FALSE && do_input_continue == FALSE) timer_update(); frameStart = SDL_GetTicks(); while (SDL_PollEvent(&event)) { if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN) { int skip_input = (strcmp(input_str, "") == 0) ? TRUE : FALSE; if (do_input_continue && strcmp(input_str, "") != 0) { if (strcmp(input_str, "nein") == 0) { quit = TRUE; } else { do_input_continue = FALSE; textlist_init(); textlist_set_random_pos(); timer_start(); inputs_count = 0; input_init(); espeak_set_run(TRUE); } } else if (do_input_name == TRUE && strcmp(input_str, "") != 0) { scorelist_add_score(input_str_w, textlist_get_chars_count(), timer_get_seconds()); do_input_continue = TRUE; do_input_name = FALSE; input_init(); } else if (textlist_current_compare(input_str_w) == 0 || skip_input == TRUE) { if (skip_input == FALSE) valid_input = TRUE; inputs_count++; espeak_lock(); textlist_remove_current(skip_input); espeak_unlock(); if (inputs_count == max_inputs) { do_input_name = TRUE; input_init(); } if (do_input_name == FALSE && quit == FALSE) { espeak_lock(); quit = (textlist_set_random_pos() == TRUE) ? FALSE : TRUE; espeak_unlock(); input_init(); espeak_set_run(TRUE); } } else { valid_input = FALSE; input_init(); espeak_set_run(TRUE); } } else { handle_input(); } if (event.type == SDL_VIDEORESIZE) { screen_width = event.resize.w; screen_height = event.resize.h; screen = SDL_SetVideoMode( screen_width, screen_height, screen_bpp, SDL_SWSURFACE | SDL_RESIZABLE ); } if (event.type == SDL_QUIT) { quit = TRUE; } } SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0, 0, 0)); show_timer_text(); input_move_y = (do_input_continue == TRUE) ? screen_height * 0.1 : 0; if (do_input_continue == TRUE) output_scores(); show_info_text(valid_input, do_input_name, do_input_continue, input_move_y); input_show_centered(input_move_y); apply_surface( screen_width - footer_message->w, screen_height - footer_message->h, footer_message, screen ); apply_surface(0, 0, header_message, screen); if (SDL_Flip(screen) == -1) return 1; if ((SDL_GetTicks() - frameStart) < (1000 / FPS)) { SDL_Delay((1000 / FPS) - (SDL_GetTicks() - frameStart)); } } clean_up(); return 0; }
int main(int argc, char *argv[]) { bool inhibit_loadfade = false; bool error = false; bool freshstart; SetLogFilename("debug.txt"); if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) { staterr("ack, sdl_init failed: %s.", SDL_GetError()); return 1; } atexit(SDL_Quit); // start up inputs first thing because settings_load may remap them input_init(); // load settings, or at least get the defaults, // so we know the initial screen resolution. settings_load(); if (Graphics::init(settings->resolution)) { staterr("Failed to initialize graphics."); return 1; } if (font_init()) { staterr("Failed to load font."); return 1; } //speed_test(); //return 1; #ifdef CONFIG_DATA_EXTRACTOR if (!settings->files_extracted) { if (extract_main()) { Graphics::close(); font_close(); return 0; } else { settings->files_extracted = true; settings_save(); } } #endif if (check_data_exists()) { return 1; } Graphics::ShowLoadingScreen(); if (sound_init()) { fatal("Failed to initialize sound."); return 1; } if (trig_init()) { fatal("Failed trig module init."); return 1; } if (tsc_init()) { fatal("Failed to initialize script engine."); return 1; } if (textbox.Init()) { fatal("Failed to initialize textboxes."); return 1; } if (Carets::init()) { fatal("Failed to initialize carets."); return 1; } if (game.init()) return 1; game.setmode(GM_NORMAL); // set null stage just to have something to do while we go to intro game.switchstage.mapno = 0; //#define REPLAY #ifdef REPLAY game.switchstage.mapno = START_REPLAY; //Replay::set_ffwd(6000); //Replay::set_stopat(3500); game.switchstage.param = 1; #else //game.switchstage.mapno = LOAD_GAME; //game.pause(GP_OPTIONS); if (settings->skip_intro && file_exists(GetProfileName(settings->last_save_slot))) game.switchstage.mapno = LOAD_GAME; else game.setmode(GM_INTRO); #endif // for debug if (game.paused) { game.switchstage.mapno = 0; game.switchstage.eventonentry = 0; } if (game.switchstage.mapno == LOAD_GAME) inhibit_loadfade = true; game.running = true; freshstart = true; stat("Entering main loop..."); #ifdef __SDLSHIM__ set_console_visible(false); #endif //speed_test(); //return 1; while(game.running) { // SSS/SPS persists across stage transitions until explicitly // stopped, or you die & reload. It seems a bit risky to me, // but that's the spec. if (game.switchstage.mapno >= MAPNO_SPECIALS) { StopLoopSounds(); } // enter next stage, whatever it may be if (game.switchstage.mapno == LOAD_GAME || \ game.switchstage.mapno == LOAD_GAME_FROM_MENU) { if (game.switchstage.mapno == LOAD_GAME_FROM_MENU) freshstart = true; stat("= Loading game ="); if (game_load(settings->last_save_slot)) { fatal("savefile error"); goto ingame_error; } Replay::OnGameStarting(); if (!inhibit_loadfade) fade.Start(FADE_IN, FADE_CENTER); else inhibit_loadfade = false; } else if (game.switchstage.mapno == START_REPLAY) { stat(">> beginning replay '%s'", GetReplayName(game.switchstage.param)); StopScripts(); if (Replay::begin_playback(GetReplayName(game.switchstage.param))) { fatal("error starting playback"); goto ingame_error; } } else { if (game.switchstage.mapno == NEW_GAME || \ game.switchstage.mapno == NEW_GAME_FROM_MENU) { bool show_intro = (game.switchstage.mapno == NEW_GAME_FROM_MENU); InitNewGame(show_intro); } // slide weapon bar on first intro to Start Point if (game.switchstage.mapno == STAGE_START_POINT && \ game.switchstage.eventonentry == 91) { freshstart = true; } // switch maps if (load_stage(game.switchstage.mapno)) goto ingame_error; player->x = (game.switchstage.playerx * TILE_W) << CSF; player->y = (game.switchstage.playery * TILE_H) << CSF; } // start the level if (game.initlevel()) return 1; if (freshstart) weapon_introslide(); gameloop(); game.stageboss.OnMapExit(); freshstart = false; } shutdown: ; Replay::close(); game.close(); Carets::close(); Graphics::close(); input_close(); font_close(); sound_close(); tsc_close(); textbox.Deinit(); return error; ingame_error: ; stat(""); stat(" ************************************************"); stat(" * An in-game error occurred. Game shutting down."); stat(" ************************************************"); error = true; goto shutdown; }
/** * @brief The entry point of Naev. * * @param[in] argc Number of arguments. * @param[in] argv Array of argc arguments. * @return EXIT_SUCCESS on success. */ int main( int argc, char** argv ) { char buf[PATH_MAX]; /* Save the binary path. */ binary_path = strdup(argv[0]); /* Print the version */ LOG( " "APPNAME" v%s", naev_version(0) ); #ifdef GIT_COMMIT DEBUG( " git HEAD at " GIT_COMMIT ); #endif /* GIT_COMMIT */ /* Initializes SDL for possible warnings. */ SDL_Init(0); /* Initialize the threadpool */ threadpool_init(); /* Set up debug signal handlers. */ debug_sigInit(); /* Must be initialized before input_init is called. */ if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { WARN("Unable to initialize SDL Video: %s", SDL_GetError()); return -1; } /* Get desktop dimensions. */ #if SDL_VERSION_ATLEAST(1,2,10) const SDL_VideoInfo *vidinfo = SDL_GetVideoInfo(); gl_screen.desktop_w = vidinfo->current_w; gl_screen.desktop_h = vidinfo->current_h; #else /* #elif SDL_VERSION_ATLEAST(1,2,10) */ gl_screen.desktop_w = 0; gl_screen.desktop_h = 0; #endif /* #elif SDL_VERSION_ATLEAST(1,2,10) */ /* We'll be parsing XML. */ LIBXML_TEST_VERSION xmlInitParser(); /* Input must be initialized for config to work. */ input_init(); conf_setDefaults(); /* set the default config values */ /* * Attempts to load the data path from datapath.lua * At this early point in the load process, the binary path * is the only place likely to be checked. */ conf_loadConfigPath(); /* Parse the user data path override first. */ conf_parseCLIPath( argc, argv ); /* Create the home directory if needed. */ if (nfile_dirMakeExist("%s", nfile_configPath())) WARN("Unable to create config directory '%s'", nfile_configPath()); /* Set the configuration. */ nsnprintf(buf, PATH_MAX, "%s"CONF_FILE, nfile_configPath()); #if HAS_UNIX /* TODO get rid of this cruft ASAP. */ int oldconfig = 0; if (!nfile_fileExists( buf )) { char *home, buf2[PATH_MAX]; home = SDL_getenv( "HOME" ); if (home != NULL) { nsnprintf( buf2, PATH_MAX, "%s/.naev/"CONF_FILE, home ); if (nfile_fileExists( buf2 )) oldconfig = 1; } } #endif /* HAS_UNIX */ conf_loadConfig(buf); /* Lua to parse the configuration file */ conf_parseCLI( argc, argv ); /* parse CLI arguments */ /* Enable FPU exceptions. */ #if defined(HAVE_FEENABLEEXCEPT) && defined(DEBUGGING) if (conf.fpu_except) feenableexcept( FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW ); #endif /* defined(HAVE_FEENABLEEXCEPT) && defined(DEBUGGING) */ /* Open data. */ if (ndata_open() != 0) ERR("Failed to open ndata."); /* Load the start info. */ if (start_load()) ERR("Failed to load module start data."); /* Load the data basics. */ LOG(" %s", ndata_name()); DEBUG(); /* Display the SDL Version. */ print_SDLversion(); DEBUG(); /* random numbers */ rng_init(); /* * OpenGL */ if (gl_init()) { /* initializes video output */ ERR("Initializing video output failed, exiting..."); SDL_Quit(); exit(EXIT_FAILURE); } window_caption(); gl_fontInit( NULL, NULL, conf.font_size_def ); /* initializes default font to size */ gl_fontInit( &gl_smallFont, NULL, conf.font_size_small ); /* small font */ /* Display the load screen. */ loadscreen_load(); loadscreen_render( 0., "Initializing subsystems..." ); time_ms = SDL_GetTicks(); /* * Input */ if ((conf.joystick_ind >= 0) || (conf.joystick_nam != NULL)) { if (joystick_init()) WARN("Error initializing joystick input"); if (conf.joystick_nam != NULL) { /* use the joystick name to find a joystick */ if (joystick_use(joystick_get(conf.joystick_nam))) { WARN("Failure to open any joystick, falling back to default keybinds"); input_setDefault(); } free(conf.joystick_nam); } else if (conf.joystick_ind >= 0) /* use a joystick id instead */ if (joystick_use(conf.joystick_ind)) { WARN("Failure to open any joystick, falling back to default keybinds"); input_setDefault(); } } /* * OpenAL - Sound */ if (conf.nosound) { LOG("Sound is disabled!"); sound_disabled = 1; music_disabled = 1; } if (sound_init()) WARN("Problem setting up sound!"); music_choose("load"); /* FPS stuff. */ fps_setPos( 15., (double)(gl_screen.h-15-gl_defFont.h) ); /* Misc graphics init */ if (nebu_init() != 0) { /* Initializes the nebula */ /* An error has happened */ ERR("Unable to initialize the Nebula subsystem!"); /* Weirdness will occur... */ } gui_init(); /* initializes the GUI graphics */ toolkit_init(); /* initializes the toolkit */ map_init(); /* initializes the map. */ cond_init(); /* Initialize conditional subsystem. */ cli_init(); /* Initialize console. */ /* Data loading */ load_all(); /* Generate the CSV. */ if (conf.devcsv) dev_csv(); /* Unload load screen. */ loadscreen_unload(); /* Start menu. */ menu_main(); /* Force a minimum delay with loading screen */ if ((SDL_GetTicks() - time_ms) < NAEV_INIT_DELAY) SDL_Delay( NAEV_INIT_DELAY - (SDL_GetTicks() - time_ms) ); fps_init(); /* initializes the time_ms */ #if HAS_UNIX /* Tell the player to migrate their configuration files out of ~/.naev */ /* TODO get rid of this cruft ASAP. */ if ((oldconfig) && (!conf.datapath)) { char path[PATH_MAX], *script, *home; uint32_t scriptsize; int ret; nsnprintf( path, PATH_MAX, "%s/naev-confupdate.sh", ndata_getDirname() ); home = SDL_getenv("HOME"); ret = dialogue_YesNo( "Warning", "Your configuration files are in a deprecated location and must be migrated:\n" " \er%s/.naev/\e0\n\n" "The update script can likely be found in your Naev data directory:\n" " \er%s\e0\n\n" "Would you like to run it automatically?", home, path ); /* Try to run the script. */ if (ret) { ret = -1; /* Running from ndata. */ if (ndata_getPath() != NULL) { script = ndata_read( "naev-confupdate.sh", &scriptsize ); if (script != NULL) ret = system(script); } /* Running from laid-out files or ndata_read failed. */ if ((nfile_fileExists(path)) && (ret == -1)) { script = nfile_readFile( (int*)&scriptsize, path ); if (script != NULL) ret = system(script); } /* We couldn't find the script. */ if (ret == -1) { dialogue_alert( "The update script was not found at:\n\er%s\e0\n\n" "Please locate and run it manually.", path ); } /* Restart, as the script succeeded. */ else if (!ret) { dialogue_msg( "Update Completed", "Configuration files were successfully migrated. Naev will now restart." ); execv(argv[0], argv); } else { /* I sincerely hope this else is never hit. */ dialogue_alert( "The update script encountered an error. Please exit Naev and move your config and save files manually:\n\n" "\er%s/%s\e0 =>\n \eD%s\e0\n\n" "\er%s/%s\e0 =>\n \eD%s\e0\n\n" "\er%s/%s\e0 =>\n \eD%snebula/\e0\n\n", home, ".naev/conf.lua", nfile_configPath(), home, ".naev/{saves,screenshots}/", nfile_dataPath(), home, ".naev/gen/*.png", nfile_cachePath() ); } } else {
void running_machine::start() { /* initialize basic can't-fail systems here */ fileio_init(this); config_init(this); input_init(this); output_init(this); state_init(this); state_save_allow_registration(this, true); palette_init(this); render_init(this); ui_init(this); generic_machine_init(this); generic_video_init(this); generic_sound_init(this); /* initialize the timers and allocate a soft_reset timer this must be done before cpu_init so that CPU's can allocate timers */ timer_init(this); m_soft_reset_timer = timer_alloc(this, static_soft_reset, NULL); /* init the osd layer */ osd_init(this); /* initialize the base time (needed for doing record/playback) */ time(&m_base_time); /* initialize the input system and input ports for the game this must be done before memory_init in order to allow specifying callbacks based on input port tags */ time_t newbase = input_port_init(this, m_game.ipt); if (newbase != 0) m_base_time = newbase; /* intialize UI input */ ui_input_init(this); /* initialize the streams engine before the sound devices start */ streams_init(this); /* first load ROMs, then populate memory, and finally initialize CPUs these operations must proceed in this order */ rom_init(this); memory_init(this); watchdog_init(this); /* allocate the gfx elements prior to device initialization */ gfx_init(this); /* initialize natural keyboard support */ inputx_init(this); /* initialize image devices */ image_init(this); /* start up the devices */ m_devicelist.start_all(); /* call the game driver's init function this is where decryption is done and memory maps are altered so this location in the init order is important */ ui_set_startup_text(this, "Initializing...", true); if (m_game.driver_init != NULL) (*m_game.driver_init)(this); /* finish image devices init process */ image_postdevice_init(this); /* start the video and audio hardware */ video_init(this); tilemap_init(this); crosshair_init(this); sound_init(this); /* initialize the debugger */ if ((debug_flags & DEBUG_FLAG_ENABLED) != 0) debugger_init(this); /* call the driver's _START callbacks */ if (m_config.m_machine_start != NULL) (*m_config.m_machine_start)(this); if (m_config.m_sound_start != NULL) (*m_config.m_sound_start)(this); if (m_config.m_video_start != NULL) (*m_config.m_video_start)(this); /* set up the cheat engine */ cheat_init(this); /* set up the hiscore engine */ hiscore_init(this); /* disallow save state registrations starting here */ state_save_allow_registration(this, false); }
result_t app_init(const char* name, const struct init_params* params) { ASSERT(g_app == NULL); if (g_app != NULL) { err_print(__FILE__, __LINE__, "application already initialized"); return RET_FAIL; } result_t r; log_print(LOG_TEXT, "init Direct3D app ..."); /* create application */ struct app_win* app = (struct app_win*)ALLOC(sizeof(struct app_win), 0); ASSERT(app); memset(app, 0x00, sizeof(struct app_win)); g_app = app; str_safecpy(app->name, sizeof(app->name), name); uint width = params->gfx.width; uint height = params->gfx.height; if (width == 0) width = DEFAULT_WIDTH; if (height == 0) height = DEFAULT_HEIGHT; HINSTANCE myinst = GetModuleHandle(NULL); /* register window class */ WNDCLASSEX wndcls; memset(&wndcls, 0x00, sizeof(WNDCLASSEX)); wndcls.cbSize = sizeof(WNDCLASSEX); wndcls.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wndcls.lpfnWndProc = msg_callback; wndcls.cbClsExtra = 0; wndcls.cbWndExtra = 0; wndcls.hInstance = myinst; wndcls.hIcon = NULL; wndcls.hCursor = LoadCursor(NULL, IDC_ARROW); wndcls.hbrBackground = (HBRUSH)(GetStockObject(WHITE_BRUSH)); wndcls.lpszMenuName = NULL; wndcls.lpszClassName = app->name; wndcls.hIconSm = NULL; if (!RegisterClassEx(&wndcls)) { err_print(__FILE__, __LINE__, "win-app init failed"); return RET_FAIL; } /* create window */ RECT wndrc = {0, 0, width, height}; uint x; uint y; AdjustWindowRect(&wndrc, WS_OVERLAPPEDWINDOW, FALSE); calc_screenpos(wndrc.right-wndrc.left, wndrc.bottom-wndrc.top, &x, &y); app->hwnd = CreateWindow(app->name, name, WS_OVERLAPPEDWINDOW, x, y, wndrc.right - wndrc.left, wndrc.bottom - wndrc.top, NULL, NULL, myinst, NULL); if (app->hwnd == NULL) { err_print(__FILE__, __LINE__, "win-app init failed: could not create window"); return RET_FAIL; } /* init DXGI */ r = app_init_dxgi(params, &app->dxgi_factory, &app->dxgi_adapter, &app->dev, &app->main_ctx, &app->d3dver); if (IS_FAIL(r)) { err_print(__FILE__, __LINE__, "win-app init failed: init DXGI failed"); return RET_FAIL; } app->d3d_dbg = BIT_CHECK(params->gfx.flags, GFX_FLAG_DEBUG); app->inst = myinst; app->width = width; app->height = height; app->always_active = TRUE; app->refresh_rate = params->gfx.refresh_rate; /* create default swapchain */ r = app_init_swapchain(&app->schain, app->hwnd, width, height, params->gfx.refresh_rate, BIT_CHECK(params->gfx.flags, GFX_FLAG_FULLSCREEN), BIT_CHECK(params->gfx.flags, GFX_FLAG_VSYNC)); if (IS_FAIL(r)) { err_print(__FILE__, __LINE__, "win-app init failed: init swapchain failed"); return RET_FAIL; } struct app_swapchain* sc = &app->schain; app->main_ctx->OMSetRenderTargets(1, &sc->rtv, sc->dsv); app->vsync = BIT_CHECK(params->gfx.flags, GFX_FLAG_VSYNC); /* input */ input_init(); app->init = TRUE; return RET_OK; }
int main(int argc, char *argv[]) { #ifdef _USE_UNPACK int clean_tmp = 0; #endif int err = 0; int i; #ifdef __APPLE__ macosx_init(); #endif #ifndef S60 putenv("SDL_MOUSE_RELATIVE=0"); /* test this! */ #endif #ifdef _WIN32_WCE libwince_init(argv[0], 1); wince_init(argv[0]); #else #ifdef S60 extern char s60_data[]; strcpy(game_cwd, s60_data); #else #ifdef _WIN32 strcpy(game_cwd, dirname(argv[0])); #else if (!getcwd(game_cwd, sizeof(game_cwd))) fprintf(stderr,"Warning: can not get current dir\n."); #endif #endif #endif unix_path(game_cwd); setdir(game_cwd); for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-vsync")) vsync_sw = 1; else if (!strcmp(argv[i], "-nosound")) nosound_sw = 1; else if (!strcmp(argv[i], "-fullscreen")) fullscreen_sw = 1; else if (!strcmp(argv[i], "-mode")) { if ((i + 1) < argc) mode_sw = argv[++i]; else mode_sw = "-1x-1"; } else if (!strcmp(argv[i], "-window")) window_sw = 1; else if (!strcmp(argv[i], "-debug")) { if (!debug_sw) debug_init(); debug_sw = 1; } else if (!strcmp(argv[i], "-owntheme")) owntheme_sw = 1; else if (!strcmp(argv[i], "-noautosave")) noauto_sw = 1; else if (!strcmp(argv[i], "-game")) { if ((i + 1) < argc) game_sw = argv[++i]; else game_sw = ""; } else if (!strcmp(argv[i], "-theme")) { if ((i + 1) < argc) theme_sw = argv[++i]; else theme_sw = ""; } else if (!strcmp(argv[i], "-nostdgames")) { nostdgames_sw = 1; #ifdef _LOCAL_APPDATA } else if (!strcmp(argv[i], "-appdata")) { if ((i + 1) < argc) appdata_sw = argv[++i]; else appdata_sw = ""; #endif } else if (!strcmp(argv[i], "-chunksize")) { if ((i + 1) < argc) chunksize_sw = atoi(argv[++i]); else chunksize_sw = DEFAULT_CHUNKSIZE; } else if (!strcmp(argv[i], "-gamespath")) { if ((i + 1) < argc) games_sw = argv[++i]; else games_sw = ""; } else if (!strcmp(argv[i], "-themespath")) { if ((i + 1) < argc) themes_sw = argv[++i]; else themes_sw = ""; } else if (!strcmp(argv[i], "-idf")) { if ((i + 1) < argc) idf_sw = argv[++i]; else { fprintf(stderr,"No data directory specified.\n"); err = 1; goto out; } } else if (!strcmp(argv[i], "-encode")) { if ((i + 1) < argc) encode_sw = argv[++i]; else { fprintf(stderr,"No lua file specified.\n"); err = 1; goto out; } if ((i + 1) < argc) encode_output = argv[++i]; else encode_output = "lua.enc"; } else if (!strcmp(argv[i], "-version")) { version_sw = 1; } else if (!strcmp(argv[i], "-nopause")) { nopause_sw = 1; } else if (!strcmp(argv[i], "-software")) { software_sw = 1; #ifdef _USE_UNPACK } else if (!strcmp(argv[i], "-install")) { if ((i + 1) < argc) { char *file = argv[++i]; char *p; if (games_sw) p = games_sw; else p = game_local_games_path(1); if (setup_zip(file, p)) { err = 1; goto out; } } #endif } else if (!strcmp(argv[i], "-quit")) { exit(0); } else if (!strcmp(argv[i], "-hinting")) { if ((i + 1) < argc) hinting_sw = atoi(argv[++i]); else hinting_sw = 1; } else if (!strcmp(argv[i], "-lua") || !strcmp(argv[i], "-luac")) { if ((i + 1) < argc) { lua_exec = !strcmp(argv[i], "-lua"); lua_sw = argv[++ i]; opt_index = i + 1; break; } else { fprintf(stderr, "No lua script.\n"); err = 1; goto out; } } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "-help") || !strcmp(argv[i], "--help")) { usage(); goto out; } else if (argv[i][0] == '-') { fprintf(stderr,"Unknown option: %s\n", argv[i]); usage(); err = 1; goto out; } else if (!start_idf(argv[i])) { fprintf(stderr, "Adding idf: %s\n", argv[i]); } else if (!run_game(argv[i])) { fprintf(stderr, "Opening game: %s\n", argv[i]); } #ifdef _USE_UNPACK else { char *p; if (games_sw) p = games_sw; else p = game_tmp_path(); if (setup_zip(argv[i], p)) { err = 1; goto out; } clean_tmp = 1; } #endif } cfg_load(); if (opt_debug == 1 && debug_sw == 0) { debug_sw = 1; debug_init(); } if (opt_vsync == 1 && vsync_sw == 0) vsync_sw = 1; if (version_sw) { fprintf(stdout, VERSION"\n"); goto out; } if (lua_sw) { err = instead_init_lua(dirname(lua_sw)); if (err) goto out; if (!err) err = instead_loadscript(lua_sw, argc - opt_index, argv + opt_index, lua_exec); instead_done(); goto out; } if (encode_sw) { err = instead_encode(encode_sw, encode_output); goto out; } if (idf_sw) { char *p = malloc(strlen(idf_sw) + 5); if (p) { char *b; strcpy(p, idf_sw); b = basename(p); strcat(b, ".idf"); idf_create(b, idf_sw); free(p); } else idf_create("data.idf", idf_sw); goto out; } menu_langs_lookup(dirpath(LANG_PATH)); if (!langs_nr) { fprintf(stderr, "No languages found in: %s.\n", dirpath(LANG_PATH)); err = 1; goto out; } if (!opt_lang || !opt_lang[0]) opt_lang = game_locale(); if (menu_lang_select(opt_lang) && menu_lang_select(LANG_DEF)) { fprintf(stderr, "Can not load default language.\n"); err = 1; goto out; } if (games_sw) games_lookup(games_sw); if (owntheme_sw && !opt_owntheme) { opt_owntheme = 2; } if (!nostdgames_sw && games_lookup(dirpath(GAMES_PATH))) fprintf(stderr, "No games found in: %s.\n", GAMES_PATH); if (themes_sw) themes_lookup(themes_sw); if (!nostdthemes_sw) { themes_lookup(dirpath(THEMES_PATH)); themes_lookup(game_local_themes_path()); } if (!nostdgames_sw) games_lookup(game_local_games_path(0)); if (start_idf_sw) { char *d, *b; char *dd, *bb; static char idf_game[255]; d = strdup(start_idf_sw); b = strdup(start_idf_sw); if (d && b) { dd = dirname(d); bb = basename(b); if (!games_replace(dirpath(dd), bb)) { game_sw = idf_game; strncpy(idf_game, bb, sizeof(idf_game) - 1); idf_game[sizeof(idf_game) - 1] = 0; } } if (d) free(d); if (b) free(b); } if (noauto_sw && opt_autosave) opt_autosave = 2; if (window_sw) opt_fs = 0; if (fullscreen_sw) opt_fs = 1; if (mode_sw) parse_mode(mode_sw, opt_mode); if (game_sw) { FREE(opt_game); opt_game = game_sw; } if (theme_sw) { FREE(opt_theme); opt_theme = theme_sw; } if (opt_theme) game_theme_select(opt_theme); if (!curtheme_dir) game_theme_select(DEFAULT_THEME); /* Initialize SDL */ if (gfx_init() < 0) return -1; #ifdef _USE_GTK gtk_init(&argc, &argv); /* must be called AFTER SDL_Init when using SDL2 */ #endif if (gfx_video_init() || input_init()) return -1; if (game_init(opt_game)) { game_error(); } game_loop(); cfg_save(); game_done(0); gfx_video_done(); #ifndef ANDROID gfx_done(); #endif out: if (debug_sw) debug_done(); #ifdef _USE_GTK /* gtk_main_quit (); */ #endif #ifdef _USE_UNPACK if (clean_tmp) remove_dir(game_tmp_path()); #endif #if defined(ANDROID) || defined(IOS) exit(err); #endif return err; }
int main(int argc, char * argv[]) { input_init(); std::string path_to_exe(""); { std::string path_with_exe(argv[0]); unsigned found = path_with_exe.find_last_of("/\\"); path_to_exe = path_with_exe.substr(0,found+1); } std::cout<<path_to_exe<<std::endl; SDL_Init( SDL_INIT_EVERYTHING ); TTF_Init(); SDL_Surface * screen = SDL_SetVideoMode( 640, 480, 32, SDL_HWSURFACE); GUI_Init(screen); { std::string font_path(path_to_exe); font_path += "freefont/FreeMono.ttf"; GUI_standard_font = TTF_OpenFont( font_path.c_str(), 15 ); } std::cout<<"fontptr: "<<GUI_standard_font<<std::endl; Area * screen_widget = new Area(0, 0, 640, 480); Area * test_widget = new Area(20, 20, 200, 200, screen_widget); test_widget->set_colour(200, 100, 100); Area * another_test_widget = new Area(240, 20, 200, 200, screen_widget); another_test_widget->set_colour(100, 200, 100); Area * ultra_test_widget = new Area(20, 20, 160, 160, another_test_widget); ultra_test_widget->set_colour(100, 100, 200); Label * test_label = new Label(10, 10, 140, 20, ultra_test_widget); test_label->set_colour(120, 120, 220); test_label->set_text("Hallo Welt!"); Button * test_button = new Button(10, 40, 120, 20, ultra_test_widget); test_button->set_colour(100, 200, 200); test_button->set_text("Test!"); Button * end_button = new Button(20, 240, 120, 20, screen_widget); end_button->set_colour(255, 0, 0); end_button->set_text("Ende!"); Text_Edit * text_edit = new Text_Edit(20, 280, 160, 20, screen_widget); text_edit->set_text("aender mich!"); input_update(); while(!key_hit(SDLK_ESCAPE) && !end_button->released)// && !mouse_hit(1)) { SDL_Surface * screen_surface = screen_widget->get_sdl_surface(); SDL_BlitSurface(screen_surface, NULL, screen, NULL); screen_widget->update(); if(test_button->released) { test_label->set_text("Button geklickt!"); } SDL_Flip(screen); flush_keys(); flush_mouse(); SDL_Delay(1000/60); input_update(); } //SDL_Delay(2000); return 0; }
bool load_main_config(const char *file, bool is_active) { input_init(); char *path; if (file != NULL) { path = strdup(file); } else { path = get_config_path(); } struct sway_config *old_config = config; config = calloc(1, sizeof(struct sway_config)); if (!config) { sway_abort("Unable to allocate config"); } config_defaults(config); if (is_active) { sway_log(L_DEBUG, "Performing configuration file reload"); config->reloading = true; config->active = true; } config->current_config = path; list_add(config->config_chain, path); config->reading = true; // Read security configs bool success = true; DIR *dir = opendir(SYSCONFDIR "/sway/security.d"); if (!dir) { sway_log(L_ERROR, "%s does not exist, sway will have no security configuration" " and will probably be broken", SYSCONFDIR "/sway/security.d"); } else { list_t *secconfigs = create_list(); char *base = SYSCONFDIR "/sway/security.d/"; struct dirent *ent = readdir(dir); struct stat s; while (ent != NULL) { char *_path = malloc(strlen(ent->d_name) + strlen(base) + 1); strcpy(_path, base); strcat(_path, ent->d_name); lstat(_path, &s); if (S_ISREG(s.st_mode)) { list_add(secconfigs, _path); } ent = readdir(dir); } closedir(dir); list_qsort(secconfigs, qstrcmp); for (int i = 0; i < secconfigs->length; ++i) { char *_path = secconfigs->items[i]; if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 || (((s.st_mode & 0777) != 0644) && (s.st_mode & 0777) != 0444)) { sway_log(L_ERROR, "Refusing to load %s - it must be owned by root and mode 644 or 444", _path); success = false; } else { success = success && load_config(_path, config); } } free_flat_list(secconfigs); } success = success && load_config(path, config); if (is_active) { config->reloading = false; } if (old_config) { free_config(old_config); } config->reading = false; if (success) { update_active_bar_modifiers(); } return success; }
void config_default(void) { /* version TAG */ strncpy(config.version,CONFIG_VERSION,16); /* sound options */ config.psg_preamp = 150; config.fm_preamp = 100; config.hq_fm = 1; config.psgBoostNoise = 1; config.filter = 1; config.lp_range = 0x9999; /* 0.6 in 16.16 fixed point */ config.low_freq = 880; config.high_freq = 5000; config.lg = 1.0; config.mg = 1.0; config.hg = 1.0; config.dac_bits = 14; config.ym2413 = 2; /* AUTO */ config.mono = 0; /* system options */ config.system = 0; /* AUTO */ config.region_detect = 0; /* AUTO */ config.vdp_mode = 0; /* AUTO */ config.master_clock = 0; /* AUTO */ config.force_dtack = 0; config.addr_error = 1; config.bios = 0; config.lock_on = 0; config.hot_swap = 0; /* video options */ config.xshift = 0; config.yshift = 0; config.xscale = 0; config.yscale = 0; config.aspect = 1; config.overscan = 3; /* FULL */ config.gg_extra = 0; config.lcd = 0; config.ntsc = 0; config.vsync = 1; /* AUTO */ config.bilinear = 0; config.vfilter = 1; if (VIDEO_HaveComponentCable()) { config.render = 2; } else { config.render = 0; } switch (vmode->viTVMode >> 2) { case VI_PAL: config.tv_mode = 1; /* 50hz only */ break; case VI_EURGB60: config.tv_mode = 2; /* 50/60hz */ break; default: config.tv_mode = 0; /* 60hz only */ break; } #ifdef HW_RVL config.trap = 0; config.gamma = VI_GM_1_0 / 10.0; #else config.v_prog = 1; #endif /* NTSC filter options */ config.ntsc_sharpness = 0.0; config.ntsc_resolution = 0.0; config.ntsc_artifacts = 0.0; config.ntsc_fringing = 0.0; config.ntsc_bleed = 0.0; /* controllers options */ config.gun_cursor[0] = 1; config.gun_cursor[1] = 1; config.invert_mouse = 0; /* on-screen options */ config.cd_leds = 0; config.fps = 0; /* menu options */ config.autoload = 0; config.autocheat = 0; config.s_auto = 1; config.s_default = 1; config.s_device = 0; config.bg_overlay = 0; config.screen_w = 658; config.bgm_volume = 100.0; config.sfx_volume = 100.0; #ifdef HW_RVL config.autosleep = 1; config.calx = 0; config.caly = 0; #endif /* default ROM directories */ #ifdef HW_RVL DIR *dir = opendir("sd:/"); if (dir) { config.l_device = TYPE_SD; closedir(dir); } else { config.l_device = TYPE_USB; } sprintf (config.lastdir[0][TYPE_SD], "sd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[1][TYPE_SD], "sd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[2][TYPE_SD], "sd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[3][TYPE_SD], "sd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[4][TYPE_SD], "sd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[0][TYPE_USB], "usb:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[1][TYPE_USB], "usb:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[2][TYPE_USB], "usb:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[3][TYPE_USB], "usb:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[4][TYPE_USB], "usb:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[0][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[1][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[2][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[3][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[4][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); #else config.l_device = TYPE_SD; sprintf (config.lastdir[0][TYPE_SD], "%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[1][TYPE_SD], "%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[2][TYPE_SD], "%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[3][TYPE_SD], "%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[4][TYPE_SD], "%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[0][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[1][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[2][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[3][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); sprintf (config.lastdir[4][TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); #endif /* system ROM paths */ sprintf (config.sys_rom[0], "%s/bios/bios_CD_U.bin", DEFAULT_PATH); sprintf (config.sys_rom[1], "%s/bios/bios_CD_E.bin", DEFAULT_PATH); sprintf (config.sys_rom[2], "%s/bios/bios_CD_J.bin", DEFAULT_PATH); sprintf (config.sys_rom[3], "%s/bios/bios_MD.bin", DEFAULT_PATH); sprintf (config.sys_rom[4], "%s/bios/bios_U.sms", DEFAULT_PATH); sprintf (config.sys_rom[5], "%s/bios/bios_E.sms", DEFAULT_PATH); sprintf (config.sys_rom[6], "%s/bios/bios_J.sms", DEFAULT_PATH); sprintf (config.sys_rom[7], "%s/bios/bios.gg", DEFAULT_PATH); sprintf (config.sys_rom[8], "%s/lock-on/ggenie.bin", DEFAULT_PATH); sprintf (config.sys_rom[9], "%s/lock-on/areplay.bin", DEFAULT_PATH); sprintf (config.sys_rom[10], "%s/lock-on/sk.bin", DEFAULT_PATH); sprintf (config.sys_rom[11], "%s/lock-on/sk2chip.bin", DEFAULT_PATH); /* try to restore user config */ int loaded = config_load(); #ifdef HW_RVL /* initialize WPAD timeout */ WPAD_SetIdleTimeout(config.autosleep ? 300 : 1800); #else /* check if component cable was detected */ if (VIDEO_HaveComponentCable()) { /* when component cable is detected, libogc automatically enables progressive mode */ /* as preferred video mode but it could still be used on TV not supporting 480p/576p */ PAD_ScanPads(); /* detect progressive mode switch requests */ if (PAD_ButtonsHeld(0) & PAD_BUTTON_B) { /* swap progressive mode enable flag */ config.v_prog ^= 1; /* play some sound to inform user */ ASND_Pause(0); int voice = ASND_GetFirstUnusedVoice(); ASND_SetVoice(voice,VOICE_MONO_16BIT,44100,0,(u8 *)intro_pcm,intro_pcm_size,200,200,NULL); sleep (2); ASND_Pause(1); } /* check if progressive mode should be disabled */ if (!config.v_prog) { /* switch menu video mode to interlaced */ vmode->viTVMode = (vmode->viTVMode & ~3) | VI_INTERLACE; VIDEO_Configure(vmode); VIDEO_Flush(); VIDEO_WaitVSync(); VIDEO_WaitVSync(); } } #endif /* inform user if default config is used */ if (!loaded) { GUI_WaitPrompt("Warning","Default Settings restored"); gx_input_SetDefault(); } /* default emulated inputs */ input.system[0] = SYSTEM_GAMEPAD; input.system[1] = (config.input[1].device != -1) ? SYSTEM_GAMEPAD : NO_SYSTEM; input_init(); }
int main(int argc, char *argv[]) { set_main_thread(); setup_fork_guards(); wsetlocale(LC_ALL, L""); program_name=L"fish_indent"; env_init(); input_init(); /* Types of output we support */ enum { output_type_plain_text, output_type_ansi, output_type_html } output_type = output_type_plain_text; /* Whether to indent (true) or just reformat to one job per line (false) */ bool do_indent = true; while (1) { const struct option long_options[] = { { "no-indent", no_argument, 0, 'i' }, { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'v' }, { "html", no_argument, 0, 1 }, { "ansi", no_argument, 0, 2 }, { 0, 0, 0, 0 } }; int opt_index = 0; int opt = getopt_long(argc, argv, "hvi", long_options, &opt_index); if (opt == -1) break; switch (opt) { case 0: { break; } case 'h': { print_help("fish_indent", 1); exit(0); assert(0 && "Unreachable code reached"); break; } case 'v': { fwprintf(stderr, _(L"%ls, version %s\n"), program_name, get_fish_version()); exit(0); assert(0 && "Unreachable code reached"); break; } case 'i': { do_indent = false; break; } case 1: { output_type = output_type_html; break; } case 2: { output_type = output_type_ansi; break; } case '?': { exit(1); } } } const wcstring src = read_file(stdin); const wcstring output_wtext = prettify(src, do_indent); /* Maybe colorize */ std::vector<highlight_spec_t> colors; if (output_type != output_type_plain_text) { highlight_shell_no_io(output_wtext, colors, output_wtext.size(), NULL, env_vars_snapshot_t::current()); } std::string colored_output; switch (output_type) { case output_type_plain_text: colored_output = no_colorize(output_wtext); break; case output_type_ansi: colored_output = ansi_colorize(output_wtext, colors); break; case output_type_html: colored_output = html_colorize(output_wtext, colors); break; } fputs(colored_output.c_str(), stdout); return 0; }
// the main game loop which will run until the game is done void game_loop() { SDL_Event event, e; SDL_TimerID timer; int last_game_update = 0; int last_particle_update = 0; int last_render = 0; int previous_level = 0; debug_print("Loading media..."); load_media(); // check if we want to show score increments game.show_score_increments = atoi(config_getValue("show_score_increments")); // setup input input_init(); // create & show menu ui_menuInit(); ui_toggleMenuVisible(); SDL_SetEventFilter(ui_handleEvents); // loop forever debug_print("Entering main game loop..."); while (1) { // see if its time to trigger an update (make sure we're not paused either) if (!game.paused && SDL_GetTicks() - last_game_update > game_getGameUpdateFreq()) { last_game_update = SDL_GetTicks(); // remember time of last update game_update(); } if (game.show_score_increments) { // at the moment we just have the one particle set // see if its time to trigger a particle update if (SDL_GetTicks() - last_particle_update > PARTICLE_UPDATE_INTERVAL) { last_particle_update = SDL_GetTicks(); particle_update(); } } // check for any events waiting while (SDL_PollEvent(&event)) { switch(event.type) { // key presses are handled in input.c case SDL_KEYDOWN: input_onKeyDown(event.key.keysym.sym); break; case LEFT_KEY: tetromino_moveLeft(current_tetromino); if (grid_checkCollision(grid, current_tetromino)) { tetromino_moveRight(current_tetromino); } break; case RIGHT_KEY: tetromino_moveRight(current_tetromino); if (grid_checkCollision(grid, current_tetromino)) { tetromino_moveLeft(current_tetromino); } break; case DOWN_KEY: // uses the key repeat interval to accelerate the tetromino down tetromino_moveDown(current_tetromino); if (grid_checkCollision(grid, current_tetromino)) { tetromino_moveUp(current_tetromino); } break; case UP_KEY: // rotate to a new position tetromino_setNextPosition(current_tetromino); tetromino_setShape(current_tetromino, current_tetromino->type, current_tetromino->position); // make sure the new position doesn't cause any collisions // if it does, reverse the rotation if (grid_checkCollision(grid, current_tetromino)) { tetromino_setPrevPosition(current_tetromino); tetromino_setShape(current_tetromino, current_tetromino->type, current_tetromino->position); } break; case SPACE_KEY: tetromino_moveDown(current_tetromino); // move the tetromino down until it causes a collision while (!grid_checkCollision(grid, current_tetromino)) { tetromino_moveDown(current_tetromino); } // once we have a collision, move it back into place tetromino_moveUp(current_tetromino); break; case PAUSE_KEY: debug_print("Pausing game"); game.paused = !game.paused; // stop the game timer if (game.paused) { SDL_RemoveTimer(timer); timer = NULL; } else { // start it again timer = SDL_AddTimer(1000, game_updateTime, NULL); } break; case ESCAPE_KEY: // pause game updates debug_print("Escape key pressed."); // toggle paused game state if we're in game if (grid && current_tetromino) { game.paused = !game.paused; if (game.paused) { // stop couting time played SDL_RemoveTimer(timer); timer = NULL; } // starting timer again, only if we're still in a game else if (grid && current_tetromino) { timer = SDL_AddTimer(1000, game_updateTime, NULL); } } // show or hide the menu if (grid && current_tetromino) { ui_toggleMenuVisible(); } // enable ui message pump if its visible if (ui_isMenuVisible()) { // if we're in game, show in-game menu if (grid && current_tetromino) { ui_menuPageSetCurrentById(MENU_IN_GAME); } // otherwise show main menu else { ui_menuPageSetCurrentById(MENU_MAIN); } SDL_SetEventFilter(ui_handleEvents); } break; case GAME_START_NEW: // set some game variables game.level = 0; game.score = 0; game.lines = 0; game.paused = 0; // time variables game.hours = 0; game.minutes = 0; game.seconds = 0; // create the grid grid = grid_createNew(GRID_WIDTH, GRID_HEIGHT); // create the first tetromino current_tetromino = tetromino_createNew(); current_tetromino->x = 0; current_tetromino->y = 0; // update time SDL_Init(SDL_INIT_TIMER); if (timer) { SDL_RemoveTimer(timer); timer = NULL; } ui_toggleMenuVisible(); timer = SDL_AddTimer(1000, game_updateTime, NULL); game.paused = 0; break; case GAME_END: // called by either the menu or game over scenario // destroy timer, grid and tetromino SDL_RemoveTimer(timer); timer = NULL; grid_destroy(grid); grid = NULL; tetromino_destroy(current_tetromino); current_tetromino = NULL; // show menu if it isn't already visible ui_menuPageSetCurrentById(MENU_MAIN); if (!ui_isMenuVisible()) { SDL_SetEventFilter(ui_handleEvents); ui_toggleMenuVisible(); } break; case TETROMINO_CREATE: // assumes that the old one has already been discarded current_tetromino = tetromino_createNew(); current_tetromino->x = 0; current_tetromino->y = 0; // check if we have an immediate collision (game over) if (grid_checkCollision(grid, current_tetromino)) { SDL_RemoveTimer(timer); timer = NULL; e.type = GAME_END; SDL_PushEvent(&e); } break; case GRID_REMOVE_LINE: if (game.show_score_increments) { // animated score increment game_showScoreIncrement(event.user.code, (game.level + 1) * 10); } grid_removeLine(grid, event.user.code); // increment number of complete lines game.lines += 1; // +10 per block and x10 per level game.score += (game.level + 1) * 10 * GRID_WIDTH; // increment the game level every 10 lines previous_level = game.level; game.level = game.lines / 10; if (previous_level != game.level) { game_showLevelIncrement(); } break; case GAME_QUIT: SDL_RemoveTimer(timer); // stop gameplay timer timer = NULL; game_shutdown(); break; // unhandled events are ignored default: break; } } // update the display // without this delay gfx card tries to commit suicide by melting if (SDL_GetTicks() - last_render > 3) { display_update(); last_render= SDL_GetTicks(); } } }
int drv_keyboard_init(void) { int error; struct stdio_dev dev = { .name = "button", .flags = DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM, .start = novena_gpio_button_init, .getc = novena_gpio_button_getc, .tstc = novena_gpio_button_tstc, }; error = input_init(&button_input, 0); if (error) { debug("%s: Cannot set up input\n", __func__); return -1; } button_input.read_keys = novena_gpio_button_read_keys; error = input_stdio_register(&dev); if (error) return error; return 0; } #endif /* * SDHC */ #ifdef CONFIG_FSL_ESDHC static struct fsl_esdhc_cfg usdhc_cfg[] = { { USDHC3_BASE_ADDR, 0, 4 }, /* Micro SD */ { USDHC2_BASE_ADDR, 0, 4 }, /* Big SD */ }; int board_mmc_getcd(struct mmc *mmc) { struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; /* There is no CD for a microSD card, assume always present. */ if (cfg->esdhc_base == USDHC3_BASE_ADDR) return 1; else return !gpio_get_value(NOVENA_SD_CD); } int board_mmc_getwp(struct mmc *mmc) { struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; /* There is no WP for a microSD card, assume always read-write. */ if (cfg->esdhc_base == USDHC3_BASE_ADDR) return 0; else return gpio_get_value(NOVENA_SD_WP); } int board_mmc_init(bd_t *bis) { s32 status = 0; int index; usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK); usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK); /* Big SD write-protect and card-detect */ gpio_direction_input(NOVENA_SD_WP); gpio_direction_input(NOVENA_SD_CD); for (index = 0; index < ARRAY_SIZE(usdhc_cfg); index++) { status = fsl_esdhc_initialize(bis, &usdhc_cfg[index]); if (status) return status; } return status; }
int main(int argc, char **argv) { int e = 0; pid_t parent_pid = 0; stored_argc = argc; stored_argv = argv; /* * Settings in order of preference: * * 1: Settings specified in command line options... * 2: Settings specified in configuration file... * 3: Default settings * * Because of this, and because one option (-c) specifies where * the configuration file is, things are done in this order: * * 1. Read and set options. * 2. Read configuration file; if option is read in configuration * file and not already set, then set it. * 3. Having read configuration file, if parameter is not set, * set it to the default value. * * It is for this reason that the default values are **NOT** set * in the variable declaration... */ /* Report that server is starting (report will be delayed) */ report(RPT_NOTICE, "LCDd version %s starting", version); report(RPT_INFO, "Built on %s, protocol version %s, API version %s", build_date, protocol_version, api_version); clear_settings(); /* Read command line*/ CHAIN(e, process_command_line(argc, argv)); /* Read config file * If config file was not given on command line use default */ if (strcmp(configfile, UNSET_STR) == 0) strncpy(configfile, DEFAULT_CONFIGFILE, sizeof(configfile)); CHAIN(e, process_configfile(configfile)); /* Set default values*/ set_default_settings(); /* Set reporting settings (will also flush delayed reports) */ set_reporting("LCDd", report_level, report_dest); report(RPT_INFO, "Set report level to %d, output to %s", report_level, ((report_dest == RPT_DEST_SYSLOG) ? "syslog" : "stderr")); CHAIN_END(e, "Critical error while processing settings, abort."); /* Now, go into daemon mode (if we should)... * We wait for the child to report it is running OK. This mechanism * is used because forking after starting the drivers causes the * child to loose the (LPT) port access. */ if (!foreground_mode) { report(RPT_INFO, "Server forking to background"); CHAIN(e, parent_pid = daemonize()); } else { output_GPL_notice(); report(RPT_INFO, "Server running in foreground"); } install_signal_handlers(!foreground_mode); /* Only catch SIGHUP if not in foreground mode */ /* Startup the subparts of the server */ CHAIN(e, sock_init(bind_addr, bind_port)); CHAIN(e, screenlist_init()); CHAIN(e, init_drivers()); CHAIN(e, clients_init()); CHAIN(e, input_init()); CHAIN(e, menuscreens_init()); CHAIN(e, server_screen_init()); CHAIN_END(e, "Critical error while initializing, abort."); if (!foreground_mode) { /* Tell to parent that startup went OK. */ wave_to_parent(parent_pid); } drop_privs(user); /* This can't be done before, because sending a signal to a process of a different user will fail */ do_mainloop(); /* This loop never stops; we'll get out only with a signal...*/ return 0; }