@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.
Files changed (67) hide show
  1. package/README.md +60 -11
  2. package/package.json +11 -3
  3. package/src/Raylib.ts +58 -3678
  4. package/src/c/common.h +0 -2
  5. package/src/constants.ts +2 -2
  6. package/src/index.ts +6 -6
  7. package/src/main.c +0 -1
  8. package/src/main.d.ts +1 -1
  9. package/src/modules/audio/AudioModule.ts +197 -0
  10. package/src/modules/audio/symbols.ts +70 -0
  11. package/src/{c/audio.c → modules/audio/wrapper.c} +40 -80
  12. package/src/modules/camera/CameraModule.ts +239 -0
  13. package/src/modules/camera/symbols.ts +49 -0
  14. package/src/modules/camera/wrapper.c +141 -0
  15. package/src/modules/collision/CollisionModule.ts +363 -0
  16. package/src/modules/collision/symbols.ts +149 -0
  17. package/src/modules/collision/wrapper.c +176 -0
  18. package/src/modules/color/ColorModule.ts +65 -0
  19. package/src/modules/color/symbols.ts +26 -0
  20. package/src/modules/color/wrapper.c +16 -0
  21. package/src/modules/draw3d/Draw3DModule.ts +441 -0
  22. package/src/modules/draw3d/symbols.ts +199 -0
  23. package/src/modules/draw3d/wrapper.c +202 -0
  24. package/src/modules/font/FontModule.ts +250 -0
  25. package/src/modules/font/symbols.ts +46 -0
  26. package/src/{c/font.c → modules/font/wrapper.c} +50 -70
  27. package/src/modules/image/ImageModule.ts +451 -0
  28. package/src/{symbols/image.ts → modules/image/symbols.ts} +15 -12
  29. package/src/{c/image.c → modules/image/wrapper.c} +23 -45
  30. package/src/modules/input/InputModule.ts +160 -0
  31. package/src/modules/input/symbols.ts +54 -0
  32. package/src/modules/input/wrapper.c +31 -0
  33. package/src/modules/model/ModelModule.ts +228 -0
  34. package/src/{symbols/model.ts → modules/model/symbols.ts} +17 -14
  35. package/src/{c/model.c → modules/model/wrapper.c} +30 -30
  36. package/src/modules/shader/ShaderModule.ts +78 -0
  37. package/src/{symbols/shader.ts → modules/shader/symbols.ts} +3 -1
  38. package/src/{c/shader.c → modules/shader/wrapper.c} +11 -1
  39. package/src/modules/shapes/ShapesModule.ts +687 -0
  40. package/src/modules/shapes/symbols.ts +161 -0
  41. package/src/modules/shapes/wrapper.c +183 -0
  42. package/src/modules/texture/TextureModule.ts +190 -0
  43. package/src/{symbols/texture.ts → modules/texture/symbols.ts} +15 -9
  44. package/src/{c/texture.c → modules/texture/wrapper.c} +7 -22
  45. package/src/modules/window/WindowModule.ts +248 -0
  46. package/src/modules/window/symbols.ts +85 -0
  47. package/src/modules/window/wrapper.c +39 -0
  48. package/src/symbols.ts +87 -47
  49. package/src/utils.ts +63 -15
  50. package/src/c/camera.c +0 -161
  51. package/src/c/collision.c +0 -176
  52. package/src/c/color.c +0 -100
  53. package/src/c/draw3d.c +0 -222
  54. package/src/c/filesystem.c +0 -36
  55. package/src/c/input.c +0 -85
  56. package/src/c/shapes.c +0 -283
  57. package/src/c/window.c +0 -150
  58. package/src/symbols/audio.ts +0 -64
  59. package/src/symbols/camera.ts +0 -46
  60. package/src/symbols/collision.ts +0 -116
  61. package/src/symbols/color.ts +0 -22
  62. package/src/symbols/draw3d.ts +0 -137
  63. package/src/symbols/filesystem.ts +0 -30
  64. package/src/symbols/font.ts +0 -40
  65. package/src/symbols/input.ts +0 -51
  66. package/src/symbols/shapes.ts +0 -92
  67. 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, int radius) {
73
+ int GenMeshPolyW(int sides, float radius) {
74
74
  int slot = meshAlloc();
75
75
  if (slot < 0) return -1;
76
- meshRegistry[slot] = GenMeshPoly(sides, i2f(radius));
76
+ meshRegistry[slot] = GenMeshPoly(sides, radius);
77
77
  return slot;
78
78
  }
79
79
 
80
- int GenMeshPlaneW(int width, int length, int resX, int resZ) {
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(i2f(width), i2f(length), resX, resZ);
83
+ meshRegistry[slot] = GenMeshPlane(width, length, resX, resZ);
84
84
  return slot;
85
85
  }
86
86
 
87
- int GenMeshCubeW(int width, int height, int length) {
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(i2f(width), i2f(height), i2f(length));
90
+ meshRegistry[slot] = GenMeshCube(width, height, length);
91
91
  return slot;
92
92
  }
93
93
 
94
- int GenMeshSphereW(int radius, int rings, int slices) {
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(i2f(radius), rings, slices);
97
+ meshRegistry[slot] = GenMeshSphere(radius, rings, slices);
98
98
  return slot;
99
99
  }
100
100
 
101
- int GenMeshHemiSphereW(int radius, int rings, int slices) {
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(i2f(radius), rings, slices);
104
+ meshRegistry[slot] = GenMeshHemiSphere(radius, rings, slices);
105
105
  return slot;
106
106
  }
107
107
 
108
- int GenMeshCylinderW(int radius, int height, int slices) {
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(i2f(radius), i2f(height), slices);
111
+ meshRegistry[slot] = GenMeshCylinder(radius, height, slices);
112
112
  return slot;
113
113
  }
114
114
 
115
- int GenMeshConeW(int radius, int height, int slices) {
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(i2f(radius), i2f(height), slices);
118
+ meshRegistry[slot] = GenMeshCone(radius, height, slices);
119
119
  return slot;
120
120
  }
121
121
 
122
- int GenMeshTorusW(int radius, int size, int radSeg, int sides) {
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(i2f(radius), i2f(size), radSeg, sides);
125
+ meshRegistry[slot] = GenMeshTorus(radius, size, radSeg, sides);
126
126
  return slot;
127
127
  }
128
128
 
129
- int GenMeshKnotW(int radius, int size, int radSeg, int sides) {
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(i2f(radius), i2f(size), radSeg, sides);
132
+ meshRegistry[slot] = GenMeshKnot(radius, size, radSeg, sides);
133
133
  return slot;
134
134
  }
135
135
 
136
- int GenMeshHeightmapW(int imageId, int sizeX, int sizeY, int sizeZ) {
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){i2f(sizeX), i2f(sizeY), i2f(sizeZ)});
141
+ (Vector3){sizeX, sizeY, sizeZ});
142
142
  return slot;
143
143
  }
144
144
 
145
- int GenMeshCubicmapW(int imageId, int sizeX, int sizeY, int sizeZ) {
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){i2f(sizeX), i2f(sizeY), i2f(sizeZ)});
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 = { texId, texW, texH, 1, 7 };
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, int frame) {
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], i2f(frame));
216
+ UpdateModelAnimation(modelRegistry[modelId], animRegistry[animId], frame);
217
217
  }
218
218
 
219
- void UpdateModelAnimationExW(int modelId, int animAId, int frameA, int animBId, int frameB, int blend) {
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], i2f(frameA),
226
- animRegistry[animBId], i2f(frameB),
227
- i2f(blend));
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 "bun:ffi";
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;