kraken-engine 1.0.0__cp311-cp311-macosx_11_0_arm64.whl → 1.1.0__cp311-cp311-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of kraken-engine might be problematic. Click here for more details.

@@ -0,0 +1,235 @@
1
+ """
2
+ Collision detection functions
3
+ """
4
+ from __future__ import annotations
5
+ import pykraken._core
6
+ import typing
7
+ __all__: list[str] = ['contains', 'overlap']
8
+ @typing.overload
9
+ def contains(outer: pykraken._core.Rect, inner: pykraken._core.Rect) -> bool:
10
+ """
11
+ Checks if one rectangle completely contains another rectangle.
12
+
13
+ Parameters:
14
+ outer (Rect): The outer rectangle.
15
+ inner (Rect): The inner rectangle.
16
+
17
+ Returns:
18
+ bool: Whether the outer rectangle completely contains the inner rectangle.
19
+ """
20
+ @typing.overload
21
+ def contains(rect: pykraken._core.Rect, circle: pykraken._core.Circle) -> bool:
22
+ """
23
+ Checks if a rectangle completely contains a circle.
24
+
25
+ Parameters:
26
+ rect (Rect): The rectangle.
27
+ circle (Circle): The circle.
28
+
29
+ Returns:
30
+ bool: Whether the rectangle completely contains the circle.
31
+ """
32
+ @typing.overload
33
+ def contains(rect: pykraken._core.Rect, line: pykraken._core.Line) -> bool:
34
+ """
35
+ Checks if a rectangle completely contains a line.
36
+
37
+ Parameters:
38
+ rect (Rect): The rectangle.
39
+ line (Line): The line.
40
+
41
+ Returns:
42
+ bool: Whether the rectangle completely contains the line.
43
+ """
44
+ @typing.overload
45
+ def contains(outer: pykraken._core.Circle, inner: pykraken._core.Circle) -> bool:
46
+ """
47
+ Checks if one circle completely contains another circle.
48
+
49
+ Parameters:
50
+ outer (Circle): The outer circle.
51
+ inner (Circle): The inner circle.
52
+
53
+ Returns:
54
+ bool: Whether the outer circle completely contains the inner circle.
55
+ """
56
+ @typing.overload
57
+ def contains(circle: pykraken._core.Circle, rect: pykraken._core.Rect) -> bool:
58
+ """
59
+ Checks if a circle completely contains a rectangle.
60
+
61
+ Parameters:
62
+ circle (Circle): The circle.
63
+ rect (Rect): The rectangle.
64
+
65
+ Returns:
66
+ bool: Whether the circle completely contains the rectangle.
67
+ """
68
+ @typing.overload
69
+ def contains(circle: pykraken._core.Circle, line: pykraken._core.Line) -> bool:
70
+ """
71
+ Checks if a circle completely contains a line.
72
+
73
+ Parameters:
74
+ circle (Circle): The circle.
75
+ line (Line): The line.
76
+
77
+ Returns:
78
+ bool: Whether the circle completely contains the line.
79
+ """
80
+ @typing.overload
81
+ def overlap(a: pykraken._core.Rect, b: pykraken._core.Rect) -> bool:
82
+ """
83
+ Checks if two rectangles overlap.
84
+
85
+ Parameters:
86
+ a (Rect): The first rectangle.
87
+ b (Rect): The second rectangle.
88
+
89
+ Returns:
90
+ bool: Whether the rectangles overlap.
91
+ """
92
+ @typing.overload
93
+ def overlap(rect: pykraken._core.Rect, circle: pykraken._core.Circle) -> bool:
94
+ """
95
+ Checks if a rectangle and a circle overlap.
96
+
97
+ Parameters:
98
+ rect (Rect): The rectangle.
99
+ circle (Circle): The circle.
100
+
101
+ Returns:
102
+ bool: Whether the rectangle and circle overlap.
103
+ """
104
+ @typing.overload
105
+ def overlap(rect: pykraken._core.Rect, line: pykraken._core.Line) -> bool:
106
+ """
107
+ Checks if a rectangle and a line overlap.
108
+
109
+ Parameters:
110
+ rect (Rect): The rectangle.
111
+ line (Line): The line.
112
+
113
+ Returns:
114
+ bool: Whether the rectangle and line overlap.
115
+ """
116
+ @typing.overload
117
+ def overlap(rect: pykraken._core.Rect, point: pykraken._core.Vec2) -> bool:
118
+ """
119
+ Checks if a rectangle contains a point.
120
+
121
+ Parameters:
122
+ rect (Rect): The rectangle.
123
+ point (Vec2): The point.
124
+
125
+ Returns:
126
+ bool: Whether the rectangle contains the point.
127
+ """
128
+ @typing.overload
129
+ def overlap(a: pykraken._core.Circle, b: pykraken._core.Circle) -> bool:
130
+ """
131
+ Checks if two circles overlap.
132
+
133
+ Parameters:
134
+ a (Circle): The first circle.
135
+ b (Circle): The second circle.
136
+
137
+ Returns:
138
+ bool: Whether the circles overlap.
139
+ """
140
+ @typing.overload
141
+ def overlap(circle: pykraken._core.Circle, rect: pykraken._core.Rect) -> bool:
142
+ """
143
+ Checks if a circle and a rectangle overlap.
144
+
145
+ Parameters:
146
+ circle (Circle): The circle.
147
+ rect (Rect): The rectangle.
148
+
149
+ Returns:
150
+ bool: Whether the circle and rectangle overlap.
151
+ """
152
+ @typing.overload
153
+ def overlap(circle: pykraken._core.Circle, line: pykraken._core.Line) -> bool:
154
+ """
155
+ Checks if a circle and a line overlap.
156
+
157
+ Parameters:
158
+ circle (Circle): The circle.
159
+ line (Line): The line.
160
+
161
+ Returns:
162
+ bool: Whether the circle and line overlap.
163
+ """
164
+ @typing.overload
165
+ def overlap(circle: pykraken._core.Circle, point: pykraken._core.Vec2) -> bool:
166
+ """
167
+ Checks if a circle contains a point.
168
+
169
+ Parameters:
170
+ circle (Circle): The circle.
171
+ point (Vec2): The point.
172
+
173
+ Returns:
174
+ bool: Whether the circle contains the point.
175
+ """
176
+ @typing.overload
177
+ def overlap(a: pykraken._core.Line, b: pykraken._core.Line) -> bool:
178
+ """
179
+ Checks if two lines overlap (intersect).
180
+
181
+ Parameters:
182
+ a (Line): The first line.
183
+ b (Line): The second line.
184
+
185
+ Returns:
186
+ bool: Whether the lines intersect.
187
+ """
188
+ @typing.overload
189
+ def overlap(line: pykraken._core.Line, rect: pykraken._core.Rect) -> bool:
190
+ """
191
+ Checks if a line and a rectangle overlap.
192
+
193
+ Parameters:
194
+ line (Line): The line.
195
+ rect (Rect): The rectangle.
196
+
197
+ Returns:
198
+ bool: Whether the line and rectangle overlap.
199
+ """
200
+ @typing.overload
201
+ def overlap(line: pykraken._core.Line, circle: pykraken._core.Circle) -> bool:
202
+ """
203
+ Checks if a line and a circle overlap.
204
+
205
+ Parameters:
206
+ line (Line): The line.
207
+ circle (Circle): The circle.
208
+
209
+ Returns:
210
+ bool: Whether the line and circle overlap.
211
+ """
212
+ @typing.overload
213
+ def overlap(point: pykraken._core.Vec2, rect: pykraken._core.Rect) -> bool:
214
+ """
215
+ Checks if a point is inside a rectangle.
216
+
217
+ Parameters:
218
+ point (Vec2): The point.
219
+ rect (Rect): The rectangle.
220
+
221
+ Returns:
222
+ bool: Whether the point is inside the rectangle.
223
+ """
224
+ @typing.overload
225
+ def overlap(point: pykraken._core.Vec2, circle: pykraken._core.Circle) -> bool:
226
+ """
227
+ Checks if a point is inside a circle.
228
+
229
+ Parameters:
230
+ point (Vec2): The point.
231
+ circle (Circle): The circle.
232
+
233
+ Returns:
234
+ bool: Whether the point is inside the circle.
235
+ """
@@ -4,7 +4,7 @@ Functions for rendering graphics
4
4
  from __future__ import annotations
