void lib3ds_util_insert_array(void ***ptr, int *n, int *size, void *element, int index) { int i; assert(ptr && n && size && element); i = ((index >= 0) && (index < *n)) ? index : *n; if (i >= *size) { int new_size = 2 * (*size); #ifdef _DEBUG if (new_size < 1) { new_size = 1; } #else if (new_size < 32) { new_size = 32; } #endif lib3ds_util_reserve_array(ptr, n, size, new_size, FALSE, NULL); } assert(*ptr); if (i < *n) { memmove(&(*ptr)[i+1], &(*ptr)[i], sizeof(void*) * (*n - i)); } (*ptr)[i] = element; *n = *n + 1; }
void lib3ds_file_reserve_cameras(Lib3dsFile *file, int size, int force) { assert(file); lib3ds_util_reserve_array((void***)&file->cameras, &file->ncameras, &file->cameras_size, size, force, (Lib3dsFreeFunc)lib3ds_camera_free); }
void lib3ds_file_reserve_lights(Lib3dsFile *file, int size, int force) { assert(file); lib3ds_util_reserve_array((void***)&file->lights, &file->nlights, &file->lights_size, size, force, (Lib3dsFreeFunc)lib3ds_light_free); }
void lib3ds_file_reserve_materials(Lib3dsFile *file, int size, int force) { assert(file); lib3ds_util_reserve_array((void***)&file->materials, &file->nmaterials, &file->materials_size, size, force, (Lib3dsFreeFunc)lib3ds_material_free); }