mirror of https://github.com/mode777/rayjs.git
Add more bindings
This commit is contained in:
parent
f4527410e1
commit
18b6c7c5f9
|
@ -96,15 +96,15 @@ function main(){
|
||||||
properties: {
|
properties: {
|
||||||
hit: { get: true, set: false },
|
hit: { get: true, set: false },
|
||||||
distance: { get: true, set: false },
|
distance: { get: true, set: false },
|
||||||
//point: { get: true, set: false },
|
point: { get: true, set: false },
|
||||||
//normal: { get: true, set: false },
|
normal: { get: true, set: false },
|
||||||
},
|
},
|
||||||
createConstructor: false
|
createConstructor: false
|
||||||
})
|
})
|
||||||
core.addApiStructByName("Camera2D",{
|
core.addApiStructByName("Camera2D",{
|
||||||
properties: {
|
properties: {
|
||||||
offset: { get: false, set: true },
|
offset: { get: true, set: true },
|
||||||
target: { get: false, set: true },
|
target: { get: true, set: true },
|
||||||
rotation: { get: true, set: true },
|
rotation: { get: true, set: true },
|
||||||
zoom: { get: true, set: true },
|
zoom: { get: true, set: true },
|
||||||
},
|
},
|
||||||
|
@ -121,7 +121,10 @@ function main(){
|
||||||
createConstructor: true
|
createConstructor: true
|
||||||
})
|
})
|
||||||
core.addApiStructByName("BoundingBox",{
|
core.addApiStructByName("BoundingBox",{
|
||||||
properties: {},
|
properties: {
|
||||||
|
min: { get: true, set: true },
|
||||||
|
max: { get: true, set: true },
|
||||||
|
},
|
||||||
createConstructor: true
|
createConstructor: true
|
||||||
})
|
})
|
||||||
core.addApiStructByName("Matrix",{
|
core.addApiStructByName("Matrix",{
|
||||||
|
@ -141,6 +144,7 @@ function main(){
|
||||||
})
|
})
|
||||||
core.addApiStructByName("Image", {
|
core.addApiStructByName("Image", {
|
||||||
properties: {
|
properties: {
|
||||||
|
//data: { set: true },
|
||||||
width: { get: true },
|
width: { get: true },
|
||||||
height: { get: true },
|
height: { get: true },
|
||||||
mipmaps: { get: true },
|
mipmaps: { get: true },
|
||||||
|
@ -166,12 +170,18 @@ function main(){
|
||||||
core.addApiStructByName("Music", {
|
core.addApiStructByName("Music", {
|
||||||
properties: {
|
properties: {
|
||||||
frameCount: { get: true },
|
frameCount: { get: true },
|
||||||
looping: { get: true, set: true }
|
looping: { get: true, set: true },
|
||||||
|
ctxType: { get: true },
|
||||||
},
|
},
|
||||||
//destructor: "UnloadMusicStream"
|
//destructor: "UnloadMusicStream"
|
||||||
})
|
})
|
||||||
core.addApiStructByName("Model", {
|
core.addApiStructByName("Model", {
|
||||||
properties: {},
|
properties: {
|
||||||
|
transform: { get: true, set: true },
|
||||||
|
meshCount: { get: true },
|
||||||
|
materialCount: { get: true },
|
||||||
|
boneCount: { get: true },
|
||||||
|
},
|
||||||
//destructor: "UnloadModel"
|
//destructor: "UnloadModel"
|
||||||
})
|
})
|
||||||
core.addApiStructByName("Mesh", {
|
core.addApiStructByName("Mesh", {
|
||||||
|
@ -195,24 +205,32 @@ function main(){
|
||||||
//destructor: "UnloadMesh"
|
//destructor: "UnloadMesh"
|
||||||
})
|
})
|
||||||
core.addApiStructByName("Shader", {
|
core.addApiStructByName("Shader", {
|
||||||
properties: {},
|
properties: {
|
||||||
|
id: { get: true }
|
||||||
|
},
|
||||||
//destructor: "UnloadShader"
|
//destructor: "UnloadShader"
|
||||||
})
|
})
|
||||||
core.addApiStructByName("Texture", {
|
core.addApiStructByName("Texture", {
|
||||||
properties: {
|
properties: {
|
||||||
width: { get: true },
|
width: { get: true },
|
||||||
height: { get: true }
|
height: { get: true },
|
||||||
|
mipmaps: { get: true },
|
||||||
|
format: { get: true },
|
||||||
},
|
},
|
||||||
//destructor: "UnloadTexture"
|
//destructor: "UnloadTexture"
|
||||||
})
|
})
|
||||||
core.addApiStructByName("Font", {
|
core.addApiStructByName("Font", {
|
||||||
properties: {
|
properties: {
|
||||||
baseSize: { get: true }
|
baseSize: { get: true },
|
||||||
|
glyphCount: { get: true },
|
||||||
|
glyphPadding: { get: true },
|
||||||
},
|
},
|
||||||
//destructor: "UnloadFont"
|
//destructor: "UnloadFont"
|
||||||
})
|
})
|
||||||
core.addApiStructByName("RenderTexture", {
|
core.addApiStructByName("RenderTexture", {
|
||||||
properties: { },
|
properties: {
|
||||||
|
id: { get: true }
|
||||||
|
},
|
||||||
//destructor: "UnloadRenderTexture"
|
//destructor: "UnloadRenderTexture"
|
||||||
})
|
})
|
||||||
core.addApiStructByName("MaterialMap", {
|
core.addApiStructByName("MaterialMap", {
|
||||||
|
@ -313,7 +331,7 @@ function main(){
|
||||||
|
|
||||||
// Shader Management
|
// Shader Management
|
||||||
core.addApiFunctionByName("LoadShader")
|
core.addApiFunctionByName("LoadShader")
|
||||||
// core.addApiFunctionByName("LoadShaderFromMemory")
|
core.addApiFunctionByName("LoadShaderFromMemory")
|
||||||
core.addApiFunctionByName("IsShaderReady")
|
core.addApiFunctionByName("IsShaderReady")
|
||||||
core.addApiFunctionByName("GetShaderLocation")
|
core.addApiFunctionByName("GetShaderLocation")
|
||||||
core.addApiFunctionByName("GetShaderLocationAttrib")
|
core.addApiFunctionByName("GetShaderLocationAttrib")
|
||||||
|
@ -382,17 +400,28 @@ function main(){
|
||||||
// Callbacks not supported on JS
|
// Callbacks not supported on JS
|
||||||
|
|
||||||
// Files management functions
|
// Files management functions
|
||||||
//core.addApiFunctionByName("LoadFileData")
|
const lfd = apiDesc.getFunction("LoadFileData")
|
||||||
//core.addApiFunctionByName("UnloadLoadFileData")
|
lfd?.params.pop()
|
||||||
//core.addApiFunctionByName("SaveFileData")
|
core.addApiFunctionByName("LoadFileData", null, { body: gen => {
|
||||||
|
gen.jsToC("const char *", "fileName", "argv[0]")
|
||||||
|
gen.declare("bytesRead", "unsigned int")
|
||||||
|
gen.call("LoadFileData", ["fileName", "&bytesRead"], { type: "unsigned char *", name: "retVal" })
|
||||||
|
gen.statement("JSValue buffer = JS_NewArrayBufferCopy(ctx, (const uint8_t*)retVal, bytesRead)")
|
||||||
|
gen.call("UnloadFileData", ["retVal"])
|
||||||
|
gen.jsCleanUpParameter("const char*","fileName")
|
||||||
|
gen.returnExp("buffer")
|
||||||
|
} })
|
||||||
|
//UnloadLoadFileData not needed, data is copied
|
||||||
|
// TODO: Works but unnecessary makes copy of memory
|
||||||
|
core.addApiFunctionByName("SaveFileData")
|
||||||
// Export data as code not needed
|
// Export data as code not needed
|
||||||
core.addApiFunctionByName("LoadFileText", null, { after: gen => gen.call("UnloadFileText", ["returnVal"]) })
|
core.addApiFunctionByName("LoadFileText", null, { after: gen => gen.call("UnloadFileText", ["returnVal"]) })
|
||||||
core.addApiFunctionByName("SaveFileText")
|
core.addApiFunctionByName("SaveFileText")
|
||||||
core.addApiFunctionByName("FileExists")
|
core.addApiFunctionByName("FileExists")
|
||||||
core.addApiFunctionByName("DirectoryExists")
|
core.addApiFunctionByName("DirectoryExists")
|
||||||
core.addApiFunctionByName("IsFileExtension")
|
core.addApiFunctionByName("IsFileExtension")
|
||||||
// TODO: Who needs to clean memory here?
|
|
||||||
core.addApiFunctionByName("GetFileLength")
|
core.addApiFunctionByName("GetFileLength")
|
||||||
|
// TODO: Who needs to clean memory here?
|
||||||
core.addApiFunctionByName("GetFileExtension")
|
core.addApiFunctionByName("GetFileExtension")
|
||||||
core.addApiFunctionByName("GetFileName")
|
core.addApiFunctionByName("GetFileName")
|
||||||
core.addApiFunctionByName("GetFileNameWithoutExt")
|
core.addApiFunctionByName("GetFileNameWithoutExt")
|
||||||
|
@ -402,15 +431,15 @@ function main(){
|
||||||
core.addApiFunctionByName("GetApplicationDirectory")
|
core.addApiFunctionByName("GetApplicationDirectory")
|
||||||
core.addApiFunctionByName("ChangeDirectory")
|
core.addApiFunctionByName("ChangeDirectory")
|
||||||
core.addApiFunctionByName("IsPathFile")
|
core.addApiFunctionByName("IsPathFile")
|
||||||
//core.addApiFunctionByName("LoadPathFiles")
|
//core.addApiFunctionByName("LoadDirectoryFiles")
|
||||||
//core.addApiFunctionByName("LoadPathFilesEx")
|
//core.addApiFunctionByName("LoadDirectoryFilesEx")
|
||||||
// UnloadDirectoryFiles
|
// UnloadDirectoryFiles
|
||||||
core.addApiFunctionByName("IsFileDropped")
|
core.addApiFunctionByName("IsFileDropped")
|
||||||
//core.addApiFunctionByName("LoadDroppedFiles")
|
//core.addApiFunctionByName("LoadDroppedFiles")
|
||||||
// UnloadDroppedFiles
|
// UnloadDroppedFiles
|
||||||
core.addApiFunctionByName("GetFileModTime")
|
core.addApiFunctionByName("GetFileModTime")
|
||||||
|
|
||||||
// Compression/encodeing functionality
|
// Compression/encoding functionality
|
||||||
//core.addApiFunctionByName("CompressData")
|
//core.addApiFunctionByName("CompressData")
|
||||||
//core.addApiFunctionByName("DecompressData")
|
//core.addApiFunctionByName("DecompressData")
|
||||||
//core.addApiFunctionByName("EncodeDataBase64")
|
//core.addApiFunctionByName("EncodeDataBase64")
|
||||||
|
@ -477,8 +506,7 @@ function main(){
|
||||||
//api.functions.forEach(x => console.log(`core.addApiFunctionByName("${x.name}")`))
|
//api.functions.forEach(x => console.log(`core.addApiFunctionByName("${x.name}")`))
|
||||||
|
|
||||||
// module: rshapes
|
// module: rshapes
|
||||||
// TODO: Do we need ref-counting here?
|
core.addApiFunctionByName("SetShapesTexture")
|
||||||
//core.addApiFunctionByName("SetShapesTexture")
|
|
||||||
|
|
||||||
// Basic shapes drawing functions
|
// Basic shapes drawing functions
|
||||||
core.addApiFunctionByName("DrawPixel")
|
core.addApiFunctionByName("DrawPixel")
|
||||||
|
@ -535,7 +563,7 @@ function main(){
|
||||||
core.addApiFunctionByName("LoadImage")
|
core.addApiFunctionByName("LoadImage")
|
||||||
core.addApiFunctionByName("LoadImageRaw")
|
core.addApiFunctionByName("LoadImageRaw")
|
||||||
// core.addApiFunctionByName("LoadImageAnim")
|
// core.addApiFunctionByName("LoadImageAnim")
|
||||||
// core.addApiFunctionByName("LoadImageFromMemory")
|
core.addApiFunctionByName("LoadImageFromMemory")
|
||||||
core.addApiFunctionByName("LoadImageFromTexture")
|
core.addApiFunctionByName("LoadImageFromTexture")
|
||||||
core.addApiFunctionByName("LoadImageFromScreen")
|
core.addApiFunctionByName("LoadImageFromScreen")
|
||||||
core.addApiFunctionByName("IsImageReady")
|
core.addApiFunctionByName("IsImageReady")
|
||||||
|
@ -625,8 +653,8 @@ function main(){
|
||||||
core.addApiFunctionByName("UnloadTexture")
|
core.addApiFunctionByName("UnloadTexture")
|
||||||
core.addApiFunctionByName("IsRenderTextureReady")
|
core.addApiFunctionByName("IsRenderTextureReady")
|
||||||
core.addApiFunctionByName("UnloadRenderTexture")
|
core.addApiFunctionByName("UnloadRenderTexture")
|
||||||
// core.addApiFunctionByName("UpdateTexture")
|
core.addApiFunctionByName("UpdateTexture")
|
||||||
// core.addApiFunctionByName("UpdateTextureRec")
|
core.addApiFunctionByName("UpdateTextureRec")
|
||||||
|
|
||||||
// Texture configuration functions
|
// Texture configuration functions
|
||||||
core.addApiFunctionByName("GenTextureMipmaps")
|
core.addApiFunctionByName("GenTextureMipmaps")
|
||||||
|
@ -746,7 +774,6 @@ function main(){
|
||||||
core.addApiFunctionByName("DrawBillboardPro")
|
core.addApiFunctionByName("DrawBillboardPro")
|
||||||
|
|
||||||
// Mesh management functions
|
// Mesh management functions
|
||||||
// TODO: Refcounting needed?
|
|
||||||
core.addApiFunctionByName("UploadMesh")
|
core.addApiFunctionByName("UploadMesh")
|
||||||
core.addApiFunctionByName("UpdateMeshBuffer")
|
core.addApiFunctionByName("UpdateMeshBuffer")
|
||||||
core.addApiFunctionByName("UnloadMesh")
|
core.addApiFunctionByName("UnloadMesh")
|
||||||
|
@ -805,12 +832,12 @@ function main(){
|
||||||
|
|
||||||
// Wave/Sound loading/unloading functions
|
// Wave/Sound loading/unloading functions
|
||||||
core.addApiFunctionByName("LoadWave")
|
core.addApiFunctionByName("LoadWave")
|
||||||
// core.addApiFunctionByName("LoadWaveFromMemory")
|
core.addApiFunctionByName("LoadWaveFromMemory")
|
||||||
core.addApiFunctionByName("IsWaveReady")
|
core.addApiFunctionByName("IsWaveReady")
|
||||||
core.addApiFunctionByName("LoadSound")
|
core.addApiFunctionByName("LoadSound")
|
||||||
core.addApiFunctionByName("LoadSoundFromWave")
|
core.addApiFunctionByName("LoadSoundFromWave")
|
||||||
core.addApiFunctionByName("IsSoundReady")
|
core.addApiFunctionByName("IsSoundReady")
|
||||||
// core.addApiFunctionByName("UpdateSound")
|
core.addApiFunctionByName("UpdateSound")
|
||||||
core.addApiFunctionByName("UnloadWave")
|
core.addApiFunctionByName("UnloadWave")
|
||||||
core.addApiFunctionByName("UnloadSound")
|
core.addApiFunctionByName("UnloadSound")
|
||||||
core.addApiFunctionByName("ExportWave")
|
core.addApiFunctionByName("ExportWave")
|
||||||
|
|
|
@ -84,6 +84,7 @@ export abstract class GenericQuickJsGenerator<T extends QuickJsGenerator> extend
|
||||||
case "float *":
|
case "float *":
|
||||||
case "unsigned short *":
|
case "unsigned short *":
|
||||||
case "unsigned char *":
|
case "unsigned char *":
|
||||||
|
case "const unsigned char *":
|
||||||
this.declare(name+"_size", "size_t")
|
this.declare(name+"_size", "size_t")
|
||||||
this.declare(name+"_js", "void *", false, `(void *)JS_GetArrayBuffer(ctx, &${name}_size, ${src})`)
|
this.declare(name+"_js", "void *", false, `(void *)JS_GetArrayBuffer(ctx, &${name}_size, ${src})`)
|
||||||
this.if(name+"_js == NULL").returnExp("JS_EXCEPTION")
|
this.if(name+"_js == NULL").returnExp("JS_EXCEPTION")
|
||||||
|
@ -161,6 +162,9 @@ export abstract class GenericQuickJsGenerator<T extends QuickJsGenerator> extend
|
||||||
case "char *":
|
case "char *":
|
||||||
this.declare(name, 'JSValue', false, `JS_NewString(ctx, ${src})`)
|
this.declare(name, 'JSValue', false, `JS_NewString(ctx, ${src})`)
|
||||||
break;
|
break;
|
||||||
|
// case "unsigned char *":
|
||||||
|
// this.declare(name, 'JSValue', false, `JS_NewString(ctx, ${src})`)
|
||||||
|
// break;
|
||||||
default:
|
default:
|
||||||
const classId = classIds[type]
|
const classId = classIds[type]
|
||||||
if(!classId) throw new Error("Cannot convert parameter type to Javascript: " + type)
|
if(!classId) throw new Error("Cannot convert parameter type to Javascript: " + type)
|
||||||
|
@ -186,6 +190,7 @@ export abstract class GenericQuickJsGenerator<T extends QuickJsGenerator> extend
|
||||||
case "float *":
|
case "float *":
|
||||||
case "unsigned short *":
|
case "unsigned short *":
|
||||||
case "unsigned char *":
|
case "unsigned char *":
|
||||||
|
case "const unsigned char *":
|
||||||
this.statement(`free((void *)${name})`)
|
this.statement(`free((void *)${name})`)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -38,6 +38,7 @@ export class TypeScriptDeclaration {
|
||||||
case "float":
|
case "float":
|
||||||
case "double":
|
case "double":
|
||||||
return "number"
|
return "number"
|
||||||
|
case "const unsigned char *":
|
||||||
case "unsigned char *":
|
case "unsigned char *":
|
||||||
case "unsigned short *":
|
case "unsigned short *":
|
||||||
case "float *":
|
case "float *":
|
||||||
|
|
|
@ -77,6 +77,10 @@ interface RayCollision {
|
||||||
hit: boolean,
|
hit: boolean,
|
||||||
/** Distance to the nearest hit */
|
/** Distance to the nearest hit */
|
||||||
distance: number,
|
distance: number,
|
||||||
|
/** Point of the nearest hit */
|
||||||
|
point: Vector3,
|
||||||
|
/** Surface normal of hit */
|
||||||
|
normal: Vector3,
|
||||||
}
|
}
|
||||||
declare var RayCollision: {
|
declare var RayCollision: {
|
||||||
prototype: RayCollision;
|
prototype: RayCollision;
|
||||||
|
@ -112,10 +116,14 @@ declare var Camera3D: {
|
||||||
new(position: Vector3, target: Vector3, up: Vector3, fovy: number, projection: number): Camera3D;
|
new(position: Vector3, target: Vector3, up: Vector3, fovy: number, projection: number): Camera3D;
|
||||||
}
|
}
|
||||||
interface BoundingBox {
|
interface BoundingBox {
|
||||||
|
/** Minimum vertex box-corner */
|
||||||
|
min: Vector3,
|
||||||
|
/** Maximum vertex box-corner */
|
||||||
|
max: Vector3,
|
||||||
}
|
}
|
||||||
declare var BoundingBox: {
|
declare var BoundingBox: {
|
||||||
prototype: BoundingBox;
|
prototype: BoundingBox;
|
||||||
new(): BoundingBox;
|
new(min: Vector3, max: Vector3): BoundingBox;
|
||||||
}
|
}
|
||||||
interface Matrix {
|
interface Matrix {
|
||||||
}
|
}
|
||||||
|
@ -178,11 +186,21 @@ interface Music {
|
||||||
frameCount: number,
|
frameCount: number,
|
||||||
/** Music looping enable */
|
/** Music looping enable */
|
||||||
looping: boolean,
|
looping: boolean,
|
||||||
|
/** Type of music context (audio filetype) */
|
||||||
|
ctxType: number,
|
||||||
}
|
}
|
||||||
declare var Music: {
|
declare var Music: {
|
||||||
prototype: Music;
|
prototype: Music;
|
||||||
}
|
}
|
||||||
interface Model {
|
interface Model {
|
||||||
|
/** Local transform matrix */
|
||||||
|
transform: Matrix,
|
||||||
|
/** Number of meshes */
|
||||||
|
meshCount: number,
|
||||||
|
/** Number of materials */
|
||||||
|
materialCount: number,
|
||||||
|
/** Number of bones */
|
||||||
|
boneCount: number,
|
||||||
}
|
}
|
||||||
declare var Model: {
|
declare var Model: {
|
||||||
prototype: Model;
|
prototype: Model;
|
||||||
|
@ -220,6 +238,8 @@ declare var Mesh: {
|
||||||
new(): Mesh;
|
new(): Mesh;
|
||||||
}
|
}
|
||||||
interface Shader {
|
interface Shader {
|
||||||
|
/** Shader program id */
|
||||||
|
id: number,
|
||||||
}
|
}
|
||||||
declare var Shader: {
|
declare var Shader: {
|
||||||
prototype: Shader;
|
prototype: Shader;
|
||||||
|
@ -229,6 +249,10 @@ interface Texture {
|
||||||
width: number,
|
width: number,
|
||||||
/** Texture base height */
|
/** Texture base height */
|
||||||
height: number,
|
height: number,
|
||||||
|
/** Mipmap levels, 1 by default */
|
||||||
|
mipmaps: number,
|
||||||
|
/** Data format (PixelFormat type) */
|
||||||
|
format: number,
|
||||||
}
|
}
|
||||||
declare var Texture: {
|
declare var Texture: {
|
||||||
prototype: Texture;
|
prototype: Texture;
|
||||||
|
@ -236,11 +260,17 @@ declare var Texture: {
|
||||||
interface Font {
|
interface Font {
|
||||||
/** Base size (default chars height) */
|
/** Base size (default chars height) */
|
||||||
baseSize: number,
|
baseSize: number,
|
||||||
|
/** Number of glyph characters */
|
||||||
|
glyphCount: number,
|
||||||
|
/** Padding around the glyph characters */
|
||||||
|
glyphPadding: number,
|
||||||
}
|
}
|
||||||
declare var Font: {
|
declare var Font: {
|
||||||
prototype: Font;
|
prototype: Font;
|
||||||
}
|
}
|
||||||
interface RenderTexture {
|
interface RenderTexture {
|
||||||
|
/** OpenGL framebuffer object id */
|
||||||
|
id: number,
|
||||||
}
|
}
|
||||||
declare var RenderTexture: {
|
declare var RenderTexture: {
|
||||||
prototype: RenderTexture;
|
prototype: RenderTexture;
|
||||||
|
@ -393,6 +423,8 @@ declare function beginScissorMode(x: number, y: number, width: number, height: n
|
||||||
declare function endScissorMode(): void;
|
declare function endScissorMode(): void;
|
||||||
/** Load shader from files and bind default locations */
|
/** Load shader from files and bind default locations */
|
||||||
declare function loadShader(vsFileName: string, fsFileName: string): Shader;
|
declare function loadShader(vsFileName: string, fsFileName: string): Shader;
|
||||||
|
/** Load shader from code strings and bind default locations */
|
||||||
|
declare function loadShaderFromMemory(vsCode: string, fsCode: string): Shader;
|
||||||
/** Check if a shader is ready */
|
/** Check if a shader is ready */
|
||||||
declare function isShaderReady(shader: Shader): boolean;
|
declare function isShaderReady(shader: Shader): boolean;
|
||||||
/** Get shader uniform location */
|
/** Get shader uniform location */
|
||||||
|
@ -443,6 +475,10 @@ declare function traceLog(logLevel: number, text: string): void;
|
||||||
declare function setTraceLogLevel(logLevel: number): void;
|
declare function setTraceLogLevel(logLevel: number): void;
|
||||||
/** Open URL with default system browser (if available) */
|
/** Open URL with default system browser (if available) */
|
||||||
declare function openURL(url: string): void;
|
declare function openURL(url: string): void;
|
||||||
|
/** Load file data as byte array (read) */
|
||||||
|
declare function loadFileData(fileName: string): ArrayBuffer;
|
||||||
|
/** Save data to file from byte array (write), returns true on success */
|
||||||
|
declare function saveFileData(fileName: string, data: any, bytesToWrite: number): boolean;
|
||||||
/** Load text data from file (read), returns a '\0' terminated string */
|
/** Load text data from file (read), returns a '\0' terminated string */
|
||||||
declare function loadFileText(fileName: string): string;
|
declare function loadFileText(fileName: string): string;
|
||||||
/** Save text data to file (write), string must be '\0' terminated, returns true on success */
|
/** Save text data to file (write), string must be '\0' terminated, returns true on success */
|
||||||
|
@ -569,6 +605,8 @@ declare function getGesturePinchAngle(): number;
|
||||||
declare function updateCamera(camera: Camera3D, mode: number): void;
|
declare function updateCamera(camera: Camera3D, mode: number): void;
|
||||||
/** Update camera movement/rotation */
|
/** Update camera movement/rotation */
|
||||||
declare function updateCameraPro(camera: Camera3D, movement: Vector3, rotation: Vector3, zoom: number): void;
|
declare function updateCameraPro(camera: Camera3D, movement: Vector3, rotation: Vector3, zoom: number): void;
|
||||||
|
/** Set texture and rectangle to be used on shapes drawing */
|
||||||
|
declare function setShapesTexture(texture: Texture, source: Rectangle): void;
|
||||||
/** Draw a pixel */
|
/** Draw a pixel */
|
||||||
declare function drawPixel(posX: number, posY: number, color: Color): void;
|
declare function drawPixel(posX: number, posY: number, color: Color): void;
|
||||||
/** Draw a pixel (Vector version) */
|
/** Draw a pixel (Vector version) */
|
||||||
|
@ -657,6 +695,8 @@ declare function getCollisionRec(rec1: Rectangle, rec2: Rectangle): Rectangle;
|
||||||
declare function loadImage(fileName: string): Image;
|
declare function loadImage(fileName: string): Image;
|
||||||
/** Load image from RAW file data */
|
/** Load image from RAW file data */
|
||||||
declare function loadImageRaw(fileName: string, width: number, height: number, format: number, headerSize: number): Image;
|
declare function loadImageRaw(fileName: string, width: number, height: number, format: number, headerSize: number): Image;
|
||||||
|
/** Load image from memory buffer, fileType refers to extension: i.e. '.png' */
|
||||||
|
declare function loadImageFromMemory(fileType: string, fileData: ArrayBuffer, dataSize: number): Image;
|
||||||
/** Load image from GPU texture data */
|
/** Load image from GPU texture data */
|
||||||
declare function loadImageFromTexture(texture: Texture): Image;
|
declare function loadImageFromTexture(texture: Texture): Image;
|
||||||
/** Load image from screen buffer and (screenshot) */
|
/** Load image from screen buffer and (screenshot) */
|
||||||
|
@ -793,6 +833,10 @@ declare function unloadTexture(texture: Texture): void;
|
||||||
declare function isRenderTextureReady(target: RenderTexture): boolean;
|
declare function isRenderTextureReady(target: RenderTexture): boolean;
|
||||||
/** Unload render texture from GPU memory (VRAM) */
|
/** Unload render texture from GPU memory (VRAM) */
|
||||||
declare function unloadRenderTexture(target: RenderTexture): void;
|
declare function unloadRenderTexture(target: RenderTexture): void;
|
||||||
|
/** Update GPU texture with new data */
|
||||||
|
declare function updateTexture(texture: Texture, pixels: any): void;
|
||||||
|
/** Update GPU texture rectangle with new data */
|
||||||
|
declare function updateTextureRec(texture: Texture, rec: Rectangle, pixels: any): void;
|
||||||
/** Generate GPU mipmaps for a texture */
|
/** Generate GPU mipmaps for a texture */
|
||||||
declare function genTextureMipmaps(texture: Texture): void;
|
declare function genTextureMipmaps(texture: Texture): void;
|
||||||
/** Set texture scaling filter mode */
|
/** Set texture scaling filter mode */
|
||||||
|
@ -1007,6 +1051,8 @@ declare function isAudioDeviceReady(): boolean;
|
||||||
declare function setMasterVolume(volume: number): void;
|
declare function setMasterVolume(volume: number): void;
|
||||||
/** Load wave data from file */
|
/** Load wave data from file */
|
||||||
declare function loadWave(fileName: string): Wave;
|
declare function loadWave(fileName: string): Wave;
|
||||||
|
/** Load wave from memory buffer, fileType refers to extension: i.e. '.wav' */
|
||||||
|
declare function loadWaveFromMemory(fileType: string, fileData: ArrayBuffer, dataSize: number): Wave;
|
||||||
/** Checks if wave data is ready */
|
/** Checks if wave data is ready */
|
||||||
declare function isWaveReady(wave: Wave): boolean;
|
declare function isWaveReady(wave: Wave): boolean;
|
||||||
/** Load sound from file */
|
/** Load sound from file */
|
||||||
|
@ -1015,6 +1061,8 @@ declare function loadSound(fileName: string): Sound;
|
||||||
declare function loadSoundFromWave(wave: Wave): Sound;
|
declare function loadSoundFromWave(wave: Wave): Sound;
|
||||||
/** Checks if a sound is ready */
|
/** Checks if a sound is ready */
|
||||||
declare function isSoundReady(sound: Sound): boolean;
|
declare function isSoundReady(sound: Sound): boolean;
|
||||||
|
/** Update sound buffer with new data */
|
||||||
|
declare function updateSound(sound: Sound, data: any, sampleCount: number): void;
|
||||||
/** Unload wave data */
|
/** Unload wave data */
|
||||||
declare function unloadWave(wave: Wave): void;
|
declare function unloadWave(wave: Wave): void;
|
||||||
/** Unload sound */
|
/** Unload sound */
|
||||||
|
|
|
@ -385,6 +385,7 @@ class GenericQuickJsGenerator extends generation_1.GenericCodeGenerator {
|
||||||
case "float *":
|
case "float *":
|
||||||
case "unsigned short *":
|
case "unsigned short *":
|
||||||
case "unsigned char *":
|
case "unsigned char *":
|
||||||
|
case "const unsigned char *":
|
||||||
this.declare(name + "_size", "size_t");
|
this.declare(name + "_size", "size_t");
|
||||||
this.declare(name + "_js", "void *", false, `(void *)JS_GetArrayBuffer(ctx, &${name}_size, ${src})`);
|
this.declare(name + "_js", "void *", false, `(void *)JS_GetArrayBuffer(ctx, &${name}_size, ${src})`);
|
||||||
this.if(name + "_js == NULL").returnExp("JS_EXCEPTION");
|
this.if(name + "_js == NULL").returnExp("JS_EXCEPTION");
|
||||||
|
@ -474,6 +475,9 @@ class GenericQuickJsGenerator extends generation_1.GenericCodeGenerator {
|
||||||
case "char *":
|
case "char *":
|
||||||
this.declare(name, 'JSValue', false, `JS_NewString(ctx, ${src})`);
|
this.declare(name, 'JSValue', false, `JS_NewString(ctx, ${src})`);
|
||||||
break;
|
break;
|
||||||
|
// case "unsigned char *":
|
||||||
|
// this.declare(name, 'JSValue', false, `JS_NewString(ctx, ${src})`)
|
||||||
|
// break;
|
||||||
default:
|
default:
|
||||||
const classId = classIds[type];
|
const classId = classIds[type];
|
||||||
if (!classId)
|
if (!classId)
|
||||||
|
@ -498,6 +502,7 @@ class GenericQuickJsGenerator extends generation_1.GenericCodeGenerator {
|
||||||
case "float *":
|
case "float *":
|
||||||
case "unsigned short *":
|
case "unsigned short *":
|
||||||
case "unsigned char *":
|
case "unsigned char *":
|
||||||
|
case "const unsigned char *":
|
||||||
this.statement(`free((void *)${name})`);
|
this.statement(`free((void *)${name})`);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -762,6 +767,7 @@ class TypeScriptDeclaration {
|
||||||
case "float":
|
case "float":
|
||||||
case "double":
|
case "double":
|
||||||
return "number";
|
return "number";
|
||||||
|
case "const unsigned char *":
|
||||||
case "unsigned char *":
|
case "unsigned char *":
|
||||||
case "unsigned short *":
|
case "unsigned short *":
|
||||||
case "float *":
|
case "float *":
|
||||||
|
@ -979,15 +985,15 @@ function main() {
|
||||||
properties: {
|
properties: {
|
||||||
hit: { get: true, set: false },
|
hit: { get: true, set: false },
|
||||||
distance: { get: true, set: false },
|
distance: { get: true, set: false },
|
||||||
//point: { get: true, set: false },
|
point: { get: true, set: false },
|
||||||
//normal: { get: true, set: false },
|
normal: { get: true, set: false },
|
||||||
},
|
},
|
||||||
createConstructor: false
|
createConstructor: false
|
||||||
});
|
});
|
||||||
core.addApiStructByName("Camera2D", {
|
core.addApiStructByName("Camera2D", {
|
||||||
properties: {
|
properties: {
|
||||||
offset: { get: false, set: true },
|
offset: { get: true, set: true },
|
||||||
target: { get: false, set: true },
|
target: { get: true, set: true },
|
||||||
rotation: { get: true, set: true },
|
rotation: { get: true, set: true },
|
||||||
zoom: { get: true, set: true },
|
zoom: { get: true, set: true },
|
||||||
},
|
},
|
||||||
|
@ -1004,7 +1010,10 @@ function main() {
|
||||||
createConstructor: true
|
createConstructor: true
|
||||||
});
|
});
|
||||||
core.addApiStructByName("BoundingBox", {
|
core.addApiStructByName("BoundingBox", {
|
||||||
properties: {},
|
properties: {
|
||||||
|
min: { get: true, set: true },
|
||||||
|
max: { get: true, set: true },
|
||||||
|
},
|
||||||
createConstructor: true
|
createConstructor: true
|
||||||
});
|
});
|
||||||
core.addApiStructByName("Matrix", {
|
core.addApiStructByName("Matrix", {
|
||||||
|
@ -1024,6 +1033,7 @@ function main() {
|
||||||
});
|
});
|
||||||
core.addApiStructByName("Image", {
|
core.addApiStructByName("Image", {
|
||||||
properties: {
|
properties: {
|
||||||
|
//data: { set: true },
|
||||||
width: { get: true },
|
width: { get: true },
|
||||||
height: { get: true },
|
height: { get: true },
|
||||||
mipmaps: { get: true },
|
mipmaps: { get: true },
|
||||||
|
@ -1049,12 +1059,18 @@ function main() {
|
||||||
core.addApiStructByName("Music", {
|
core.addApiStructByName("Music", {
|
||||||
properties: {
|
properties: {
|
||||||
frameCount: { get: true },
|
frameCount: { get: true },
|
||||||
looping: { get: true, set: true }
|
looping: { get: true, set: true },
|
||||||
|
ctxType: { get: true },
|
||||||
},
|
},
|
||||||
//destructor: "UnloadMusicStream"
|
//destructor: "UnloadMusicStream"
|
||||||
});
|
});
|
||||||
core.addApiStructByName("Model", {
|
core.addApiStructByName("Model", {
|
||||||
properties: {},
|
properties: {
|
||||||
|
transform: { get: true, set: true },
|
||||||
|
meshCount: { get: true },
|
||||||
|
materialCount: { get: true },
|
||||||
|
boneCount: { get: true },
|
||||||
|
},
|
||||||
//destructor: "UnloadModel"
|
//destructor: "UnloadModel"
|
||||||
});
|
});
|
||||||
core.addApiStructByName("Mesh", {
|
core.addApiStructByName("Mesh", {
|
||||||
|
@ -1078,24 +1094,32 @@ function main() {
|
||||||
//destructor: "UnloadMesh"
|
//destructor: "UnloadMesh"
|
||||||
});
|
});
|
||||||
core.addApiStructByName("Shader", {
|
core.addApiStructByName("Shader", {
|
||||||
properties: {},
|
properties: {
|
||||||
|
id: { get: true }
|
||||||
|
},
|
||||||
//destructor: "UnloadShader"
|
//destructor: "UnloadShader"
|
||||||
});
|
});
|
||||||
core.addApiStructByName("Texture", {
|
core.addApiStructByName("Texture", {
|
||||||
properties: {
|
properties: {
|
||||||
width: { get: true },
|
width: { get: true },
|
||||||
height: { get: true }
|
height: { get: true },
|
||||||
|
mipmaps: { get: true },
|
||||||
|
format: { get: true },
|
||||||
},
|
},
|
||||||
//destructor: "UnloadTexture"
|
//destructor: "UnloadTexture"
|
||||||
});
|
});
|
||||||
core.addApiStructByName("Font", {
|
core.addApiStructByName("Font", {
|
||||||
properties: {
|
properties: {
|
||||||
baseSize: { get: true }
|
baseSize: { get: true },
|
||||||
|
glyphCount: { get: true },
|
||||||
|
glyphPadding: { get: true },
|
||||||
},
|
},
|
||||||
//destructor: "UnloadFont"
|
//destructor: "UnloadFont"
|
||||||
});
|
});
|
||||||
core.addApiStructByName("RenderTexture", {
|
core.addApiStructByName("RenderTexture", {
|
||||||
properties: {},
|
properties: {
|
||||||
|
id: { get: true }
|
||||||
|
},
|
||||||
//destructor: "UnloadRenderTexture"
|
//destructor: "UnloadRenderTexture"
|
||||||
});
|
});
|
||||||
core.addApiStructByName("MaterialMap", {
|
core.addApiStructByName("MaterialMap", {
|
||||||
|
@ -1190,7 +1214,7 @@ function main() {
|
||||||
//core.addApiFunctionByName("UnloadVrStereoConfig")
|
//core.addApiFunctionByName("UnloadVrStereoConfig")
|
||||||
// Shader Management
|
// Shader Management
|
||||||
core.addApiFunctionByName("LoadShader");
|
core.addApiFunctionByName("LoadShader");
|
||||||
// core.addApiFunctionByName("LoadShaderFromMemory")
|
core.addApiFunctionByName("LoadShaderFromMemory");
|
||||||
core.addApiFunctionByName("IsShaderReady");
|
core.addApiFunctionByName("IsShaderReady");
|
||||||
core.addApiFunctionByName("GetShaderLocation");
|
core.addApiFunctionByName("GetShaderLocation");
|
||||||
core.addApiFunctionByName("GetShaderLocationAttrib");
|
core.addApiFunctionByName("GetShaderLocationAttrib");
|
||||||
|
@ -1254,17 +1278,28 @@ function main() {
|
||||||
core.addApiFunctionByName("OpenURL");
|
core.addApiFunctionByName("OpenURL");
|
||||||
// Callbacks not supported on JS
|
// Callbacks not supported on JS
|
||||||
// Files management functions
|
// Files management functions
|
||||||
//core.addApiFunctionByName("LoadFileData")
|
const lfd = apiDesc.getFunction("LoadFileData");
|
||||||
//core.addApiFunctionByName("UnloadLoadFileData")
|
lfd?.params.pop();
|
||||||
//core.addApiFunctionByName("SaveFileData")
|
core.addApiFunctionByName("LoadFileData", null, { body: gen => {
|
||||||
|
gen.jsToC("const char *", "fileName", "argv[0]");
|
||||||
|
gen.declare("bytesRead", "unsigned int");
|
||||||
|
gen.call("LoadFileData", ["fileName", "&bytesRead"], { type: "unsigned char *", name: "retVal" });
|
||||||
|
gen.statement("JSValue buffer = JS_NewArrayBufferCopy(ctx, (const uint8_t*)retVal, bytesRead)");
|
||||||
|
gen.call("UnloadFileData", ["retVal"]);
|
||||||
|
gen.jsCleanUpParameter("const char*", "fileName");
|
||||||
|
gen.returnExp("buffer");
|
||||||
|
} });
|
||||||
|
//UnloadLoadFileData not needed, data is copied
|
||||||
|
// TODO: Works but unnecessary makes copy of memory
|
||||||
|
core.addApiFunctionByName("SaveFileData");
|
||||||
// Export data as code not needed
|
// Export data as code not needed
|
||||||
core.addApiFunctionByName("LoadFileText", null, { after: gen => gen.call("UnloadFileText", ["returnVal"]) });
|
core.addApiFunctionByName("LoadFileText", null, { after: gen => gen.call("UnloadFileText", ["returnVal"]) });
|
||||||
core.addApiFunctionByName("SaveFileText");
|
core.addApiFunctionByName("SaveFileText");
|
||||||
core.addApiFunctionByName("FileExists");
|
core.addApiFunctionByName("FileExists");
|
||||||
core.addApiFunctionByName("DirectoryExists");
|
core.addApiFunctionByName("DirectoryExists");
|
||||||
core.addApiFunctionByName("IsFileExtension");
|
core.addApiFunctionByName("IsFileExtension");
|
||||||
// TODO: Who needs to clean memory here?
|
|
||||||
core.addApiFunctionByName("GetFileLength");
|
core.addApiFunctionByName("GetFileLength");
|
||||||
|
// TODO: Who needs to clean memory here?
|
||||||
core.addApiFunctionByName("GetFileExtension");
|
core.addApiFunctionByName("GetFileExtension");
|
||||||
core.addApiFunctionByName("GetFileName");
|
core.addApiFunctionByName("GetFileName");
|
||||||
core.addApiFunctionByName("GetFileNameWithoutExt");
|
core.addApiFunctionByName("GetFileNameWithoutExt");
|
||||||
|
@ -1274,14 +1309,14 @@ function main() {
|
||||||
core.addApiFunctionByName("GetApplicationDirectory");
|
core.addApiFunctionByName("GetApplicationDirectory");
|
||||||
core.addApiFunctionByName("ChangeDirectory");
|
core.addApiFunctionByName("ChangeDirectory");
|
||||||
core.addApiFunctionByName("IsPathFile");
|
core.addApiFunctionByName("IsPathFile");
|
||||||
//core.addApiFunctionByName("LoadPathFiles")
|
//core.addApiFunctionByName("LoadDirectoryFiles")
|
||||||
//core.addApiFunctionByName("LoadPathFilesEx")
|
//core.addApiFunctionByName("LoadDirectoryFilesEx")
|
||||||
// UnloadDirectoryFiles
|
// UnloadDirectoryFiles
|
||||||
core.addApiFunctionByName("IsFileDropped");
|
core.addApiFunctionByName("IsFileDropped");
|
||||||
//core.addApiFunctionByName("LoadDroppedFiles")
|
//core.addApiFunctionByName("LoadDroppedFiles")
|
||||||
// UnloadDroppedFiles
|
// UnloadDroppedFiles
|
||||||
core.addApiFunctionByName("GetFileModTime");
|
core.addApiFunctionByName("GetFileModTime");
|
||||||
// Compression/encodeing functionality
|
// Compression/encoding functionality
|
||||||
//core.addApiFunctionByName("CompressData")
|
//core.addApiFunctionByName("CompressData")
|
||||||
//core.addApiFunctionByName("DecompressData")
|
//core.addApiFunctionByName("DecompressData")
|
||||||
//core.addApiFunctionByName("EncodeDataBase64")
|
//core.addApiFunctionByName("EncodeDataBase64")
|
||||||
|
@ -1340,8 +1375,7 @@ function main() {
|
||||||
core.addApiFunctionByName("UpdateCameraPro");
|
core.addApiFunctionByName("UpdateCameraPro");
|
||||||
//api.functions.forEach(x => console.log(`core.addApiFunctionByName("${x.name}")`))
|
//api.functions.forEach(x => console.log(`core.addApiFunctionByName("${x.name}")`))
|
||||||
// module: rshapes
|
// module: rshapes
|
||||||
// TODO: Do we need ref-counting here?
|
core.addApiFunctionByName("SetShapesTexture");
|
||||||
//core.addApiFunctionByName("SetShapesTexture")
|
|
||||||
// Basic shapes drawing functions
|
// Basic shapes drawing functions
|
||||||
core.addApiFunctionByName("DrawPixel");
|
core.addApiFunctionByName("DrawPixel");
|
||||||
core.addApiFunctionByName("DrawPixelV");
|
core.addApiFunctionByName("DrawPixelV");
|
||||||
|
@ -1395,7 +1429,7 @@ function main() {
|
||||||
core.addApiFunctionByName("LoadImage");
|
core.addApiFunctionByName("LoadImage");
|
||||||
core.addApiFunctionByName("LoadImageRaw");
|
core.addApiFunctionByName("LoadImageRaw");
|
||||||
// core.addApiFunctionByName("LoadImageAnim")
|
// core.addApiFunctionByName("LoadImageAnim")
|
||||||
// core.addApiFunctionByName("LoadImageFromMemory")
|
core.addApiFunctionByName("LoadImageFromMemory");
|
||||||
core.addApiFunctionByName("LoadImageFromTexture");
|
core.addApiFunctionByName("LoadImageFromTexture");
|
||||||
core.addApiFunctionByName("LoadImageFromScreen");
|
core.addApiFunctionByName("LoadImageFromScreen");
|
||||||
core.addApiFunctionByName("IsImageReady");
|
core.addApiFunctionByName("IsImageReady");
|
||||||
|
@ -1481,8 +1515,8 @@ function main() {
|
||||||
core.addApiFunctionByName("UnloadTexture");
|
core.addApiFunctionByName("UnloadTexture");
|
||||||
core.addApiFunctionByName("IsRenderTextureReady");
|
core.addApiFunctionByName("IsRenderTextureReady");
|
||||||
core.addApiFunctionByName("UnloadRenderTexture");
|
core.addApiFunctionByName("UnloadRenderTexture");
|
||||||
// core.addApiFunctionByName("UpdateTexture")
|
core.addApiFunctionByName("UpdateTexture");
|
||||||
// core.addApiFunctionByName("UpdateTextureRec")
|
core.addApiFunctionByName("UpdateTextureRec");
|
||||||
// Texture configuration functions
|
// Texture configuration functions
|
||||||
core.addApiFunctionByName("GenTextureMipmaps");
|
core.addApiFunctionByName("GenTextureMipmaps");
|
||||||
core.addApiFunctionByName("SetTextureFilter");
|
core.addApiFunctionByName("SetTextureFilter");
|
||||||
|
@ -1588,7 +1622,6 @@ function main() {
|
||||||
core.addApiFunctionByName("DrawBillboardRec");
|
core.addApiFunctionByName("DrawBillboardRec");
|
||||||
core.addApiFunctionByName("DrawBillboardPro");
|
core.addApiFunctionByName("DrawBillboardPro");
|
||||||
// Mesh management functions
|
// Mesh management functions
|
||||||
// TODO: Refcounting needed?
|
|
||||||
core.addApiFunctionByName("UploadMesh");
|
core.addApiFunctionByName("UploadMesh");
|
||||||
core.addApiFunctionByName("UpdateMeshBuffer");
|
core.addApiFunctionByName("UpdateMeshBuffer");
|
||||||
core.addApiFunctionByName("UnloadMesh");
|
core.addApiFunctionByName("UnloadMesh");
|
||||||
|
@ -1640,12 +1673,12 @@ function main() {
|
||||||
core.addApiFunctionByName("SetMasterVolume");
|
core.addApiFunctionByName("SetMasterVolume");
|
||||||
// Wave/Sound loading/unloading functions
|
// Wave/Sound loading/unloading functions
|
||||||
core.addApiFunctionByName("LoadWave");
|
core.addApiFunctionByName("LoadWave");
|
||||||
// core.addApiFunctionByName("LoadWaveFromMemory")
|
core.addApiFunctionByName("LoadWaveFromMemory");
|
||||||
core.addApiFunctionByName("IsWaveReady");
|
core.addApiFunctionByName("IsWaveReady");
|
||||||
core.addApiFunctionByName("LoadSound");
|
core.addApiFunctionByName("LoadSound");
|
||||||
core.addApiFunctionByName("LoadSoundFromWave");
|
core.addApiFunctionByName("LoadSoundFromWave");
|
||||||
core.addApiFunctionByName("IsSoundReady");
|
core.addApiFunctionByName("IsSoundReady");
|
||||||
// core.addApiFunctionByName("UpdateSound")
|
core.addApiFunctionByName("UpdateSound");
|
||||||
core.addApiFunctionByName("UnloadWave");
|
core.addApiFunctionByName("UnloadWave");
|
||||||
core.addApiFunctionByName("UnloadSound");
|
core.addApiFunctionByName("UnloadSound");
|
||||||
core.addApiFunctionByName("ExportWave");
|
core.addApiFunctionByName("ExportWave");
|
||||||
|
|
|
@ -494,9 +494,31 @@ static JSValue js_RayCollision_get_distance(JSContext* ctx, JSValueConst this_va
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_RayCollision_get_point(JSContext* ctx, JSValueConst this_val) {
|
||||||
|
RayCollision* ptr = JS_GetOpaque2(ctx, this_val, js_RayCollision_class_id);
|
||||||
|
Vector3 point = ptr->point;
|
||||||
|
Vector3* ret_ptr = (Vector3*)js_malloc(ctx, sizeof(Vector3));
|
||||||
|
*ret_ptr = point;
|
||||||
|
JSValue ret = JS_NewObjectClass(ctx, js_Vector3_class_id);
|
||||||
|
JS_SetOpaque(ret, ret_ptr);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_RayCollision_get_normal(JSContext* ctx, JSValueConst this_val) {
|
||||||
|
RayCollision* ptr = JS_GetOpaque2(ctx, this_val, js_RayCollision_class_id);
|
||||||
|
Vector3 normal = ptr->normal;
|
||||||
|
Vector3* ret_ptr = (Vector3*)js_malloc(ctx, sizeof(Vector3));
|
||||||
|
*ret_ptr = normal;
|
||||||
|
JSValue ret = JS_NewObjectClass(ctx, js_Vector3_class_id);
|
||||||
|
JS_SetOpaque(ret, ret_ptr);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_RayCollision_proto_funcs[] = {
|
static const JSCFunctionListEntry js_RayCollision_proto_funcs[] = {
|
||||||
JS_CGETSET_DEF("hit",js_RayCollision_get_hit,NULL),
|
JS_CGETSET_DEF("hit",js_RayCollision_get_hit,NULL),
|
||||||
JS_CGETSET_DEF("distance",js_RayCollision_get_distance,NULL),
|
JS_CGETSET_DEF("distance",js_RayCollision_get_distance,NULL),
|
||||||
|
JS_CGETSET_DEF("point",js_RayCollision_get_point,NULL),
|
||||||
|
JS_CGETSET_DEF("normal",js_RayCollision_get_normal,NULL),
|
||||||
JS_PROP_STRING_DEF("[Symbol.toStringTag]","RayCollision", JS_PROP_CONFIGURABLE),
|
JS_PROP_STRING_DEF("[Symbol.toStringTag]","RayCollision", JS_PROP_CONFIGURABLE),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -517,6 +539,16 @@ static void js_Camera2D_finalizer(JSRuntime * rt, JSValue val) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_Camera2D_get_offset(JSContext* ctx, JSValueConst this_val) {
|
||||||
|
Camera2D* ptr = JS_GetOpaque2(ctx, this_val, js_Camera2D_class_id);
|
||||||
|
Vector2 offset = ptr->offset;
|
||||||
|
Vector2* ret_ptr = (Vector2*)js_malloc(ctx, sizeof(Vector2));
|
||||||
|
*ret_ptr = offset;
|
||||||
|
JSValue ret = JS_NewObjectClass(ctx, js_Vector2_class_id);
|
||||||
|
JS_SetOpaque(ret, ret_ptr);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static JSValue js_Camera2D_set_offset(JSContext* ctx, JSValueConst this_val, JSValueConst v) {
|
static JSValue js_Camera2D_set_offset(JSContext* ctx, JSValueConst this_val, JSValueConst v) {
|
||||||
Camera2D* ptr = JS_GetOpaque2(ctx, this_val, js_Camera2D_class_id);
|
Camera2D* ptr = JS_GetOpaque2(ctx, this_val, js_Camera2D_class_id);
|
||||||
Vector2* value_ptr = (Vector2*)JS_GetOpaque2(ctx, v, js_Vector2_class_id);
|
Vector2* value_ptr = (Vector2*)JS_GetOpaque2(ctx, v, js_Vector2_class_id);
|
||||||
|
@ -526,6 +558,16 @@ static JSValue js_Camera2D_set_offset(JSContext* ctx, JSValueConst this_val, JSV
|
||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_Camera2D_get_target(JSContext* ctx, JSValueConst this_val) {
|
||||||
|
Camera2D* ptr = JS_GetOpaque2(ctx, this_val, js_Camera2D_class_id);
|
||||||
|
Vector2 target = ptr->target;
|
||||||
|
Vector2* ret_ptr = (Vector2*)js_malloc(ctx, sizeof(Vector2));
|
||||||
|
*ret_ptr = target;
|
||||||
|
JSValue ret = JS_NewObjectClass(ctx, js_Vector2_class_id);
|
||||||
|
JS_SetOpaque(ret, ret_ptr);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static JSValue js_Camera2D_set_target(JSContext* ctx, JSValueConst this_val, JSValueConst v) {
|
static JSValue js_Camera2D_set_target(JSContext* ctx, JSValueConst this_val, JSValueConst v) {
|
||||||
Camera2D* ptr = JS_GetOpaque2(ctx, this_val, js_Camera2D_class_id);
|
Camera2D* ptr = JS_GetOpaque2(ctx, this_val, js_Camera2D_class_id);
|
||||||
Vector2* value_ptr = (Vector2*)JS_GetOpaque2(ctx, v, js_Vector2_class_id);
|
Vector2* value_ptr = (Vector2*)JS_GetOpaque2(ctx, v, js_Vector2_class_id);
|
||||||
|
@ -568,8 +610,8 @@ static JSValue js_Camera2D_set_zoom(JSContext* ctx, JSValueConst this_val, JSVal
|
||||||
}
|
}
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_Camera2D_proto_funcs[] = {
|
static const JSCFunctionListEntry js_Camera2D_proto_funcs[] = {
|
||||||
JS_CGETSET_DEF("offset",NULL,js_Camera2D_set_offset),
|
JS_CGETSET_DEF("offset",js_Camera2D_get_offset,js_Camera2D_set_offset),
|
||||||
JS_CGETSET_DEF("target",NULL,js_Camera2D_set_target),
|
JS_CGETSET_DEF("target",js_Camera2D_get_target,js_Camera2D_set_target),
|
||||||
JS_CGETSET_DEF("rotation",js_Camera2D_get_rotation,js_Camera2D_set_rotation),
|
JS_CGETSET_DEF("rotation",js_Camera2D_get_rotation,js_Camera2D_set_rotation),
|
||||||
JS_CGETSET_DEF("zoom",js_Camera2D_get_zoom,js_Camera2D_set_zoom),
|
JS_CGETSET_DEF("zoom",js_Camera2D_get_zoom,js_Camera2D_set_zoom),
|
||||||
JS_PROP_STRING_DEF("[Symbol.toStringTag]","Camera2D", JS_PROP_CONFIGURABLE),
|
JS_PROP_STRING_DEF("[Symbol.toStringTag]","Camera2D", JS_PROP_CONFIGURABLE),
|
||||||
|
@ -696,7 +738,47 @@ static void js_BoundingBox_finalizer(JSRuntime * rt, JSValue val) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_BoundingBox_get_min(JSContext* ctx, JSValueConst this_val) {
|
||||||
|
BoundingBox* ptr = JS_GetOpaque2(ctx, this_val, js_BoundingBox_class_id);
|
||||||
|
Vector3 min = ptr->min;
|
||||||
|
Vector3* ret_ptr = (Vector3*)js_malloc(ctx, sizeof(Vector3));
|
||||||
|
*ret_ptr = min;
|
||||||
|
JSValue ret = JS_NewObjectClass(ctx, js_Vector3_class_id);
|
||||||
|
JS_SetOpaque(ret, ret_ptr);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_BoundingBox_set_min(JSContext* ctx, JSValueConst this_val, JSValueConst v) {
|
||||||
|
BoundingBox* ptr = JS_GetOpaque2(ctx, this_val, js_BoundingBox_class_id);
|
||||||
|
Vector3* value_ptr = (Vector3*)JS_GetOpaque2(ctx, v, js_Vector3_class_id);
|
||||||
|
if(value_ptr == NULL) return JS_EXCEPTION;
|
||||||
|
Vector3 value = *value_ptr;
|
||||||
|
ptr->min = value;
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_BoundingBox_get_max(JSContext* ctx, JSValueConst this_val) {
|
||||||
|
BoundingBox* ptr = JS_GetOpaque2(ctx, this_val, js_BoundingBox_class_id);
|
||||||
|
Vector3 max = ptr->max;
|
||||||
|
Vector3* ret_ptr = (Vector3*)js_malloc(ctx, sizeof(Vector3));
|
||||||
|
*ret_ptr = max;
|
||||||
|
JSValue ret = JS_NewObjectClass(ctx, js_Vector3_class_id);
|
||||||
|
JS_SetOpaque(ret, ret_ptr);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_BoundingBox_set_max(JSContext* ctx, JSValueConst this_val, JSValueConst v) {
|
||||||
|
BoundingBox* ptr = JS_GetOpaque2(ctx, this_val, js_BoundingBox_class_id);
|
||||||
|
Vector3* value_ptr = (Vector3*)JS_GetOpaque2(ctx, v, js_Vector3_class_id);
|
||||||
|
if(value_ptr == NULL) return JS_EXCEPTION;
|
||||||
|
Vector3 value = *value_ptr;
|
||||||
|
ptr->max = value;
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_BoundingBox_proto_funcs[] = {
|
static const JSCFunctionListEntry js_BoundingBox_proto_funcs[] = {
|
||||||
|
JS_CGETSET_DEF("min",js_BoundingBox_get_min,js_BoundingBox_set_min),
|
||||||
|
JS_CGETSET_DEF("max",js_BoundingBox_get_max,js_BoundingBox_set_max),
|
||||||
JS_PROP_STRING_DEF("[Symbol.toStringTag]","BoundingBox", JS_PROP_CONFIGURABLE),
|
JS_PROP_STRING_DEF("[Symbol.toStringTag]","BoundingBox", JS_PROP_CONFIGURABLE),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1015,9 +1097,17 @@ static JSValue js_Music_set_looping(JSContext* ctx, JSValueConst this_val, JSVal
|
||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_Music_get_ctxType(JSContext* ctx, JSValueConst this_val) {
|
||||||
|
Music* ptr = JS_GetOpaque2(ctx, this_val, js_Music_class_id);
|
||||||
|
int ctxType = ptr->ctxType;
|
||||||
|
JSValue ret = JS_NewInt32(ctx, ctxType);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_Music_proto_funcs[] = {
|
static const JSCFunctionListEntry js_Music_proto_funcs[] = {
|
||||||
JS_CGETSET_DEF("frameCount",js_Music_get_frameCount,NULL),
|
JS_CGETSET_DEF("frameCount",js_Music_get_frameCount,NULL),
|
||||||
JS_CGETSET_DEF("looping",js_Music_get_looping,js_Music_set_looping),
|
JS_CGETSET_DEF("looping",js_Music_get_looping,js_Music_set_looping),
|
||||||
|
JS_CGETSET_DEF("ctxType",js_Music_get_ctxType,NULL),
|
||||||
JS_PROP_STRING_DEF("[Symbol.toStringTag]","Music", JS_PROP_CONFIGURABLE),
|
JS_PROP_STRING_DEF("[Symbol.toStringTag]","Music", JS_PROP_CONFIGURABLE),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1038,7 +1128,51 @@ static void js_Model_finalizer(JSRuntime * rt, JSValue val) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_Model_get_transform(JSContext* ctx, JSValueConst this_val) {
|
||||||
|
Model* ptr = JS_GetOpaque2(ctx, this_val, js_Model_class_id);
|
||||||
|
Matrix transform = ptr->transform;
|
||||||
|
Matrix* ret_ptr = (Matrix*)js_malloc(ctx, sizeof(Matrix));
|
||||||
|
*ret_ptr = transform;
|
||||||
|
JSValue ret = JS_NewObjectClass(ctx, js_Matrix_class_id);
|
||||||
|
JS_SetOpaque(ret, ret_ptr);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_Model_set_transform(JSContext* ctx, JSValueConst this_val, JSValueConst v) {
|
||||||
|
Model* ptr = JS_GetOpaque2(ctx, this_val, js_Model_class_id);
|
||||||
|
Matrix* value_ptr = (Matrix*)JS_GetOpaque2(ctx, v, js_Matrix_class_id);
|
||||||
|
if(value_ptr == NULL) return JS_EXCEPTION;
|
||||||
|
Matrix value = *value_ptr;
|
||||||
|
ptr->transform = value;
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_Model_get_meshCount(JSContext* ctx, JSValueConst this_val) {
|
||||||
|
Model* ptr = JS_GetOpaque2(ctx, this_val, js_Model_class_id);
|
||||||
|
int meshCount = ptr->meshCount;
|
||||||
|
JSValue ret = JS_NewInt32(ctx, meshCount);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_Model_get_materialCount(JSContext* ctx, JSValueConst this_val) {
|
||||||
|
Model* ptr = JS_GetOpaque2(ctx, this_val, js_Model_class_id);
|
||||||
|
int materialCount = ptr->materialCount;
|
||||||
|
JSValue ret = JS_NewInt32(ctx, materialCount);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_Model_get_boneCount(JSContext* ctx, JSValueConst this_val) {
|
||||||
|
Model* ptr = JS_GetOpaque2(ctx, this_val, js_Model_class_id);
|
||||||
|
int boneCount = ptr->boneCount;
|
||||||
|
JSValue ret = JS_NewInt32(ctx, boneCount);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_Model_proto_funcs[] = {
|
static const JSCFunctionListEntry js_Model_proto_funcs[] = {
|
||||||
|
JS_CGETSET_DEF("transform",js_Model_get_transform,js_Model_set_transform),
|
||||||
|
JS_CGETSET_DEF("meshCount",js_Model_get_meshCount,NULL),
|
||||||
|
JS_CGETSET_DEF("materialCount",js_Model_get_materialCount,NULL),
|
||||||
|
JS_CGETSET_DEF("boneCount",js_Model_get_boneCount,NULL),
|
||||||
JS_PROP_STRING_DEF("[Symbol.toStringTag]","Model", JS_PROP_CONFIGURABLE),
|
JS_PROP_STRING_DEF("[Symbol.toStringTag]","Model", JS_PROP_CONFIGURABLE),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1266,7 +1400,15 @@ static void js_Shader_finalizer(JSRuntime * rt, JSValue val) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_Shader_get_id(JSContext* ctx, JSValueConst this_val) {
|
||||||
|
Shader* ptr = JS_GetOpaque2(ctx, this_val, js_Shader_class_id);
|
||||||
|
unsigned int id = ptr->id;
|
||||||
|
JSValue ret = JS_NewUint32(ctx, id);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_Shader_proto_funcs[] = {
|
static const JSCFunctionListEntry js_Shader_proto_funcs[] = {
|
||||||
|
JS_CGETSET_DEF("id",js_Shader_get_id,NULL),
|
||||||
JS_PROP_STRING_DEF("[Symbol.toStringTag]","Shader", JS_PROP_CONFIGURABLE),
|
JS_PROP_STRING_DEF("[Symbol.toStringTag]","Shader", JS_PROP_CONFIGURABLE),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1301,9 +1443,25 @@ static JSValue js_Texture_get_height(JSContext* ctx, JSValueConst this_val) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_Texture_get_mipmaps(JSContext* ctx, JSValueConst this_val) {
|
||||||
|
Texture* ptr = JS_GetOpaque2(ctx, this_val, js_Texture_class_id);
|
||||||
|
int mipmaps = ptr->mipmaps;
|
||||||
|
JSValue ret = JS_NewInt32(ctx, mipmaps);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_Texture_get_format(JSContext* ctx, JSValueConst this_val) {
|
||||||
|
Texture* ptr = JS_GetOpaque2(ctx, this_val, js_Texture_class_id);
|
||||||
|
int format = ptr->format;
|
||||||
|
JSValue ret = JS_NewInt32(ctx, format);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_Texture_proto_funcs[] = {
|
static const JSCFunctionListEntry js_Texture_proto_funcs[] = {
|
||||||
JS_CGETSET_DEF("width",js_Texture_get_width,NULL),
|
JS_CGETSET_DEF("width",js_Texture_get_width,NULL),
|
||||||
JS_CGETSET_DEF("height",js_Texture_get_height,NULL),
|
JS_CGETSET_DEF("height",js_Texture_get_height,NULL),
|
||||||
|
JS_CGETSET_DEF("mipmaps",js_Texture_get_mipmaps,NULL),
|
||||||
|
JS_CGETSET_DEF("format",js_Texture_get_format,NULL),
|
||||||
JS_PROP_STRING_DEF("[Symbol.toStringTag]","Texture", JS_PROP_CONFIGURABLE),
|
JS_PROP_STRING_DEF("[Symbol.toStringTag]","Texture", JS_PROP_CONFIGURABLE),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1331,8 +1489,24 @@ static JSValue js_Font_get_baseSize(JSContext* ctx, JSValueConst this_val) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_Font_get_glyphCount(JSContext* ctx, JSValueConst this_val) {
|
||||||
|
Font* ptr = JS_GetOpaque2(ctx, this_val, js_Font_class_id);
|
||||||
|
int glyphCount = ptr->glyphCount;
|
||||||
|
JSValue ret = JS_NewInt32(ctx, glyphCount);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_Font_get_glyphPadding(JSContext* ctx, JSValueConst this_val) {
|
||||||
|
Font* ptr = JS_GetOpaque2(ctx, this_val, js_Font_class_id);
|
||||||
|
int glyphPadding = ptr->glyphPadding;
|
||||||
|
JSValue ret = JS_NewInt32(ctx, glyphPadding);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_Font_proto_funcs[] = {
|
static const JSCFunctionListEntry js_Font_proto_funcs[] = {
|
||||||
JS_CGETSET_DEF("baseSize",js_Font_get_baseSize,NULL),
|
JS_CGETSET_DEF("baseSize",js_Font_get_baseSize,NULL),
|
||||||
|
JS_CGETSET_DEF("glyphCount",js_Font_get_glyphCount,NULL),
|
||||||
|
JS_CGETSET_DEF("glyphPadding",js_Font_get_glyphPadding,NULL),
|
||||||
JS_PROP_STRING_DEF("[Symbol.toStringTag]","Font", JS_PROP_CONFIGURABLE),
|
JS_PROP_STRING_DEF("[Symbol.toStringTag]","Font", JS_PROP_CONFIGURABLE),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1353,7 +1527,15 @@ static void js_RenderTexture_finalizer(JSRuntime * rt, JSValue val) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_RenderTexture_get_id(JSContext* ctx, JSValueConst this_val) {
|
||||||
|
RenderTexture* ptr = JS_GetOpaque2(ctx, this_val, js_RenderTexture_class_id);
|
||||||
|
unsigned int id = ptr->id;
|
||||||
|
JSValue ret = JS_NewUint32(ctx, id);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static const JSCFunctionListEntry js_RenderTexture_proto_funcs[] = {
|
static const JSCFunctionListEntry js_RenderTexture_proto_funcs[] = {
|
||||||
|
JS_CGETSET_DEF("id",js_RenderTexture_get_id,NULL),
|
||||||
JS_PROP_STRING_DEF("[Symbol.toStringTag]","RenderTexture", JS_PROP_CONFIGURABLE),
|
JS_PROP_STRING_DEF("[Symbol.toStringTag]","RenderTexture", JS_PROP_CONFIGURABLE),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2112,6 +2294,19 @@ static JSValue js_loadShader(JSContext * ctx, JSValueConst this_val, int argc, J
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_loadShaderFromMemory(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
||||||
|
const char * vsCode = (const char *)JS_ToCString(ctx, argv[0]);
|
||||||
|
const char * fsCode = (const char *)JS_ToCString(ctx, argv[1]);
|
||||||
|
Shader returnVal = LoadShaderFromMemory(vsCode, fsCode);
|
||||||
|
JS_FreeCString(ctx, vsCode);
|
||||||
|
JS_FreeCString(ctx, fsCode);
|
||||||
|
Shader* ret_ptr = (Shader*)js_malloc(ctx, sizeof(Shader));
|
||||||
|
*ret_ptr = returnVal;
|
||||||
|
JSValue ret = JS_NewObjectClass(ctx, js_Shader_class_id);
|
||||||
|
JS_SetOpaque(ret, ret_ptr);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static JSValue js_isShaderReady(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
static JSValue js_isShaderReady(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
||||||
Shader* shader_ptr = (Shader*)JS_GetOpaque2(ctx, argv[0], js_Shader_class_id);
|
Shader* shader_ptr = (Shader*)JS_GetOpaque2(ctx, argv[0], js_Shader_class_id);
|
||||||
if(shader_ptr == NULL) return JS_EXCEPTION;
|
if(shader_ptr == NULL) return JS_EXCEPTION;
|
||||||
|
@ -2416,6 +2611,33 @@ static JSValue js_openURL(JSContext * ctx, JSValueConst this_val, int argc, JSVa
|
||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_loadFileData(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
||||||
|
const char * fileName = (const char *)JS_ToCString(ctx, argv[0]);
|
||||||
|
unsigned int bytesRead;
|
||||||
|
unsigned char * retVal = LoadFileData(fileName, &bytesRead);
|
||||||
|
JSValue buffer = JS_NewArrayBufferCopy(ctx, (const uint8_t*)retVal, bytesRead);
|
||||||
|
UnloadFileData(retVal);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_saveFileData(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
||||||
|
const char * fileName = (const char *)JS_ToCString(ctx, argv[0]);
|
||||||
|
size_t data_size;
|
||||||
|
void * data_js = (void *)JS_GetArrayBuffer(ctx, &data_size, argv[1]);
|
||||||
|
if(data_js == NULL) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
void * data = malloc(data_size);
|
||||||
|
memcpy((void *)data, (const void *)data_js, data_size);
|
||||||
|
unsigned int bytesToWrite;
|
||||||
|
JS_ToUint32(ctx, &bytesToWrite, argv[2]);
|
||||||
|
bool returnVal = SaveFileData(fileName, data, bytesToWrite);
|
||||||
|
JS_FreeCString(ctx, fileName);
|
||||||
|
free((void *)data);
|
||||||
|
JSValue ret = JS_NewBool(ctx, returnVal);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static JSValue js_loadFileText(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
static JSValue js_loadFileText(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
||||||
const char * fileName = (const char *)JS_ToCString(ctx, argv[0]);
|
const char * fileName = (const char *)JS_ToCString(ctx, argv[0]);
|
||||||
char * returnVal = LoadFileText(fileName);
|
char * returnVal = LoadFileText(fileName);
|
||||||
|
@ -2922,6 +3144,17 @@ static JSValue js_updateCameraPro(JSContext * ctx, JSValueConst this_val, int ar
|
||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_setShapesTexture(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
||||||
|
Texture2D* texture_ptr = (Texture2D*)JS_GetOpaque2(ctx, argv[0], js_Texture_class_id);
|
||||||
|
if(texture_ptr == NULL) return JS_EXCEPTION;
|
||||||
|
Texture2D texture = *texture_ptr;
|
||||||
|
Rectangle* source_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[1], js_Rectangle_class_id);
|
||||||
|
if(source_ptr == NULL) return JS_EXCEPTION;
|
||||||
|
Rectangle source = *source_ptr;
|
||||||
|
SetShapesTexture(texture, source);
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
static JSValue js_drawPixel(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
static JSValue js_drawPixel(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
||||||
int posX;
|
int posX;
|
||||||
JS_ToInt32(ctx, &posX, argv[0]);
|
JS_ToInt32(ctx, &posX, argv[0]);
|
||||||
|
@ -3671,6 +3904,27 @@ static JSValue js_loadImageRaw(JSContext * ctx, JSValueConst this_val, int argc,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_loadImageFromMemory(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
||||||
|
const char * fileType = (const char *)JS_ToCString(ctx, argv[0]);
|
||||||
|
size_t fileData_size;
|
||||||
|
void * fileData_js = (void *)JS_GetArrayBuffer(ctx, &fileData_size, argv[1]);
|
||||||
|
if(fileData_js == NULL) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
const unsigned char * fileData = malloc(fileData_size);
|
||||||
|
memcpy((void *)fileData, (const void *)fileData_js, fileData_size);
|
||||||
|
int dataSize;
|
||||||
|
JS_ToInt32(ctx, &dataSize, argv[2]);
|
||||||
|
Image returnVal = LoadImageFromMemory(fileType, fileData, dataSize);
|
||||||
|
JS_FreeCString(ctx, fileType);
|
||||||
|
free((void *)fileData);
|
||||||
|
Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image));
|
||||||
|
*ret_ptr = returnVal;
|
||||||
|
JSValue ret = JS_NewObjectClass(ctx, js_Image_class_id);
|
||||||
|
JS_SetOpaque(ret, ret_ptr);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static JSValue js_loadImageFromTexture(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
static JSValue js_loadImageFromTexture(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
||||||
Texture2D* texture_ptr = (Texture2D*)JS_GetOpaque2(ctx, argv[0], js_Texture_class_id);
|
Texture2D* texture_ptr = (Texture2D*)JS_GetOpaque2(ctx, argv[0], js_Texture_class_id);
|
||||||
if(texture_ptr == NULL) return JS_EXCEPTION;
|
if(texture_ptr == NULL) return JS_EXCEPTION;
|
||||||
|
@ -4556,6 +4810,41 @@ static JSValue js_unloadRenderTexture(JSContext * ctx, JSValueConst this_val, in
|
||||||
return JS_UNDEFINED;
|
return JS_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_updateTexture(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
||||||
|
Texture2D* texture_ptr = (Texture2D*)JS_GetOpaque2(ctx, argv[0], js_Texture_class_id);
|
||||||
|
if(texture_ptr == NULL) return JS_EXCEPTION;
|
||||||
|
Texture2D texture = *texture_ptr;
|
||||||
|
size_t pixels_size;
|
||||||
|
void * pixels_js = (void *)JS_GetArrayBuffer(ctx, &pixels_size, argv[1]);
|
||||||
|
if(pixels_js == NULL) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
const void * pixels = malloc(pixels_size);
|
||||||
|
memcpy((void *)pixels, (const void *)pixels_js, pixels_size);
|
||||||
|
UpdateTexture(texture, pixels);
|
||||||
|
free((void *)pixels);
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static JSValue js_updateTextureRec(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
||||||
|
Texture2D* texture_ptr = (Texture2D*)JS_GetOpaque2(ctx, argv[0], js_Texture_class_id);
|
||||||
|
if(texture_ptr == NULL) return JS_EXCEPTION;
|
||||||
|
Texture2D texture = *texture_ptr;
|
||||||
|
Rectangle* rec_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[1], js_Rectangle_class_id);
|
||||||
|
if(rec_ptr == NULL) return JS_EXCEPTION;
|
||||||
|
Rectangle rec = *rec_ptr;
|
||||||
|
size_t pixels_size;
|
||||||
|
void * pixels_js = (void *)JS_GetArrayBuffer(ctx, &pixels_size, argv[2]);
|
||||||
|
if(pixels_js == NULL) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
const void * pixels = malloc(pixels_size);
|
||||||
|
memcpy((void *)pixels, (const void *)pixels_js, pixels_size);
|
||||||
|
UpdateTextureRec(texture, rec, pixels);
|
||||||
|
free((void *)pixels);
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
static JSValue js_genTextureMipmaps(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
static JSValue js_genTextureMipmaps(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
||||||
Texture2D* texture = (Texture2D*)JS_GetOpaque2(ctx, argv[0], js_Texture_class_id);
|
Texture2D* texture = (Texture2D*)JS_GetOpaque2(ctx, argv[0], js_Texture_class_id);
|
||||||
if(texture == NULL) return JS_EXCEPTION;
|
if(texture == NULL) return JS_EXCEPTION;
|
||||||
|
@ -6159,6 +6448,27 @@ static JSValue js_loadWave(JSContext * ctx, JSValueConst this_val, int argc, JSV
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_loadWaveFromMemory(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
||||||
|
const char * fileType = (const char *)JS_ToCString(ctx, argv[0]);
|
||||||
|
size_t fileData_size;
|
||||||
|
void * fileData_js = (void *)JS_GetArrayBuffer(ctx, &fileData_size, argv[1]);
|
||||||
|
if(fileData_js == NULL) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
const unsigned char * fileData = malloc(fileData_size);
|
||||||
|
memcpy((void *)fileData, (const void *)fileData_js, fileData_size);
|
||||||
|
int dataSize;
|
||||||
|
JS_ToInt32(ctx, &dataSize, argv[2]);
|
||||||
|
Wave returnVal = LoadWaveFromMemory(fileType, fileData, dataSize);
|
||||||
|
JS_FreeCString(ctx, fileType);
|
||||||
|
free((void *)fileData);
|
||||||
|
Wave* ret_ptr = (Wave*)js_malloc(ctx, sizeof(Wave));
|
||||||
|
*ret_ptr = returnVal;
|
||||||
|
JSValue ret = JS_NewObjectClass(ctx, js_Wave_class_id);
|
||||||
|
JS_SetOpaque(ret, ret_ptr);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static JSValue js_isWaveReady(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
static JSValue js_isWaveReady(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
||||||
Wave* wave_ptr = (Wave*)JS_GetOpaque2(ctx, argv[0], js_Wave_class_id);
|
Wave* wave_ptr = (Wave*)JS_GetOpaque2(ctx, argv[0], js_Wave_class_id);
|
||||||
if(wave_ptr == NULL) return JS_EXCEPTION;
|
if(wave_ptr == NULL) return JS_EXCEPTION;
|
||||||
|
@ -6200,6 +6510,24 @@ static JSValue js_isSoundReady(JSContext * ctx, JSValueConst this_val, int argc,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static JSValue js_updateSound(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
||||||
|
Sound* sound_ptr = (Sound*)JS_GetOpaque2(ctx, argv[0], js_Sound_class_id);
|
||||||
|
if(sound_ptr == NULL) return JS_EXCEPTION;
|
||||||
|
Sound sound = *sound_ptr;
|
||||||
|
size_t data_size;
|
||||||
|
void * data_js = (void *)JS_GetArrayBuffer(ctx, &data_size, argv[1]);
|
||||||
|
if(data_js == NULL) {
|
||||||
|
return JS_EXCEPTION;
|
||||||
|
}
|
||||||
|
const void * data = malloc(data_size);
|
||||||
|
memcpy((void *)data, (const void *)data_js, data_size);
|
||||||
|
int sampleCount;
|
||||||
|
JS_ToInt32(ctx, &sampleCount, argv[2]);
|
||||||
|
UpdateSound(sound, data, sampleCount);
|
||||||
|
free((void *)data);
|
||||||
|
return JS_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
static JSValue js_unloadWave(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
static JSValue js_unloadWave(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) {
|
||||||
Wave* wave_ptr = (Wave*)JS_GetOpaque2(ctx, argv[0], js_Wave_class_id);
|
Wave* wave_ptr = (Wave*)JS_GetOpaque2(ctx, argv[0], js_Wave_class_id);
|
||||||
if(wave_ptr == NULL) return JS_EXCEPTION;
|
if(wave_ptr == NULL) return JS_EXCEPTION;
|
||||||
|
@ -8065,6 +8393,7 @@ static const JSCFunctionListEntry js_raylib_core_funcs[] = {
|
||||||
JS_CFUNC_DEF("beginScissorMode",4,js_beginScissorMode),
|
JS_CFUNC_DEF("beginScissorMode",4,js_beginScissorMode),
|
||||||
JS_CFUNC_DEF("endScissorMode",0,js_endScissorMode),
|
JS_CFUNC_DEF("endScissorMode",0,js_endScissorMode),
|
||||||
JS_CFUNC_DEF("loadShader",2,js_loadShader),
|
JS_CFUNC_DEF("loadShader",2,js_loadShader),
|
||||||
|
JS_CFUNC_DEF("loadShaderFromMemory",2,js_loadShaderFromMemory),
|
||||||
JS_CFUNC_DEF("isShaderReady",1,js_isShaderReady),
|
JS_CFUNC_DEF("isShaderReady",1,js_isShaderReady),
|
||||||
JS_CFUNC_DEF("getShaderLocation",2,js_getShaderLocation),
|
JS_CFUNC_DEF("getShaderLocation",2,js_getShaderLocation),
|
||||||
JS_CFUNC_DEF("getShaderLocationAttrib",2,js_getShaderLocationAttrib),
|
JS_CFUNC_DEF("getShaderLocationAttrib",2,js_getShaderLocationAttrib),
|
||||||
|
@ -8090,6 +8419,8 @@ static const JSCFunctionListEntry js_raylib_core_funcs[] = {
|
||||||
JS_CFUNC_DEF("traceLog",2,js_traceLog),
|
JS_CFUNC_DEF("traceLog",2,js_traceLog),
|
||||||
JS_CFUNC_DEF("setTraceLogLevel",1,js_setTraceLogLevel),
|
JS_CFUNC_DEF("setTraceLogLevel",1,js_setTraceLogLevel),
|
||||||
JS_CFUNC_DEF("openURL",1,js_openURL),
|
JS_CFUNC_DEF("openURL",1,js_openURL),
|
||||||
|
JS_CFUNC_DEF("loadFileData",1,js_loadFileData),
|
||||||
|
JS_CFUNC_DEF("saveFileData",3,js_saveFileData),
|
||||||
JS_CFUNC_DEF("loadFileText",1,js_loadFileText),
|
JS_CFUNC_DEF("loadFileText",1,js_loadFileText),
|
||||||
JS_CFUNC_DEF("saveFileText",2,js_saveFileText),
|
JS_CFUNC_DEF("saveFileText",2,js_saveFileText),
|
||||||
JS_CFUNC_DEF("fileExists",1,js_fileExists),
|
JS_CFUNC_DEF("fileExists",1,js_fileExists),
|
||||||
|
@ -8153,6 +8484,7 @@ static const JSCFunctionListEntry js_raylib_core_funcs[] = {
|
||||||
JS_CFUNC_DEF("getGesturePinchAngle",0,js_getGesturePinchAngle),
|
JS_CFUNC_DEF("getGesturePinchAngle",0,js_getGesturePinchAngle),
|
||||||
JS_CFUNC_DEF("updateCamera",2,js_updateCamera),
|
JS_CFUNC_DEF("updateCamera",2,js_updateCamera),
|
||||||
JS_CFUNC_DEF("updateCameraPro",4,js_updateCameraPro),
|
JS_CFUNC_DEF("updateCameraPro",4,js_updateCameraPro),
|
||||||
|
JS_CFUNC_DEF("setShapesTexture",2,js_setShapesTexture),
|
||||||
JS_CFUNC_DEF("drawPixel",3,js_drawPixel),
|
JS_CFUNC_DEF("drawPixel",3,js_drawPixel),
|
||||||
JS_CFUNC_DEF("drawPixelV",2,js_drawPixelV),
|
JS_CFUNC_DEF("drawPixelV",2,js_drawPixelV),
|
||||||
JS_CFUNC_DEF("drawLine",5,js_drawLine),
|
JS_CFUNC_DEF("drawLine",5,js_drawLine),
|
||||||
|
@ -8197,6 +8529,7 @@ static const JSCFunctionListEntry js_raylib_core_funcs[] = {
|
||||||
JS_CFUNC_DEF("getCollisionRec",2,js_getCollisionRec),
|
JS_CFUNC_DEF("getCollisionRec",2,js_getCollisionRec),
|
||||||
JS_CFUNC_DEF("loadImage",1,js_loadImage),
|
JS_CFUNC_DEF("loadImage",1,js_loadImage),
|
||||||
JS_CFUNC_DEF("loadImageRaw",5,js_loadImageRaw),
|
JS_CFUNC_DEF("loadImageRaw",5,js_loadImageRaw),
|
||||||
|
JS_CFUNC_DEF("loadImageFromMemory",3,js_loadImageFromMemory),
|
||||||
JS_CFUNC_DEF("loadImageFromTexture",1,js_loadImageFromTexture),
|
JS_CFUNC_DEF("loadImageFromTexture",1,js_loadImageFromTexture),
|
||||||
JS_CFUNC_DEF("loadImageFromScreen",0,js_loadImageFromScreen),
|
JS_CFUNC_DEF("loadImageFromScreen",0,js_loadImageFromScreen),
|
||||||
JS_CFUNC_DEF("isImageReady",1,js_isImageReady),
|
JS_CFUNC_DEF("isImageReady",1,js_isImageReady),
|
||||||
|
@ -8265,6 +8598,8 @@ static const JSCFunctionListEntry js_raylib_core_funcs[] = {
|
||||||
JS_CFUNC_DEF("unloadTexture",1,js_unloadTexture),
|
JS_CFUNC_DEF("unloadTexture",1,js_unloadTexture),
|
||||||
JS_CFUNC_DEF("isRenderTextureReady",1,js_isRenderTextureReady),
|
JS_CFUNC_DEF("isRenderTextureReady",1,js_isRenderTextureReady),
|
||||||
JS_CFUNC_DEF("unloadRenderTexture",1,js_unloadRenderTexture),
|
JS_CFUNC_DEF("unloadRenderTexture",1,js_unloadRenderTexture),
|
||||||
|
JS_CFUNC_DEF("updateTexture",2,js_updateTexture),
|
||||||
|
JS_CFUNC_DEF("updateTextureRec",3,js_updateTextureRec),
|
||||||
JS_CFUNC_DEF("genTextureMipmaps",1,js_genTextureMipmaps),
|
JS_CFUNC_DEF("genTextureMipmaps",1,js_genTextureMipmaps),
|
||||||
JS_CFUNC_DEF("setTextureFilter",2,js_setTextureFilter),
|
JS_CFUNC_DEF("setTextureFilter",2,js_setTextureFilter),
|
||||||
JS_CFUNC_DEF("setTextureWrap",2,js_setTextureWrap),
|
JS_CFUNC_DEF("setTextureWrap",2,js_setTextureWrap),
|
||||||
|
@ -8372,10 +8707,12 @@ static const JSCFunctionListEntry js_raylib_core_funcs[] = {
|
||||||
JS_CFUNC_DEF("isAudioDeviceReady",0,js_isAudioDeviceReady),
|
JS_CFUNC_DEF("isAudioDeviceReady",0,js_isAudioDeviceReady),
|
||||||
JS_CFUNC_DEF("setMasterVolume",1,js_setMasterVolume),
|
JS_CFUNC_DEF("setMasterVolume",1,js_setMasterVolume),
|
||||||
JS_CFUNC_DEF("loadWave",1,js_loadWave),
|
JS_CFUNC_DEF("loadWave",1,js_loadWave),
|
||||||
|
JS_CFUNC_DEF("loadWaveFromMemory",3,js_loadWaveFromMemory),
|
||||||
JS_CFUNC_DEF("isWaveReady",1,js_isWaveReady),
|
JS_CFUNC_DEF("isWaveReady",1,js_isWaveReady),
|
||||||
JS_CFUNC_DEF("loadSound",1,js_loadSound),
|
JS_CFUNC_DEF("loadSound",1,js_loadSound),
|
||||||
JS_CFUNC_DEF("loadSoundFromWave",1,js_loadSoundFromWave),
|
JS_CFUNC_DEF("loadSoundFromWave",1,js_loadSoundFromWave),
|
||||||
JS_CFUNC_DEF("isSoundReady",1,js_isSoundReady),
|
JS_CFUNC_DEF("isSoundReady",1,js_isSoundReady),
|
||||||
|
JS_CFUNC_DEF("updateSound",3,js_updateSound),
|
||||||
JS_CFUNC_DEF("unloadWave",1,js_unloadWave),
|
JS_CFUNC_DEF("unloadWave",1,js_unloadWave),
|
||||||
JS_CFUNC_DEF("unloadSound",1,js_unloadSound),
|
JS_CFUNC_DEF("unloadSound",1,js_unloadSound),
|
||||||
JS_CFUNC_DEF("exportWave",2,js_exportWave),
|
JS_CFUNC_DEF("exportWave",2,js_exportWave),
|
||||||
|
|
Loading…
Reference in New Issue