Class: BulldogPhysics::Particles::ParticleForceRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/Particles/particle_force_registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParticleForceRegistry

Returns a new instance of ParticleForceRegistry.



7
8
9
# File 'lib/Particles/particle_force_registry.rb', line 7

def initialize()
  @registrations = Array.new # array of ParticleForceRegistration(s)
end

Instance Attribute Details

#registrationsObject

Returns the value of attribute registrations.



5
6
7
# File 'lib/Particles/particle_force_registry.rb', line 5

def registrations
  @registrations
end

Instance Method Details

#add(particle, force_generator) ⇒ Object

Registers the given force generator to apply to the given particle.



13
14
15
16
17
18
19
# File 'lib/Particles/particle_force_registry.rb', line 13

def add(particle, force_generator)
  particle_registration = ParticleForceRegistration.new
  particle_registration.particle = particle
  particle_registration.particle_force_generator = force_generator
  @registrations << particle_registration
  puts "Registration count #{@registrations.count}"
end

#clearObject

Clears all registrations from the registry. This will not delete the particles or the force generators themselves, just the records of their connection.



34
35
36
# File 'lib/Particles/particle_force_registry.rb', line 34

def clear
  @registrations = Array.new
end

#remove(particle, force_generator) ⇒ Object

Removes the given registered pair from the registry. If the pair is not registered, this method will have no effect.



25
26
27
28
29
# File 'lib/Particles/particle_force_registry.rb', line 25

def remove(particle,force_generator)
  @registrations.remove_if do |registry|
    registry.particle.eql? particle and registry.force_generator.eql? force_generator
  end
end

#update_forces(duration) ⇒ Object

Calls all the force generators to update the forces of their corresponding particles.



41
42
43
44
45
# File 'lib/Particles/particle_force_registry.rb', line 41

def update_forces(duration)
  for registry in @registrations
    registry.particle_force_generator.update_force(registry.particle,duration)
  end
end