Skip to content

Commit 1d5579d

Browse files
reorg modules
1 parent 7262e4f commit 1d5579d

File tree

9 files changed

+66
-61
lines changed

9 files changed

+66
-61
lines changed

README.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,41 +47,43 @@ CloseWindow()
4747
4848
```
4949

50-
## raylib.dynamic
50+
## raylib.pyray
5151

52-
In addition to the API static bindings we have CFFI ABI dynamic bindings in order to avoid the need to compile a C extension module.
53-
There have been some weird failures with dynamic bindings and ctypes bindings before and often the failures are silent
54-
so you dont even know. Also the static bindings should be faster. Therefore I recommend the static ones...
52+
Wrapper around the static bindings. Makes the names snakecase and converts strings to bytes automatically. See test_pyray.py.
5553

56-
BUT the dynamic bindings have the big advantage that you don't need to compile anything to install. You just need a Raylib DLL,
57-
which we supply for Windows/Mac/Linux.
5854

59-
See test_dynamic.py for how to use.
55+
```
56+
from raylib.pyray import PyRay
57+
from raylib.colors import *
6058
61-
## raylib.static.pyray
59+
pyray = PyRay()
6260
63-
Wrapper around the static bindings. Makes the names snakecase and converts strings to bytes automatically. See test_pyray.py.
61+
pyray.init_window(800, 450, "Hello Pyray")
62+
pyray.set_target_fps(60)
6463
64+
camera = pyray.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0)
65+
pyray.set_camera_mode(camera, pyray.CAMERA_ORBITAL)
66+
67+
while not pyray.window_should_close():
68+
pyray.update_camera(pyray.pointer(camera))
69+
pyray.begin_drawing()
70+
pyray.clear_background(RAYWHITE)
71+
pyray.draw_text("Hello world", 190, 200, 20, VIOLET)
72+
pyray.end_drawing()
73+
pyray.close_window()
6574
6675
```
67-
from raylib.static.pyray import pyray as prl
68-
from raylib.colors import *
6976

70-
prl.init_window(800, 450, "Hello Pyray")
71-
prl.set_target_fps(60)
77+
## raylib.dynamic
7278

73-
camera = prl.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0)
74-
prl.set_camera_mode(camera, prl.CAMERA_ORBITAL)
79+
In addition to the API static bindings we have CFFI ABI dynamic bindings in order to avoid the need to compile a C extension module.
80+
There have been some weird failures with dynamic bindings and ctypes bindings before and often the failures are silent
81+
so you dont even know. Also the static bindings should be faster. Therefore I recommend the static ones...
7582

76-
while not prl.window_should_close():
77-
prl.update_camera(prl.pointer(camera))
78-
prl.begin_drawing()
79-
prl.clear_background(RAYWHITE)
80-
prl.draw_text("Hello world", 190, 200, 20, VIOLET)
81-
prl.end_drawing()
82-
prl.close_window()
83+
BUT the dynamic bindings have the big advantage that you don't need to compile anything to install. You just need a Raylib DLL,
84+
which we supply for Windows/Mac/Linux.
8385

84-
```
86+
See test_dynamic.py for how to use.
8587

8688
## raylib.richlib
8789

@@ -98,4 +100,5 @@ A very easy to use library on top of static bindings, modelled after Pygame Zero
98100
* converting more examples from C to python
99101
* testing and building on more platforms
100102
* sorting out binary wheel distribution for Mac/Win and compile-from-source distributtion for Linux
103+
* dealing with conversions to pointers in PyRay automatically
101104

coords_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from raylib.richlib import *
2-
from raylib.static.pyray import pyray
2+
33

44
WIDTH=1200
55
HEIGHT=800

raylib/static/pyray.py renamed to raylib/pyray.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
from . import rl, ffi
2-
from ..colors import *
1+
from .static import rl, ffi
2+
from .colors import *
33
from inspect import ismethod,getmembers,isbuiltin
44
import inflection
55

66
class PyRay:
77
def pointer(self, struct):
88
return ffi.addressof(struct)
99

10-
pyray = PyRay()
11-
1210

1311
def makefunc(a):
1412
#print("makefunc ",a)
@@ -31,10 +29,12 @@ def func(self, *args):
3129

3230

