You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
2.6 KiB
59 lines
2.6 KiB
5 months ago
|
#include <data/data_center.hpp>
|
||
|
|
||
|
namespace internal
|
||
|
{
|
||
|
void cylinder_t::initialize(primitive_data_center_t &data_center)
|
||
|
{
|
||
|
auto [bottom_plane_iter, _] = data_center.transform_blocks.acquire(internal::plane_to_z_neg_1_model_matrix);
|
||
|
auto [cylinder_iter, __] = data_center.transform_blocks.acquire(internal::identity_model_matrix);
|
||
|
auto [top_plane_iter, ___] = data_center.transform_blocks.acquire(internal::plane_to_z_pos_1_model_matrix);
|
||
|
initialize(data_center,
|
||
|
{std::pair(cylinder_iter.operator->(), false),
|
||
|
std::pair(bottom_plane_iter.operator->(), true),
|
||
|
std::pair(top_plane_iter.operator->(), false)});
|
||
|
}
|
||
|
|
||
|
void cylinder_t::destroy()
|
||
|
{
|
||
|
auto data_center = bottom_plane.get_ptr()->data_center;
|
||
|
data_center->planes.release(plane_paired_model_matrix{bottom_plane.get_ptr()->model_matrices});
|
||
|
|
||
|
data_center->planes.release(plane_paired_model_matrix{top_plane.get_ptr()->model_matrices});
|
||
|
}
|
||
|
|
||
|
void cylinder_t::initialize(primitive_data_center_t &data_center,
|
||
|
const std::vector<std::pair<internal::paired_model_matrix *, bool>> &new_model_matrices)
|
||
|
{
|
||
|
std::array<subface *, 3> old_ptrs{bottom_plane.get_ptr(), cylinder_face.get_ptr(), top_plane.get_ptr()};
|
||
|
std::array<paired_model_matrix *, 3> old_model_matrices{nullptr, nullptr, nullptr};
|
||
|
for (size_t i = 0; i < 3; ++i) {
|
||
|
if (old_ptrs[i] != nullptr) old_model_matrices[i] = old_ptrs[i]->model_matrices;
|
||
|
}
|
||
|
|
||
|
{
|
||
|
auto [iter, is_new] = data_center.cylinders.acquire(cylinder_paired_model_matrix{new_model_matrices[0].first});
|
||
|
cylinder_face.set_ptr(iter.operator->());
|
||
|
cylinder_face.set_mark(new_model_matrices[0].second);
|
||
|
if (is_new) cylinder_face.get_ptr()->data_center = &data_center;
|
||
|
}
|
||
|
|
||
|
{
|
||
|
auto [iter, is_new] = data_center.planes.acquire(plane_paired_model_matrix{new_model_matrices[1].first});
|
||
|
bottom_plane.set_ptr(iter.operator->());
|
||
|
bottom_plane.set_mark(new_model_matrices[1].second);
|
||
|
if (is_new) bottom_plane.get_ptr()->data_center = &data_center;
|
||
|
}
|
||
|
|
||
|
{
|
||
|
auto [iter, is_new] = data_center.planes.acquire(plane_paired_model_matrix{new_model_matrices[2].first});
|
||
|
top_plane.set_ptr(iter.operator->());
|
||
|
top_plane.set_mark(new_model_matrices[2].second);
|
||
|
if (is_new) top_plane.get_ptr()->data_center = &data_center;
|
||
|
}
|
||
|
|
||
|
// deferred release to avoid acquiring the same just-released subface
|
||
|
for (size_t i = 0; i < 3; ++i) {
|
||
|
if (old_ptrs[i] != nullptr) data_center.spheres.release(old_model_matrices[i]);
|
||
|
}
|
||
|
}
|
||
|
} // namespace internal
|