void game_end(void) { console_add_system("Closing Game"); // blank progress progress_initialize("Ending"); progress_draw(0); // close any network joins or hosting if (net_setup.client.joined) { if (!net_setup.host.hosting) { net_client_send_leave_host(object_player_get_remote_uid()); net_client_end_message_queue(); net_client_join_host_end(); } else { net_host_game_end(); net_client_end_message_queue_local(); } } // stop view view_game_stop(); // stop server server_game_stop(); // game closed server.game_open=FALSE; }
/* make it look pretty at the end - display done bytes (usually total) */ int progress_complete(progress_t *prog, uint64_t done) { progress_update(prog, done); progress_draw(prog); printf("\n"); return 1; }
bool game_start(int skill,network_reply_join_remotes *remotes,char *err_str) { // pause time game_time_pause_start(); // reset random numbers random_reset(); // start progress console_add_system("Starting Game"); progress_initialize("Starting"); progress_draw(0); // start server if (!server_game_start("Game",skill,remotes,err_str)) { return(FALSE); } // start view view_game_start(); // game in running state server.game_open=TRUE; server.state=gs_running; game_time_pause_end(); return(TRUE); }
/* * Download firmware stored in buf to cam_dev. If simulation mode * is enabled, only show what packet sizes would be sent to the * device but do not sent any actual packets */ static int fw_download_img(struct cam_device *cam_dev, const struct fw_vendor *vp, char *buf, int img_size, int sim_mode, int printerrors, int retry_count, int timeout, const char *imgname, const char *type) { struct scsi_write_buffer cdb; progress_t progress; int size; union ccb *ccb; int pkt_count = 0; int max_pkt_size; u_int32_t pkt_size = 0; char *pkt_ptr = buf; u_int32_t offset; int last_pkt = 0; int16_t *ptr; if ((ccb = cam_getccb(cam_dev)) == NULL) { warnx("Could not allocate CCB"); return (1); } if (strcmp(type, "scsi") == 0) { scsi_test_unit_ready(&ccb->csio, 0, NULL, MSG_SIMPLE_Q_TAG, SSD_FULL_SIZE, 5000); } else if (strcmp(type, "ata") == 0) { /* cam_getccb cleans up the header, caller has to zero the payload */ bzero(&(&ccb->ccb_h)[1], sizeof(struct ccb_ataio) - sizeof(struct ccb_hdr)); ptr = (uint16_t *)malloc(sizeof(struct ata_params)); if (ptr == NULL) { cam_freeccb(ccb); warnx("can't malloc memory for identify\n"); return(1); } bzero(ptr, sizeof(struct ata_params)); cam_fill_ataio(&ccb->ataio, 1, NULL, /*flags*/CAM_DIR_IN, MSG_SIMPLE_Q_TAG, /*data_ptr*/(uint8_t *)ptr, /*dxfer_len*/sizeof(struct ata_params), timeout ? timeout : 30 * 1000); ata_28bit_cmd(&ccb->ataio, ATA_ATA_IDENTIFY, 0, 0, 0); } else { warnx("weird disk type '%s'", type); return 1; } /* Disable freezing the device queue. */ ccb->ccb_h.flags |= CAM_DEV_QFRZDIS; if (cam_send_ccb(cam_dev, ccb) < 0) { warnx("Error sending identify/test unit ready"); if (printerrors) cam_error_print(cam_dev, ccb, CAM_ESF_ALL, CAM_EPF_ALL, stderr); cam_freeccb(ccb); return(1); } if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { warnx("Device is not ready"); if (printerrors) cam_error_print(cam_dev, ccb, CAM_ESF_ALL, CAM_EPF_ALL, stderr); cam_freeccb(ccb); return (1); } max_pkt_size = vp->max_pkt_size; if (vp->max_pkt_size == 0 && strcmp(type, "ata") == 0) { max_pkt_size = UNKNOWN_MAX_PKT_SIZE; } pkt_size = vp->max_pkt_size; progress_init(&progress, imgname, size = img_size); /* Download single fw packets. */ do { if (img_size <= max_pkt_size) { last_pkt = 1; pkt_size = img_size; } progress_update(&progress, size - img_size); progress_draw(&progress); bzero(&cdb, sizeof(cdb)); if (strcmp(type, "scsi") == 0) { cdb.opcode = WRITE_BUFFER; cdb.control = 0; /* Parameter list length. */ scsi_ulto3b(pkt_size, &cdb.length[0]); offset = vp->inc_cdb_offset ? (pkt_ptr - buf) : 0; scsi_ulto3b(offset, &cdb.offset[0]); cdb.byte2 = last_pkt ? vp->cdb_byte2_last : vp->cdb_byte2; cdb.buffer_id = vp->inc_cdb_buffer_id ? pkt_count : 0; /* Zero out payload of ccb union after ccb header. */ bzero((u_char *)ccb + sizeof(struct ccb_hdr), sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr)); /* Copy previously constructed cdb into ccb_scsiio struct. */ bcopy(&cdb, &ccb->csio.cdb_io.cdb_bytes[0], sizeof(struct scsi_write_buffer)); /* Fill rest of ccb_scsiio struct. */ if (!sim_mode) { cam_fill_csio(&ccb->csio, /* ccb_scsiio */ retry_count, /* retries */ NULL, /* cbfcnp */ CAM_DIR_OUT | CAM_DEV_QFRZDIS, /* flags */ CAM_TAG_ACTION_NONE, /* tag_action */ (u_char *)pkt_ptr, /* data_ptr */ pkt_size, /* dxfer_len */ SSD_FULL_SIZE, /* sense_len */ sizeof(struct scsi_write_buffer), /* cdb_len */ timeout ? timeout : CMD_TIMEOUT); /* timeout */ } } else if (strcmp(type, "ata") == 0) { bzero(&(&ccb->ccb_h)[1], sizeof(struct ccb_ataio) - sizeof(struct ccb_hdr)); if (!sim_mode) { uint32_t off; cam_fill_ataio(&ccb->ataio, (last_pkt) ? 256 : retry_count, NULL, /*flags*/CAM_DIR_OUT | CAM_DEV_QFRZDIS, CAM_TAG_ACTION_NONE, /*data_ptr*/(uint8_t *)pkt_ptr, /*dxfer_len*/pkt_size, timeout ? timeout : 30 * 1000); off = (uint32_t)(pkt_ptr - buf); ata_28bit_cmd(&ccb->ataio, ATA_DOWNLOAD_MICROCODE, USE_OFFSETS_FEATURE, ATA_MAKE_LBA(off, pkt_size), ATA_MAKE_SECTORS(pkt_size)); } } if (!sim_mode) { /* Execute the command. */ if (cam_send_ccb(cam_dev, ccb) < 0 || (ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { warnx("Error writing image to device"); if (printerrors) cam_error_print(cam_dev, ccb, CAM_ESF_ALL, CAM_EPF_ALL, stderr); goto bailout; } } /* Prepare next round. */ pkt_count++; pkt_ptr += pkt_size; img_size -= pkt_size; } while(!last_pkt); progress_complete(&progress, size - img_size); cam_freeccb(ccb); return (0); bailout: progress_complete(&progress, size - img_size); cam_freeccb(ccb); return (1); }
bool game_file_load(char *file_name,char *err_str) { char *c,path[1024],fname[256]; file_save_header head; // load and expand strcpy(fname,file_name); c=strrchr(fname,'.'); if (c!=NULL) *c=0x0; // remove any extensions file_paths_documents(&setup.file_path_setup,path,"Saved Games",fname,"sav"); if (!game_file_expand_load(path,err_str)) return(FALSE); game_file_pos=0; progress_initialize("Loading"); // if game isn't running, then start if (!server.game_open) { if (!game_start(skill_medium,NULL,err_str)) { free(game_file_data); return(FALSE); } } // get header game_file_get_chunk(&head); // check version if (strcmp(head.version,dim3_version)!=0) { sprintf(err_str,"This saved game file is from a different version of dim3"); free(game_file_data); return(FALSE); } // reload map progress_draw(10); if ((!server.map_open) || (strcmp(head.map_name,map.info.name)!=0)) { // need to load a map? if (server.map_open) map_end(); strcpy(map.info.name,head.map_name); map.info.player_start_name[0]=0x0; map.info.player_start_type[0]=0x0; map.info.in_load=TRUE; if (!map_start(TRUE,err_str)) { free(game_file_data); return(FALSE); } } // timing game_time_set(head.tick); // view and server objects progress_draw(20); game_file_get_chunk(&view.time); game_file_get_chunk(&view.fps); game_file_get_chunk(&camera); game_file_get_chunk(&server.time); game_file_get_chunk(&server.player_obj_uid); game_file_get_chunk(&server.skill); game_file_get_chunk(&server.uid); game_file_get_chunk(&server.count); progress_draw(30); free(server.objs); free(server.weapons); free(server.proj_setups); server.objs=(obj_type*)game_file_replace_chunk(); server.weapons=(weapon_type*)game_file_replace_chunk(); server.proj_setups=(proj_setup_type*)game_file_replace_chunk(); if ((server.objs==NULL) || (server.weapons==NULL) || (server.proj_setups==NULL)) { free(game_file_data); return(FALSE); } progress_draw(40); game_file_get_chunk(server.projs); game_file_get_chunk(server.effects); game_file_get_chunk(server.decals); progress_draw(50); game_file_get_chunk(hud.bitmaps); game_file_get_chunk(hud.texts); game_file_get_chunk(hud.bars); game_file_get_chunk(&hud.radar); // map changes progress_draw(60); game_file_get_chunk(&map.ambient); game_file_get_chunk(&map.rain); game_file_get_chunk(&map.background); game_file_get_chunk(&map.sky); game_file_get_chunk(&map.fog); progress_draw(70); map_group_dispose_unit_list(&map); // need to destroy and rebuild unit lists game_file_get_chunk(map.groups); map_group_create_unit_list(&map); game_file_get_chunk(map.movements); group_moves_synch_with_load(); // script objects progress_draw(80); game_file_get_chunk(&js.script_current_uid); game_file_get_chunk(&js.count); game_file_get_chunk(&js.time); game_file_get_chunk(js.timers); game_file_get_chunk(js.globals); // reset model UIDs progress_draw(90); models_reset_uid(); // send scripts load event // to restore globals progress_draw(95); script_state_load(); // free game data progress_draw(100); free(game_file_data); // finished progress_shutdown(); // fix some necessary functions map.rain.reset=TRUE; fade_screen_cancel(); // return to old game time game_time_reset(); return(TRUE); }
bool game_file_save(char *err_str) { int tick; char path[1024],file_name[256]; bool ok; file_save_header head; progress_initialize("Saving"); progress_draw(5); // get saved data file names tick=game_time_get(); game_file_create_name(tick,file_name); // save screen file_paths_documents(&setup.file_path_setup,path,"Saved Games",file_name,"png"); view_capture_draw(path); // start chunks game_file_sz=0; game_file_data=malloc(32); // header head.tick=tick; strcpy(head.version,dim3_version); strcpy(head.map_name,map.info.name); game_file_add_chunk(&head,1,sizeof(file_save_header)); // send scripts save event // to backup globals progress_draw(10); script_state_save(); // view & server objects progress_draw(20); game_file_add_chunk(&view.time,1,sizeof(view_time_type)); game_file_add_chunk(&view.fps,1,sizeof(view_fps_type)); game_file_add_chunk(&camera,1,sizeof(camera_type)); game_file_add_chunk(&server.time,1,sizeof(server_time_type)); game_file_add_chunk(&server.player_obj_uid,1,sizeof(int)); game_file_add_chunk(&server.skill,1,sizeof(int)); game_file_add_chunk(&server.uid,1,sizeof(server_uid_type)); game_file_add_chunk(&server.count,1,sizeof(server_count_type)); progress_draw(30); game_file_add_chunk(server.objs,server.count.obj,sizeof(obj_type)); game_file_add_chunk(server.weapons,server.count.weapon,sizeof(weapon_type)); game_file_add_chunk(server.proj_setups,server.count.proj_setup,sizeof(proj_setup_type)); progress_draw(40); game_file_add_chunk(server.projs,server.count.proj,sizeof(proj_type)); game_file_add_chunk(server.effects,server.count.effect,sizeof(effect_type)); game_file_add_chunk(server.decals,server.count.decal,sizeof(decal_type)); progress_draw(50); game_file_add_chunk(hud.bitmaps,hud.count.bitmap,sizeof(hud_bitmap_type)); game_file_add_chunk(hud.texts,hud.count.text,sizeof(hud_text_type)); game_file_add_chunk(hud.bars,hud.count.bar,sizeof(hud_bar_type)); game_file_add_chunk(&hud.radar,1,sizeof(hud_radar_type)); // map changes progress_draw(60); game_file_add_chunk(&map.ambient,1,sizeof(map_ambient_type)); game_file_add_chunk(&map.rain,1,sizeof(map_rain_type)); game_file_add_chunk(&map.background,1,sizeof(map_background_type)); game_file_add_chunk(&map.sky,1,sizeof(map_sky_type)); game_file_add_chunk(&map.fog,1,sizeof(map_fog_type)); progress_draw(70); game_file_add_chunk(map.groups,1,sizeof(group_type)*map.ngroup); game_file_add_chunk(map.movements,1,sizeof(movement_type)*map.nmovement); // script objects progress_draw(80); game_file_add_chunk(&js.script_current_uid,1,sizeof(int)); game_file_add_chunk(&js.count,1,sizeof(script_count_type)); game_file_add_chunk(&js.time,1,sizeof(script_time_type)); game_file_add_chunk(js.timers,js.count.timer,sizeof(timer_type)); game_file_add_chunk(js.globals,js.count.global,sizeof(global_type)); // compress and save progress_draw(90); file_paths_documents(&setup.file_path_setup,path,"Saved Games",file_name,"sav"); ok=game_file_compress_save(path,err_str); progress_draw(100); free(game_file_data); // remember last map strcpy(game_file_last_save_name,strrchr(path,'/')); // finished progress_shutdown(); return(ok); }
int main(int argc, char *argv[]) { int res; int src; int opt; int i; char *size_suf = NULL; int size_in_lines = -1; off_t size_base1000 = 0; off_t size_base1024 = 0; off_t user_defined_size = 0; off_t user_defined_size_lines = 0; struct copy_options copy_options; copy_options_init(©_options); copy_options.lines_mode = 0; copy_options.read_only = 0; copy_options.bar = &PROGRESS; while((opt = getopt(argc, argv, "rlhs:")) != -1) { switch(opt) { case 'r': copy_options.read_only = 1; break; case 'l': copy_options.lines_mode = 1; if(size_in_lines < 0) size_in_lines = 1; break; case 's': size_base1000 = parse_size(optarg, 1000, &size_suf); size_base1024 = parse_size(optarg, 1024, &size_suf); if(size_base1000 == -1) { fprintf(stderr, "Invalid argument: %s\n", optarg); exit(255); } if(strcasecmp(size_suf, "b") == 0) { size_in_lines = 0; } else if(strcasecmp(size_suf, "ln") == 0 || strcasecmp(size_suf, "l") == 0) { size_in_lines = 1; } else if(*size_suf != 0) { fprintf(stderr, "Invalid argument: %s\n", optarg); exit(255); } break; case 'h': case '?': default: usage(); exit(255); } } if(size_base1000 || size_base1024) { if(size_in_lines > 0) { if(!copy_options.lines_mode) { fprintf(stderr, "Error: size in lines has no effect without -l option!\n"); exit(255); } user_defined_size_lines = size_base1000; } else { user_defined_size = size_base1024; } } signal(SIGALRM, draw_progress); alarm(1); if(argc > optind) { for(i = optind; i < argc; i++) { if(argc - optind > 1) fprintf(stderr, "File %s:\n", argv[i]); while((src = open(argv[i], O_RDONLY)) < 1) { if(errno != EINTR) { perror(argv[i]); exit(errno); } } progress_init(&PROGRESS, STDERR_FILENO); PROGRESS.lines_mode = copy_options.lines_mode; PROGRESS.size = user_defined_size ? user_defined_size : filesize(src); PROGRESS.size_lines = user_defined_size_lines; DRAW_PROGRESS = 1; progress_draw(&PROGRESS); res = copy(src, STDOUT_FILENO, ©_options); if(res >= 0) PROGRESS.force_done = 1; progress_draw(&PROGRESS); DRAW_PROGRESS = 0; fputs("\n", stderr); if(res < 0) { perror("copy"); exit(errno); } close(src); } } else { progress_init(&PROGRESS, STDERR_FILENO); PROGRESS.lines_mode = copy_options.lines_mode; /* if used `pp < file` form */ PROGRESS.size = user_defined_size ? user_defined_size : filesize(STDIN_FILENO); PROGRESS.size_lines = user_defined_size_lines; DRAW_PROGRESS = 1; progress_draw(&PROGRESS); res = copy(STDIN_FILENO, STDOUT_FILENO, ©_options); if(res >= 0) PROGRESS.force_done = 1; progress_draw(&PROGRESS); DRAW_PROGRESS = 0; fputs("\n", stderr); } return EXIT_SUCCESS; }
void draw_progress(int s) { if(DRAW_PROGRESS) progress_draw(&PROGRESS); alarm(1); }
// Progress window task void __saveds progress_task(void) { IPCData *ipc; ProgressWindow *prog; IPCMessage *msg; // Do startup if (!(ipc=L_IPC_ProcStartup((ULONG *)&prog,0))) return; // Fix A4 pointer putreg(REG_A4,prog->pw_A4); /* // Debug? if (prog->pw_Flags&PWF_DEBUG) KPrintF("progress task : code entry %lx\n",(ULONG)progress_task); */ // Open invisibly? if (prog->pw_Flags&PWF_INVISIBLE) prog->pw_Flags&=~PWF_INVISIBLE; // Open progress window else progress_open(prog); // Loop for messages FOREVER { BOOL quit=0; // Window open? if (prog->pw_Window) { struct IntuiMessage *msg; // Look for messages while (msg=(struct IntuiMessage *)GetMsg(prog->pw_Window->UserPort)) { // Look at message switch (msg->Class) { // Key press case IDCMP_RAWKEY: // If not escape, break if (msg->Code!=0x45) break; // Abort case IDCMP_CLOSEWINDOW: case IDCMP_GADGETUP: // Task to signal? if (prog->pw_SigTask) Signal(prog->pw_SigTask,1<<prog->pw_SigBit); // Set flag prog->pw_Flags|=PWF_ABORTED; break; // Refresh case IDCMP_REFRESHWINDOW: // Refresh window BeginRefresh(prog->pw_Window); progress_draw(prog,PWF_ALL); EndRefresh(prog->pw_Window,TRUE); break; } // Reply the message ReplyMsg((struct Message *)msg); } } // Any messages? while (msg=(IPCMessage *)GetMsg(ipc->command_port)) { // Look at message switch (msg->command) { // Hide case IPC_HIDE: progress_close(prog); break; // Show case IPC_SHOW: progress_open(prog); break; // Quit case IPC_QUIT: quit=1; break; // Set parameters case PROGRESS_SET: progress_set(prog,(struct TagItem *)msg->data); break; // Get parameters case PROGRESS_GET: progress_get(prog,(struct TagItem *)msg->data); break; } // Reply to the message IPC_Reply(msg); } // Quit? if (quit) break; // Wait for messages Wait( 1<<ipc->command_port->mp_SigBit| ((prog->pw_Window)?1<<prog->pw_Window->UserPort->mp_SigBit:0)); } // Close window progress_close(prog); // Free IPC data IPC_Free(ipc); // Free control structure FreeVec(prog); }
void sub_shc_handle_input(unsigned int button) { switch (button) { case GP2X_BUTTON_B: { sfx_play(SFXBACK); if(shc_showpopup) { POPUP_empty(); xmb_deactivateFlag(XMB_NOBATT | XMB_FOCUS); shc_showpopup = 0; } else { shc_init_stage = 10; shc_timer = 0; } break; } case GP2X_BUTTON_LEFT: { if(shc_showpopup) break; sfx_play(SFXBACK); shc_init_stage = 10; shc_timer = 0; break; } case GP2X_BUTTON_UP: { if(shc_showpopup) { if(POPUP_up()) sfx_play(SFXMOVE); break; } if (shc_selection > 0) { shc_movereq += 1; shc_selection--; } break; } case GP2X_BUTTON_DOWN: { if(shc_showpopup) { if(POPUP_down()) sfx_play(SFXMOVE); break; } if (shc_selection + 1 < shc_menucount) { shc_movereq -= 1; shc_selection++; } break; } case GP2X_BUTTON_Y: { shc_node *curr = shc_root; unsigned int i = 0; for (i = 0; curr != NULL && i < shc_selection; curr = curr->next, i++); if (!shc_init_stage && curr && !shc_showpopup) { struct stat statbuf; stat(curr->path, &statbuf); if (S_ISREG(statbuf.st_mode)) { xmb_activateFlag(XMB_NOBATT | XMB_FOCUS); POPUP_setrevert(NULL, 0); POPUP_add(NULL, "Delete Shortcut", sub_shc_popexec, 0); POPUP_setselected(0); shc_showpopup = 1; } } break; } case GP2X_BUTTON_X: { shc_node *curr = shc_root; unsigned int i = 0; if (shc_showpopup) { POPUP_execsel(); sub_shc_destroy(); /* Empty list */ sub_shc_init(shc_self); /* Reload */ xmb_deactivateFlag(XMB_NOBATT | XMB_FOCUS); POPUP_empty(); shc_showpopup = 0; break; } for (i = 0; curr != NULL && i < shc_selection; curr = curr->next, i++); if (curr) { char *dir_name = (char *) calloc(1, 1024); if (config_lookup_bool(&CONFIG, "outro")) gfx_draw_outro(SDL_GetVideoSurface()); gp2xmb_deinit(); if (dir_name) { strncpy(dir_name, curr->path, 1023); chdir(dirname(dir_name)); free(dir_name); } gp2x_setclock(200); if (execl(curr->path, curr->path, NULL)) { gp2xmb_init(); /* start everything up again */ while (!xmb_getFlagState(XMB_LOADED)) { bg_draw(SDL_GetVideoSurface()); progress_draw(SDL_GetVideoSurface(), 1); SDL_Flip(SDL_GetVideoSurface()); } msgbox(SDL_GetVideoSurface(),NULL, "System Error", "Failed to execute program.", OK); msgbox_retval(); return; } } break; } default: break; } }