#include 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_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> &new_model_matrices) { std::array old_ptrs{cylinder_face.get_ptr(), bottom_plane.get_ptr(), top_plane.get_ptr()}; std::array 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 { if (old_ptrs[0] != nullptr) data_center.cylinders.release(cylinder_paired_model_matrix{old_model_matrices[0]}); if (old_ptrs[1] != nullptr) data_center.planes.release(plane_paired_model_matrix{old_model_matrices[1]}); if (old_ptrs[2] != nullptr) data_center.planes.release(plane_paired_model_matrix{old_model_matrices[2]}); } } } // namespace internal