[Bf-blender-cvs] [c77945366cb] functions: pass elapsed seconds into step function

Jacques Lucke noreply at git.blender.org
Sat Jun 8 14:22:01 CEST 2019


Commit: c77945366cbaea121912a1e2044e18c57d501f31
Author: Jacques Lucke
Date:   Sat Jun 8 13:39:49 2019 +0200
Branches: functions
https://developer.blender.org/rBc77945366cbaea121912a1e2044e18c57d501f31

pass elapsed seconds into step function

===================================================================

M	source/blender/modifiers/intern/MOD_nodeparticles.c
M	source/blender/simulations/BParticles.h
M	source/blender/simulations/bparticles/c_wrapper.cpp
M	source/blender/simulations/bparticles/core.hpp
M	source/blender/simulations/bparticles/playground_solver.cpp

===================================================================

diff --git a/source/blender/modifiers/intern/MOD_nodeparticles.c b/source/blender/modifiers/intern/MOD_nodeparticles.c
index 058a9a77a7a..0147165b6f1 100644
--- a/source/blender/modifiers/intern/MOD_nodeparticles.c
+++ b/source/blender/modifiers/intern/MOD_nodeparticles.c
@@ -102,6 +102,7 @@ static Mesh *applyModifier(ModifierData *md,
 
   Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
   float current_frame = BKE_scene_frame_get(scene);
+  float fps = FPS;
 
   if (current_frame != runtime->last_simulated_frame) {
     BParticlesDescription new_description = BParticles_playground_description(npmd->control1,
@@ -116,7 +117,7 @@ static Mesh *applyModifier(ModifierData *md,
       runtime->description = new_description;
       runtime->solver = new_solver;
 
-      BParticles_state_step(runtime->solver, runtime->state);
+      BParticles_state_step(runtime->solver, runtime->state, 1.0f / fps);
     }
     else {
       BParticles_state_free(runtime->state);
diff --git a/source/blender/simulations/BParticles.h b/source/blender/simulations/BParticles.h
index 07bced86d11..3acf8d8be8d 100644
--- a/source/blender/simulations/BParticles.h
+++ b/source/blender/simulations/BParticles.h
@@ -20,7 +20,7 @@ void BParticles_solver_free(BParticlesSolver solver);
 
 BParticlesState BParticles_state_init(BParticlesSolver solver);
 void BParticles_state_adapt(BParticlesSolver new_solver, BParticlesState state_to_adapt);
-void BParticles_state_step(BParticlesSolver solver, BParticlesState state);
+void BParticles_state_step(BParticlesSolver solver, BParticlesState state, float elapsed_seconds);
 void BParticles_state_free(BParticlesState state);
 
 uint BParticles_state_particle_count(BParticlesSolver solver, BParticlesState state);
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 28bcb600b74..10426396ba4 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -77,7 +77,7 @@ class TestEmitter : public BParticles::Emitter {
     BLI_assert(dst.size() > 0);
 
     dst.vec3_buffer("Position")[0] = {(float)(rand() % 100) / 30.0f, 0, 1};
-    dst.vec3_buffer("Velocity")[0] = {0, 0.1, 0.1};
+    dst.vec3_buffer("Velocity")[0] = {0, 1, 1};
     dst.initialized_n(1);
   }
 };
@@ -115,13 +115,15 @@ void BParticles_state_adapt(BParticlesSolver new_solver_c, BParticlesState state
   WrappedState *wrapped_state = unwrap(state_to_adapt_c);
   BParticles::adapt_state(new_solver, wrapped_state);
 }
-void BParticles_state_step(BParticlesSolver solver_c, BParticlesState state_c)
+void BParticles_state_step(BParticlesSolver solver_c,
+                           BParticlesState state_c,
+                           float elapsed_seconds)
 {
   Solver *solver = unwrap(solver_c);
   WrappedState *wrapped_state = unwrap(state_c);
 
   BLI_assert(solver == &wrapped_state->solver());
-  solver->step(*wrapped_state);
+  solver->step(*wrapped_state, elapsed_seconds);
 }
 void BParticles_state_free(BParticlesState state_c)
 {
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index 388877bf7c3..5349f805e1d 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -114,7 +114,7 @@ class Solver {
   virtual ~Solver();
 
   virtual StateBase *init() = 0;
-  virtual void step(WrappedState &wrapped_state) = 0;
+  virtual void step(WrappedState &wrapped_state, float elapsed_seconds) = 0;
 
   virtual uint particle_amount(WrappedState &wrapped_state) = 0;
   virtual void get_positions(WrappedState &wrapped_state, float (*dst)[3]) = 0;
diff --git a/source/blender/simulations/bparticles/playground_solver.cpp b/source/blender/simulations/bparticles/playground_solver.cpp
index ab84ce8a804..fc16789e05d 100644
--- a/source/blender/simulations/bparticles/playground_solver.cpp
+++ b/source/blender/simulations/bparticles/playground_solver.cpp
@@ -43,7 +43,7 @@ class SimpleSolver : public Solver {
     return state;
   }
 
-  void step_block(ParticlesBlock *block)
+  void step_block(ParticlesBlock *block, float elapsed_seconds)
   {
     uint active_amount = block->active_amount();
 
@@ -52,7 +52,7 @@ class SimpleSolver : public Solver {
     float *age = block->float_buffer("Age");
 
     for (uint i = 0; i < active_amount; i++) {
-      positions[i] += velocities[i];
+      positions[i] += velocities[i] * elapsed_seconds;
       age[i] += 1;
     }
 
@@ -65,9 +65,8 @@ class SimpleSolver : public Solver {
       force->add_force(slice, combined_force);
     }
 
-    float time_step = 0.01f;
     for (uint i = 0; i < active_amount; i++) {
-      velocities[i] += combined_force[i] * time_step;
+      velocities[i] += combined_force[i] * elapsed_seconds;
     }
 
     if (rand() % 10 == 0) {
@@ -153,14 +152,14 @@ class SimpleSolver : public Solver {
     }
   }
 
-  void step(WrappedState &wrapped_state) override
+  void step(WrappedState &wrapped_state, float elapsed_seconds) override
   {
     MyState &state = wrapped_state.state<MyState>();
 
     ParticlesContainer &particles = *state.particles;
 
     for (ParticlesBlock *block : particles.active_blocks()) {
-      this->step_block(block);
+      this->step_block(block, elapsed_seconds);
       this->delete_old_particles(block);
     }



More information about the Bf-blender-cvs mailing list