void *manage_egg(t_elem* ptr, float time) { t_elem *tmp; t_egg *egg; void *data; egg = ptr->data; ptr = ptr->next; egg->time -= time; if (egg->time <= 0.0000 && egg->state == EGG) { egg->state = WAITING; egg->time = 1260.0f * (1.0f / g_serv.opt.delay); egg_clot(egg); tmp = g_serv.graphic.first; while (tmp != NULL) { data = tmp->data; tmp = tmp->next; if (ehtg(data, egg) == FAIL) erase_graphic(data); } } else if (egg->time <= 0.0000) destroy_egg(egg); return (ptr); }
/* do_load: * Worker function for loading EGG scripts. */ static EGG *do_load(char *error) { EGG *egg; EGG_COMMAND *cmd; egg_line = 1; egg_unget_char = 0; error[0] = 0; egg = malloc(sizeof(EGG)); egg->frame = 0; egg->part_count = 0; egg->part_num = 0; egg->part = NULL; egg->type = NULL; egg->var = NULL; cmd = load_egg_cmd(egg, TRUE, error); if (error[0]) { destroy_egg(egg); return NULL; } process_egg_cmd(egg, NULL, NULL, cmd, TRUE, TRUE, error); destroy_egg_cmd(cmd); if (error[0]) { destroy_egg(egg); return NULL; } return egg; }
int main(int argc, char *argv[]) { int ret = 0; int i; allegro_init(); install_keyboard(); install_mouse(); install_timer(); srand(time(NULL)); for (i=1; i<argc; i++) { if (stricmp(argv[i], "-bpp") == 0) { if ((i >= argc-1) || (bpp > 0)) { usage(); return 1; } bpp = atoi(argv[++i]); } else if (stricmp(argv[i], "-frames") == 0) { if ((i >= argc-1) || (frames > 0)) { usage(); return 1; } frames = atoi(argv[++i]); } else if (stricmp(argv[i], "-size") == 0) { if ((i >= argc-2) || (size_x > 0) || (size_y > 0)) { usage(); return 1; } size_x = atoi(argv[++i]); size_y = atoi(argv[++i]); } else if (stricmp(argv[i], "-mode") == 0) { if ((i >= argc-2) || (mode_x > 0) || (mode_y > 0)) { usage(); return 1; } mode_x = atoi(argv[++i]); mode_y = atoi(argv[++i]); } else if (stricmp(argv[i], "-step") == 0) { step = TRUE; } else if (stricmp(argv[i], "-modesel") == 0) { modesel = TRUE; } else if (stricmp(argv[i], "-pregen") == 0) { pregen = TRUE; } else if (stricmp(argv[i], "-o") == 0) { if ((i >= argc-1) || (out_file)) { usage(); return 1; } out_file = argv[++i]; } else if (stricmp(argv[i], "-pal") == 0) { if ((i >= argc-1) || (pal_file)) { usage(); return 1; } pal_file = argv[++i]; } else { if ((*argv[i] == '-') || (in_file)) { usage(); return 1; } in_file = argv[i]; } } if (!in_file) { usage(); return 1; } if ((pregen) && ((frames <= 0) || (step))) { allegro_message("The '-pregen' option requires '-frames num' to be specified,\nand cannot be used at the same time as '-step'\n"); return 1; } if (!set_video_mode()) { ret = 1; goto getout; } the_egg = load_egg(in_file, error); if (!the_egg) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("%s", error); return 1; } if (size_x <= 0) size_x = 128; if (size_y <= 0) size_y = 128; if (pal_file) { BITMAP *tmp = load_bitmap(pal_file, pal); if (!tmp) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Error reading palette from '%s'\n", pal_file); ret = 1; goto getout; } destroy_bitmap(tmp); } else generate_332_palette(pal); clear(screen); set_palette(pal); text_mode(0); do { if (pregen) { textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H/2-24, makecol(128, 128, 128), "Rendering frame %d/%d", the_egg->frame+1, frames); textprintf_centre(screen, font, SCREEN_W/2, SCREEN_H/2+24, makecol(128, 128, 128), "Please Wait"); } if (update_egg(the_egg, error) != 0) { allegro_exit(); printf("Error running EGG script:\n%s\n\n", error); ret = 1; goto getout; } bmp[frame] = create_bitmap(size_x, size_y); lay_egg(the_egg, bmp[frame]); if (!pregen) { vsync(); blit(bmp[frame], screen, 0, 0, (SCREEN_W-size_x)/2, (SCREEN_H-size_y)/2, size_x, size_y); textprintf(screen, font, 0, 0, makecol(128, 128, 128), "Frame %d, %d particles ", the_egg->frame, the_egg->part_count); } if ((!pregen) && (!out_file)) { destroy_bitmap(bmp[frame]); bmp[frame] = NULL; } frame++; if ((step) || (keypressed())) { if ((readkey()&0xFF) == 27) break; clear_keybuf(); } } while (((frames <= 0) || (frame < frames)) && (frame < 4096)); if (pregen) view_animation(); if (out_file) save_animation(); getout: if (the_egg) destroy_egg(the_egg); for (i=0; i<frame; i++) if (bmp[frame]) destroy_bitmap(bmp[frame]); return ret; }