@dayme/bunraylib 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -11
- package/package.json +11 -3
- package/src/Raylib.ts +58 -3678
- package/src/c/common.h +0 -2
- package/src/constants.ts +2 -2
- package/src/index.ts +6 -6
- package/src/main.c +0 -1
- package/src/main.d.ts +1 -1
- package/src/modules/audio/AudioModule.ts +197 -0
- package/src/modules/audio/symbols.ts +70 -0
- package/src/{c/audio.c → modules/audio/wrapper.c} +40 -80
- package/src/modules/camera/CameraModule.ts +239 -0
- package/src/modules/camera/symbols.ts +49 -0
- package/src/modules/camera/wrapper.c +141 -0
- package/src/modules/collision/CollisionModule.ts +363 -0
- package/src/modules/collision/symbols.ts +149 -0
- package/src/modules/collision/wrapper.c +176 -0
- package/src/modules/color/ColorModule.ts +65 -0
- package/src/modules/color/symbols.ts +26 -0
- package/src/modules/color/wrapper.c +16 -0
- package/src/modules/draw3d/Draw3DModule.ts +441 -0
- package/src/modules/draw3d/symbols.ts +199 -0
- package/src/modules/draw3d/wrapper.c +202 -0
- package/src/modules/font/FontModule.ts +250 -0
- package/src/modules/font/symbols.ts +46 -0
- package/src/{c/font.c → modules/font/wrapper.c} +50 -70
- package/src/modules/image/ImageModule.ts +451 -0
- package/src/{symbols/image.ts → modules/image/symbols.ts} +15 -12
- package/src/{c/image.c → modules/image/wrapper.c} +23 -45
- package/src/modules/input/InputModule.ts +160 -0
- package/src/modules/input/symbols.ts +54 -0
- package/src/modules/input/wrapper.c +31 -0
- package/src/modules/model/ModelModule.ts +228 -0
- package/src/{symbols/model.ts → modules/model/symbols.ts} +17 -14
- package/src/{c/model.c → modules/model/wrapper.c} +30 -30
- package/src/modules/shader/ShaderModule.ts +78 -0
- package/src/{symbols/shader.ts → modules/shader/symbols.ts} +3 -1
- package/src/{c/shader.c → modules/shader/wrapper.c} +11 -1
- package/src/modules/shapes/ShapesModule.ts +687 -0
- package/src/modules/shapes/symbols.ts +161 -0
- package/src/modules/shapes/wrapper.c +183 -0
- package/src/modules/texture/TextureModule.ts +190 -0
- package/src/{symbols/texture.ts → modules/texture/symbols.ts} +15 -9
- package/src/{c/texture.c → modules/texture/wrapper.c} +7 -22
- package/src/modules/window/WindowModule.ts +248 -0
- package/src/modules/window/symbols.ts +85 -0
- package/src/modules/window/wrapper.c +39 -0
- package/src/symbols.ts +87 -47
- package/src/utils.ts +63 -15
- package/src/c/camera.c +0 -161
- package/src/c/collision.c +0 -176
- package/src/c/color.c +0 -100
- package/src/c/draw3d.c +0 -222
- package/src/c/filesystem.c +0 -36
- package/src/c/input.c +0 -85
- package/src/c/shapes.c +0 -283
- package/src/c/window.c +0 -150
- package/src/symbols/audio.ts +0 -64
- package/src/symbols/camera.ts +0 -46
- package/src/symbols/collision.ts +0 -116
- package/src/symbols/color.ts +0 -22
- package/src/symbols/draw3d.ts +0 -137
- package/src/symbols/filesystem.ts +0 -30
- package/src/symbols/font.ts +0 -40
- package/src/symbols/input.ts +0 -51
- package/src/symbols/shapes.ts +0 -92
- package/src/symbols/window.ts +0 -83
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#include "common.h"
|
|
1
|
+
#include "../../c/common.h"
|
|
2
2
|
|
|
3
3
|
int LoadModelW(const char* fileName) {
|
|
4
4
|
int slot = modelAlloc();
|
|
@@ -70,84 +70,84 @@ bool ExportMeshAsCodeW(int id, const char* fileName) {
|
|
|
70
70
|
return ExportMeshAsCode(meshRegistry[id], fileName);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
int GenMeshPolyW(int sides,
|
|
73
|
+
int GenMeshPolyW(int sides, float radius) {
|
|
74
74
|
int slot = meshAlloc();
|
|
75
75
|
if (slot < 0) return -1;
|
|
76
|
-
meshRegistry[slot] = GenMeshPoly(sides,
|
|
76
|
+
meshRegistry[slot] = GenMeshPoly(sides, radius);
|
|
77
77
|
return slot;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
int GenMeshPlaneW(
|
|
80
|
+
int GenMeshPlaneW(float width, float length, int resX, int resZ) {
|
|
81
81
|
int slot = meshAlloc();
|
|
82
82
|
if (slot < 0) return -1;
|
|
83
|
-
meshRegistry[slot] = GenMeshPlane(
|
|
83
|
+
meshRegistry[slot] = GenMeshPlane(width, length, resX, resZ);
|
|
84
84
|
return slot;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
int GenMeshCubeW(
|
|
87
|
+
int GenMeshCubeW(float width, float height, float length) {
|
|
88
88
|
int slot = meshAlloc();
|
|
89
89
|
if (slot < 0) return -1;
|
|
90
|
-
meshRegistry[slot] = GenMeshCube(
|
|
90
|
+
meshRegistry[slot] = GenMeshCube(width, height, length);
|
|
91
91
|
return slot;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
int GenMeshSphereW(
|
|
94
|
+
int GenMeshSphereW(float radius, int rings, int slices) {
|
|
95
95
|
int slot = meshAlloc();
|
|
96
96
|
if (slot < 0) return -1;
|
|
97
|
-
meshRegistry[slot] = GenMeshSphere(
|
|
97
|
+
meshRegistry[slot] = GenMeshSphere(radius, rings, slices);
|
|
98
98
|
return slot;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
int GenMeshHemiSphereW(
|
|
101
|
+
int GenMeshHemiSphereW(float radius, int rings, int slices) {
|
|
102
102
|
int slot = meshAlloc();
|
|
103
103
|
if (slot < 0) return -1;
|
|
104
|
-
meshRegistry[slot] = GenMeshHemiSphere(
|
|
104
|
+
meshRegistry[slot] = GenMeshHemiSphere(radius, rings, slices);
|
|
105
105
|
return slot;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
int GenMeshCylinderW(
|
|
108
|
+
int GenMeshCylinderW(float radius, float height, int slices) {
|
|
109
109
|
int slot = meshAlloc();
|
|
110
110
|
if (slot < 0) return -1;
|
|
111
|
-
meshRegistry[slot] = GenMeshCylinder(
|
|
111
|
+
meshRegistry[slot] = GenMeshCylinder(radius, height, slices);
|
|
112
112
|
return slot;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
int GenMeshConeW(
|
|
115
|
+
int GenMeshConeW(float radius, float height, int slices) {
|
|
116
116
|
int slot = meshAlloc();
|
|
117
117
|
if (slot < 0) return -1;
|
|
118
|
-
meshRegistry[slot] = GenMeshCone(
|
|
118
|
+
meshRegistry[slot] = GenMeshCone(radius, height, slices);
|
|
119
119
|
return slot;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
int GenMeshTorusW(
|
|
122
|
+
int GenMeshTorusW(float radius, float size, int radSeg, int sides) {
|
|
123
123
|
int slot = meshAlloc();
|
|
124
124
|
if (slot < 0) return -1;
|
|
125
|
-
meshRegistry[slot] = GenMeshTorus(
|
|
125
|
+
meshRegistry[slot] = GenMeshTorus(radius, size, radSeg, sides);
|
|
126
126
|
return slot;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
int GenMeshKnotW(
|
|
129
|
+
int GenMeshKnotW(float radius, float size, int radSeg, int sides) {
|
|
130
130
|
int slot = meshAlloc();
|
|
131
131
|
if (slot < 0) return -1;
|
|
132
|
-
meshRegistry[slot] = GenMeshKnot(
|
|
132
|
+
meshRegistry[slot] = GenMeshKnot(radius, size, radSeg, sides);
|
|
133
133
|
return slot;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
int GenMeshHeightmapW(int imageId,
|
|
136
|
+
int GenMeshHeightmapW(int imageId, float sizeX, float sizeY, float sizeZ) {
|
|
137
137
|
if (imageId < 0 || imageId >= MAX_IMAGES || !imageUsed[imageId]) return -1;
|
|
138
138
|
int slot = meshAlloc();
|
|
139
139
|
if (slot < 0) return -1;
|
|
140
140
|
meshRegistry[slot] = GenMeshHeightmap(imageRegistry[imageId],
|
|
141
|
-
(Vector3){
|
|
141
|
+
(Vector3){sizeX, sizeY, sizeZ});
|
|
142
142
|
return slot;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
int GenMeshCubicmapW(int imageId,
|
|
145
|
+
int GenMeshCubicmapW(int imageId, float sizeX, float sizeY, float sizeZ) {
|
|
146
146
|
if (imageId < 0 || imageId >= MAX_IMAGES || !imageUsed[imageId]) return -1;
|
|
147
147
|
int slot = meshAlloc();
|
|
148
148
|
if (slot < 0) return -1;
|
|
149
149
|
meshRegistry[slot] = GenMeshCubicmap(imageRegistry[imageId],
|
|
150
|
-
(Vector3){
|
|
150
|
+
(Vector3){sizeX, sizeY, sizeZ});
|
|
151
151
|
return slot;
|
|
152
152
|
}
|
|
153
153
|
|
|
@@ -176,7 +176,7 @@ void UnloadMaterialW(int id) {
|
|
|
176
176
|
|
|
177
177
|
void SetMaterialTextureW(int id, int mapType, unsigned int texId, int texW, int texH) {
|
|
178
178
|
if (id < 0 || id >= MAX_MATERIALS || !materialUsed[id]) return;
|
|
179
|
-
Texture2D tex = {
|
|
179
|
+
Texture2D tex = {texId, texW, texH, 1, 7};
|
|
180
180
|
SetMaterialTexture(&materialRegistry[id], mapType, tex);
|
|
181
181
|
}
|
|
182
182
|
|
|
@@ -210,21 +210,21 @@ void LoadModelAnimationsW(int* outSlotStart, int* outAnimCount, const char* file
|
|
|
210
210
|
if (anims && count > 0) UnloadModelAnimations(anims, count);
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
void UpdateModelAnimationW(int modelId, int animId,
|
|
213
|
+
void UpdateModelAnimationW(int modelId, int animId, float frame) {
|
|
214
214
|
if (modelId < 0 || modelId >= MAX_MODELS || !modelUsed[modelId]) return;
|
|
215
215
|
if (animId < 0 || animId >= MAX_ANIMATIONS || !animUsed[animId]) return;
|
|
216
|
-
UpdateModelAnimation(modelRegistry[modelId], animRegistry[animId],
|
|
216
|
+
UpdateModelAnimation(modelRegistry[modelId], animRegistry[animId], frame);
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
void UpdateModelAnimationExW(int modelId, int animAId,
|
|
219
|
+
void UpdateModelAnimationExW(int modelId, int animAId, float frameA, int animBId, float frameB, float blend) {
|
|
220
220
|
if (modelId < 0 || modelId >= MAX_MODELS || !modelUsed[modelId]) return;
|
|
221
221
|
if (animAId < 0 || animAId >= MAX_ANIMATIONS || !animUsed[animAId]) return;
|
|
222
222
|
if (animBId < 0 || animBId >= MAX_ANIMATIONS || !animUsed[animBId]) return;
|
|
223
223
|
UpdateModelAnimationEx(
|
|
224
224
|
modelRegistry[modelId],
|
|
225
|
-
animRegistry[animAId],
|
|
226
|
-
animRegistry[animBId],
|
|
227
|
-
|
|
225
|
+
animRegistry[animAId], frameA,
|
|
226
|
+
animRegistry[animBId], frameB,
|
|
227
|
+
blend);
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
void UnloadModelAnimationsW(int startSlot, int count) {
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { getSymbols } from '../../symbols';
|
|
2
|
+
import { cstr, i } from '../../utils';
|
|
3
|
+
import type { Shader, Texture2D } from '../../types';
|
|
4
|
+
|
|
5
|
+
const r = () => getSymbols();
|
|
6
|
+
|
|
7
|
+
export class ShaderModule {
|
|
8
|
+
static loadShader(vsFileName: string | null, fsFileName: string | null): Shader {
|
|
9
|
+
return r().symbols.LoadShaderW(
|
|
10
|
+
vsFileName ? cstr(vsFileName) : null,
|
|
11
|
+
fsFileName ? cstr(fsFileName) : null,
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
static loadShaderFromMemory(vsCode: string | null, fsCode: string | null): Shader {
|
|
15
|
+
return r().symbols.LoadShaderFromMemoryW(
|
|
16
|
+
vsCode ? cstr(vsCode) : null,
|
|
17
|
+
fsCode ? cstr(fsCode) : null,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
static isShaderValid(shader: Shader): boolean {
|
|
21
|
+
return r().symbols.IsShaderValidW(i(shader));
|
|
22
|
+
}
|
|
23
|
+
static getShaderLocation(shader: Shader, uniformName: string): number {
|
|
24
|
+
return r().symbols.GetShaderLocationW(i(shader), cstr(uniformName));
|
|
25
|
+
}
|
|
26
|
+
static getShaderLocationAttrib(shader: Shader, attribName: string): number {
|
|
27
|
+
return r().symbols.GetShaderLocationAttribW(i(shader), cstr(attribName));
|
|
28
|
+
}
|
|
29
|
+
static setShaderValue(
|
|
30
|
+
shader: Shader,
|
|
31
|
+
locIndex: number,
|
|
32
|
+
value: Buffer | Uint8Array | ArrayBufferView,
|
|
33
|
+
uniformType: number,
|
|
34
|
+
): void {
|
|
35
|
+
r().symbols.SetShaderValueW(i(shader), i(locIndex), value as unknown as Buffer, i(uniformType));
|
|
36
|
+
}
|
|
37
|
+
static setShaderValueV(
|
|
38
|
+
shader: Shader,
|
|
39
|
+
locIndex: number,
|
|
40
|
+
value: Buffer | Uint8Array | ArrayBufferView,
|
|
41
|
+
uniformType: number,
|
|
42
|
+
count: number,
|
|
43
|
+
): void {
|
|
44
|
+
r().symbols.SetShaderValueVW(
|
|
45
|
+
i(shader),
|
|
46
|
+
i(locIndex),
|
|
47
|
+
value as unknown as Buffer,
|
|
48
|
+
i(uniformType),
|
|
49
|
+
i(count),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
static setShaderValueMatrix(shader: Shader, locIndex: number, mat: Float32Array): void {
|
|
53
|
+
if (mat.length !== 16) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
`setShaderValueMatrix: mat must have exactly 16 elements (got ${mat.length})`,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
r().symbols.SetShaderValueMatrixW(i(shader), i(locIndex), mat);
|
|
59
|
+
}
|
|
60
|
+
static setShaderValueTexture(shader: Shader, locIndex: number, texture: Texture2D): void {
|
|
61
|
+
r().symbols.SetShaderValueTextureW(
|
|
62
|
+
i(shader),
|
|
63
|
+
i(locIndex),
|
|
64
|
+
i(texture.id),
|
|
65
|
+
i(texture.width),
|
|
66
|
+
i(texture.height),
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
static unloadShader(shader: Shader): void {
|
|
70
|
+
r().symbols.UnloadShaderW(i(shader));
|
|
71
|
+
}
|
|
72
|
+
static beginShaderMode(shader: Shader): void {
|
|
73
|
+
r().symbols.BeginShaderModeW(i(shader));
|
|
74
|
+
}
|
|
75
|
+
static endShaderMode(): void {
|
|
76
|
+
r().symbols.EndShaderModeW();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FFIType } from
|
|
1
|
+
import { FFIType } from 'bun:ffi';
|
|
2
2
|
const { i32, cstring, bool, ptr } = FFIType;
|
|
3
3
|
|
|
4
4
|
export const shaderSymbols = {
|
|
@@ -7,6 +7,8 @@ export const shaderSymbols = {
|
|
|
7
7
|
IsShaderValidW: { args: [i32], returns: bool },
|
|
8
8
|
GetShaderLocationW: { args: [i32, cstring], returns: i32 },
|
|
9
9
|
GetShaderLocationAttribW: { args: [i32, cstring], returns: i32 },
|
|
10
|
+
SetShaderValueW: { args: [i32, i32, ptr, i32], returns: FFIType.void },
|
|
11
|
+
SetShaderValueVW: { args: [i32, i32, ptr, i32, i32], returns: FFIType.void },
|
|
10
12
|
SetShaderValueMatrixW: { args: [i32, i32, ptr], returns: FFIType.void },
|
|
11
13
|
SetShaderValueTextureW: { args: [i32, i32, i32, i32, i32], returns: FFIType.void },
|
|
12
14
|
UnloadShaderW: { args: [i32], returns: FFIType.void },
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#include "common.h"
|
|
1
|
+
#include "../../c/common.h"
|
|
2
2
|
|
|
3
3
|
int LoadShaderW(const char* vsFileName, const char* fsFileName) {
|
|
4
4
|
int slot = shaderAlloc();
|
|
@@ -29,6 +29,16 @@ int GetShaderLocationAttribW(int id, const char* attribName) {
|
|
|
29
29
|
return GetShaderLocationAttrib(shaderRegistry[id], attribName);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
void SetShaderValueW(int id, int locIndex, const void* value, int uniformType) {
|
|
33
|
+
if (id < 0 || id >= MAX_SHADERS || !shaderUsed[id]) return;
|
|
34
|
+
SetShaderValue(shaderRegistry[id], locIndex, value, uniformType);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
void SetShaderValueVW(int id, int locIndex, const void* value, int uniformType, int count) {
|
|
38
|
+
if (id < 0 || id >= MAX_SHADERS || !shaderUsed[id]) return;
|
|
39
|
+
SetShaderValueV(shaderRegistry[id], locIndex, value, uniformType, count);
|
|
40
|
+
}
|
|
41
|
+
|
|
32
42
|
void SetShaderValueMatrixW(int id, int locIndex, const float* mat) {
|
|
33
43
|
if (id < 0 || id >= MAX_SHADERS || !shaderUsed[id]) return;
|
|
34
44
|
Matrix m;
|