5
5
  import pykraken._core
6
6
  import typing
7
- __all__: list[str] = ['clear', 'draw', 'get_res', 'present']
7
+ __all__: list[str] = ['clear', 'draw', 'get_res', 'present', 'read_pixels']
8
8
  @typing.overload
9
9
  def clear(color: typing.Any = None) -> None:
10
10
  """
@@ -30,22 +30,22 @@ def clear(r: typing.SupportsInt, g: typing.SupportsInt, b: typing.SupportsInt, a
30
30
  @typing.overload
31
31
  def draw(texture: pykraken._core.Texture, dst: pykraken._core.Rect, src: typing.Any = None) -> None:
32
32
  """
33
- Render a texture with specified destination and source rectangles.
33
+ Render a texture with specified destination and source rectangles.
34
34
 
35
- Args:
36
- texture (Texture): The texture to render.
37
- dst (Rect): The destination rectangle on the renderer.
38
- src (Rect, optional): The source rectangle from the texture. Defaults to entire texture if not specified.
35
+ Args:
36
+ texture (Texture): The texture to render.
37
+ dst (Rect): The destination rectangle on the renderer.
38
+ src (Rect, optional): The source rectangle from the texture. Defaults to entire texture if not specified.
39
39
  """
40
40
  @typing.overload
41
41
  def draw(texture: pykraken._core.Texture, pos: typing.Any = None, anchor: pykraken._core.Anchor = pykraken._core.Anchor.CENTER) -> None:
42
42
  """
