From 775d2da32df895e4c407d86b7d4a5e826bbd9424 Mon Sep 17 00:00:00 2001 From: richard Date: Wed, 13 Oct 2021 16:35:35 +0100 Subject: [PATCH] remove depreciated stuff, tidy build a bit for 4.0 --- MANIFEST.in | 2 + README.md | 6 + dynamic/test_dynamic.py | 2 +- dynamic/test_pyray.py | 2 +- examples/models/models_cubicmap.py | 2 +- examples/models/models_heightmap.py | 2 +- examples/models/models_obj_loading.py | 2 +- raylib/build.py | 63 ++++++---- raylib/pyray.py | 118 ------------------ setup.py | 6 +- tests/test_pyray.py | 2 +- tests/test_pyray_no_prefix.py | 2 +- tests/test_pyray_old_api.py | 47 ------- tests/test_static.py | 2 +- .../test_static_with_only_api_from_dynamic.py | 2 +- tests/test_static_with_prefix.py | 2 +- version.py | 2 +- 17 files changed, 63 insertions(+), 201 deletions(-) delete mode 100644 raylib/pyray.py delete mode 100644 tests/test_pyray_old_api.py diff --git a/MANIFEST.in b/MANIFEST.in index 9446b73..f7df82a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -6,3 +6,5 @@ include raylib/*.h include raylib/*.pyi exclude raylib/*.c exclude raylib/*.o +include version.py + diff --git a/README.md b/README.md index f696db3..8251d5c 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,12 @@ There is now a separate dynamic version of this binding: [Read this before using raylib_dynamic](https://electronstudio.github.io/raylib-python-cffi/dynamic.html) +## Beta testing + +You can install an alpha or beta version by specifying the version number like this: + + python3 -m pip install raylib==4.0a3 + # How to use diff --git a/dynamic/test_dynamic.py b/dynamic/test_dynamic.py index ed783e3..a1a09a3 100644 --- a/dynamic/test_dynamic.py +++ b/dynamic/test_dynamic.py @@ -14,7 +14,7 @@ texture = rl.LoadTextureFromImage(image) mesh = rl.GenMeshHeightmap(image, [16, 8, 16]) model = rl.LoadModelFromMesh(mesh) print(model.materials) # SHOULD BE A pointer to a 'struct Material' but some is NULL pointer to 'Material' ? -model.materials.maps[rl.MATERIAL_MAP_DIFFUSE].texture = texture +model.materials.maps[rl.MATERIAL_MAP_ALBEDO].texture = texture rl.UnloadImage(image) rl.SetCameraMode(camera[0], rl.CAMERA_ORBITAL) diff --git a/dynamic/test_pyray.py b/dynamic/test_pyray.py index 44def06..3b7c8fd 100644 --- a/dynamic/test_pyray.py +++ b/dynamic/test_pyray.py @@ -16,7 +16,7 @@ image = pr.load_image("examples/models/resources/heightmap.png") texture = pr.load_texture_from_image(image) mesh = pr.gen_mesh_heightmap(image, (16, 8, 16)) model = pr.load_model_from_mesh(mesh) -model.materials.maps[pr.MATERIAL_MAP_DIFFUSE].texture = texture +model.materials.maps[pr.MATERIAL_MAP_ALBEDO].texture = texture pr.unload_image(image) pr.set_camera_mode(camera, pr.CAMERA_ORBITAL) diff --git a/examples/models/models_cubicmap.py b/examples/models/models_cubicmap.py index 9738719..c33bf97 100644 --- a/examples/models/models_cubicmap.py +++ b/examples/models/models_cubicmap.py @@ -30,7 +30,7 @@ model = LoadModelFromMesh(mesh) # NOTE: By default each cube is mapped to one part of texture atlas texture = LoadTexture(b"resources/cubicmap_atlas.png") # Load map texture -model.materials[0].maps[MATERIAL_MAP_DIFFUSE ].texture = texture # Set map diffuse texture +model.materials[0].maps[MATERIAL_MAP_ALBEDO ].texture = texture # Set map diffuse texture mapPosition = [ -16.0, 0.0, -8.0 ] # Set model position diff --git a/examples/models/models_heightmap.py b/examples/models/models_heightmap.py index f226399..e9b3a75 100644 --- a/examples/models/models_heightmap.py +++ b/examples/models/models_heightmap.py @@ -27,7 +27,7 @@ texture = LoadTextureFromImage(image) # Convert image to texture mesh = GenMeshHeightmap(image, ( 16, 8, 16 )) # Generate heightmap mesh (RAM and VRAM) model = LoadModelFromMesh(mesh) # Load model from generated mesh -model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture # Set map diffuse texture +model.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = texture # Set map diffuse texture mapPosition = ( -8.0, 0.0, -8.0 ) # Define model position UnloadImage(image) # Unload heightmap image from RAM, already uploaded to VRAM diff --git a/examples/models/models_obj_loading.py b/examples/models/models_obj_loading.py index bec3fe6..0890cff 100644 --- a/examples/models/models_obj_loading.py +++ b/examples/models/models_obj_loading.py @@ -30,7 +30,7 @@ rl.SetCameraMode(camera[0], rl.CAMERA_ORBITAL) model = LoadModel(b"resources/models/house.obj") # Load OBJ model texture = LoadTexture(b"resources/models/house_diffuse.png") # Load model texture -model.materials.maps[MATERIAL_MAP_DIFFUSE].texture = texture # Set map diffuse texture +model.materials.maps[MATERIAL_MAP_ALBEDO].texture = texture # Set map diffuse texture position = [ 0.0, 0.0, 0.0 ] # Set model position SetTargetFPS(60) # Set our game to run at 60 frames-per-second diff --git a/raylib/build.py b/raylib/build.py index e629985..8f7df08 100644 --- a/raylib/build.py +++ b/raylib/build.py @@ -22,14 +22,14 @@ import os import platform import sys - ffibuilder = FFI() + def mangle(file): result = "" skip = False for line in open(file): - line = line.strip().replace("va_list", "void *")+"\n" + line = line.strip().replace("va_list", "void *") + "\n" if skip: if line.startswith("#endif"): skip = False @@ -50,16 +50,14 @@ def mangle(file): if line.startswith("PHYSACDEF"): line = line.replace('PHYSACDEF ', '') result += line - print(line) + # print(line) return result def build_linux(): print("BUILDING FOR LINUX") - ffibuilder.cdef(mangle("raylib/raylib.h")) - #ffibuilder.cdef(mangle("raylib/raygui.h")) + ffibuilder.cdef(mangle("/usr/local/include/raylib.h")) ffibuilder.cdef(open("raylib/raygui_modified.h").read().replace('RAYGUIDEF ', '')) - #ffibuilder.cdef(mangle("raylib/physac.h")) ffibuilder.cdef(open("raylib/physac_modified.h").read().replace('PHYSACDEF ', '')) ffibuilder.set_source("raylib._raylib_cffi", """ @@ -70,18 +68,20 @@ def build_linux(): #define PHYSAC_IMPLEMENTATION #include "physac.h" """, - extra_link_args=['/usr/local/lib/libraylib.a','-lm', '-lpthread', '-lGLU', '-lGL', '-lrt', '-lm', '-ldl', '-lX11', '-lpthread'], - libraries=['GL','m','pthread', 'dl', 'rt', 'X11'], + extra_link_args=['/usr/local/lib/libraylib.a', '-lm', '-lpthread', '-lGLU', '-lGL', '-lrt', + '-lm', '-ldl', '-lX11', '-lpthread'], + libraries=['GL', 'm', 'pthread', 'dl', 'rt', 'X11'], include_dirs=['raylib'] ) if __name__ == "__main__": ffibuilder.compile(verbose=True) + def build_windows(): print("BUILDING FOR WINDOWS") - ffibuilder.cdef(mangle("raylib/raylib.h")) - ffibuilder.cdef(open("raylib/raygui_modified.h").read().replace('RAYGUIDEF ', '').replace('bool','int')) - ffibuilder.cdef(open("raylib/physac_modified.h").read().replace('PHYSACDEF ', '').replace('bool','int')) + ffibuilder.cdef(mangle("raylib/raylib.h").replace('bool', 'int')) + ffibuilder.cdef(open("raylib/raygui_modified.h").read().replace('RAYGUIDEF ', '').replace('bool', 'int')) + ffibuilder.cdef(open("raylib/physac_modified.h").read().replace('PHYSACDEF ', '').replace('bool', 'int')) ffibuilder.set_source("raylib._raylib_cffi", """ #include "raylib.h" @@ -92,20 +92,31 @@ def build_windows(): #include "physac.h" """, extra_link_args=['/NODEFAULTLIB:MSVCRTD'], - libraries=['raylib', 'gdi32', 'shell32', 'user32','OpenGL32', 'winmm'], + libraries=['raylib', 'gdi32', 'shell32', 'user32', 'OpenGL32', 'winmm'], include_dirs=['raylib'], ) if __name__ == "__main__": ffibuilder.compile(verbose=True) + def build_mac(): print("BUILDING FOR MAC") - ffibuilder.cdef(open("raylib/raylib_modified.h").read().replace('RLAPI ', '')) + ffibuilder.cdef(mangle("/usr/local/include/raylib.h")) + ffibuilder.cdef(open("raylib/raygui_modified.h").read().replace('RAYGUIDEF ', '')) + ffibuilder.cdef(open("raylib/physac_modified.h").read().replace('PHYSACDEF ', '')) ffibuilder.set_source("raylib._raylib_cffi", """ - #include "../../raylib/raylib.h" // the C header of the library, supplied by us here + #include "raylib.h" + #define RAYGUI_IMPLEMENTATION + #define RAYGUI_SUPPORT_RICONS + #include "raygui.h" + #define PHYSAC_IMPLEMENTATION + #include "physac.h" """, - extra_link_args=['/usr/local/lib/libraylib.a', '-framework', 'OpenGL', '-framework', 'Cocoa', '-framework', 'IOKit', '-framework', 'CoreFoundation', '-framework', 'CoreVideo'], + extra_link_args=['/usr/local/lib/libraylib.a', '-framework', 'OpenGL', '-framework', 'Cocoa', + '-framework', 'IOKit', '-framework', 'CoreFoundation', '-framework', + 'CoreVideo'], + include_dirs=['raylib'], ) if __name__ == "__main__": @@ -114,32 +125,38 @@ def build_mac(): def build_rpi_nox(): print("BUILDING FOR RASPBERRY PI") - ffibuilder.cdef(mangle("raylib/raylib.h")) + ffibuilder.cdef(mangle("/usr/local/include/raylib.h")) + ffibuilder.cdef(open("raylib/raygui_modified.h").read().replace('RAYGUIDEF ', '')) + ffibuilder.cdef(open("raylib/physac_modified.h").read().replace('PHYSACDEF ', '')) ffibuilder.set_source("raylib._raylib_cffi", """ - #include "../../raylib/raylib.h" + #include "raylib.h" + #define RAYGUI_IMPLEMENTATION + #define RAYGUI_SUPPORT_RICONS + #include "raygui.h" + #define PHYSAC_IMPLEMENTATION + #include "physac.h" """, extra_link_args=['/usr/local/lib/libraylib.a', '/opt/vc/lib/libEGL_static.a', '/opt/vc/lib/libGLESv2_static.a', '-L/opt/vc/lib', '-lvcos', '-lbcm_host', '-lbrcmEGL', '-lbrcmGLESv2', '-lm', '-lpthread', '-lrt'], + include_dirs=['raylib'], ) - if __name__ == "__main__": ffibuilder.compile(verbose=True) - -if platform.system()=="Darwin": +if platform.system() == "Darwin": build_mac() -elif platform.system()=="Linux": +elif platform.system() == "Linux": if "x86" in platform.machine(): build_linux() elif "arm" in platform.machine(): build_rpi_nox() -elif platform.system()=="Windows": +elif platform.system() == "Windows": build_windows() else: print("WARNING: UKKNOWN PLATFORM - trying Linux build") - build_linux() \ No newline at end of file + build_linux() diff --git a/raylib/pyray.py b/raylib/pyray.py deleted file mode 100644 index 8f1c032..0000000 --- a/raylib/pyray.py +++ /dev/null @@ -1,118 +0,0 @@ -# Copyright (c) 2021 Richard Smith and others -# -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License 2.0 which is available at -# http://www.eclipse.org/legal/epl-2.0. -# -# This Source Code may also be made available under the following Secondary -# licenses when the conditions for such availability set forth in the Eclipse -# Public License, v. 2.0 are satisfied: GNU General Public License, version 2 -# with the GNU Classpath Exception which is -# available at https://www.gnu.org/software/classpath/license.html. -# -# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - -from raylib import rl, ffi -from .colors import * -from inspect import ismethod,getmembers,isbuiltin -import inflection - -class PyRay: - - print(""" - - *********************************************** - - WARNING - - Class raylib.PyRay() is depreciated. - - Instead please use module, e.g. - - import pyray - pyray.init_window(500, 500, '') - - or even: - - import * from pyray - init_window(500, 500, '') - - - ********************************************** - - """) - - def pointer(self, struct): - return ffi.addressof(struct) - - LIGHTGRAY =( 200, 200, 200, 255 ) - GRAY =( 130, 130, 130, 255 ) - DARKGRAY =( 80, 80, 80, 255 ) - YELLOW =( 253, 249, 0, 255 ) - GOLD =( 255, 203, 0, 255 ) - ORANGE =( 255, 161, 0, 255 ) - PINK =( 255, 109, 194, 255 ) - RED =( 230, 41, 55, 255 ) - MAROON =( 190, 33, 55, 255 ) - GREEN =( 0, 228, 48, 255 ) - LIME =( 0, 158, 47, 255 ) - DARKGREEN =( 0, 117, 44, 255 ) - SKYBLUE =( 102, 191, 255, 255 ) - BLUE =( 0, 121, 241, 255 ) - DARKBLUE =( 0, 82, 172, 255 ) - PURPLE =( 200, 122, 255, 255 ) - VIOLET =( 135, 60, 190, 255 ) - DARKPURPLE =( 112, 31, 126, 255 ) - BEIGE =( 211, 176, 131, 255 ) - BROWN =( 127, 106, 79, 255 ) - DARKBROWN =( 76, 63, 47, 255 ) - WHITE =( 255, 255, 255, 255 ) - BLACK =( 0, 0, 0, 255 ) - BLANK =( 0, 0, 0, 0 ) - MAGENTA =( 255, 0, 255, 255 ) - RAYWHITE =( 245, 245, 245, 255 ) - - -def makefunc(a): - #print("makefunc ",a, ffi.typeof(a).args) - def func(self, *args): - modified_args = [] - for (c_arg, arg) in zip(ffi.typeof(a).args, args): - #print(arg, c_arg.kind) - if type(arg) == str: - encoded = arg.encode('utf-8') - modified_args.append(encoded) - elif c_arg.kind == 'pointer' and str(type(arg)) == "": - modified_args.append(ffi.addressof(arg)) - else: - modified_args.append(arg) - return a(*modified_args) - return func - -def makeStructHelper(struct): - def func(self, *args): - return ffi.new(f"struct {struct} *", args)[0] - return func - - -for name, attr in getmembers(rl): - #print(name, attr) - uname = inflection.underscore(name).replace('3_d','_3d').replace('2_d','_2d') - if isbuiltin(attr) or str(type(attr)) == "" or str(type(attr)) == "": - #print(attr.__call__) - #print(attr.__doc__) - #print(attr.__text_signature__) - #print(dir(attr)) - #print(dir(attr.__repr__)) - f = makefunc(attr) - setattr(PyRay, uname, f) - #def wrap(*args): - # print("call to ",attr) - #setattr(PyRay, uname, lambda *args: print("call to ",attr)) - else: - setattr(PyRay, name, attr) - -for struct in ffi.list_types()[0]: - f = makeStructHelper(struct) - setattr(PyRay, struct, f) - diff --git a/setup.py b/setup.py index 6000f8c..a9d4435 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,15 @@ import pathlib from setuptools import setup from setuptools.dist import Distribution -from version import __version__ + # The directory containing this file HERE = pathlib.Path(__file__).parent # The text of the README file README = (HERE / "README.md").read_text() +VERSION = (HERE / "version.py").read_text().split()[-1].strip("\"'") + class BinaryDistribution(Distribution): """Distribution which always forces a binary package with platform name""" @@ -17,7 +19,7 @@ class BinaryDistribution(Distribution): # This call to setup() does all the work setup( name="raylib", - version=__version__, + version=VERSION, description="Python CFFI bindings for Raylib", long_description=README, long_description_content_type="text/markdown", diff --git a/tests/test_pyray.py b/tests/test_pyray.py index dcb2787..8c9b430 100644 --- a/tests/test_pyray.py +++ b/tests/test_pyray.py @@ -16,7 +16,7 @@ image = pr.load_image("examples/models/resources/heightmap.png") texture = pr.load_texture_from_image(image) mesh = pr.gen_mesh_heightmap(image, (16, 8, 16)) model = pr.load_model_from_mesh(mesh) -model.materials.maps[pr.MATERIAL_MAP_DIFFUSE].texture = texture +model.materials.maps[pr.MATERIAL_MAP_ALBEDO].texture = texture pr.unload_image(image) pr.set_camera_mode(camera, pr.CAMERA_ORBITAL) diff --git a/tests/test_pyray_no_prefix.py b/tests/test_pyray_no_prefix.py index a03cbe8..df453a3 100644 --- a/tests/test_pyray_no_prefix.py +++ b/tests/test_pyray_no_prefix.py @@ -16,7 +16,7 @@ image = load_image("examples/models/resources/heightmap.png") texture = load_texture_from_image(image) mesh = gen_mesh_heightmap(image, (16, 8, 16)) model = load_model_from_mesh(mesh) -model.materials.maps[MATERIAL_MAP_DIFFUSE].texture = texture +model.materials.maps[MATERIAL_MAP_ALBEDO].texture = texture unload_image(image) set_camera_mode(camera, CAMERA_ORBITAL) diff --git a/tests/test_pyray_old_api.py b/tests/test_pyray_old_api.py deleted file mode 100644 index 13c1f3e..0000000 --- a/tests/test_pyray_old_api.py +++ /dev/null @@ -1,47 +0,0 @@ -""" -This shows how to use the Pyray wrapper around the static binding. -""" - -from raylib import pyray - -pr = pyray.PyRay() - -pr.init_window(800, 450, "Raylib texture test") -pr.set_target_fps(60) - -image = pr.gen_image_color(800, 400, (0,0,0,255) ) -texture = pr.load_texture_from_image(image) -pr.update_texture(texture, image.data) - -camera = pr.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0) -image = pr.load_image("examples/models/resources/heightmap.png") -texture = pr.load_texture_from_image(image) -mesh = pr.gen_mesh_heightmap(image, (16, 8, 16)) -model = pr.load_model_from_mesh(mesh) -model.materials.maps[pr.MATERIAL_MAP_DIFFUSE].texture = texture - -pr.unload_image(image) -pr.set_camera_mode(camera, pr.CAMERA_ORBITAL) - -pos = pr.get_mouse_position() -ray = pr.get_mouse_ray(pos, camera) -#rayhit = pr.get_ray_collision_ground(ray, 0) -#print(str(rayhit.position.x)) - -while not pr.window_should_close(): - pr.update_camera(camera) - pr.begin_drawing() - pr.clear_background(pr.RAYWHITE) - pr.begin_mode_3d(camera) - pr.draw_model(model, (-8.0, 0.0, -8.0), 1.0, pr.RED) - pr.draw_grid(20, 1.0) - pr.end_mode_3d() - pr.draw_text("This mesh should be textured", 190, 200, 20, pr.VIOLET) - pr.end_drawing() - - pos = pr.get_mouse_position() - ray = pr.get_mouse_ray(pos, camera) - #rayhit = pr.get_ray_collision_ground(ray, 0) - #print(str(rayhit.position.x)) - -pr.close_window() diff --git a/tests/test_static.py b/tests/test_static.py index 269b0a5..71e1b81 100644 --- a/tests/test_static.py +++ b/tests/test_static.py @@ -13,7 +13,7 @@ image = LoadImage(b"examples/models/resources/heightmap.png") texture = LoadTextureFromImage(image) mesh = GenMeshHeightmap(image, (16, 8, 16)) model = LoadModelFromMesh(mesh) -model.materials.maps[MATERIAL_MAP_DIFFUSE].texture = texture +model.materials.maps[MATERIAL_MAP_ALBEDO].texture = texture UnloadImage(image) SetCameraMode(camera[0], CAMERA_ORBITAL) diff --git a/tests/test_static_with_only_api_from_dynamic.py b/tests/test_static_with_only_api_from_dynamic.py index a574084..ae3f6ce 100644 --- a/tests/test_static_with_only_api_from_dynamic.py +++ b/tests/test_static_with_only_api_from_dynamic.py @@ -14,7 +14,7 @@ texture = rl.LoadTextureFromImage(image) mesh = rl.GenMeshHeightmap(image, [16, 8, 16]) model = rl.LoadModelFromMesh(mesh) print(model.materials) # SHOULD BE A pointer to a 'struct Material' but some is NULL pointer to 'Material' ? -model.materials.maps[rl.MATERIAL_MAP_DIFFUSE].texture = texture +model.materials.maps[rl.MATERIAL_MAP_ALBEDO].texture = texture rl.UnloadImage(image) rl.SetCameraMode(camera[0], rl.CAMERA_ORBITAL) diff --git a/tests/test_static_with_prefix.py b/tests/test_static_with_prefix.py index 7b612e3..0c625e5 100644 --- a/tests/test_static_with_prefix.py +++ b/tests/test_static_with_prefix.py @@ -14,7 +14,7 @@ texture = rl.LoadTextureFromImage(image) mesh = rl.GenMeshHeightmap(image, [16, 8, 16]) model = rl.LoadModelFromMesh(mesh) print(model.materials) # SHOULD BE A pointer to a 'struct Material' but some is NULL pointer to 'Material' ? -model.materials.maps[rl.MATERIAL_MAP_DIFFUSE].texture = texture +model.materials.maps[rl.MATERIAL_MAP_ALBEDO].texture = texture rl.UnloadImage(image) rl.SetCameraMode(camera[0], rl.CAMERA_ORBITAL) diff --git a/version.py b/version.py index 1cbc0f6..2ac87fb 100644 --- a/version.py +++ b/version.py @@ -1 +1 @@ -__version__ = "4.0a2" \ No newline at end of file +__version__ = "4.0a4" \ No newline at end of file