void export_to(sd_font *font, const char *filename, int split) { if(split) { char path[256]; sd_rgba_image ch_img; sd_rgba_image_create(&ch_img, font->h, font->h); for(int i = 32; i < 256; i++) { sd_font_decode(font, &ch_img, (char)(i-32), 0, 0, 0); sprintf(path, "%s/uni%04x.png", filename, i); int ret = sd_rgba_image_to_png(&ch_img, path); if(ret != SD_SUCCESS) { printf("Error while exporting to %s: %s.", path, sd_get_error(ret)); } } sd_rgba_image_free(&ch_img); } else { sd_rgba_image ch_img; sd_rgba_image dst_img; sd_rgba_image_create(&dst_img, font->h * 16, font->h * 16); sd_rgba_image_create(&ch_img, font->h, font->h); for(int i = 32; i < 256; i++) { int x = i % 16; int y = i / 16; sd_font_decode(font, &ch_img, (char)(i-32), 0, 0, 0); sd_rgba_image_blit(&dst_img, &ch_img, x * font->h, y * font->h); } sd_rgba_image_free(&ch_img); int ret = sd_rgba_image_to_png(&dst_img, filename); if(ret != SD_SUCCESS) { printf("Error while exporting to %s: %s.", filename, sd_get_error(ret)); } sd_rgba_image_free(&dst_img); } }
void sprite_export_key(sd_sprite *s, const char **key, int kcount, const char *filename, sd_bk_file *bk) { switch(sprite_key_get_id(key[0])) { case 1: case 2: case 3: printf("Value fetching not supported for this key.\n"); break; case 4: { sd_palette *pal = sd_bk_get_palette(bk, 0); if(pal == NULL) { printf("Palette required for exporting to PNG.\n"); return; } sd_vga_image img; int ret = sd_sprite_vga_decode(&img, s); if(ret != SD_SUCCESS) { printf("Sprite decoding failed.\n"); return; } ret = sd_vga_image_to_png(&img, pal, filename); sd_vga_image_free(&img); if(ret != SD_SUCCESS) { printf("Error while exporting sprite to %s: %s\n", filename, sd_get_error(ret)); return; } } break; default: printf("Unknown key!\n"); } }
void sprite_import_key(sd_sprite *s, const char **key, int kcount, const char *filename, int transparent_index) { switch(sprite_key_get_id(key[0])) { case 1: case 2: case 3: printf("Value fetching not supported for this key.\n"); break; case 4: { sd_vga_image img; int ret = sd_vga_image_from_png(&img, filename); if(ret != SD_SUCCESS) { printf("Error while importing sprite from %s: %s\n", filename, sd_get_error(ret)); return; } ret = sd_vga_image_stencil_index(&img, transparent_index); if(ret != SD_SUCCESS) { printf("Stencil oculd not be set: %s\n", sd_get_error(ret)); return; } ret = sd_sprite_vga_encode(s, &img); sd_vga_image_free(&img); if(ret != SD_SUCCESS) { printf("Error while converting VGA image to sprite.\n"); return; } } break; default: printf("Unknown key!\n"); } }
void player_reload_with_str(object *obj, const char* custom_str) { // Free and reload parser sd_script_free(&obj->animation_state.parser); sd_script_create(&obj->animation_state.parser); int ret; int err_pos; ret = sd_script_decode(&obj->animation_state.parser, custom_str, &err_pos); if(ret != SD_SUCCESS) { PERROR("Decoder error %s at position %d in string \"%s\"", sd_get_error(ret), err_pos, custom_str); } // Set player state player_reset(obj); obj->animation_state.reverse = 0; obj->slide_state.timer = 0; obj->slide_state.vel = vec2f_create(0,0); obj->enemy_slide_state.timer = 0; obj->enemy_slide_state.dest = vec2i_create(0,0); obj->enemy_slide_state.duration = 0; obj->hit_frames = 0; obj->can_hit = 0; }
int main(int argc, char *argv[]) { SDL_AudioSpec want, have; SDL_AudioDeviceID dev; Streamer streamer; int retcode = 0; // Init SDL Audio if(SDL_Init(SDL_INIT_AUDIO) != 0) { fprintf(stderr, "Error: %s\n", SDL_GetError()); return 1; } // commandline argument parser options struct arg_lit *help = arg_lit0("h", "help", "print this help and exit"); struct arg_lit *vers = arg_lit0("v", "version", "print version information and exit"); struct arg_file *file = arg_file1("f", "file", "<file>", "SOUNDS.DAT file"); struct arg_file *output = arg_file0("o", "output", "<file>", "Output sounds file"); struct arg_int *sid = arg_int0("s", "sound", "<int>", "Sound ID"); struct arg_int *sampleprint = arg_int0(NULL, "print", "<int>", "Print first n bytes from selected sound"); struct arg_lit *play = arg_lit0("p", "play", "Play selected sound"); struct arg_file *export = arg_file0("e", "export", "<file>", "Export selected sound to AU file"); struct arg_file *import = arg_file0("i", "import", "<file>", "Import selected sound from AU file"); struct arg_end *end = arg_end(20); void* argtable[] = {help,vers,file,output,sid,sampleprint,play,export,import,end}; const char* progname = "soundtool"; // Make sure everything got allocated if(arg_nullcheck(argtable) != 0) { printf("%s: insufficient memory\n", progname); goto exit_0; } // Parse arguments int nerrors = arg_parse(argc, argv, argtable); // Handle help if(help->count > 0) { printf("Usage: %s", progname); arg_print_syntax(stdout, argtable, "\n"); printf("\nArguments:\n"); arg_print_glossary(stdout, argtable, "%-25s %s\n"); goto exit_0; } // Handle version if(vers->count > 0) { printf("%s v0.1\n", progname); printf("Command line One Must Fall 2097 SOUNDS.DAT file editor.\n"); printf("Source code is available at https://github.com/omf2097 under MIT license.\n"); printf("(C) 2013 Tuomas Virtanen\n"); goto exit_0; } // Handle errors if(nerrors > 0) { arg_print_errors(stdout, end, progname); printf("Try '%s --help' for more information.\n", progname); goto exit_0; } // Open sounds.dat sd_sound_file sf; sd_sounds_create(&sf); retcode = sd_sounds_load(&sf, file->filename[0]); if(retcode) { printf("Error %d: %s\n", retcode, sd_get_error(retcode)); goto exit_1; } if(sid->count > 0) { // Sound ID to handle int sound_id = sid->ival[0]; const sd_sound *sound = sd_sounds_get(&sf, sound_id-1); if(sound == NULL) { printf("Invalid sound ID"); goto exit_1; } if(sampleprint->count > 0) { int count = (sampleprint->ival[0] > sound->len) ? sound->len : sampleprint->ival[0]; printf("Sample size = %d\n", sound->len); printf("Unknown = %d\n", sound->unknown); printf("Attempting to print %d first bytes.\n", count); for(int i = 0; i < count; i++) { unsigned int s = sound->data[i] & 0xFF; printf("%2x ", s); } } else if(play->count > 0) { printf("Attempting to play sample #%d.\n", sound_id); // Make sure there is data at requested ID position if(sound->len <= 0) { printf("Sample does not contain data.\n"); goto exit_1; } // Streamer streamer.size = sound->len; streamer.pos = 0; streamer.data = sound->data; // Initialize required audio SDL_zero(want); want.freq = 8000; want.format = AUDIO_U8; want.channels = 1; want.samples = 4096; want.callback = stream; want.userdata = &streamer; // Open device, play file dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, 0); if(dev == 0) { printf("Failed to open audio dev: %s\n", SDL_GetError()); goto exit_0; } else { if(have.format != want.format) { printf("Could not get correct playback format.\n"); } else { printf("Starting playback ...\n"); SDL_PauseAudioDevice(dev, 0); while(streamer.pos < streamer.size) { SDL_Delay(100); } printf("All done.\n"); } SDL_CloseAudioDevice(dev); } } else if(import->count > 0) { if(sd_sound_from_au(&sf, sound_id, import->filename[0]) != SD_SUCCESS) { printf("Importing sample %d from file %s failed.\n", sound_id, import->filename[0]); } else { printf("Importing sample %d from file %s succeeded.\n", sound_id, import->filename[0]); } } else if(export->count > 0) { if(sd_sound_to_au(&sf, sound_id, export->filename[0]) != SD_SUCCESS) { printf("Exporting sample %d to file %s failed.\n", sound_id, export->filename[0]); } else { printf("Exporting sample %d to file %s succeeded.\n", sound_id, export->filename[0]); } } else {
int main(int argc, char* argv[]) { // commandline argument parser options struct arg_lit *help = arg_lit0("h", "help", "print this help and exit"); struct arg_lit *vers = arg_lit0("v", "version", "print version information and exit"); struct arg_file *file = arg_file1("f", "file", "<file>", "Input altpals file"); struct arg_int *pal = arg_int1("p", "palette", "<number>", "Select a palette"); struct arg_file *export = arg_file0("e", "export", "<file>", "Export selected palette to GPL file"); struct arg_file *import = arg_file0("i", "import", "<file>", "Import selected palette from GPL file"); struct arg_file *output = arg_file0("o", "output", "<file>", "Output altpals file"); struct arg_end *end = arg_end(20); void* argtable[] = {help,vers,file,pal,output,import,export,end}; const char* progname = "altpaltool"; // Make sure everything got allocated if(arg_nullcheck(argtable) != 0) { printf("%s: insufficient memory\n", progname); goto exit_0; } // Parse arguments int nerrors = arg_parse(argc, argv, argtable); // Handle help if(help->count > 0) { printf("Usage: %s", progname); arg_print_syntax(stdout, argtable, "\n"); printf("\nArguments:\n"); arg_print_glossary(stdout, argtable, "%-25s %s\n"); goto exit_0; } // Handle version if(vers->count > 0) { printf("%s v0.1\n", progname); printf("Command line One Must Fall 2097 Altpals file editor.\n"); printf("Source code is available at https://github.com/omf2097 under MIT license.\n"); printf("(C) 2014 Tuomas Virtanen\n"); goto exit_0; } // Handle errors if(nerrors > 0) { arg_print_errors(stdout, end, progname); printf("Try '%s --help' for more information.\n", progname); goto exit_0; } // Need import or export ... if(pal->count > 0 && import->count == 0 && export->count == 0) { printf("Define either --import or --export with --palette!\n"); goto exit_0; } // Make sure output is set if(import->count > 0 && output->count <= 0) { printf("Define --output with --import.\n"); goto exit_0; } // Load file sd_altpal_file alt; sd_altpal_create(&alt); int ret = sd_altpals_load(&alt, file->filename[0]); if(ret != SD_SUCCESS) { printf("Unable to load altpals file %s: %s.\n", file->filename[0], sd_get_error(ret)); goto exit_1; } // Check ID int pal_id = pal->ival[0]; if(pal_id < 0 || pal_id > SD_ALTPALS_PALETTES) { printf("Palette index %d does not exist!\n", pal_id); goto exit_1; } // Check what to do if(export->count > 0) { ret = sd_palette_to_gimp_palette(&alt.palettes[pal_id], export->filename[0]); if(ret == SD_SUCCESS) { printf("Palette %d exported to file %s succesfully.\n", pal_id, export->filename[0]); } else {
// Init mechlab int mechlab_create(scene *scene) { // Alloc mechlab_local *local = malloc(sizeof(mechlab_local)); memset(local, 0, sizeof(mechlab_local)); animation *bg_ani[3]; // Init the background for(int i = 0; i < sizeof(bg_ani)/sizeof(animation*); i++) { sprite *spr = sprite_copy(animation_get_sprite(&bk_get_info(&scene->bk_data, 14)->ani, i)); bg_ani[i] = create_animation_from_single(spr, spr->pos); object_create(&local->bg_obj[i], scene->gs, vec2i_create(0,0), vec2f_create(0,0)); object_set_animation(&local->bg_obj[i], bg_ani[i]); object_select_sprite(&local->bg_obj[i], 0); object_set_repeat(&local->bg_obj[i], 1); object_set_animation_owner(&local->bg_obj[i], OWNER_OBJECT); } // Find last saved game ... game_player *p1 = game_state_get_player(scene->gs, 0); const char* last_name = settings_get()->tournament.last_name; if(last_name == NULL || strlen(last_name) == 0) { last_name = NULL; } // ... and attempt to load it, if one was found. if(last_name != NULL) { int ret = sg_load(&p1->pilot, last_name); if(ret != SD_SUCCESS) { PERROR("Could not load saved game for playername '%s': %s!", last_name, sd_get_error(ret)); last_name = NULL; } else { DEBUG("Loaded savegame for playername '%s'.", last_name); } } // Either initialize a new tournament if no savegame is found, // or just show old savegame stats directly if it was. local->dashtype = DASHBOARD_NONE; if(last_name == NULL) { DEBUG("No previous savegame found"); } else { DEBUG("Previous savegame found; loading as default."); } mechlab_select_dashboard(scene, local, DASHBOARD_STATS); // Create main menu local->frame = guiframe_create(0, 0, 320, 200); guiframe_set_root(local->frame, lab_menu_main_create(scene)); guiframe_layout(local->frame); // Load HAR animation *initial_har_ani = &bk_get_info(&scene->bk_data, 15 + p1->pilot.har_id)->ani; local->mech = malloc(sizeof(object)); object_create(local->mech, scene->gs, vec2i_create(0,0), vec2f_create(0,0)); object_set_animation(local->mech, initial_har_ani); object_set_repeat(local->mech, 1); object_dynamic_tick(local->mech); // Set callbacks scene_set_userdata(scene, local); scene_set_input_poll_cb(scene, mechlab_input_tick); scene_set_event_cb(scene, mechlab_event); scene_set_render_cb(scene, mechlab_render); scene_set_free_cb(scene, mechlab_free); scene_set_dynamic_tick_cb(scene, mechlab_tick); // Pick renderer video_select_renderer(VIDEO_RENDERER_HW); return 0; }
int main(int argc, char *argv[]) { // commandline argument parser options struct arg_lit *help = arg_lit0("h", "help", "print this help and exit"); struct arg_lit *vers = arg_lit0("v", "version", "print version information and exit"); struct arg_file *file = arg_file1("f", "file", "<file>", "Score file"); struct arg_int *page = arg_int0("p", "page", "<int>", "Page ID"); struct arg_file *output = arg_file0("o", "output", "<file>", "Output file"); struct arg_end *end = arg_end(20); void* argtable[] = {help,vers,file,page,output,end}; const char* progname = "scoretool"; // Make sure everything got allocated if(arg_nullcheck(argtable) != 0) { printf("%s: insufficient memory\n", progname); goto exit_0; } // Parse arguments int nerrors = arg_parse(argc, argv, argtable); // Handle help if(help->count > 0) { printf("Usage: %s", progname); arg_print_syntax(stdout, argtable, "\n"); printf("\nArguments:\n"); arg_print_glossary(stdout, argtable, "%-25s %s\n"); goto exit_0; } // Handle version if(vers->count > 0) { printf("%s v0.1\n", progname); printf("Command line One Must Fall 2097 Score file editor.\n"); printf("Source code is available at https://github.com/omf2097 under MIT license.\n"); printf("(C) 2014 Tuomas Virtanen\n"); goto exit_0; } // Handle errors if(nerrors > 0) { arg_print_errors(stdout, end, progname); printf("Try '%s --help' for more information.\n", progname); goto exit_0; } // Get score information sd_score score; sd_score_create(&score); int ret = sd_score_load(&score, file->filename[0]); if(ret != SD_SUCCESS) { printf("Score file %s could not be loaded: %s\n", file->filename[0], sd_get_error(ret)); goto exit_0; } // See if we want to print a single page or all pages if(page->count > 0) { int page_id = page->ival[0]; if(page_id < 0 || page_id >= SD_SCORE_PAGES) { printf("Page must be between 0 and 3.\n"); goto exit_1; } // Print only this page print_page(&score, page_id); } else { for(int i = 0; i < SD_SCORE_PAGES; i++) { print_page(&score, i); printf("\n"); } } // Save if necessary if(output->count > 0) { ret = sd_score_save(&score, output->filename[0]); if(ret != SD_SUCCESS) { printf("Failed to save scores file to %s: %s\n", output->filename[0], sd_get_error(ret)); } } exit_1: sd_score_free(&score); exit_0: arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 0; }
int main(int argc, char* argv[]) { // commandline argument parser options struct arg_lit *help = arg_lit0("h", "help", "print this help and exit"); struct arg_lit *vers = arg_lit0("v", "version", "print version information and exit"); struct arg_file *file = arg_file1("f", "file", "<file>", "font file"); struct arg_int *fh = arg_int1("g", "height", "<value>", "font height in pixels (6 or 8)"); struct arg_str *text = arg_str0("t", "text", "<value>", "text to show"); struct arg_int *scale = arg_int0("s", "scale", "<value>", "scaling for the window"); struct arg_file *export = arg_file0("e", "export", "<file>", "Export the full font to a PNG file"); struct arg_lit *split = arg_lit0(NULL, "split", "Split to separate PNG files (set path in -e)."); struct arg_end *end = arg_end(20); void* argtable[] = {help,vers,file,fh,text,scale,export,split,end}; const char* progname = "fonttool"; // Make sure everything got allocated if(arg_nullcheck(argtable) != 0) { printf("%s: insufficient memory\n", progname); goto exit_0; } // Parse arguments int nerrors = arg_parse(argc, argv, argtable); // Handle help if(help->count > 0) { printf("Usage: %s", progname); arg_print_syntax(stdout, argtable, "\n"); printf("\nArguments:\n"); arg_print_glossary(stdout, argtable, "%-25s %s\n"); goto exit_0; } // Handle version if(vers->count > 0) { printf("%s v0.1\n", progname); printf("Command line One Must Fall 2097 Font file editor.\n"); printf("Source code is available at https://github.com/omf2097 under MIT license.\n"); printf("(C) 2013 Tuomas Virtanen\n"); goto exit_0; } // Handle errors if(nerrors > 0) { arg_print_errors(stdout, end, progname); printf("Try '%s --help' for more information.\n", progname); goto exit_0; } // Requite either export or text if(export->count <= 0 && text->count <= 0) { printf("Use either --export or --text arguments!\n"); goto exit_0; } // Font size int _fs = fh->ival[0]; if(_fs < 6 || _fs > 8 || _fs == 7) { printf("Only valid values for fontsize are 6 and 8.\n"); goto exit_0; } // Load fonts sd_font font; sd_font_create(&font); int ret = sd_font_load(&font, file->filename[0], _fs); if(ret != SD_SUCCESS) { printf("Couldn't load small font file! Error [%d] %s.\n", ret, sd_get_error(ret)); goto exit_1; } // Export or display if(export->count > 0) { export_to(&font, export->filename[0], (split->count > 0)); } else {