Commits

German Larrain committed 0c9332b

model.physics: added signal dispatching for:
-worl pre and post step,
-body post attach geom,
-body pre and post set position,
-body pre and post set rotation.

Comments (0)

Files changed (2)

ars/model/physics/adapters.py

 import ode
 
 import ars.exceptions as exc
+from ars.lib.pydispatch import dispatcher
 import ars.model.collision.adapters as shapes
 
 import base
+from ars.model.physics import signals
 
 
 class OdeWorld(base.World):
 		return self._inner_object.getGravity()
 
 	def step(self, time_step):
+		dispatcher.send(signals.WORLD_PRE_STEP, sender=self)
 		self._inner_object.step(time_step)
+		dispatcher.send(signals.WORLD_POST_STEP, sender=self)
 
 
 class OdeEngine(base.Engine):
 		return self._inner_object.getMass().I
 
 	def set_position(self, pos):
+		dispatcher.send(signals.BODY_PRE_SET_POSITION, sender=self)
 		self._inner_object.setPosition(pos)
+		dispatcher.send(signals.BODY_POST_SET_POSITION, sender=self)
 
 	def set_rotation(self, rot):
+		dispatcher.send(signals.BODY_PRE_SET_ROTATION, sender=self)
 		self._inner_object.setRotation(rot)
+		dispatcher.send(signals.BODY_POST_SET_ROTATION, sender=self)
 
 class Capsule(OdeBody, base.Capsule):
 	def __init__(self, world, space, length, radius, mass=None, density=None):

ars/model/physics/base.py

 from abc import ABCMeta, abstractmethod, abstractproperty
 
 import ars.exceptions as exc
+from ars.lib.pydispatch import dispatcher
 import ars.utils.mathematical as mut
 
+from ars.model.physics import signals
+
 
 class Engine:
 	__metaclass__ = ABCMeta
 
 	@abstractmethod
 	def step(self, time_step):
+		"""Subclasses implementing this method must send the corresponding
+		signals, defined in :mod:`ars.model.physics.signals`.
+		
+		"""
 		raise NotImplementedError()
 
 
 	def attach_geom(self, geom):
 		geom.attach_body(self)
 		self._attached_geom = geom
+		dispatcher.send(signals.BODY_POST_ATTACH_GEOM, sender=self)
 
 	#==========================================================================
 	# Calculations
 
 	@abstractmethod
 	def set_position(self, pos):
+		"""Subclasses implementing this method must send the correponding
+		signals, defined in :mod:`ars.model.physics.signals`.
+		
+		"""
 		raise NotImplementedError()
 
 	@abstractmethod
 	def set_rotation(self, rot):
+		"""Subclasses implementing this method must send the correponding
+		signals, defined in :mod:`ars.model.physics.signals`.
+		
+		"""
 		raise NotImplementedError()
 
 	def save_velocities(self):