annotate src/parpg/bGrease/component/__init__.py @ 70:ee350343b69b

Changed data subrepo to a grease specific one
author KarstenBock@gmx.net
date Tue, 06 Sep 2011 15:39:27 +0200
parents 96af64cf3b81
children 0f659c7675f6
rev   line source
27
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
1 #############################################################################
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
2 #
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
3 # Copyright (c) 2010 by Casey Duncan and contributors
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
4 # All Rights Reserved.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
5 #
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
6 # This software is subject to the provisions of the MIT License
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
7 # A copy of the license should accompany this distribution.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
8 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
9 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
10 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
11 #
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
12 #############################################################################
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
13 """Components store all entity data in a given |World|. You can
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
14 think of components as tables with entities as their primary keys. Like
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
15 database tables, components are defined with a "schema" that specifies
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
16 the data fields. Each field in a component has a name and a type.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
17
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
18 Component objects themselves have a dict-like interface with entities
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
19 as keys and data records as values. An application will typically
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
20 interact with components via entity attributes, entity extents or
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
21 by joining them. For more information see:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
22
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
23 - :class:`~grease.entity.Entity` class.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
24 - :class:`~grease.world.EntityExtent` class.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
25 - :meth:`~grease.world.ComponentParts.join` method of ComponentParts.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
26
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
27 See also :ref:`defining custom components in the tutorial <custom-component-example>`.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
28 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
29
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
30 __version__ = '$Id$'
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
31
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
32 __all__ = ('Component', 'ComponentError', 'Position', 'Transform', 'Movement',
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
33 'Shape', 'Renderable', 'Collision')
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
34
66
96af64cf3b81 Renamed grease to bGrease (Basic Grease) to get rid of conflicts with an already installed grease.
KarstenBock@gmx.net
parents: 27
diff changeset
35 from bGrease.component.general import Component
96af64cf3b81 Renamed grease to bGrease (Basic Grease) to get rid of conflicts with an already installed grease.
KarstenBock@gmx.net
parents: 27
diff changeset
36 from bGrease.geometry import Vec2d, Vec2dArray, Rect
96af64cf3b81 Renamed grease to bGrease (Basic Grease) to get rid of conflicts with an already installed grease.
KarstenBock@gmx.net
parents: 27
diff changeset
37 from bGrease import color
27
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
38
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
39
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
40 class ComponentError(Exception):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
41 """General component error"""
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
42
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
43
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
44 class Position(Component):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
45 """Predefined component that stores position and orientation info for
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
46 entities.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
47
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
48 Fields:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
49
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
50 - **position** (Vec2d) -- Position vector
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
51 - **angle** (float) -- Angle, in degrees
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
52 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
53
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
54 def __init__(self):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
55 Component.__init__(self, position=Vec2d, angle=float)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
56
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
57
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
58 class Transform(Component):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
59 """Predefined component that stores offset, shear,
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
60 rotation and scale info for entity shapes.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
61
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
62 Fields:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
63
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
64 - **offset** (Vec2d)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
65 - **shear** (Vec2d)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
66 - **rotation** (float)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
67 - **scale** (float, default 1.0)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
68 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
69
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
70 def __init__(self):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
71 Component.__init__(self, offset=Vec2d, shear=Vec2d, rotation=float, scale=float)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
72 self.fields['scale'].default = lambda: 1.0
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
73
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
74
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
75 class Movement(Component):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
76 """Predefined component that stores velocity,
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
77 acceleration and rotation info for entities.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
78
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
79 Fields:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
80
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
81 - **velocity** (Vec2d) -- Rate of change of entity position
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
82 - **accel** (Vec2d) -- Rate of change of entity velocity
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
83 - **rotation** (Vec2d) -- Rate of change of entity angle, in degrees/time
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
84 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
85
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
86 def __init__(self):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
87 Component.__init__(self, velocity=Vec2d, accel=Vec2d, rotation=float)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
88
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
89
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
90 class Shape(Component):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
91 """Predefined component that stores shape vertices for entities
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
92
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
93 - **closed** (bool) -- If the shapes is closed implying an edge between
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
94 last and first vertices.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
95 - **verts** (Vec2dArray) -- Array of vertex points
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
96 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
97
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
98 def __init__(self):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
99 Component.__init__(self, closed=int, verts=Vec2dArray)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
100 self.fields['closed'].default = lambda: 1
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
101
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
102
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
103 class Renderable(Component):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
104 """Predefined component that identifies entities to be
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
105 rendered and provides their depth and color.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
106
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
107 - **depth** (float) -- Drawing depth, can be used to determine z-order
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
108 while rendering.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
109 - **color** (color.RGBA) -- Color used for entity. The effect of this
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
110 field depends on the renderer.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
111 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
112
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
113 def __init__(self):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
114 Component.__init__(self, depth=float, color=color.RGBA)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
115 self.fields['color'].default = lambda: color.RGBA(1,1,1,1)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
116
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
117
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
118 class Collision(Component):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
119 """Predefined component that stores collision masks to determine
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
120 which entities can collide.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
121
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
122 Fields:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
123
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
124 - **aabb** (Rect) -- The axis-aligned bounding box for the entity.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
125 This is used for broad-phase collision detection.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
126
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
127 - **radius** (float) -- The collision radius of the entity, used for narrow-phase
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
128 collision detection. The exact meaning of this value depends on the collision
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
129 system in use.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
130
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
131 - **from_mask** (int) -- A bitmask that determines what entities this object
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
132 can collide with.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
133
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
134 - **into_mask** (int) -- A bitmask that determines what entities can collide
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
135 with this object.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
136
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
137 When considering an entity A for collision with entity B, A's ``from_mask`` is
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
138 bit ANDed with B's ``into_mask``. If the result is nonzero (meaning 1 or more
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
139 bits is set the same for each) then the collision test is made. Otherwise,
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
140 the pair cannot collide.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
141
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
142 The default value for both of these masks is ``0xffffffff``, which means that
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
143 all entities will collide with each other by default.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
144 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
145 def __init__(self):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
146 Component.__init__(self, aabb=Rect, radius=float, from_mask=int, into_mask=int)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
147 self.fields['into_mask'].default = lambda: 0xffffffff
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
148 self.fields['from_mask'].default = lambda: 0xffffffff
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
149