Cleanup: Keep common IDTypeInfo code separated from ID type specific API.

Also remove useless IDTypeInfo callbacks.
This commit is contained in:
Bastien Montagne 2020-05-20 16:45:47 +02:00
parent 4d613018ee
commit 2059b30ee2
2 changed files with 64 additions and 72 deletions

View File

@ -48,23 +48,7 @@
/* PointCloud datablock */
static void pointcloud_random(PointCloud *pointcloud)
{
pointcloud->totpoint = 400;
CustomData_realloc(&pointcloud->pdata, pointcloud->totpoint);
BKE_pointcloud_update_customdata_pointers(pointcloud);
RNG *rng = BLI_rng_new(0);
for (int i = 0; i < pointcloud->totpoint; i++) {
pointcloud->co[i][0] = 2.0f * BLI_rng_get_float(rng) - 1.0f;
pointcloud->co[i][1] = 2.0f * BLI_rng_get_float(rng) - 1.0f;
pointcloud->co[i][2] = 2.0f * BLI_rng_get_float(rng) - 1.0f;
pointcloud->radius[i] = 0.05f * BLI_rng_get_float(rng);
}
BLI_rng_free(rng);
}
static void pointcloud_random(PointCloud *pointcloud);
static void pointcloud_init_data(ID *id)
{
@ -81,15 +65,6 @@ static void pointcloud_init_data(ID *id)
pointcloud_random(pointcloud);
}
void *BKE_pointcloud_add(Main *bmain, const char *name)
{
PointCloud *pointcloud = BKE_libblock_alloc(bmain, ID_PT, name, 0);
pointcloud_init_data(&pointcloud->id);
return pointcloud;
}
static void pointcloud_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int flag)
{
PointCloud *pointcloud_dst = (PointCloud *)id_dst;
@ -105,18 +80,6 @@ static void pointcloud_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_s
BKE_pointcloud_update_customdata_pointers(pointcloud_dst);
}
PointCloud *BKE_pointcloud_copy(Main *bmain, const PointCloud *pointcloud)
{
PointCloud *pointcloud_copy;
BKE_id_copy(bmain, &pointcloud->id, (ID **)&pointcloud_copy);
return pointcloud_copy;
}
static void pointcloud_make_local(Main *bmain, ID *id, const int flags)
{
BKE_lib_id_make_local_generic(bmain, id, flags);
}
static void pointcloud_free_data(ID *id)
{
PointCloud *pointcloud = (PointCloud *)id;
@ -139,9 +102,43 @@ IDTypeInfo IDType_ID_PT = {
.init_data = pointcloud_init_data,
.copy_data = pointcloud_copy_data,
.free_data = pointcloud_free_data,
.make_local = pointcloud_make_local,
.make_local = NULL,
};
static void pointcloud_random(PointCloud *pointcloud)
{
pointcloud->totpoint = 400;
CustomData_realloc(&pointcloud->pdata, pointcloud->totpoint);
BKE_pointcloud_update_customdata_pointers(pointcloud);
RNG *rng = BLI_rng_new(0);
for (int i = 0; i < pointcloud->totpoint; i++) {
pointcloud->co[i][0] = 2.0f * BLI_rng_get_float(rng) - 1.0f;
pointcloud->co[i][1] = 2.0f * BLI_rng_get_float(rng) - 1.0f;
pointcloud->co[i][2] = 2.0f * BLI_rng_get_float(rng) - 1.0f;
pointcloud->radius[i] = 0.05f * BLI_rng_get_float(rng);
}
BLI_rng_free(rng);
}
void *BKE_pointcloud_add(Main *bmain, const char *name)
{
PointCloud *pointcloud = BKE_libblock_alloc(bmain, ID_PT, name, 0);
pointcloud_init_data(&pointcloud->id);
return pointcloud;
}
PointCloud *BKE_pointcloud_copy(Main *bmain, const PointCloud *pointcloud)
{
PointCloud *pointcloud_copy;
BKE_id_copy(bmain, &pointcloud->id, (ID **)&pointcloud_copy);
return pointcloud_copy;
}
BoundBox *BKE_pointcloud_boundbox_get(Object *ob)
{
BLI_assert(ob->type == OB_POINTCLOUD);

View File

@ -442,26 +442,6 @@ static void volume_init_data(ID *id)
BKE_volume_init_grids(volume);
}
void BKE_volume_init_grids(Volume *volume)
{
#ifdef WITH_OPENVDB
if (volume->runtime.grids == NULL) {
volume->runtime.grids = OBJECT_GUARDED_NEW(VolumeGridVector);
}
#else
UNUSED_VARS(volume);
#endif
}
void *BKE_volume_add(Main *bmain, const char *name)
{
Volume *volume = (Volume *)BKE_libblock_alloc(bmain, ID_VO, name, 0);
volume_init_data(&volume->id);
return volume;
}
static void volume_copy_data(Main *UNUSED(bmain),
ID *id_dst,
const ID *id_src,
@ -483,18 +463,6 @@ static void volume_copy_data(Main *UNUSED(bmain),
#endif
}
Volume *BKE_volume_copy(Main *bmain, const Volume *volume)
{
Volume *volume_copy;
BKE_id_copy(bmain, &volume->id, (ID **)&volume_copy);
return volume_copy;
}
static void volume_make_local(Main *bmain, ID *id, const int flags)
{
BKE_lib_id_make_local_generic(bmain, id, flags);
}
static void volume_free_data(ID *id)
{
Volume *volume = (Volume *)id;
@ -519,9 +487,36 @@ IDTypeInfo IDType_ID_VO = {
/* init_data */ volume_init_data,
/* copy_data */ volume_copy_data,
/* free_data */ volume_free_data,
/* make_local */ volume_make_local,
/* make_local */ nullptr,
};
void BKE_volume_init_grids(Volume *volume)
{
#ifdef WITH_OPENVDB
if (volume->runtime.grids == NULL) {
volume->runtime.grids = OBJECT_GUARDED_NEW(VolumeGridVector);
}
#else
UNUSED_VARS(volume);
#endif
}
void *BKE_volume_add(Main *bmain, const char *name)
{
Volume *volume = (Volume *)BKE_libblock_alloc(bmain, ID_VO, name, 0);
volume_init_data(&volume->id);
return volume;
}
Volume *BKE_volume_copy(Main *bmain, const Volume *volume)
{
Volume *volume_copy;
BKE_id_copy(bmain, &volume->id, (ID **)&volume_copy);
return volume_copy;
}
/* Sequence */
static int volume_sequence_frame(const Depsgraph *depsgraph, const Volume *volume)