diff options
author | Jacques Lucke <mail@jlucke.com> | 2019-07-29 18:03:32 +0300 |
---|---|---|
committer | Jacques Lucke <mail@jlucke.com> | 2019-07-29 18:03:32 +0300 |
commit | f78e2837ffe06b36fd689f8ef29eacc92e986f5b (patch) | |
tree | 5395c2b363587009fc36f80cb094cfe36029c5e5 /source/blender/simulations | |
parent | deecc8c6f8dfe8e2598a643100e62bce61256f68 (diff) |
change get_T to get<T> when accessing attributes
Diffstat (limited to 'source/blender/simulations')
10 files changed, 60 insertions, 86 deletions
diff --git a/source/blender/simulations/bparticles/action_interface.hpp b/source/blender/simulations/bparticles/action_interface.hpp index 2ea5b7da668..cebe829740b 100644 --- a/source/blender/simulations/bparticles/action_interface.hpp +++ b/source/blender/simulations/bparticles/action_interface.hpp @@ -103,7 +103,7 @@ inline void Action::execute_from_emitter(ParticleSets &particle_sets, emitter_interface.array_allocator(), particles, offsets, - particles.attributes().get_float("Birth Time"), + particles.attributes().get<float>("Birth Time"), durations, used_action_context); this->execute(action_interface); @@ -171,7 +171,7 @@ inline ArrayRef<float> ActionInterface::current_times() inline void ActionInterface::kill(ArrayRef<uint> pindices) { - auto kill_states = m_particles.attributes().get_byte("Kill State"); + auto kill_states = m_particles.attributes().get<uint8_t>("Kill State"); for (uint pindex : pindices) { kill_states[pindex] = 1; } diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp index 1a633f1e643..26daafb00f2 100644 --- a/source/blender/simulations/bparticles/actions.cpp +++ b/source/blender/simulations/bparticles/actions.cpp @@ -11,7 +11,7 @@ void NoneAction::execute(ActionInterface &UNUSED(interface)) void ChangeDirectionAction::execute(ActionInterface &interface) { ParticleSet particles = interface.particles(); - auto velocities = particles.attributes().get_float3("Velocity"); + auto velocities = particles.attributes().get<float3>("Velocity"); auto position_offsets = interface.attribute_offsets().try_get_float3("Position"); auto velocity_offsets = interface.attribute_offsets().try_get_float3("Velocity"); @@ -54,7 +54,7 @@ void ExplodeAction::execute(ActionInterface &interface) { ParticleSet &particles = interface.particles(); - auto positions = particles.attributes().get_float3("Position"); + auto positions = particles.attributes().get<float3>("Position"); Vector<float3> new_positions; Vector<float3> new_velocities; diff --git a/source/blender/simulations/bparticles/attributes.hpp b/source/blender/simulations/bparticles/attributes.hpp index 8655d5a39a2..97f53e5e80d 100644 --- a/source/blender/simulations/bparticles/attributes.hpp +++ b/source/blender/simulations/bparticles/attributes.hpp @@ -34,6 +34,21 @@ enum AttributeType { Float3, }; +template<typename T> struct attribute_type_by_type { +}; + +#define ATTRIBUTE_TYPE_BY_TYPE(CPP_TYPE, ATTRIBUTE_TYPE) \ + template<> struct attribute_type_by_type<CPP_TYPE> { \ + static const AttributeType value = AttributeType::ATTRIBUTE_TYPE; \ + } + +ATTRIBUTE_TYPE_BY_TYPE(uint8_t, Byte); +ATTRIBUTE_TYPE_BY_TYPE(int32_t, Integer); +ATTRIBUTE_TYPE_BY_TYPE(float, Float); +ATTRIBUTE_TYPE_BY_TYPE(float3, Float3); + +#undef ATTRIBUTE_TYPE_BY_TYPE + /** * Get the size of an attribute type. * @@ -394,14 +409,17 @@ class AttributeArrays { * Get access to the underlying attribute arrays. * Asserts when the attribute does not exists. */ - ArrayRef<uint8_t> get_byte(uint index) const; - ArrayRef<uint8_t> get_byte(StringRef name); - ArrayRef<int32_t> get_integer(uint index) const; - ArrayRef<int32_t> get_integer(StringRef name); - ArrayRef<float> get_float(uint index) const; - ArrayRef<float> get_float(StringRef name); - ArrayRef<float3> get_float3(uint index) const; - ArrayRef<float3> get_float3(StringRef name); + template<typename T> ArrayRef<T> get(uint index) const + { + BLI_assert(attribute_type_by_type<T>::value == m_core.info().type_of(index)); + void *ptr = this->get_ptr(index); + return ArrayRef<T>((T *)ptr, m_size); + } + template<typename T> ArrayRef<T> get(StringRef name) + { + uint index = this->attribute_index(name); + return this->get<T>(index); + } /** * Get access to the arrays. @@ -541,50 +559,6 @@ inline void AttributeArrays::init_default(StringRef name) this->init_default(this->attribute_index(name)); } -inline ArrayRef<uint8_t> AttributeArrays::get_byte(uint index) const -{ - BLI_assert(m_core.get_type(index) == AttributeType::Byte); - return ArrayRef<uint8_t>((uint8_t *)m_core.get_ptr(index) + m_start, m_size); -} - -inline ArrayRef<uint8_t> AttributeArrays::get_byte(StringRef name) -{ - return this->get_byte(this->attribute_index(name)); -} - -inline ArrayRef<int32_t> AttributeArrays::get_integer(uint index) const -{ - BLI_assert(m_core.get_type(index) == AttributeType::Integer); - return ArrayRef<int32_t>((int32_t *)m_core.get_ptr(index) + m_start, m_size); -} - -inline ArrayRef<int32_t> AttributeArrays::get_integer(StringRef name) -{ - return this->get_integer(this->attribute_index(name)); -} - -inline ArrayRef<float> AttributeArrays::get_float(uint index) const -{ - BLI_assert(m_core.get_type(index) == AttributeType::Float); - return ArrayRef<float>((float *)m_core.get_ptr(index) + m_start, m_size); -} - -inline ArrayRef<float> AttributeArrays::get_float(StringRef name) -{ - return this->get_float(this->attribute_index(name)); -} - -inline ArrayRef<float3> AttributeArrays::get_float3(uint index) const -{ - BLI_assert(m_core.get_type(index) == AttributeType::Float3); - return ArrayRef<float3>((float3 *)m_core.get_ptr(index) + m_start, m_size); -} - -inline ArrayRef<float3> AttributeArrays::get_float3(StringRef name) -{ - return this->get_float3(this->attribute_index(name)); -} - inline Optional<ArrayRef<uint8_t>> AttributeArrays::try_get_byte(StringRef name) { int index = this->info().attribute_index_try(name, AttributeType::Byte); @@ -592,7 +566,7 @@ inline Optional<ArrayRef<uint8_t>> AttributeArrays::try_get_byte(StringRef name) return {}; } else { - return this->get_byte((uint)index); + return this->get<uint8_t>((uint)index); } } @@ -603,7 +577,7 @@ inline Optional<ArrayRef<int32_t>> AttributeArrays::try_get_integer(StringRef na return {}; } else { - return this->get_integer((uint)index); + return this->get<int32_t>((uint)index); } } @@ -614,7 +588,7 @@ inline Optional<ArrayRef<float>> AttributeArrays::try_get_float(StringRef name) return {}; } else { - return this->get_float((uint)index); + return this->get<float>((uint)index); } } @@ -625,7 +599,7 @@ inline Optional<ArrayRef<float3>> AttributeArrays::try_get_float3(StringRef name return {}; } else { - return this->get_float3((uint)index); + return this->get<float3>((uint)index); } } diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp index 0ffc1ad7880..59e4e6493b9 100644 --- a/source/blender/simulations/bparticles/events.cpp +++ b/source/blender/simulations/bparticles/events.cpp @@ -13,8 +13,8 @@ void AgeReachedEvent::attributes(AttributesDeclaration &builder) void AgeReachedEvent::filter(EventFilterInterface &interface) { ParticleSet particles = interface.particles(); - auto birth_times = particles.attributes().get_float("Birth Time"); - auto was_activated_before = particles.attributes().get_byte(m_identifier); + auto birth_times = particles.attributes().get<float>("Birth Time"); + auto was_activated_before = particles.attributes().get<uint8_t>(m_identifier); float end_time = interface.step_end_time(); @@ -50,7 +50,7 @@ void AgeReachedEvent::execute(EventExecuteInterface &interface) { ParticleSet particles = interface.particles(); - auto was_activated_before = particles.attributes().get_byte(m_identifier); + auto was_activated_before = particles.attributes().get<uint8_t>(m_identifier); for (uint pindex : particles.pindices()) { was_activated_before[pindex] = true; } @@ -74,9 +74,9 @@ uint MeshCollisionEvent::storage_size() void MeshCollisionEvent::filter(EventFilterInterface &interface) { ParticleSet particles = interface.particles(); - auto positions = particles.attributes().get_float3("Position"); - auto last_collision_times = particles.attributes().get_float(m_identifier); - auto position_offsets = interface.attribute_offsets().get_float3("Position"); + auto positions = particles.attributes().get<float3>("Position"); + auto last_collision_times = particles.attributes().get<float>(m_identifier); + auto position_offsets = interface.attribute_offsets().get<float3>("Position"); for (uint pindex : particles.pindices()) { float3 ray_start = m_world_to_local.transform_position(positions[pindex]); @@ -121,7 +121,7 @@ void MeshCollisionEvent::execute(EventExecuteInterface &interface) { ParticleSet particles = interface.particles(); Vector<float3> normals(particles.block().active_amount()); - auto last_collision_times = particles.attributes().get_float(m_identifier); + auto last_collision_times = particles.attributes().get<float>(m_identifier); for (uint pindex : particles.pindices()) { auto storage = interface.get_storage<EventStorage>(pindex); @@ -136,7 +136,7 @@ void MeshCollisionEvent::execute(EventExecuteInterface &interface) void CloseByPointsEvent::filter(EventFilterInterface &interface) { ParticleSet particles = interface.particles(); - auto positions = particles.attributes().get_float3("Position"); + auto positions = particles.attributes().get<float3>("Position"); for (uint pindex : particles.pindices()) { KDTreeNearest_3d nearest; diff --git a/source/blender/simulations/bparticles/forces.cpp b/source/blender/simulations/bparticles/forces.cpp index d5b8a9d3c9a..8c2a7db7feb 100644 --- a/source/blender/simulations/bparticles/forces.cpp +++ b/source/blender/simulations/bparticles/forces.cpp @@ -26,7 +26,7 @@ void TurbulenceForce::add_force(ForceInterface &interface) ParticlesBlock &block = interface.block(); ArrayRef<float3> destination = interface.combined_destination(); - auto positions = block.attributes().get_float3("Position"); + auto positions = block.attributes().get<float3>("Position"); auto inputs = m_compute_inputs->compute(interface); diff --git a/source/blender/simulations/bparticles/integrator.cpp b/source/blender/simulations/bparticles/integrator.cpp index 7ef3f06d6fa..714c867312d 100644 --- a/source/blender/simulations/bparticles/integrator.cpp +++ b/source/blender/simulations/bparticles/integrator.cpp @@ -17,8 +17,8 @@ AttributesInfo &ConstantVelocityIntegrator::offset_attributes_info() void ConstantVelocityIntegrator::integrate(IntegratorInterface &interface) { ParticlesBlock &block = interface.block(); - auto velocities = block.attributes().get_float3("Velocity"); - auto position_offsets = interface.attribute_offsets().get_float3("Position"); + auto velocities = block.attributes().get<float3>("Velocity"); + auto position_offsets = interface.attribute_offsets().get<float3>("Position"); auto durations = interface.remaining_durations(); for (uint pindex = 0; pindex < block.active_amount(); pindex++) { @@ -54,10 +54,10 @@ void EulerIntegrator::integrate(IntegratorInterface &interface) ArrayAllocator::Array<float3> combined_force(interface.array_allocator()); this->compute_combined_force(interface, combined_force); - auto last_velocities = interface.block().attributes().get_float3("Velocity"); + auto last_velocities = interface.block().attributes().get<float3>("Velocity"); - auto position_offsets = r_offsets.get_float3("Position"); - auto velocity_offsets = r_offsets.get_float3("Velocity"); + auto position_offsets = r_offsets.get<float3>("Position"); + auto velocity_offsets = r_offsets.get<float3>("Velocity"); this->compute_offsets( durations, last_velocities, combined_force, position_offsets, velocity_offsets); } diff --git a/source/blender/simulations/bparticles/offset_handlers.cpp b/source/blender/simulations/bparticles/offset_handlers.cpp index 2d20dd99cb3..00d3153a212 100644 --- a/source/blender/simulations/bparticles/offset_handlers.cpp +++ b/source/blender/simulations/bparticles/offset_handlers.cpp @@ -5,8 +5,8 @@ namespace BParticles { void CreateTrailHandler::execute(OffsetHandlerInterface &interface) { ParticleSet particles = interface.particles(); - auto positions = particles.attributes().get_float3("Position"); - auto position_offsets = interface.attribute_offsets().get_float3("Position"); + auto positions = particles.attributes().get<float3>("Position"); + auto position_offsets = interface.attribute_offsets().get<float3>("Position"); auto inputs = m_compute_inputs->compute(interface); diff --git a/source/blender/simulations/bparticles/particle_allocator.cpp b/source/blender/simulations/bparticles/particle_allocator.cpp index 718a9e0962a..adc7237ddf7 100644 --- a/source/blender/simulations/bparticles/particle_allocator.cpp +++ b/source/blender/simulations/bparticles/particle_allocator.cpp @@ -58,7 +58,7 @@ void ParticleAllocator::initialize_new_particles(ParticlesBlock &block, Range<ui attributes.init_default(i); } - ArrayRef<int32_t> particle_ids = block.attributes_all().get_integer("ID"); + ArrayRef<int32_t> particle_ids = block.attributes_all().get<int32_t>("ID"); Range<uint> new_ids = block.container().new_particle_ids(pindices.size()); for (uint i = 0; i < pindices.size(); i++) { uint pindex = pindices[i]; diff --git a/source/blender/simulations/bparticles/particle_function_builder.cpp b/source/blender/simulations/bparticles/particle_function_builder.cpp index 9e7428cc880..003d007a867 100644 --- a/source/blender/simulations/bparticles/particle_function_builder.cpp +++ b/source/blender/simulations/bparticles/particle_function_builder.cpp @@ -82,7 +82,7 @@ class CollisionNormalInputProvider : public ParticleFunctionInputProvider { class AgeInputProvider : public ParticleFunctionInputProvider { ParticleFunctionInputArray get(InputProviderInterface &interface) override { - auto birth_times = interface.particles().attributes().get_float("Birth Time"); + auto birth_times = interface.particles().attributes().get<float>("Birth Time"); float *ages = interface.array_allocator().allocate<float>(); ParticleTimes × = interface.particle_times(); diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp index 54640f6b6d1..15bd5da9934 100644 --- a/source/blender/simulations/bparticles/simulate.cpp +++ b/source/blender/simulations/bparticles/simulate.cpp @@ -78,8 +78,8 @@ BLI_NOINLINE static void forward_particles_to_next_event_or_end( for (uint attribute_index : attribute_offsets.info().float3_attributes()) { StringRef name = attribute_offsets.info().name_of(attribute_index); - auto values = particles.attributes().get_float3(name); - auto offsets = attribute_offsets.get_float3(attribute_index); + auto values = particles.attributes().get<float3>(name); + auto offsets = attribute_offsets.get<float3>(attribute_index); if (particles.pindices_are_trivial()) { for (uint pindex : particles.trivial_pindices()) { @@ -102,7 +102,7 @@ BLI_NOINLINE static void update_remaining_attribute_offsets( AttributeArrays attribute_offsets) { for (uint attribute_index : attribute_offsets.info().float3_attributes()) { - auto offsets = attribute_offsets.get_float3(attribute_index); + auto offsets = attribute_offsets.get<float3>(attribute_index); for (uint pindex : pindices_with_event) { float factor = 1.0f - time_factors_to_next_event[pindex]; @@ -219,7 +219,7 @@ BLI_NOINLINE static void simulate_to_next_event(BlockStepData &step_data, find_unfinished_particles(pindices_with_event, time_factors_to_next_event, - step_data.block.attributes().get_byte("Kill State"), + step_data.block.attributes().get<uint8_t>("Kill State"), r_unfinished_pindices); } @@ -301,8 +301,8 @@ BLI_NOINLINE static void apply_remaining_offsets(BlockStepData &step_data, Array for (uint attribute_index : attribute_offsets.info().float3_attributes()) { StringRef name = attribute_offsets.info().name_of(attribute_index); - auto values = particles.attributes().get_float3(name); - auto offsets = attribute_offsets.get_float3(attribute_index); + auto values = particles.attributes().get<float3>(name); + auto offsets = attribute_offsets.get<float3>(attribute_index); if (particles.pindices_are_trivial()) { add_float3_arrays(values.take_front(particles.size()), offsets.take_front(particles.size())); @@ -362,7 +362,7 @@ BLI_NOINLINE static void simulate_block(ArrayAllocator &array_allocator, BLI_NOINLINE static void delete_tagged_particles_and_reorder(ParticlesBlock &block) { - auto kill_states = block.attributes().get_byte("Kill State"); + auto kill_states = block.attributes().get<uint8_t>("Kill State"); uint index = 0; while (index < block.active_amount()) { @@ -476,7 +476,7 @@ BLI_NOINLINE static void simulate_blocks_from_birth_to_current_time( uint active_amount = block->active_amount(); Vector<float> durations(active_amount); - auto birth_times = block->attributes().get_float("Birth Time"); + auto birth_times = block->attributes().get<float>("Birth Time"); for (uint i = 0; i < active_amount; i++) { durations[i] = end_time - birth_times[i]; } |