char *cleanstr(char *nbr) { char *clean; int p; int i; if ((clean = bunny_malloc(sizeof(char) * 10)) == NULL) return (NULL); clean = set_line_null(clean, 10); p = 0; while (nbr[p++] == '0' && p < 10); if (p == 10) { clean[0] = '0'; clean[1] = 0; bunny_free(nbr); return (clean); } i = 0; p--; while (nbr[p] != 0) clean[i++] = nbr[p++]; bunny_free(nbr); return (clean); }
void free_button(void *data) { t_button *s; s = data; bunny_free(s->link); bunny_free(s); }
void free_sampler(t_data *data) { int i; i = 0; while (i < NB_SAMPLES) { bunny_free(data->samples[i]->pitch); bunny_free(data->samples[i]->duration); bunny_delete_ini(data->samples[i]->ini); bunny_delete_sound(&data->samples[i]->music->sound); i += 1; } }
void delete_item(t_item *item) { int i; i = 0; if (!item) return ; while (item->sprite[i]) { bunny_delete_clipable(&item->sprite[i]->clipable); bunny_free(item->pos); bunny_free(item->selected); i++; } }
void tekline2(t_bunny_pixelarray *pix, t_bunny_position *pos, int *coords, t_color *color) { int i; int cumul; t_color *col; cumul = coords[5] / 2; i = 1; while (i <= coords[5]) { pos[0].y += coords[3]; cumul += coords[4]; if (cumul >= coords[5]) { cumul -= coords[5]; pos[0].x += coords[2]; } col = tekline_colorconvert(i, coords[5], color); tekpixel(pix, pos, col); bunny_free(col); i++; } }
int free_on_musicerror(t_main_menu *data) { bunny_stop(data->win); bunny_delete_clipable(&data->pix->clipable); bunny_free(data); return (1); }
int main(int ac, char **av) { t_data data; set_max_heap_size(30); data.sup = bunny_malloc(sizeof(struct s_support)); if (ac == 2) data.sup->name = av[1]; else data.sup->name = NULL; data.sup->pos.x = 0; data.sup->pos.y = 0; if (init_button(&data) == 1) return (1); init_main_variables(&data); init_all_pixarray(&data); data.window = bunny_start(WIN_WIDTH, WIN_HEIGHT, 0, "Chroma"); display_it(&data, data.pixbg, 0, 0); display_it(&data, data.pixbgtool, WIN_WIDTH - 255, 150); display_it(&data, data.pixbgcalc, WIN_WIDTH - 255, WIN_HEIGHT - 282); bunny_set_loop_main_function(mainloop); bunny_set_key_response(key_actions); bunny_set_click_response(click_actions); bunny_loop(data.window, 60, &data); bunny_stop(data.window); delete_all_clipables(&data); empty_list(data.tool, free_calc); bunny_free(data.tool); return (0); }
void bunny_delete_clipable(t_bunny_clipable *clip) { size_t *type = (size_t*)clip; switch (*type) { case GRAPHIC_RAM: { struct bunny_picture *pic = (struct bunny_picture*)clip; delete pic->texture; delete pic; return ; } case SYSTEM_RAM: { struct bunny_pixelarray *pic = (struct bunny_pixelarray*)clip; bunny_free(pic->rawpixels); delete pic; return ; } default: return ; } }
int main(int ac, char **av) { t_ray *ray; if (ac < 2) { my_putstr_err("Error : No .ini file.\nAborting...\n"); return (0); } if ((ray = bunny_malloc(sizeof(t_ray))) == NULL) return (1); if ((init_my_struct(ray)) == 1) { my_putstr_err("Fatal error ! Malloc failed\n"); return (1); } ini_loader(ac, av, ray); if ((ray->pix = bunny_new_pixelarray(ray->width, ray->height)) == NULL) return (1); ray->win = bunny_start(ray->width, ray->height, false, "Raytracer 1 | uberti_l"); bunny_set_loop_main_function(main_loop); bunny_loop(ray->win, 60, ray); bunny_delete_clipable(&ray->pix->clipable); bunny_stop(ray->win); bunny_free(ray); return (0); }
int save(t_struct *my_st, int tmp, int j) { int i; int fd; unsigned int *pixarray; pixarray = my_st->pix->pixels; if (tmp == 0) { good_save(my_st); if ((fd = open(my_st->file, O_RDWR | O_CREAT, 00644)) == 1) return (1); } else if ((fd = open(".tmp", O_RDWR | O_CREAT, 00644)) == 1) return (1); while (j++ < my_st->pix->clipable.clip_height) { i = 160; while (i++ < my_st->pix->clipable.clip_width) write(fd, &pixarray[i + j * my_st->pix->clipable.clip_width], 4); } close(fd); bunny_free(my_st->file); if ((my_st->file = bunny_malloc(sizeof(char) * 1)) == NULL) return (EXIT_ON_ERROR); my_st->file[0] = '\0'; return (0); }
int import_format_fox(int fd, t_tekpain *paint) { t_format_fox_header header; t_layer *cur; char name[1024]; unsigned int *pixels; if (read(fd, &header, sizeof(t_format_fox_header)) == -1) return (my_printf(2, "Erreur read import_format_fox\n")); paint->workzone = header.workzone; if ((pixels = bunny_malloc(sizeof(unsigned int) * header.workzone.x * header.workzone.y)) == NULL) return (-1); while (header.count--) { read(fd, &name, sizeof(char) * 1024); layer_add(paint, layer_new(name, bunny_new_pixelarray(header.workzone.x, header.workzone.y), 0)); cur = paint->current_layer->data; read(fd, pixels, sizeof(unsigned int) * header.workzone.x * header.workzone.y); my_memcpy(cur->pix->pixels, pixels, sizeof(unsigned int) * header.workzone.x * header.workzone.y); } bunny_free(pixels); return (0); }
int main(int ac, char **av) { t_data data; /* t_color color[2]; color[0].full = BLACK; color[1].full = RED;*/ if (ac != 2) return (-1); data.ini = av[1]; if (data.win == NULL) return (-1); if ((data.wolf = init_map(data.ini)) == (t_wolf *)-1) return (EXIT_ON_ERROR); data.win = bunny_start(1200, 800, false, "Wolf3D"); data.pix = bunny_new_pixelarray(1200, 800); data.color[0].argb[0] = 100; data.color[0].argb[1] = 100; data.color[0].argb[2] = 100; data.color[0].argb[3] = 255; init_value(data.wolf); bunny_set_loop_main_function((t_bunny_loop)main_loop); bunny_loop(data.win, 22, &data); bunny_free(data.wolf); bunny_delete_clipable(&data.pix->clipable); bunny_stop(data.win); return (0); }
void delete_node(t_scope *node, t_scope **head) { t_scope *temp; t_scope *current; t_scope *previous; if (node == *head) { temp = *head; *head = (*head)->next; return; } current = (*head)->next; previous = *head; while (current != NULL && previous != NULL) { if (node == current) { temp = current; previous->next = current->next; bunny_free(temp); return; } previous = current; current = current->next; } return; }
void print_screen(t_base *a) { t_bunny_position pos; int i; i = -1; a->color_pixel = bunny_malloc(sizeof(t_color_pixel)); while (++i < a->pix->clipable.clip_width * a->pix->clipable.clip_height) { a->color_pixel->delt = -1; pos.x = i % a->pix->clipable.clip_width; pos.y = i / a->pix->clipable.clip_width; print_pixel(a, pos); if (a->color_pixel->delt != -1) { dist_light(a); pixel(a->pix, &pos, a->color_pixel->color); } } bunny_free(a->color_pixel); while (a->element) a->element = del_mylist(a->element); while (a->light) a->light = del_mylist(a->light); }
t_bunny_response my_fct_free(t_data *data, int error_true) { bunny_delete_clipable(&data->pix->clipable); bunny_stop(data->win); bunny_free(data); if (error_true == 1) return (EXIT_ON_ERROR); return (EXIT_ON_SUCCESS); }
void clean(t_data *data) { int curs; curs = 0; bunny_delete_ini(data->ini); bunny_delete_sound(&data->music->sound); bunny_delete_sound(&data->sound->sound); bunny_delete_sound(&data->bad->sound); bunny_free(data->map->spawn); while (curs != data->map->height) { bunny_free(data->map->data[curs]); curs++; } bunny_free(data->map); bunny_free(data->pl); }
void free_data(t_data data[4]) { int i; i = 0; while (i < 4) { bunny_free(data[i].fptr_objs); i++; } }
char *str_realloc(char *str, int size) { char *tmp; if ((tmp = bunny_malloc(sizeof(char) * size)) == NULL) return (NULL); str_all(tmp, NULL, 0, size); str_all(tmp, str, 1, 0); bunny_free(str); return (tmp); }
void free_buttons(t_button *button) { int i; i = 0; while (i < 4) { bunny_free(button[i].name); bunny_delete_clipable(&button[i].sprite->clipable); bunny_delete_clipable(&button[i].active_sprite->clipable); i++; } }
void analyse_codes(const char *str, int *i, t_text *text, t_bunny_position *pos) { int *recup; int move; int idx; move = get_all_codes(str, *i, &recup); if (move == 0 || recup == NULL) return ; idx = -1; while (++idx < *recup) parse_glob(recup, idx, text); pos[2].x -= 6 * 3; *i += move; bunny_free(recup); }
int delete_inter_list(t_inter *root) { t_inter *it; t_inter *tmp; if (root == NULL) return (0); it = root; while (it != NULL) { tmp = it; it = it->next; bunny_free(tmp); } return (0); }
void del_rest_of_the_list(t_data *data) { t_elem *old; t_elem *tmp; tmp = data->current->next; while (tmp) { old = tmp; tmp = tmp->next; my_free_inttab(old->grid, GRID_HEIGHT); bunny_free(old); } data->current = data->list.tail; data->current->next = NULL; }
int delete_false_hit_objects(t_rt *s) { t_object *it; it = s->obj_hit; if (s->obj_hit->next == NULL) return (0); while (it->next != NULL && it->next->next != NULL) it = it->next; while (it->next->real == 0) { bunny_free(it->next); it->next = NULL; it = it->prev; } return (0); }
void my_save(t_bunny_pixelarray *pix, char *filename) { unsigned int *data; int i; int size; i = 0; size = (pix->clipable.clip_width * pix->clipable.clip_height); data = bunny_malloc(sizeof(unsigned int) * (size + 1)); if (data == NULL) return; while (i < size) { data[i] = ((unsigned int *)pix->pixels)[i]; i = i + 1; } create_file(data, filename, pix); bunny_free(data); }
void free_data(t_data *data) { int i; i = -1; free_buttons(data->menu->buttons); while (++i < 14) { bunny_free(data->tab[i].name); bunny_delete_clipable(&data->tab[i].front->clipable); delete_item(data->tab[i].item); if (i == 0 || i == 1 || i == 4 || i == 9) bunny_delete_clipable(&data->tab[i].back->clipable); else if (i == 3 || i == 5 || i == 6) { bunny_delete_clipable(&data->tab[i].back->clipable); bunny_delete_clipable(&data->tab[i].middle->clipable); } } }
void my_free_board(t_board *board) { int i; i = - 1; while (board->button[++i] != NULL) bunny_free(board->button[i]); i = - 1; while (board->obj[++i] != NULL) { bunny_free(board->obj[i]->calque); bunny_free(board->obj[i]); } bunny_delete_clipable(&board->calque->pix->clipable); bunny_free(board->calque); bunny_free(board->button); bunny_free(board->obj); bunny_free(board); }
char save_tkp(t_tekpaint *tekpaint) { char *buffer; int readv; if (NULL == (buffer = bunny_malloc(sizeof(char)*101))) return (0); clean_buffer(buffer, 101); my_putstr("Entrez le chemin du fichier à sauvegarder : "); readv = read(0, buffer, 100); remove_carriage_return(buffer); buffer = my_strcat(buffer, ".tkp"); if (save_pixelarray(buffer, tekpaint->workplan.buffer) && readv > 0) { my_putstr("Fichier sauvegardé vers : "); my_putstr(buffer); my_putchar('\n'); } else my_putstr("Erreur durant la sauvegarde, try again\n"); bunny_free(buffer); return (1); }
int free_on_winerror(t_main_menu *data) { bunny_free(data); return (1); }
int free_on_pixerror(t_main_menu *data) { bunny_stop(data->win); bunny_free(data); return (1); }
void mouse_history_remove(t_node *node) { bunny_free(node->data); bunny_free(node); }