Skip to content

Commit ef2d563

Browse files
generate h files on linux and then use them on windows
1 parent 10545a2 commit ef2d563

16 files changed

+2533
-384
lines changed

create_stub_static.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class struct: ...
6666
" ", "")+"_"+str(i)
6767
if 'params' in json_object:
6868
p = json_object['params']
69+
#print("param_name: ", param_name, "i", i, "params: ",p,file=sys.stderr)
6970
param_name = list(p)[i]
7071
param_type = ctype_to_python_type(arg.cname)
7172
sig += f"{param_name}: {param_type},"

raylib/build.py

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ def pre_process_header(filename):
4545
print("Pre-processing " + filename)
4646
file = open(filename, "r")
4747
filetext = "".join([line for line in file if '#include' not in line])
48-
command = ['gcc', '-CC', '-P', '-undef', '-nostdinc', '-DRLAPI=', '-DPHYSACDEF=', '-DRAYGUIDEF=',
48+
command = ['gcc', '-CC', '-P', '-undef', '-nostdinc', '-DRL_MATRIX_TYPE',
49+
#'-DRL_QUATERNION_TYPE','-DRL_VECTOR4_TYPE','-DRL_VECTOR3_TYPE','-DRL_VECTOR2_TYPE'
50+
'-DRLAPI=', '-DPHYSACDEF=', '-DRAYGUIDEF=',
4951
'-dDI', '-E', '-']
5052
filetext2 = subprocess.run(command, text=True, input=filetext, stdout=subprocess.PIPE).stdout
5153
filetext3 = filetext2.replace("va_list", "void *")
5254
filetext4 = "\n".join([line for line in filetext3.splitlines() if not line.startswith("#")])
55+
file = open("raylib/"+os.path.basename(filename)+".modified", "w")
56+
file.write(filetext4)
5357
# print(r)
5458
return filetext4
5559

@@ -65,44 +69,53 @@ def check_header_exists(file):
6569
return True
6670

6771

68-
def mangle(file):
69-
result = ""
70-
skip = False
71-
for line in open(file):
72-
line = line.strip().replace("va_list", "void *") + "\n"
73-
if skip:
74-
if line.startswith("#endif"):
75-
skip = False
76-
continue
77-
if line.startswith("#if defined(__cplusplus)"):
78-
skip = True
79-
continue
80-
if line.startswith("#endif // RAYGUI_H"):
81-
break
82-
if line.startswith("#"):
83-
continue
84-
if line.startswith("RLAPI"):
85-
line = line.replace('RLAPI ', '')
86-
if line.startswith("RAYGUIDEF"):
87-
line = line.replace('RAYGUIDEF ', '')
88-
if line.startswith("PHYSACDEF"):
89-
line = line.replace('PHYSACDEF ', '')
90-
result += line
91-
# print(line)
92-
return result
72+
# def mangle(file):
73+
# result = ""
74+
# skip = False
75+
# for line in open(file):
76+
# line = line.strip().replace("va_list", "void *") + "\n"
77+
# if skip:
78+
# if line.startswith("#endif"):
79+
# skip = False
80+
# continue
81+
# if line.startswith("#if defined(__cplusplus)"):
82+
# skip = True
83+
# continue
84+
# if line.startswith("#endif // RAYGUI_H"):
85+
# break
86+
# if line.startswith("#"):
87+
# continue
88+
# if line.startswith("RLAPI"):
89+
# line = line.replace('RLAPI ', '')
90+
# if line.startswith("RAYGUIDEF"):
91+
# line = line.replace('RAYGUIDEF ', '')
92+
# if line.startswith("PHYSACDEF"):
93+
# line = line.replace('PHYSACDEF ', '')
94+
# result += line
95+
# # print(line)
96+
# return result
9397

9498

9599
def build_unix():
96100
if not check_raylib_installed():
97101
raise Exception("ERROR: raylib not found by pkg-config. Please install pkg-config and Raylib.")
98102

99103
raylib_h = get_the_include_path() + "/raylib.h"
104+
rlgl_h = get_the_include_path() + "/rlgl.h"
105+
#raymath_h = get_the_include_path() + "/raymath.h"
100106

101107
if not os.path.isfile(raylib_h):
102108
raise Exception("ERROR: " + raylib_h + " not found. Please install Raylib.")
103109

110+
if not os.path.isfile(rlgl_h):
111+
raise Exception("ERROR: " + raylib_h + " not found. Please install Raylib.")
112+
113+
#if not os.path.isfile(raymath_h):
114+
# raise Exception("ERROR: " + raylib_h + " not found. Please install Raylib.")
115+
104116
ffi_includes = """
105117
#include "raylib.h"
118+
#include "rlgl.h"
106119
"""
107120

108121
raygui_h = get_the_include_path() + "/raygui.h"
@@ -121,6 +134,10 @@ def build_unix():
121134
"""
122135

123136
ffibuilder.cdef(pre_process_header(raylib_h))
137+
ffibuilder.cdef(pre_process_header(rlgl_h))
138+
#ffibuilder.cdef(pre_process_header(raymath_h))
139+
#print("******************************\n\n\n")
140+
#print(pre_process_header(rlgl_h))
124141
if os.path.isfile(raygui_h):
125142
ffibuilder.cdef(pre_process_header(raygui_h))
126143
if os.path.isfile(physac_h):
@@ -132,30 +149,30 @@ def build_unix():
132149
'-framework', 'IOKit', '-framework', 'CoreFoundation', '-framework',
133150
'CoreVideo']
134151
libraries = []
135-
elif platform.system() == "Linux":
136-
if "x86" in platform.machine():
137-
print("BUILDING FOR LINUX")
138-
extra_link_args = [get_the_lib_path() + '/libraylib.a', '-lm', '-lpthread', '-lGLU', '-lGL',
139-
'-lrt', '-lm', '-ldl', '-lX11', '-lpthread']
140-
libraries = ['GL', 'm', 'pthread', 'dl', 'rt', 'X11']
141-
elif "arm" in platform.machine():
152+
else: #platform.system() == "Linux":
153+
if "arm" in platform.machine():
142154
print("BUILDING FOR RASPBERRY PI")
143155
extra_link_args = [get_the_lib_path() + '/libraylib.a',
144156
'/opt/vc/lib/libEGL_static.a', '/opt/vc/lib/libGLESv2_static.a',
145157
'-L/opt/vc/lib', '-lvcos', '-lbcm_host', '-lbrcmEGL', '-lbrcmGLESv2',
146158
'-lm', '-lpthread', '-lrt']
147159
libraries = []
160+
else: #"x86" in platform.machine():
161+
print("BUILDING FOR LINUX")
162+
extra_link_args = [get_the_lib_path() + '/libraylib.a', '-lm', '-lpthread', '-lGLU', '-lGL',
163+
'-lrt', '-lm', '-ldl', '-lX11', '-lpthread']
164+
libraries = ['GL', 'm', 'pthread', 'dl', 'rt', 'X11']
148165

149166
ffibuilder.set_source("raylib._raylib_cffi", ffi_includes, extra_link_args=extra_link_args,
150-
libraries=libraries,
151-
include_dirs=['raylib'])
167+
libraries=libraries)
152168

153169

154170
def build_windows():
155171
print("BUILDING FOR WINDOWS")
156-
ffibuilder.cdef(mangle("raylib/raylib.h"))
157-
ffibuilder.cdef(open("raylib/raygui_modified.h").read().replace('RAYGUIDEF ', ''))
158-
ffibuilder.cdef(open("raylib/physac_modified.h").read().replace('PHYSACDEF ', ''))
172+
ffibuilder.cdef(open("raylib/raylib.h.modified").read())
173+
ffibuilder.cdef(open("raylib/rlgl.h.modified").read())
174+
ffibuilder.cdef(open("raylib/raygui.h.modified").read())
175+
ffibuilder.cdef(open("raylib/physac.h.modified").read())
159176
ffibuilder.set_source("raylib._raylib_cffi", """
160177
#include "raylib.h"
161178
#define RAYGUI_IMPLEMENTATION

raylib/build_multi.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ function build() {
2020
build 3.9.5
2121
build 3.8.10
2222
build 3.7.10
23-
build 3.6.13
23+
2424

raylib/build_multi_linux.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ function build() {
2020
build 3.9.5
2121
build 3.8.10
2222
build 3.7.10
23-
build 3.6.13
23+
2424

raylib/build_multi_rpi_nox.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ function build() {
2020
build 3.9.5
2121
build 3.8.10
2222
build 3.7.10
23-
build 3.6.13
23+
2424

raylib/physac.h.modified

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/**********************************************************************************************
2+
*
3+
* Physac v1.1 - 2D Physics library for videogames
4+
*
5+
* DESCRIPTION:
6+
*
7+
* Physac is a small 2D physics engine written in pure C. The engine uses a fixed time-step thread loop
8+
* to simluate physics. A physics step contains the following phases: get collision information,
9+
* apply dynamics, collision solving and position correction. It uses a very simple struct for physic
10+
* bodies with a position vector to be used in any 3D rendering API.
11+
*
12+
* CONFIGURATION:
13+
*
14+
* #define PHYSAC_IMPLEMENTATION
15+
* Generates the implementation of the library into the included file.
16+
* If not defined, the library is in header only mode and can be included in other headers
17+
* or source files without problems. But only ONE file should hold the implementation.
18+
*
19+
* #define PHYSAC_STATIC (defined by default)
20+
* The generated implementation will stay private inside implementation file and all
21+
* internal symbols and functions will only be visible inside that file.
22+
*
23+
* #define PHYSAC_DEBUG
24+
* Show debug traces log messages about physic bodies creation/destruction, physic system errors,
25+
* some calculations results and NULL reference exceptions
26+
*
27+
* #define PHYSAC_DEFINE_VECTOR2_TYPE
28+
* Forces library to define struct Vector2 data type (float x; float y)
29+
*
30+
* #define PHYSAC_AVOID_TIMMING_SYSTEM
31+
* Disables internal timming system, used by UpdatePhysics() to launch timmed physic steps,
32+
* it allows just running UpdatePhysics() automatically on a separate thread at a desired time step.
33+
* In case physics steps update needs to be controlled by user with a custom timming mechanism,
34+
* just define this flag and the internal timming mechanism will be avoided, in that case,
35+
* timming libraries are neither required by the module.
36+
*
37+
* #define PHYSAC_MALLOC()
38+
* #define PHYSAC_CALLOC()
39+
* #define PHYSAC_FREE()
40+
* You can define your own malloc/free implementation replacing stdlib.h malloc()/free() functions.
41+
* Otherwise it will include stdlib.h and use the C standard library malloc()/free() function.
42+
*
43+
* COMPILATION:
44+
*
45+
* Use the following code to compile with GCC:
46+
* gcc -o $(NAME_PART).exe $(FILE_NAME) -s -static -lraylib -lopengl32 -lgdi32 -lwinmm -std=c99
47+
*
48+
* VERSIONS HISTORY:
49+
* 1.1 (20-Jan-2021) @raysan5: Library general revision
50+
* Removed threading system (up to the user)
51+
* Support MSVC C++ compilation using CLITERAL()
52+
* Review DEBUG mechanism for TRACELOG() and all TRACELOG() messages
53+
* Review internal variables/functions naming for consistency
54+
* Allow option to avoid internal timming system, to allow app manage the steps
55+
* 1.0 (12-Jun-2017) First release of the library
56+
*
57+
*
58+
* LICENSE: zlib/libpng
59+
*
60+
* Copyright (c) 2016-2021 Victor Fisac (@victorfisac) and Ramon Santamaria (@raysan5)
61+
*
62+
* This software is provided "as-is", without any express or implied warranty. In no event
63+
* will the authors be held liable for any damages arising from the use of this software.
64+
*
65+
* Permission is granted to anyone to use this software for any purpose, including commercial
66+
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
67+
*
68+
* 1. The origin of this software must not be misrepresented; you must not claim that you
69+
* wrote the original software. If you use this software in a product, an acknowledgment
70+
* in the product documentation would be appreciated but is not required.
71+
*
72+
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
73+
* as being the original software.
74+
*
75+
* 3. This notice may not be removed or altered from any source distribution.
76+
*
77+
**********************************************************************************************/
78+
// Allow custom memory allocators
79+
//----------------------------------------------------------------------------------
80+
// Defines and Macros
81+
//----------------------------------------------------------------------------------
82+
//----------------------------------------------------------------------------------
83+
// Data Types Structure Definition
84+
//----------------------------------------------------------------------------------
85+
typedef enum PhysicsShapeType { PHYSICS_CIRCLE = 0, PHYSICS_POLYGON } PhysicsShapeType;
86+
// Previously defined to be used in PhysicsShape struct as circular dependencies
87+
typedef struct PhysicsBodyData *PhysicsBody;
88+
// Matrix2x2 type (used for polygon shape rotation matrix)
89+
typedef struct Matrix2x2 {
90+
float m00;
91+
float m01;
92+
float m10;
93+
float m11;
94+
} Matrix2x2;
95+
typedef struct PhysicsVertexData {
96+
unsigned int vertexCount; // Vertex count (positions and normals)
97+
Vector2 positions[24 /* Maximum number of vertex for polygons shapes*/]; // Vertex positions vectors
98+
Vector2 normals[24 /* Maximum number of vertex for polygons shapes*/]; // Vertex normals vectors
99+
} PhysicsVertexData;
100+
typedef struct PhysicsShape {
101+
PhysicsShapeType type; // Shape type (circle or polygon)
102+
PhysicsBody body; // Shape physics body data pointer
103+
PhysicsVertexData vertexData; // Shape vertices data (used for polygon shapes)
104+
float radius; // Shape radius (used for circle shapes)
105+
Matrix2x2 transform; // Vertices transform matrix 2x2
106+
} PhysicsShape;
107+
typedef struct PhysicsBodyData {
108+
unsigned int id; // Unique identifier
109+
bool enabled; // Enabled dynamics state (collisions are calculated anyway)
110+
Vector2 position; // Physics body shape pivot
111+
Vector2 velocity; // Current linear velocity applied to position
112+
Vector2 force; // Current linear force (reset to 0 every step)
113+
float angularVelocity; // Current angular velocity applied to orient
114+
float torque; // Current angular force (reset to 0 every step)
115+
float orient; // Rotation in radians
116+
float inertia; // Moment of inertia
117+
float inverseInertia; // Inverse value of inertia
118+
float mass; // Physics body mass
119+
float inverseMass; // Inverse value of mass
120+
float staticFriction; // Friction when the body has not movement (0 to 1)
121+
float dynamicFriction; // Friction when the body has movement (0 to 1)
122+
float restitution; // Restitution coefficient of the body (0 to 1)
123+
bool useGravity; // Apply gravity force to dynamics
124+
bool isGrounded; // Physics grounded on other body state
125+
bool freezeOrient; // Physics rotation constraint
126+
PhysicsShape shape; // Physics body shape information (type, radius, vertices, transform)
127+
} PhysicsBodyData;
128+
typedef struct PhysicsManifoldData {
129+
unsigned int id; // Unique identifier
130+
PhysicsBody bodyA; // Manifold first physics body reference
131+
PhysicsBody bodyB; // Manifold second physics body reference
132+
float penetration; // Depth of penetration from collision
133+
Vector2 normal; // Normal direction vector from 'a' to 'b'
134+
Vector2 contacts[2]; // Points of contact during collision
135+
unsigned int contactsCount; // Current collision number of contacts
136+
float restitution; // Mixed restitution during collision
137+
float dynamicFriction; // Mixed dynamic friction during collision
138+
float staticFriction; // Mixed static friction during collision
139+
} PhysicsManifoldData, *PhysicsManifold;
140+
//----------------------------------------------------------------------------------
141+
// Module Functions Declaration
142+
//----------------------------------------------------------------------------------
143+
// Physics system management
144+
extern /* Functions visible from other files*/ void InitPhysics(void); // Initializes physics system
145+
extern /* Functions visible from other files*/ void UpdatePhysics(void); // Update physics system
146+
extern /* Functions visible from other files*/ void ResetPhysics(void); // Reset physics system (global variables)
147+
extern /* Functions visible from other files*/ void ClosePhysics(void); // Close physics system and unload used memory
148+
extern /* Functions visible from other files*/ void SetPhysicsTimeStep(double delta); // Sets physics fixed time step in milliseconds. 1.666666 by default
149+
extern /* Functions visible from other files*/ void SetPhysicsGravity(float x, float y); // Sets physics global gravity force
150+
// Physic body creation/destroy
151+
extern /* Functions visible from other files*/ PhysicsBody CreatePhysicsBodyCircle(Vector2 pos, float radius, float density); // Creates a new circle physics body with generic parameters
152+
extern /* Functions visible from other files*/ PhysicsBody CreatePhysicsBodyRectangle(Vector2 pos, float width, float height, float density); // Creates a new rectangle physics body with generic parameters
153+
extern /* Functions visible from other files*/ PhysicsBody CreatePhysicsBodyPolygon(Vector2 pos, float radius, int sides, float density); // Creates a new polygon physics body with generic parameters
154+
extern /* Functions visible from other files*/ void DestroyPhysicsBody(PhysicsBody body); // Destroy a physics body
155+
// Physic body forces
156+
extern /* Functions visible from other files*/ void PhysicsAddForce(PhysicsBody body, Vector2 force); // Adds a force to a physics body
157+
extern /* Functions visible from other files*/ void PhysicsAddTorque(PhysicsBody body, float amount); // Adds an angular force to a physics body
158+
extern /* Functions visible from other files*/ void PhysicsShatter(PhysicsBody body, Vector2 position, float force); // Shatters a polygon shape physics body to little physics bodies with explosion force
159+
extern /* Functions visible from other files*/ void SetPhysicsBodyRotation(PhysicsBody body, float radians); // Sets physics body shape transform based on radians parameter
160+
// Query physics info
161+
extern /* Functions visible from other files*/ PhysicsBody GetPhysicsBody(int index); // Returns a physics body of the bodies pool at a specific index
162+
extern /* Functions visible from other files*/ int GetPhysicsBodiesCount(void); // Returns the current amount of created physics bodies
163+
extern /* Functions visible from other files*/ int GetPhysicsShapeType(int index); // Returns the physics body shape type (PHYSICS_CIRCLE or PHYSICS_POLYGON)
164+
extern /* Functions visible from other files*/ int GetPhysicsShapeVerticesCount(int index); // Returns the amount of vertices of a physics body shape
165+
extern /* Functions visible from other files*/ Vector2 GetPhysicsShapeVertex(PhysicsBody body, int vertex); // Returns transformed position of a body shape (body position + vertex transformed position)
166+
/***********************************************************************************
167+
*
168+
* PHYSAC IMPLEMENTATION
169+
*
170+
************************************************************************************/

0 commit comments

Comments
 (0)