luma-engine 0.1.0__tar.gz

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.
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: luma-engine
3
+ Version: 0.1.0
4
+ Summary: A lightweight python game engine powered by SDL3
5
+ Author-email: CyzmiX <itzmedigamingx@gmail.com>
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+
12
+ # Luma
13
+
14
+ Luma is a lightweight Python game engine powered by SDL3.
@@ -0,0 +1,3 @@
1
+ # Luma
2
+
3
+ Luma is a lightweight Python game engine powered by SDL3.
@@ -0,0 +1,19 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+
6
+ [project]
7
+ version = "0.1.0"
8
+ name = "luma-engine"
9
+ requires-python = ">=3.8"
10
+ description = "A lightweight python game engine powered by SDL3"
11
+ readme = "README.md"
12
+ authors = [
13
+ { name="CyzmiX", email="itzmedigamingx@gmail.com" },
14
+ ]
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ from .core.engine import Luma
File without changes
@@ -0,0 +1,214 @@
1
+ import ctypes
2
+ import os
3
+ from luma.sdl.event import SDL_Event
4
+ from luma.graphics.graphics import Luma_Graphics
5
+ from luma.core.event import Luma_EventManager, DEFAULT_EVENTS_ENUM
6
+ import luma.sdl.keys
7
+ from platform import system
8
+ import sys
9
+
10
+
11
+ def get_sdl_path():
12
+ if getattr(sys, "frozen", False):
13
+ base = sys._MEIPASS
14
+ else:
15
+ base = os.path.dirname(__file__)
16
+
17
+ lib_ext = "dll"
18
+
19
+ if system() == "Linux":
20
+ lib_ext = "so"
21
+ elif system() == "Darwin":
22
+ lib_ext = "dylib"
23
+
24
+ return os.path.join(base, os.path.abspath(f"./src/luma/lib/SDL3.{lib_ext}"))
25
+
26
+
27
+ class Luma:
28
+
29
+ SDL_INIT_AUDIO = 0x10
30
+ SDL_INIT_VIDEO = 0x20
31
+ SDL_INIT_JOYSTICK = 0x200
32
+ SDL_INIT_HAPTIC = 0x1000
33
+ SDL_INIT_GAMEPAD = 0x2000
34
+ SDL_INIT_EVENTS = 0x4000
35
+ SDL_INIT_SENSOR = 0x8000
36
+ SDL_INIT_CAMERA = 0x10000
37
+ SDL_EVENT_QUIT = 0x100
38
+ SDL_BLENDMODE_BLEND = 0x00000001
39
+
40
+ SDL_EVENT_KEY_DOWN = 0x300
41
+ SDL_EVENT_KEY_UP = 0x301
42
+
43
+ KEYS = luma.sdl.keys
44
+
45
+ EVENTS = DEFAULT_EVENTS_ENUM
46
+
47
+ def __init__(self, sdl_path: str | None = None):
48
+ self.window = None
49
+ self.renderer = None
50
+
51
+ lib_ext = "dll"
52
+
53
+ if system() == "Linux":
54
+ lib_ext = "so"
55
+ elif system() == "Darwin":
56
+ lib_ext = "dylib"
57
+
58
+ self.sdl_path = sdl_path or os.path.abspath(f"./src/luma/lib/SDL3.{lib_ext}")
59
+ self.sdl = ctypes.CDLL(self.sdl_path)
60
+ self._setup_functions()
61
+ self.graphics = None
62
+
63
+ self.running = True
64
+ self._draw_method = None
65
+ self._update_method = None
66
+ self.event_manager = Luma_EventManager()
67
+
68
+ self._keys_pressed = set()
69
+
70
+ self.sdl.SDL_Init(Luma.SDL_INIT_VIDEO)
71
+
72
+ def _setup_functions(self):
73
+ self.sdl.SDL_CreateWindow.argtypes = [
74
+ ctypes.c_char_p, # title
75
+ ctypes.c_int, # w
76
+ ctypes.c_int, # h
77
+ ctypes.c_uint64, # SDL_WindowFlags
78
+ ]
79
+
80
+ self.sdl.SDL_CreateWindow.restype = ctypes.c_void_p
81
+
82
+ self.sdl.SDL_CreateRenderer.argtypes = [
83
+ ctypes.c_void_p, # window
84
+ ctypes.c_char_p, # renderer name
85
+ ]
86
+
87
+ self.sdl.SDL_CreateRenderer.restype = ctypes.c_void_p
88
+
89
+ self.sdl.SDL_RenderClear.argtypes = [
90
+ ctypes.c_void_p, # renderer
91
+ ]
92
+
93
+ self.sdl.SDL_RenderClear.restype = ctypes.c_bool
94
+
95
+ self.sdl.SDL_RenderPresent.argtypes = [
96
+ ctypes.c_void_p, # renderer
97
+ ]
98
+
99
+ self.sdl.SDL_RenderPresent.restype = ctypes.c_bool
100
+
101
+ self.sdl.SDL_DestroyRenderer.argtypes = [
102
+ ctypes.c_void_p, # renderer
103
+ ]
104
+
105
+ self.sdl.SDL_DestroyRenderer.restype = ctypes.c_void_p
106
+
107
+ self.sdl.SDL_DestroyWindow.argtypes = [
108
+ ctypes.c_void_p, # window
109
+ ]
110
+
111
+ self.sdl.SDL_DestroyWindow.restype = ctypes.c_void_p
112
+
113
+ self.sdl.SDL_PollEvent.argtypes = [ctypes.POINTER(SDL_Event)]
114
+
115
+ self.sdl.SDL_PollEvent.restype = ctypes.c_bool
116
+
117
+ self.sdl.SDL_GetTicks.restype = ctypes.c_uint64
118
+
119
+ self.sdl.SDL_SetRenderDrawBlendMode.argtypes = [
120
+ ctypes.c_void_p,
121
+ ctypes.c_uint64,
122
+ ]
123
+
124
+ self.sdl.SDL_SetRenderDrawBlendMode.restype = ctypes.c_bool
125
+
126
+ def create_window(self, title: str, width: int, height: int, flags: int = 0):
127
+
128
+ self.window = self.sdl.SDL_CreateWindow(title.encode(), width, height, flags)
129
+
130
+ if self.window is None:
131
+ self.quit()
132
+
133
+ self.renderer = self.sdl.SDL_CreateRenderer(self.window, None)
134
+
135
+ if self.renderer is None:
136
+ self.quit()
137
+
138
+ self.sdl.SDL_SetRenderDrawBlendMode(self.renderer, Luma.SDL_BLENDMODE_BLEND)
139
+
140
+ self.graphics = Luma_Graphics(self)
141
+
142
+ def draw(self, fn):
143
+ self._draw_method = fn
144
+
145
+ def update(self, func):
146
+ self._update_method = func
147
+
148
+ def on(self, event_name: str):
149
+ def decorator(func):
150
+ self.event_manager.new_event_callback(event_name, func)
151
+ return func
152
+
153
+ return decorator
154
+
155
+ def isKeyHeld(self, key: str):
156
+ return key in self._keys_pressed
157
+
158
+ def run(self):
159
+ lastTime = self.sdl.SDL_GetTicks()
160
+ try:
161
+ while self.running:
162
+
163
+ now = self.sdl.SDL_GetTicks()
164
+
165
+ dt = float(now - lastTime) / 1000.0
166
+
167
+ lastTime = now
168
+ event = SDL_Event()
169
+
170
+ while self.sdl.SDL_PollEvent(ctypes.byref(event)):
171
+ if event.type == Luma.SDL_EVENT_QUIT:
172
+ self.running = False
173
+ break
174
+
175
+ if event.type == Luma.SDL_EVENT_KEY_DOWN:
176
+
177
+ if event.key.key not in self._keys_pressed:
178
+ self.event_manager.dispatch(
179
+ Luma.EVENTS.KEYPRESS, event.key.key
180
+ )
181
+
182
+ self._keys_pressed.add(event.key.key)
183
+
184
+ if event.type == Luma.SDL_EVENT_KEY_UP:
185
+
186
+ self._keys_pressed.discard(event.key.key)
187
+
188
+ self.event_manager.dispatch(Luma.EVENTS.KEYUP, event.key.key)
189
+
190
+ if callable(self._update_method):
191
+ self._update_method(dt)
192
+
193
+ self.sdl.SDL_RenderClear(self.renderer)
194
+
195
+ if callable(self._draw_method):
196
+ self._draw_method()
197
+
198
+ self.sdl.SDL_RenderPresent(self.renderer)
199
+
200
+ except Exception as e:
201
+ print(e)
202
+
203
+ finally:
204
+ self.quit()
205
+
206
+ def quit(self):
207
+ if self.renderer:
208
+ self.sdl.SDL_DestroyRenderer(self.renderer)
209
+ if self.window:
210
+ self.sdl.SDL_DestroyWindow(self.window)
211
+
212
+ self.sdl.SDL_Quit()
213
+
214
+ self.event_manager.dispatch(Luma.EVENTS.QUIT)
@@ -0,0 +1,34 @@
1
+ class DEFAULT_EVENTS_ENUM:
2
+ KEYPRESS = "keypress"
3
+ KEYUP = "keyup"
4
+ QUIT = "quit"
5
+
6
+
7
+ class Luma_Event:
8
+ def __init__(self, name: str, callback_=None):
9
+ self.name = name
10
+
11
+ self.callbacks = [callback_]
12
+
13
+ def dispatch(self, *args):
14
+ for c in self.callbacks:
15
+ if callable(c):
16
+ c(*args)
17
+
18
+
19
+ class Luma_EventManager:
20
+ def __init__(self):
21
+ self._events = {}
22
+
23
+ def new_event_callback(self, name, callback_):
24
+ if self._events.get(name):
25
+ self._events[name].callbacks.append(callback_)
26
+ else:
27
+ self._events[name] = Luma_Event(name, callback_)
28
+
29
+ def dispatch(self, name, *args):
30
+ event = self._events.get(name)
31
+ if not event or not hasattr(event, "callbacks"):
32
+ return
33
+
34
+ event.dispatch(*args)
@@ -0,0 +1,69 @@
1
+ import ctypes
2
+
3
+ from typing import TYPE_CHECKING
4
+ from luma.sdl.shapes import SDL_Rect
5
+
6
+ if TYPE_CHECKING:
7
+ from luma.core.engine import Luma
8
+
9
+
10
+ class Luma_Graphics:
11
+ OPAQUE = 255
12
+ TRANSPARENT = 0
13
+ RED = (255, 0, 0, 255)
14
+ GREEN = (0, 255, 0, 255)
15
+ BLUE = (0, 0, 255, 255)
16
+ BLACK = (0, 0, 0, 255)
17
+ WHITE = (255, 255, 255, 255)
18
+
19
+ def __init__(self, sdl: "Luma"):
20
+ self.engine = sdl
21
+ self._setup_functions()
22
+
23
+ def _setup_functions(self):
24
+ self.sdl.SDL_SetRenderDrawColor.argtypes = [
25
+ ctypes.c_void_p,
26
+ ctypes.c_uint8,
27
+ ctypes.c_uint8,
28
+ ctypes.c_uint8,
29
+ ctypes.c_uint8,
30
+ ]
31
+
32
+ self.sdl.SDL_SetRenderDrawColor.restype = ctypes.c_bool
33
+
34
+ self.sdl.SDL_RenderRect.argtypes = [ctypes.c_void_p, ctypes.POINTER(SDL_Rect)]
35
+
36
+ self.sdl.SDL_RenderRect.restype = ctypes.c_bool
37
+
38
+ self.sdl.SDL_RenderFillRect.argtypes = [
39
+ ctypes.c_void_p,
40
+ ctypes.POINTER(SDL_Rect),
41
+ ]
42
+
43
+ self.sdl.SDL_RenderFillRect.restype = ctypes.c_bool
44
+
45
+ @property
46
+ def renderer(self):
47
+ return self.engine.renderer
48
+
49
+ @property
50
+ def sdl(self):
51
+ return self.engine.sdl
52
+
53
+ def setDrawColor(self, *args):
54
+ if len(args) == 1 and isinstance(args[0], (tuple, list)):
55
+ args = args[0]
56
+
57
+ r, g, b, *alpha = args
58
+ a = alpha[0] if alpha else 255
59
+
60
+ self.sdl.SDL_SetRenderDrawColor(self.renderer, r, g, b, a)
61
+
62
+ def resetDrawColor(self):
63
+ self.sdl.SDL_SetRenderDrawColor(self.renderer, 0, 0, 0, 255)
64
+
65
+ def drawRect(self, x, y, w, h, fill: bool = True):
66
+ if fill:
67
+ self.sdl.SDL_RenderFillRect(self.renderer, SDL_Rect(x, y, w, h))
68
+ else:
69
+ self.sdl.SDL_RenderRect(self.renderer, SDL_Rect(x, y, w, h))
@@ -0,0 +1,10 @@
1
+ import ctypes
2
+ from luma.sdl.keys import SDL_KeyboardEvent
3
+
4
+
5
+ class SDL_Event(ctypes.Union):
6
+ _fields_ = [
7
+ ("type", ctypes.c_uint32),
8
+ ("padding", ctypes.c_uint8 * 128),
9
+ ("key", SDL_KeyboardEvent),
10
+ ]
@@ -0,0 +1,106 @@
1
+ RETURN = 0x0000000D
2
+ ESCAPE = 0x0000001B
3
+ BACKSPACE = 0x00000008
4
+ TAB = 0x00000009
5
+ SPACE = 0x00000020
6
+ EXCLAIM = 0x00000021
7
+ DBLAPOSTROPHE = 0x00000022
8
+ HASH = 0x00000023
9
+ DOLLAR = 0x00000024
10
+ PERCENT = 0x00000025
11
+ AMPERSAND = 0x00000026
12
+ APOSTROPHE = 0x00000027
13
+ LEFTPAREN = 0x00000028
14
+ RIGHTPAREN = 0x00000029
15
+ ASTERISK = 0x0000002A
16
+ PLUS = 0x0000002B
17
+ COMMA = 0x0000002C
18
+ MINUS = 0x0000002D
19
+ PERIOD = 0x0000002E
20
+ SLASH = 0x0000002F
21
+ NUM_0 = 0x00000030
22
+ NUM_1 = 0x00000031
23
+ NUM_2 = 0x00000032
24
+ NUM_3 = 0x00000033
25
+ NUM_4 = 0x00000034
26
+ NUM_5 = 0x00000035
27
+ NUM_6 = 0x00000036
28
+ NUM_7 = 0x00000037
29
+ NUM_8 = 0x00000038
30
+ NUM_9 = 0x00000039
31
+ COLON = 0x0000003A
32
+ SEMICOLON = 0x0000003B
33
+ LESS = 0x0000003C
34
+ EQUALS = 0x0000003D
35
+ GREATER = 0x0000003E
36
+ QUESTION = 0x0000003F
37
+ AT = 0x00000040
38
+ LEFTBRACKET = 0x0000005B
39
+ BACKSLASH = 0x0000005C
40
+ RIGHTBRACKET = 0x0000005D
41
+ CARET = 0x0000005E
42
+ UNDERSCORE = 0x0000005F
43
+ GRAVE = 0x00000060
44
+ A = 0x00000061
45
+ B = 0x00000062
46
+ C = 0x00000063
47
+ D = 0x00000064
48
+ E = 0x00000065
49
+ F = 0x00000066
50
+ G = 0x00000067
51
+ H = 0x00000068
52
+ I = 0x00000069
53
+ J = 0x0000006A
54
+ K = 0x0000006B
55
+ L = 0x0000006C
56
+ M = 0x0000006D
57
+ N = 0x0000006E
58
+ O = 0x0000006F
59
+ P = 0x00000070
60
+ Q = 0x00000071
61
+ R = 0x00000072
62
+ S = 0x00000073
63
+ T = 0x00000074
64
+ U = 0x00000075
65
+ V = 0x00000076
66
+ W = 0x00000077
67
+ X = 0x00000078
68
+ Y = 0x00000079
69
+ Z = 0x0000007A
70
+ LEFTBRACE = 0x0000007B
71
+ PIPE = 0x0000007C
72
+ RIGHTBRACE = 0x0000007D
73
+ TILDE = 0x0000007E
74
+ DELETE = 0x0000007F
75
+ PLUSMINUS = 0x000000B1
76
+ CAPSLOCK = 0x40000039
77
+ F1 = 0x4000003A
78
+ F2 = 0x4000003B
79
+ F3 = 0x4000003C
80
+ F4 = 0x4000003D
81
+ F5 = 0x4000003E
82
+ F6 = 0x4000003F
83
+ F7 = 0x40000040
84
+ F8 = 0x40000041
85
+ F9 = 0x40000042
86
+ F10 = 0x40000043
87
+ F11 = 0x40000044
88
+ F12 = 0x40000045
89
+
90
+ import ctypes
91
+
92
+
93
+ class SDL_KeyboardEvent(ctypes.Structure):
94
+ _fields_ = [
95
+ ("type", ctypes.c_uint32),
96
+ ("reserved", ctypes.c_uint32),
97
+ ("timestamp", ctypes.c_uint64),
98
+ ("windowID", ctypes.c_uint32),
99
+ ("which", ctypes.c_uint32),
100
+ ("scancode", ctypes.c_uint32),
101
+ ("key", ctypes.c_uint32),
102
+ ("mod", ctypes.c_uint32),
103
+ ("raw", ctypes.c_uint16),
104
+ ("down", ctypes.c_bool),
105
+ ("repeat", ctypes.c_bool),
106
+ ]
@@ -0,0 +1,10 @@
1
+ import ctypes
2
+
3
+
4
+ class SDL_Rect(ctypes.Structure):
5
+ _fields_ = [
6
+ ("x", ctypes.c_float),
7
+ ("y", ctypes.c_float),
8
+ ("w", ctypes.c_float),
9
+ ("h", ctypes.c_float),
10
+ ]
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: luma-engine
3
+ Version: 0.1.0
4
+ Summary: A lightweight python game engine powered by SDL3
5
+ Author-email: CyzmiX <itzmedigamingx@gmail.com>
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+
12
+ # Luma
13
+
14
+ Luma is a lightweight Python game engine powered by SDL3.
@@ -0,0 +1,14 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/luma/__init__.py
4
+ src/luma/consts.py
5
+ src/luma/core/engine.py
6
+ src/luma/core/event.py
7
+ src/luma/graphics/graphics.py
8
+ src/luma/sdl/event.py
9
+ src/luma/sdl/keys.py
10
+ src/luma/sdl/shapes.py
11
+ src/luma_engine.egg-info/PKG-INFO
12
+ src/luma_engine.egg-info/SOURCES.txt
13
+ src/luma_engine.egg-info/dependency_links.txt
14
+ src/luma_engine.egg-info/top_level.txt