43
- Render a texture at the specified position with anchor alignment.
43
+ Render a texture at the specified position with anchor alignment.
44
44
 
45
- Args:
46
- texture (Texture): The texture to render.
47
- pos (Vec2, optional): The position to draw at. Defaults to (0, 0).
48
- anchor (Anchor, optional): The anchor point for positioning. Defaults to CENTER.
45
+ Args:
46
+ texture (Texture): The texture to render.
47
+ pos (Vec2, optional): The position to draw at. Defaults to (0, 0).
48
+ anchor (Anchor, optional): The anchor point for positioning. Defaults to CENTER.
49
49
  """
50
50
  def get_res() -> pykraken._core.Vec2:
51
51
  """
@@ -61,3 +61,14 @@ def present() -> None:
61
61
  This finalizes the current frame and displays it. Should be called after
62
62
  all drawing operations for the frame are complete.
63
63
  """
64
+ def read_pixels(src: typing.Any = None) -> pykraken._core.PixelArray:
65
+ """
66
+ Read pixel data from the renderer within the specified rectangle.
67
+
68
+ Args:
69
+ src (Rect, optional): The rectangle area to read pixels from. Defaults to entire renderer if None.
70
+ Returns:
71
+ PixelArray: An array containing the pixel data.
72
+ Raises:
73
+ RuntimeError: If reading pixels fails.
74
+ """
Binary file
@@ -0,0 +1,55 @@
1
+ from pydantic import BaseModel
2
+ import struct
3
+
4
+
5
+ class ShaderUniform(BaseModel):
6
+ """
7
+ Base class for shader uniform data structures.
8
+
9
+ Inherits from Pydantic's BaseModel to provide type validation and serialization
10
+ for shader uniform buffers. Subclass this to define your shader's uniform layout,
11
+ and use `to_bytes()` to convert the data to a binary format suitable for upload
12
+ to the GPU via `ShaderState.set_uniform()`.
13
+
14
+ Supported field types:
15
+ - float: Packed as 'f' (4 bytes)
16
+ - int: Packed as 'i' (4 bytes, signed)
17
+ - bool: Packed as '?' (1 byte)
18
+ - tuple/list of 2-4 floats: Packed as vectors (vec2, vec3, vec4)
19
+ """
20
+
21
+ def to_bytes(self) -> bytes:
22
+ """
23
+ Converts the uniform data to a packed binary format.
24
+
25
+ Serializes all fields in the model to a bytes object using Python's struct
26
+ module, suitable for uploading to GPU uniform buffers. The packing format
27
+ is automatically determined based on field types.
28
+
29
+ Returns:
30
+ bytes: The packed binary representation of the uniform data.
31
+
32
+ Raises:
33
+ ValueError: If a tuple/list field has an invalid length (not 2, 3, or 4).
34
+ TypeError: If a field has an unsupported type.
35
+ """
36
+ fmt = ""
37
+ values = []
38
+
39
+ for name, value in self.model_dump().items():
40
+ if isinstance(value, float):
41
+ fmt += "f"; values.append(value)
42
+ elif isinstance(value, int):
43
+ fmt += "i"; values.append(value)
44
+ elif isinstance(value, bool):
45
+ fmt += "?"; values.append(value)
46
+ elif isinstance(value, (tuple, list)):
47
+ n = len(value)
48
+ if n not in (2, 3, 4):
49
+ raise ValueError(f"Field '{name}' length {n} invalid, must be 2, 3, or 4.")
50
+ fmt += f"{n}f"
51
+ values.extend(map(float, value))
52
+ else:
53
+ raise TypeError(f"Unsupported uniform field '{name}' of type '{type(value)}'")
54
+
55
+ return struct.pack(fmt, *values)
@@ -0,0 +1,59 @@
1
+ from __future__ import annotations
2
+ import inspect
3
+ import pydantic._internal._decorators
4
+ import pydantic.main
5
+ from pydantic.main import BaseModel
6
+ import pydantic_core._pydantic_core
7
+ import struct as struct
8
+ import typing
9
+ __all__: list[str] = ['BaseModel', 'ShaderUniform', 'struct']
10
+ class ShaderUniform(pydantic.main.BaseModel):
11
+ """
12
+
13
+ Base class for shader uniform data structures.
14
+
15
+ Inherits from Pydantic's BaseModel to provide type validation and serialization
16
+ for shader uniform buffers. Subclass this to define your shader's uniform layout,
17
+ and use `to_bytes()` to convert the data to a binary format suitable for upload
18
+ to the GPU via `ShaderState.set_uniform()`.
19
+
20
+ Supported field types:
21
+ - float: Packed as 'f' (4 bytes)
22
+ - int: Packed as 'i' (4 bytes, signed)
23
+ - bool: Packed as '?' (1 byte)
24
+ - tuple/list of 2-4 floats: Packed as vectors (vec2, vec3, vec4)
25
+ """
26
+ __abstractmethods__: typing.ClassVar[frozenset] # value = frozenset()
27
+ __class_vars__: typing.ClassVar[set] = set()
28
+ __private_attributes__: typing.ClassVar[dict] = {}
29
+ __pydantic_complete__: typing.ClassVar[bool] = True
30
+ __pydantic_computed_fields__: typing.ClassVar[dict] = {}
31
+ __pydantic_core_schema__: typing.ClassVar[dict] = {'type': 'model', 'cls': ShaderUniform, 'schema': {'type': 'model-fields', 'fields': {}, 'model_name': 'ShaderUniform', 'computed_fields': list()}, 'custom_init': False, 'root_model': False, 'config': {'title': 'ShaderUniform'}, 'ref': 'pykraken.shader_uniform.ShaderUniform:2062985552560', 'metadata': {'pydantic_js_functions': [pydantic.main.BaseModel.__get_pydantic_json_schema__]}}
32
+ __pydantic_custom_init__: typing.ClassVar[bool] = False
33
+ __pydantic_decorators__: typing.ClassVar[pydantic._internal._decorators.DecoratorInfos] # value = DecoratorInfos(validators={}, field_validators={}, root_validators={}, field_serializers={}, model_serializers={}, model_validators={}, computed_fields={})
34
+ __pydantic_fields__: typing.ClassVar[dict] = {}
35
+ __pydantic_generic_metadata__: typing.ClassVar[dict] = {'origin': None, 'args': tuple(), 'parameters': tuple()}
36
+ __pydantic_parent_namespace__ = None
37
+ __pydantic_post_init__ = None
38
+ __pydantic_serializer__: typing.ClassVar[pydantic_core._pydantic_core.SchemaSerializer] # value = SchemaSerializer(serializer=Model(...
39
+ __pydantic_setattr_handlers__: typing.ClassVar[dict] = {}
40
+ __pydantic_validator__: typing.ClassVar[pydantic_core._pydantic_core.SchemaValidator] # value = SchemaValidator(title="ShaderUniform", validator=Model(...
41
+ __signature__: typing.ClassVar[inspect.Signature] # value = <Signature () -> None>
42
+ _abc_impl: typing.ClassVar[_abc._abc_data] # value = <_abc._abc_data object>
43
+ model_config: typing.ClassVar[dict] = {}
44
+ def to_bytes(self) -> bytes:
45
+ """
46
+
47
+ Converts the uniform data to a packed binary format.
48
+
49
+ Serializes all fields in the model to a bytes object using Python's struct
50
+ module, suitable for uploading to GPU uniform buffers. The packing format
51
+ is automatically determined based on field types.
52
+
53
+ Returns:
54
+ bytes: The packed binary representation of the uniform data.
55
+
56
+ Raises:
57
+ ValueError: If a tuple/list field has an invalid length (not 2, 3, or 4).
58
+ TypeError: If a field has an unsupported type.
59
+ """