remove depreciated stuff, tidy build a bit for 4.0

This commit is contained in:
richard 2021-10-13 16:35:35 +01:00
parent c818fae902
commit 775d2da32d
17 changed files with 63 additions and 201 deletions

View file

@ -6,3 +6,5 @@ include raylib/*.h
include raylib/*.pyi
exclude raylib/*.c
exclude raylib/*.o
include version.py

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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()
build_linux()

View file

@ -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)) == "<class '_cffi_backend.__CDataOwn'>":
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)) == "<class '_cffi_backend.__FFIFunctionWrapper'>" or str(type(attr)) == "<class '_cffi_backend._CDataBase'>":
#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)

View file

@ -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",

View file

@ -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)

View file

@ -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)

View file

@ -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()

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -1 +1 @@
__version__ = "4.0a2"
__version__ = "4.0a4"