ó
X–Tc           @   s8   d  Z  d d l Z d d l Z d e f d „  ƒ  YZ d S(   sJ   Actors are tools for rapidly adding multiprocessing behavior to your game.iÿÿÿÿNt   Actorc           B   s5   e  Z d  Z d „  Z d d „ Z d „  Z d „  Z RS(   s"  
    Actors are a powerful mechanism for quickly adding multiprocessing behavior
    to your game through `Greenlets <http://greenlet.readthedocs.org/>`_ .
    Any object that subclasses the Actor
    mixin can implement a `main` method that will run concurrently. You can put
    a non-terminating loop into it, and it will work like magic, allowing
    other actors and the main game itself to keep processing::
    
        class MyActor(spyral.Actor):
            def main(self, delta):
                while True:
                    print "Acting!"
                    
    When an instance of the above class is created in a scene, it will
    continuously print "Acting!" until the scene ends. Like a Sprite, An Actor
    belongs to the Scene that was currently active when it was created.
    c         C   s8   t  j  |  j ƒ |  _ t j ƒ  } | j |  |  j ƒ d  S(   N(   t   greenlett   maint	   _greenlett   spyralt   _get_executing_scenet   _register_actor(   t   selft   scene(    (    s0   /usr/lib/python2.7/site-packages/spyral/actor.pyt   __init__   s    i    c         C   s2   | d k r |  j  j j t ƒ S|  j  j j | ƒ S(   s  
        Switches execution from this Actor for *delta* frames to the other
        Actors. Returns the amount of time that this actor was left waiting.

        :param delta: the number of frames(?) to wait.
        :type delta: number
        :rtype: float
        i    (   R   t   parentt   switcht   True(   R   t   delta(    (    s0   /usr/lib/python2.7/site-packages/spyral/actor.pyt   wait   s    	c         C   s¶   d } d } x£ | | j  k  r± | | 7} | | j  k rP | | j  } | j  } n d } | j |  | ƒ } x4 | j D]) } | | k rr t |  | | | ƒ qr qr W|  j | ƒ } q Wd S(   sk   
        Run this animation, without blocking other Actors, until the animation
        completes.
        g        i    N(   t   durationt   evaluatet
   propertiest   setattrR   (   R   t	   animationt   progressR   t   extrat   valuest   property(    (    s0   /usr/lib/python2.7/site-packages/spyral/actor.pyt   run_animation*   s    
c         C   s   d S(   s¯  
        The main function is executed continuously until either the program
        ends or the main function ends. While the Actor's scene is not on the
        top of the stack, the Actor is paused; it will continue when the Scene
        is back on the top of the Directory's stack.
        
        :param float delta: The amount of time that has passed since this
                            method was last invoked.
        N(    (   R   R   (    (    s0   /usr/lib/python2.7/site-packages/spyral/actor.pyR   ?   s    
(   t   __name__t
   __module__t   __doc__R	   R   R   R   (    (    (    s0   /usr/lib/python2.7/site-packages/spyral/actor.pyR       s
   		(   R   R   R   t   objectR    (    (    (    s0   /usr/lib/python2.7/site-packages/spyral/actor.pyt   <module>   s   