raylib 5.0.0.0__tar.gz → 5.0.0.2__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.

Potentially problematic release.


This version of raylib might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: raylib
3
- Version: 5.0.0.0
3
+ Version: 5.0.0.2
4
4
  Summary: Python CFFI bindings for Raylib
5
5
  Home-page: https://github.com/electronstudio/raylib-python-cffi
6
6
  Author: Electron Studio
@@ -24,7 +24,7 @@ original Raylib.
24
24
  * Faster, fewer bugs and easier to maintain than ctypes.
25
25
  * Commercial-friendly license.
26
26
  * Docstrings and auto-completion.
27
- * **Now includes extra libraries: raymath, raygui, rlgl and physac**
27
+ * **Now includes extra libraries: raymath, raygui, rlgl, physac and GLFW**
28
28
 
29
29
  [Full documentation](http://electronstudio.github.io/raylib-python-cffi)
30
30
 
@@ -99,6 +99,48 @@ Use [the C API](https://electronstudio.github.io/raylib-python-cffi/raylib.html)
99
99
 
100
100
  Use [the Python API](https://electronstudio.github.io/raylib-python-cffi/pyray.html).
101
101
 
102
+ # Running in a web browser
103
+
104
+ [Pygbag](https://pypi.org/project/pygbag/) >=0.8.7 supports running in a web browser.
105
+
106
+ Make a folder `my_project` with a file `main.py`:
107
+
108
+ # /// script
109
+ # dependencies = [
110
+ # "cffi",
111
+ # "inflection",
112
+ # "raylib"
113
+ # ]
114
+ # ///
115
+ import asyncio
116
+ import platform
117
+ from pyray import *
118
+
119
+ async def main(): # You must have an async main function
120
+ init_window(500, 500, "Hello")
121
+ platform.window.window_resize() # You must add this line
122
+ while not window_should_close():
123
+ begin_drawing()
124
+ clear_background(WHITE)
125
+ draw_text("Hello world", 190, 200, 20, VIOLET)
126
+ end_drawing()
127
+ await asyncio.sleep(0) # You must call this in your main loop
128
+ close_window()
129
+
130
+ asyncio.run(main())
131
+
132
+ Then to create the web files and launch a web server:
133
+
134
+ python3 -m pip install --user --upgrade git+https://github.com/pygame-web/pygbag
135
+ python3 -m pygbag --git --PYBUILD 3.12 --ume_block 0 --template noctx.tmpl my_project
136
+
137
+ Point your browser to http://localhost:8000
138
+
139
+ This is all done by Pygbag rather than by me, so you should probably contact them with any issues.
140
+ Carefully read all their [documentation](https://pygame-web.github.io/).
141
+
142
+ It does work for most of the examples at https://electronstudio.github.io/raylib-python-cffi-pygbag-examples/
143
+
102
144
  # App showcase
103
145
 
104
146
  [Tanki](https://github.com/pkulev/tanki)
@@ -6,7 +6,7 @@ original Raylib.
6
6
  * Faster, fewer bugs and easier to maintain than ctypes.
7
7
  * Commercial-friendly license.
8
8
  * Docstrings and auto-completion.
9
- * **Now includes extra libraries: raymath, raygui, rlgl and physac**
9
+ * **Now includes extra libraries: raymath, raygui, rlgl, physac and GLFW**
10
10
 
11
11
  [Full documentation](http://electronstudio.github.io/raylib-python-cffi)
12
12
 
@@ -81,6 +81,48 @@ Use [the C API](https://electronstudio.github.io/raylib-python-cffi/raylib.html)
81
81
 
82
82
  Use [the Python API](https://electronstudio.github.io/raylib-python-cffi/pyray.html).
83
83
 
84
+ # Running in a web browser
85
+
86
+ [Pygbag](https://pypi.org/project/pygbag/) >=0.8.7 supports running in a web browser.
87
+
88
+ Make a folder `my_project` with a file `main.py`:
89
+
90
+ # /// script
91
+ # dependencies = [
92
+ # "cffi",
93
+ # "inflection",
94
+ # "raylib"
95
+ # ]
96
+ # ///
97
+ import asyncio
98
+ import platform
99
+ from pyray import *
100
+
101
+ async def main(): # You must have an async main function
102
+ init_window(500, 500, "Hello")
103
+ platform.window.window_resize() # You must add this line
104
+ while not window_should_close():
105
+ begin_drawing()
106
+ clear_background(WHITE)
107
+ draw_text("Hello world", 190, 200, 20, VIOLET)
108
+ end_drawing()
109
+ await asyncio.sleep(0) # You must call this in your main loop
110
+ close_window()
111
+
112
+ asyncio.run(main())
113
+
114
+ Then to create the web files and launch a web server:
115
+
116
+ python3 -m pip install --user --upgrade git+https://github.com/pygame-web/pygbag
117
+ python3 -m pygbag --git --PYBUILD 3.12 --ume_block 0 --template noctx.tmpl my_project
118
+
119
+ Point your browser to http://localhost:8000
120
+
121
+ This is all done by Pygbag rather than by me, so you should probably contact them with any issues.
122
+ Carefully read all their [documentation](https://pygame-web.github.io/).
123
+
124
+ It does work for most of the examples at https://electronstudio.github.io/raylib-python-cffi-pygbag-examples/
125
+
84
126
  # App showcase
85
127
 
86
128
  [Tanki](https://github.com/pkulev/tanki)
@@ -0,0 +1,143 @@
1
+ # Copyright (c) 2021 Richard Smith and others
2
+ #
3
+ # This program and the accompanying materials are made available under the
4
+ # terms of the Eclipse Public License 2.0 which is available at
5
+ # http://www.eclipse.org/legal/epl-2.0.
6
+ #
7
+ # This Source Code may also be made available under the following Secondary
8
+ # licenses when the conditions for such availability set forth in the Eclipse
9
+ # Public License, v. 2.0 are satisfied: GNU General Public License, version 2
10
+ # with the GNU Classpath Exception which is
11
+ # available at https://www.gnu.org/software/classpath/license.html.
12
+ #
13
+ # SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
14
+ import re
15
+ import weakref
16
+ from array import array
17
+
18
+ from raylib import rl, ffi
19
+ from raylib.colors import *
20
+
21
+ try:
22
+ from raylib.defines import *
23
+ except AttributeError:
24
+ print("sorry deprecated enums dont work on dynamic version")
25
+
26
+ from inspect import getmembers, isbuiltin
27
+
28
+ current_module = __import__(__name__)
29
+
30
+
31
+ def _underscore(word: str) -> str:
32
+ """
33
+ from inflection
34
+ """
35
+ word = re.sub(r"([A-Z]+)([A-Z][a-z])", r'\1_\2', word)
36
+ word = re.sub(r"([a-z\d])([A-Z])", r'\1_\2', word)
37
+ word = word.replace("-", "_")
38
+ return word.lower()
39
+
40
+
41
+ def pointer(struct):
42
+ return ffi.addressof(struct)
43
+
44
+
45
+ # I'm concerned that we are doing a lot of string comparisons on every function call to detect types.
46
+ # Quickest way would probably be isinstance(result, ffi._backend._CDataBase) but that class name varies
47
+ # depending on if binding is static/dynamic
48
+ # (and possibly also different on pypy implementations?).
49
+ # which makes me reluctant to rely on it.
50
+ # Another possibility is ffi.typeof() but that will throw an exception if you give it a type that isn't a ctype
51
+ # Another way to improve performance might be to special-case simple types before doing the string comparisons
52
+
53
+ def _wrap_function(original_func):
54
+ # print("makefunc ",a, ffi.typeof(a).args)
55
+ def wrapped_func(*args):
56
+ modified_args = []
57
+ for (c_arg, arg) in zip(ffi.typeof(original_func).args, args):
58
+ # print("arg:",str(arg), "c_arg.kind:", c_arg.kind, "c_arg:", c_arg, "type(arg):",str(type(arg)))
59
+ if c_arg.kind == 'pointer':
60
+ if type(arg) is str:
61
+ arg = arg.encode('utf-8')
62
+ # if c_arg is a 'char *' not a 'const char *' then we ought to raise here because its an out
63
+ # parameter and user should supply a ctype pointer, but cffi cant detect const
64
+ # so we would have to get the info from raylib.json
65
+ elif type(arg) is list and str(c_arg) == "<ctype 'char * *'>":
66
+ arg = [ffi.new("char[]", x.encode('utf-8')) for x in arg]
67
+ elif is_cdata(arg) and "*" not in str(arg):
68
+ arg = ffi.addressof(arg)
69
+ elif arg is None:
70
+ arg = ffi.NULL
71
+ elif not is_cdata(arg):
72
+ if str(c_arg) == "<ctype '_Bool *'>":
73
+ raise TypeError(
74
+ "Argument must be a ctype bool, please create one with: pyray.ffi.new('bool *', True)")
75
+ elif str(c_arg) == "<ctype 'int *'>":
76
+ raise TypeError(
77
+ "Argument must be a ctype int, please create one with: pyray.ffi.new('int *', 1)")
78
+ elif str(c_arg) == "<ctype 'float *'>":
79
+ raise TypeError(
80
+ "Argument must be a ctype float, please create one with: pyray.ffi.new('float *', 1.0)")
81
+ modified_args.append(arg)
82
+ result = original_func(*modified_args)
83
+ if result is None:
84
+ return
85
+ elif is_cdata(result) and str(result).startswith("<cdata 'char *'"):
86
+ if str(result) == "<cdata 'char *' NULL>":
87
+ return ""
88
+ else:
89
+ return ffi.string(result).decode('utf-8')
90
+ else:
91
+ return result
92
+
93
+ # apparently pypy and cpython produce different types so check for both
94
+ def is_cdata(arg):
95
+ return str(type(arg)) == "<class '_cffi_backend.__CDataOwn'>" or str(
96
+ type(arg)) == "<class '_cffi_backend._CDataBase'>"
97
+
98
+ return wrapped_func
99
+
100
+
101
+ global_weakkeydict = weakref.WeakKeyDictionary()
102
+
103
+
104
+ def _make_struct_constructor_function(struct):
105
+ def func(*args):
106
+ # print(struct, args)
107
+ modified_args = []
108
+ for (field, arg) in zip(ffi.typeof(struct).fields, args):
109
+ # print("arg:", str(arg), "field:", field[1], "field type:", field[1].type, "type(arg):", str(type(arg)))
110
+ if arg is None:
111
+ arg = ffi.NULL
112
+ elif (field[1].type.kind == 'pointer'
113
+ and (str(type(arg)) == "<class 'numpy.ndarray'>"
114
+ or isinstance(arg, (array, bytes, bytearray, memoryview)))):
115
+ arg = ffi.from_buffer(field[1].type, arg)
116
+ modified_args.append(arg)
117
+ s = ffi.new(f"struct {struct} *", modified_args)[0]
118
+ global_weakkeydict[s] = modified_args
119
+ return s
120
+
121
+ return func
122
+
123
+
124
+ for name, attr in getmembers(rl):
125
+ # print(name, attr)
126
+ uname = _underscore(name).replace('3_d', '_3d').replace('2_d', '_2d')
127
+ if isbuiltin(attr) or str(type(attr)) == "<class '_cffi_backend.__FFIFunctionWrapper'>" or str(
128
+ type(attr)) == "<class '_cffi_backend._CDataBase'>":
129
+ # print(attr.__call__)
130
+ # print(attr.__doc__)
131
+ # print(dir(attr))
132
+ # print(dir(attr.__repr__))
133
+ f = _wrap_function(attr)
134
+ setattr(current_module, uname, f)
135
+ else:
136
+ setattr(current_module, name, attr)
137
+
138
+ for struct in ffi.list_types()[0]:
139
+ f = _make_struct_constructor_function(struct)
140
+ setattr(current_module, struct, f)
141
+
142
+ # overwrite ffi enums with our own
143
+ from raylib.enums import *