27
|
1 #############################################################################
|
|
2 #
|
|
3 # Copyright (c) 2010 by Casey Duncan and contributors
|
|
4 # All Rights Reserved.
|
|
5 #
|
|
6 # This software is subject to the provisions of the MIT License
|
|
7 # A copy of the license should accompany this distribution.
|
|
8 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
9 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
10 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
11 #
|
|
12 #############################################################################
|
|
13
|
|
14 __versioninfo__ = (0, 3, 0)
|
|
15 __version__ = '.'.join(str(n) for n in __versioninfo__)
|
|
16
|
|
17 __all__ = ('BaseWorld', 'Entity', 'System', 'Renderer')
|
|
18
|
|
19 import grease.component
|
|
20 import grease.geometry
|
|
21 import grease.collision
|
|
22 from grease.entity import Entity
|
|
23 from grease.world import BaseWorld
|
|
24
|
|
25 import abc
|
|
26
|
|
27 class System(object):
|
|
28 """Grease system abstract base class. Systems define behaviorial aspects
|
|
29 of a |World|. All systems must define a :meth:`step`
|
|
30 method that is invoked by the world each timestep. User-defined systems
|
|
31 are not required to subclass this class.
|
|
32
|
|
33 See :ref:`an example system from the tutorial <tut-system-example>`.
|
|
34 """
|
|
35 __metaclass__ = abc.ABCMeta
|
|
36
|
|
37 world = None
|
|
38 """The |World| this system belongs to"""
|
|
39
|
|
40 def set_world(self, world):
|
|
41 """Bind the system to a world"""
|
|
42 self.world = world
|
|
43
|
|
44 @abc.abstractmethod
|
|
45 def step(self, dt):
|
|
46 """Execute a time step for the system. Must be defined
|
|
47 by all system classes.
|
|
48
|
|
49 :param dt: Time since last step invocation
|
|
50 :type dt: float
|
|
51 """
|
|
52
|
|
53 class Renderer(object):
|
|
54 """Grease renderer abstract base class. Renderers define the presentation
|
|
55 of a |World|. All renderers must define a :meth:`draw`
|
|
56 method that is invoked by the world when the display needs to be redrawn.
|
|
57 User-defined renderers are not required to subclass this class.
|
|
58
|
|
59 See :ref:`an example renderer from the tutorial <tut-renderer-example>`.
|
|
60 """
|
|
61 __metaclass__ = abc.ABCMeta
|
|
62
|
|
63 world = None
|
|
64 """The |World| this renderer belongs to"""
|
|
65
|
|
66 def set_world(self, world):
|
|
67 """Bind the system to a world"""
|
|
68 self.world = world
|
|
69
|
|
70 @abc.abstractmethod
|
|
71 def draw(self):
|
|
72 """Issue drawing commands for this renderer. Must be defined
|
|
73 for all renderer classes.
|
|
74 """
|
|
75
|