test_particlesystem.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. from panda3d.core import NodePath, PandaNode
  2. from direct.particles.ParticleEffect import ParticleEffect
  3. from direct.particles.Particles import Particles
  4. def test_particle_birth_rate():
  5. # Tests a system with a standard birth rate of 0.5, that it is
  6. # indeed birthing at that rate. It serves as a control for the
  7. # next test as well.
  8. system = Particles("testSystem", 2)
  9. system.set_render_parent(NodePath(PandaNode("test")))
  10. system.set_spawn_render_node_path(NodePath(PandaNode("test")))
  11. assert system.get_birth_rate() == 0.5
  12. assert system.get_tics_since_birth() == 0
  13. assert system.get_living_particles() == 0
  14. system.update(0.6)
  15. assert system.get_living_particles() == 1
  16. system.update(0.5)
  17. assert system.get_living_particles() == 2
  18. # Should still be 2, since the pool size was 2.
  19. system.update(0.5)
  20. assert system.get_living_particles() == 2
  21. def test_particle_soft_start():
  22. # Create a particle effect and a particle system.
  23. # The effect serves to test the Python-level "soft_start" method,
  24. # while the system serves to test the C++-level "soft_start" method
  25. # (via the associated Python "soft_start" method)
  26. effect = ParticleEffect()
  27. system = Particles("testSystem", 10)
  28. # Setup some dummy nodes, since it seems to want them
  29. system.set_render_parent(NodePath(PandaNode("test")))
  30. system.set_spawn_render_node_path(NodePath(PandaNode("test")))
  31. # Add the system to the effect
  32. effect.add_particles(system)
  33. # Re-assign the system, just to make sure that we have the
  34. # right object.
  35. system = effect.get_particles_list()[0]
  36. # First, standard "soft_start"--i.e. without either changing
  37. # the birth-rate or applying a delay. This should work as it
  38. # used to.
  39. effect.soft_start()
  40. assert system.get_birth_rate() == 0.5
  41. # Now, check that the pre-existing single-parameter soft-start,
  42. # which alters the birth-rate, still does so.
  43. system.soft_start(1)
  44. assert system.get_birth_rate() == 1
  45. # Next, birth-delaying.
  46. # Run a standard soft-start, then check that the birth-timer
  47. # is zero, as used to be the case on running this command.
  48. effect.soft_start()
  49. assert system.get_tics_since_birth() == 0
  50. # Run an delayed soft-start via the system, then check that the
  51. # birth-timer has the assigned value, and that the birth-rate is
  52. # unchanged.
  53. # (We pass in a birth-rate ("br") of -1 because the related code
  54. # checks for a birth-rate greater than 0, I believe. This allows
  55. # us to change the delay without affecting the birth-rate.)
  56. system.soft_start(br=-1, first_birth_delay=-2)
  57. assert system.get_birth_rate() == 1
  58. assert system.get_tics_since_birth() == 2
  59. # Now, run a delayed soft-start via the effect, and
  60. # again check that the birth-timer has changed as intended,
  61. # and the birth-rate hasn't changed at all.
  62. effect.soft_start(firstBirthDelay=0.25)
  63. assert system.get_birth_rate() == 1
  64. assert system.get_tics_since_birth() == -0.25
  65. # Update the system, advancing it far enough that it should
  66. # have birthed a particle if not for the delay, but not
  67. # so far that it should have birthed a particle >with<
  68. # the delay. Check thus that no particles have been birthed.
  69. system.update(1)
  70. assert system.get_living_particles() == 0
  71. # Update the system again, this time far enough that with the
  72. # delay it should have birthed just one particle, and
  73. # then check that this is the case.
  74. system.update(1)
  75. assert system.get_living_particles() == 1