[Bf-blender-cvs] [d40031df15b] functions: remove event storage concept
Jacques Lucke
noreply at git.blender.org
Fri Dec 20 18:23:13 CET 2019
Commit: d40031df15b0f326fe668395747ad1a84ed8d9a0
Author: Jacques Lucke
Date: Fri Dec 20 15:39:17 2019 +0100
Branches: functions
https://developer.blender.org/rBd40031df15b0f326fe668395747ad1a84ed8d9a0
remove event storage concept
===================================================================
M source/blender/simulations/bparticles/event_interface.hpp
M source/blender/simulations/bparticles/events.cpp
M source/blender/simulations/bparticles/events.hpp
M source/blender/simulations/bparticles/simulate.cpp
===================================================================
diff --git a/source/blender/simulations/bparticles/event_interface.hpp b/source/blender/simulations/bparticles/event_interface.hpp
index 7bc3103f6d3..482ffa4cb58 100644
--- a/source/blender/simulations/bparticles/event_interface.hpp
+++ b/source/blender/simulations/bparticles/event_interface.hpp
@@ -5,37 +5,6 @@
namespace BParticles {
-/**
- * Utility array wrapper that can hold different kinds of plain-old-data values.
- */
-class EventStorage {
- private:
- void *m_array;
- uint m_stride;
-
- public:
- EventStorage(void *array, uint stride) : m_array(array), m_stride(stride)
- {
- }
-
- EventStorage(EventStorage &other) = delete;
-
- void *operator[](uint index)
- {
- return POINTER_OFFSET(m_array, m_stride * index);
- }
-
- template<typename T> T &get(uint index)
- {
- return *(T *)(*this)[index];
- }
-
- uint max_element_size() const
- {
- return m_stride;
- }
-};
-
/**
* Interface between the Event->filter() function and the core simulation code.
*/
@@ -44,7 +13,6 @@ class EventFilterInterface : public BlockStepDataAccess {
ArrayRef<uint> m_pindices;
ArrayRef<float> m_known_min_time_factors;
- EventStorage &m_event_storage;
Vector<uint> &m_filtered_pindices;
Vector<float> &m_filtered_time_factors;
@@ -55,13 +23,11 @@ class EventFilterInterface : public BlockStepDataAccess {
EventFilterInterface(BlockStepData &step_data,
ArrayRef<uint> pindices,
ArrayRef<float> known_min_time_factors,
- EventStorage &r_event_storage,
Vector<uint> &r_filtered_pindices,
Vector<float> &r_filtered_time_factors)
: BlockStepDataAccess(step_data),
m_pindices(pindices),
m_known_min_time_factors(known_min_time_factors),
- m_event_storage(r_event_storage),
m_filtered_pindices(r_filtered_pindices),
m_filtered_time_factors(r_filtered_time_factors)
{
@@ -88,26 +54,6 @@ class EventFilterInterface : public BlockStepDataAccess {
m_filtered_time_factors.append(time_factor);
}
}
-
- /**
- * Same as above but returns a reference to a struct that can be used to pass data to the execute
- * function. The reference might point to a dummy buffer when the time_factor is after a known
- * other event.
- */
- template<typename T> T &trigger_particle(uint pindex, float time_factor)
- {
- BLI_STATIC_ASSERT(std::is_trivial<T>::value, "");
- BLI_assert(sizeof(T) <= m_event_storage.max_element_size());
- BLI_assert(sizeof(m_dummy_event_storage) >= m_event_storage.max_element_size());
-
- if (time_factor <= m_known_min_time_factors[pindex]) {
- this->trigger_particle(pindex, time_factor);
- return m_event_storage.get<T>(pindex);
- }
- else {
- return *(T *)m_dummy_event_storage;
- }
- }
};
/**
@@ -117,19 +63,16 @@ class EventExecuteInterface : public BlockStepDataAccess {
private:
ArrayRef<uint> m_pindices;
ArrayRef<float> m_current_times;
- EventStorage &m_event_storage;
ParticleAllocator &m_particle_allocator;
public:
EventExecuteInterface(BlockStepData &step_data,
ArrayRef<uint> pindices,
ArrayRef<float> current_times,
- EventStorage &event_storage,
ParticleAllocator &particle_allocator)
: BlockStepDataAccess(step_data),
m_pindices(pindices),
m_current_times(current_times),
- m_event_storage(event_storage),
m_particle_allocator(particle_allocator)
{
}
@@ -152,24 +95,6 @@ class EventExecuteInterface : public BlockStepDataAccess {
return m_current_times;
}
- /**
- * Get the data stored in the Event->filter() function for a particle index.
- */
- template<typename T> T &get_storage(uint pindex)
- {
- BLI_STATIC_ASSERT(std::is_trivial<T>::value, "");
- BLI_assert(sizeof(T) <= m_event_storage.max_element_size());
- return m_event_storage.get<T>(pindex);
- }
-
- /**
- * Get the entire event storage.
- */
- EventStorage &event_storage()
- {
- return m_event_storage;
- }
-
ParticleAllocator &particle_allocator()
{
return m_particle_allocator;
@@ -191,14 +116,6 @@ class Event {
{
}
- /**
- * Return how many bytes this event wants to pass between the filter and execute function.
- */
- virtual uint storage_size()
- {
- return 0;
- }
-
/**
* Gets a set of particles and checks which of those trigger the event.
*/
diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp
index ff11c443308..335e407eab0 100644
--- a/source/blender/simulations/bparticles/events.cpp
+++ b/source/blender/simulations/bparticles/events.cpp
@@ -96,11 +96,6 @@ void CustomEvent::execute(EventExecuteInterface &interface)
/* Collision Event
***********************************************/
-uint MeshCollisionEvent::storage_size()
-{
- return sizeof(EventStorage);
-}
-
void MeshCollisionEvent::filter(EventFilterInterface &interface)
{
AttributesRef attributes = interface.attributes();
@@ -127,13 +122,10 @@ void MeshCollisionEvent::filter(EventFilterInterface &interface)
auto result = this->ray_cast(local_ray_start, local_ray_direction, local_ray_length);
if (result.success) {
float time_factor = result.distance / local_ray_length;
- auto &storage = interface.trigger_particle<EventStorage>(pindex, time_factor);
+ interface.trigger_particle(pindex, time_factor);
if (float3::dot(result.normal, local_ray_direction) > 0) {
result.normal = -result.normal;
}
- storage.local_normal = result.normal;
- storage.local_position = local_ray_start + local_ray_direction * result.distance;
- storage.looptri_index = result.index;
}
}
}
diff --git a/source/blender/simulations/bparticles/events.hpp b/source/blender/simulations/bparticles/events.hpp
index 4424c5d303e..ab8a44b2217 100644
--- a/source/blender/simulations/bparticles/events.hpp
+++ b/source/blender/simulations/bparticles/events.hpp
@@ -70,12 +70,6 @@ class MeshCollisionEvent : public Event {
float distance;
};
- struct EventStorage {
- uint looptri_index;
- float3 local_normal;
- float3 local_position;
- };
-
public:
MeshCollisionEvent(StringRef last_collision_attribute,
Object *object,
@@ -98,7 +92,6 @@ class MeshCollisionEvent : public Event {
free_bvhtree_from_mesh(&m_bvhtree_data);
}
- uint storage_size() override;
void filter(EventFilterInterface &interface) override;
void execute(EventExecuteInterface &interface) override;
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 61e72e58793..4203886abf1 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -19,20 +19,10 @@ using BLI::LargeScopedVector;
using BLI::VectorAdaptor;
using FN::CPPType;
-static uint get_max_event_storage_size(ArrayRef<Event *> events)
-{
- uint max_size = 0;
- for (Event *event : events) {
- max_size = std::max(max_size, event->storage_size());
- }
- return max_size;
-}
-
BLI_NOINLINE static void find_next_event_per_particle(
BlockStepData &step_data,
ArrayRef<uint> pindices,
ArrayRef<Event *> events,
- EventStorage &r_event_storage,
MutableArrayRef<int> r_next_event_indices,
MutableArrayRef<float> r_time_factors_to_next_event,
LargeScopedVector<uint> &r_pindices_with_event)
@@ -48,7 +38,6 @@ BLI_NOINLINE static void find_next_event_per_particle(
EventFilterInterface interface(step_data,
pindices,
r_time_factors_to_next_event,
- r_event_storage,
triggered_pindices,
triggered_time_factors);
event->filter(interface);
@@ -166,7 +155,6 @@ BLI_NOINLINE static void execute_events(BlockStepData &step_data,
ParticleAllocator &particle_allocator,
ArrayRef<Vector<uint>> pindices_per_event,
ArrayRef<float> current_times,
- EventStorage &event_storage,
ArrayRef<Event *> events)
{
BLI_assert(events.size() == pindices_per_event.size());
@@ -179,8 +167,7 @@ BLI_NOINLINE static void execute_events(BlockStepData &step_data,
continue;
}
- EventExecuteInterface interface(
- step_data, pindices, current_times, event_storage, particle_allocator);
+ EventExecuteInterface interface(step_data, pindices, current_times, particle_allocator);
event->execute(interface);
}
}
@@ -196,14 +183,9 @@ BLI_NOINLINE static void simulate_to_next_event(BlockStepData &step_data,
LargeScopedArray<float> time_factors_to_next_event(amount);
LargeScopedVector<uint> pindices_with_event;
- uint max_event_storage_size = std::max(get_max_event_storage_size(system_info.events), 1u);
- LargeScopedArray<bool> event_storage_array(max_event_storage_size * amount);
- EventStorage event_storage((void *)event_storage_array.begin(), max_event_storage_size);
-
find_next_event_per_particle(step_data,
pindices,
system_info.events,
- event_storage,
next_event_indices,
time_factors_to_next_event,
pindices_with_event);
@@ -227,12 +209,8 @@ BLI_NOINLINE static void simulate_to_next_event(BlockStepData &step_data,
compute_current_time_per_particle(
pindices_with_event, step_data.remaining_durations, step_data.step_end_time, current_times);
- execute_events(step_data,
- particle_allocator,
- particles_per_event,
- current_times,
- event_storage,
- sys
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list