3331
for name, attr in getmembers(rl):
34-
print(name, attr)
32+
#print(name, attr)
3533
uname = inflection.underscore(name).replace('3_d','_3d').replace('2_d','_2d')
3634
if isbuiltin(attr):
37-
#print(attr)
35+
#print(attr.__call__)
36+
#print(attr.__doc__)
37+
#print(attr.__text_signature__)
3838
#print(dir(attr))
3939
#print(dir(attr.__repr__))
4040
f = makefunc(attr)
@@ -47,4 +47,5 @@ def func(self, *args):
4747

4848
for struct in ('Vector2','Vector3','Vector4','Camera2D', 'Camera3D', 'Quaternion', 'Color'):
4949
f = makeStructHelper(struct)
50-
setattr(PyRay, struct, f)
50+
setattr(PyRay, struct, f)
51+

raylib/richlib/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
data_dir = ""
1212

13+
from ..pyray import PyRay
14+
15+
pyray = PyRay()
16+
1317
camera = ffi.new("struct Camera3D *")
1418
camera.position = (0.0, 100, 100)
1519
camera.target = (0.0, 0.0, 0.0)

raylib/static/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from ._raylib_cffi import ffi, lib as rl
22
from _raylib_cffi.lib import *
33
from raylib.colors import *
4-
from .helpers import *
54

65

76
print("RAYLIB STATIC LOADED")

raylib/static/helpers.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# This call to setup() does all the work
1111
setup(
1212
name="raylib",
13-
version="2.5.0.post2",
13+
version="2.5.0.post3",
1414
description="Python CFFI bindings for Raylib",
1515
long_description=README,
1616
long_description_content_type="text/markdown",

test_pyray.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
"""
22
This shows how to use the Pyray wrapper around the static binding.
33
"""
4-
from raylib.static.pyray import pyray as prl
4+
5+
from raylib.pyray import PyRay
56
from raylib.colors import *
67

7-
prl.init_window(800, 450, "Raylib texture test")
8-
prl.set_target_fps(60)
8+
pyray = PyRay()
9+
10+
pyray.init_window(800, 450, "Raylib texture test")
11+
pyray.set_target_fps(60)
912

10-
camera = prl.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0)
11-
image = prl.load_image("examples/models/resources/heightmap.png")
12-
texture = prl.load_texture_from_image(image)
13-
mesh = prl.gen_mesh_heightmap(image, (16, 8, 16))
14-
model = prl.load_model_from_mesh(mesh)
15-
model.materials.maps[prl.MAP_DIFFUSE].texture = texture
13+
camera = pyray.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0)
14+
image = pyray.load_image("examples/models/resources/heightmap.png")
15+
texture = pyray.load_texture_from_image(image)
16+
mesh = pyray.gen_mesh_heightmap(image, (16, 8, 16))
17+
model = pyray.load_model_from_mesh(mesh)
18+
model.materials.maps[pyray.MAP_DIFFUSE].texture = texture
1619

17-
prl.unload_image(image)
18-
prl.set_camera_mode(camera, prl.CAMERA_ORBITAL)
20+
pyray.unload_image(image)
21+
pyray.set_camera_mode(camera, pyray.CAMERA_ORBITAL)
1922

20-
while not prl.window_should_close():
21-
prl.update_camera(prl.pointer(camera))
22-
prl.begin_drawing()
23-
prl.clear_background(RAYWHITE)
24-
prl.begin_mode_3d(camera)
25-
prl.draw_model(model, (-8.0, 0.0, -8.0), 1.0, RED)
26-
prl.draw_grid(20, 1.0)
27-
prl.end_mode_3d()
28-
prl.draw_text("This mesh should be textured", 190, 200, 20, VIOLET)
29-
prl.end_drawing()
30-
prl.close_window()
23+
while not pyray.window_should_close():
24+
pyray.update_camera(pyray.pointer(camera))
25+
pyray.begin_drawing()
26+
pyray.clear_background(RAYWHITE)
27+
pyray.begin_mode_3d(camera)
28+
pyray.draw_model(model, (-8.0, 0.0, -8.0), 1.0, RED)
29+
pyray.draw_grid(20, 1.0)
30+
pyray.end_mode_3d()
31+
pyray.draw_text("This mesh should be textured", 190, 200, 20, VIOLET)
32+
pyray.end_drawing()
33+
pyray.close_window()

test_richlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from raylib.richlib import *
2-
from raylib.static.pyray import pyray
2+
33

44
WIDTH=800
55
HEIGHT=640

0 commit comments

Comments
 (0)