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

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