diff --git a/docs/API.md b/docs/API.md index ab2e930..271e58f 100644 --- a/docs/API.md +++ b/docs/API.md @@ -295,7 +295,7 @@
OpenURL(url)undefined

Open URL with default system browser (if available)

-
LoadFileData(fileName, bytesRead)Buffer
+
LoadFileData(fileName, bytesRead)UInt8Array

Load file data as byte array (read)

UnloadFileData(data)undefined
@@ -376,16 +376,16 @@
GetFileModTime(fileName)number

Get file modification time (last write time)

-
CompressData(data, dataSize, compDataSize)Buffer
+
CompressData(data, dataSize, compDataSize)UInt8Array

Compress data (DEFLATE algorithm), memory must be MemFree()

-
DecompressData(compData, compDataSize, dataSize)Buffer
+
DecompressData(compData, compDataSize, dataSize)UInt8Array

Decompress data (DEFLATE algorithm), memory must be MemFree()

EncodeDataBase64(data, dataSize, outputSize)string

Encode data to Base64 string, memory must be MemFree()

-
DecodeDataBase64(data, outputSize)Buffer
+
DecodeDataBase64(data, outputSize)UInt8Array

Decode Base64 string data, memory must be MemFree()

IsKeyPressed(key)boolean
@@ -934,7 +934,7 @@
UnloadUTF8(text)undefined

Unload UTF-8 text encoded from codepoints array

-
LoadCodepoints(text, count)number
+
LoadCodepoints(text, count)Int32Array

Load all codepoints from a UTF-8 text string, codepoints count returned by parameter

UnloadCodepoints(codepoints)undefined
@@ -1255,7 +1255,7 @@
WaveCopy(wave)Wave

Copy a wave to a new wave

-
LoadWaveSamples(wave)number
+
LoadWaveSamples(wave)Float32Array

Load samples data from wave as a 32bit float data array

UnloadWaveSamples(samples)undefined
@@ -1585,7 +1585,7 @@
GuiIconText(iconId, text)string

Get text with icon id prepended (if supported)

-
GuiGetIcons()number
+
GuiGetIcons()UInt32Array

Get raygui icons data pointer

GuiLoadIcons(fileName, loadIconsName)number
@@ -1822,7 +1822,7 @@
rlGetShaderIdDefault()number

Get default shader id

-
rlGetShaderLocsDefault()number
+
rlGetShaderLocsDefault()Int32Array

Get default shader locations

rlLoadRenderBatch(numBuffers, bufferElements)rlRenderBatch
@@ -1891,7 +1891,7 @@
rlReadTexturePixels(id, width, height, format)number

Read texture pixel data

-
rlReadScreenPixels(width, height)Buffer
+
rlReadScreenPixels(width, height)UInt8Array

Read screen pixel data (color buffer)

rlLoadFramebuffer(width, height)number
@@ -3093,11 +3093,11 @@ Open URL with default system browser (if available) -## LoadFileData(fileName, bytesRead) ⇒ Buffer +## LoadFileData(fileName, bytesRead) ⇒ UInt8Array Load file data as byte array (read) **Kind**: global function -**Returns**: Buffer - The resulting unsigned char *. +**Returns**: UInt8Array - The resulting unsigned char *. | Param | Type | | --- | --- | @@ -3113,7 +3113,7 @@ Unload file data allocated by LoadFileData() | Param | Type | | --- | --- | -| data | Buffer | +| data | UInt8Array | @@ -3139,7 +3139,7 @@ Export data to code (.h), returns true on success | Param | Type | | --- | --- | -| data | Buffer | +| data | UInt8Array | | size | number | | fileName | string | @@ -3402,29 +3402,29 @@ Get file modification time (last write time) -## CompressData(data, dataSize, compDataSize) ⇒ Buffer +## CompressData(data, dataSize, compDataSize) ⇒ UInt8Array Compress data (DEFLATE algorithm), memory must be MemFree() **Kind**: global function -**Returns**: Buffer - The resulting unsigned char *. +**Returns**: UInt8Array - The resulting unsigned char *. | Param | Type | | --- | --- | -| data | Buffer | +| data | UInt8Array | | dataSize | number | | compDataSize | number | -## DecompressData(compData, compDataSize, dataSize) ⇒ Buffer +## DecompressData(compData, compDataSize, dataSize) ⇒ UInt8Array Decompress data (DEFLATE algorithm), memory must be MemFree() **Kind**: global function -**Returns**: Buffer - The resulting unsigned char *. +**Returns**: UInt8Array - The resulting unsigned char *. | Param | Type | | --- | --- | -| compData | Buffer | +| compData | UInt8Array | | compDataSize | number | | dataSize | number | @@ -3438,21 +3438,21 @@ Encode data to Base64 string, memory must be MemFree() | Param | Type | | --- | --- | -| data | Buffer | +| data | UInt8Array | | dataSize | number | | outputSize | number | -## DecodeDataBase64(data, outputSize) ⇒ Buffer +## DecodeDataBase64(data, outputSize) ⇒ UInt8Array Decode Base64 string data, memory must be MemFree() **Kind**: global function -**Returns**: Buffer - The resulting unsigned char *. +**Returns**: UInt8Array - The resulting unsigned char *. | Param | Type | | --- | --- | -| data | Buffer | +| data | UInt8Array | | outputSize | number | @@ -4650,7 +4650,7 @@ Load image from memory buffer, fileType refers to extension: i.e. '.png' | Param | Type | | --- | --- | | fileType | string | -| fileData | Buffer | +| fileData | UInt8Array | | dataSize | number | @@ -5484,7 +5484,7 @@ Load font from file with extended parameters, use NULL for fontChars and 0 for g | --- | --- | | fileName | string | | fontSize | number | -| fontChars | number | +| fontChars | Int32Array | | glyphCount | number | @@ -5512,10 +5512,10 @@ Load font from memory buffer, fileType refers to extension: i.e. '.ttf' | Param | Type | | --- | --- | | fileType | string | -| fileData | Buffer | +| fileData | UInt8Array | | dataSize | number | | fontSize | number | -| fontChars | number | +| fontChars | Int32Array | | glyphCount | number | @@ -5540,10 +5540,10 @@ Load font data for further use | Param | Type | | --- | --- | -| fileData | Buffer | +| fileData | UInt8Array | | dataSize | number | | fontSize | number | -| fontChars | number | +| fontChars | Int32Array | | glyphCount | number | | type | number | @@ -5686,7 +5686,7 @@ Draw multiple character (codepoint) | Param | Type | | --- | --- | | font | Font | -| codepoints | number | +| codepoints | Int32Array | | count | number | | position | [Vector2](#Vector2) | | fontSize | number | @@ -5770,7 +5770,7 @@ Load UTF-8 text encoded from codepoints array | Param | Type | | --- | --- | -| codepoints | number | +| codepoints | Int32Array | | length | number | @@ -5786,11 +5786,11 @@ Unload UTF-8 text encoded from codepoints array -## LoadCodepoints(text, count) ⇒ number +## LoadCodepoints(text, count) ⇒ Int32Array Load all codepoints from a UTF-8 text string, codepoints count returned by parameter **Kind**: global function -**Returns**: number - The resulting int *. +**Returns**: Int32Array - The resulting int *. | Param | Type | | --- | --- | @@ -5806,7 +5806,7 @@ Unload codepoints data from memory | Param | Type | | --- | --- | -| codepoints | number | +| codepoints | Int32Array | @@ -5870,7 +5870,7 @@ Encode one codepoint into UTF-8 byte array (array length returned as parameter) | Param | Type | | --- | --- | | codepoint | number | -| utf8Size | number | +| utf8Size | Int32Array | @@ -6968,7 +6968,7 @@ Load wave from memory buffer, fileType refers to extension: i.e. '.wav' | Param | Type | | --- | --- | | fileType | string | -| fileData | Buffer | +| fileData | UInt8Array | | dataSize | number | @@ -7186,11 +7186,11 @@ Copy a wave to a new wave -## LoadWaveSamples(wave) ⇒ number +## LoadWaveSamples(wave) ⇒ Float32Array Load samples data from wave as a 32bit float data array **Kind**: global function -**Returns**: number - The resulting float *. +**Returns**: Float32Array - The resulting float *. | Param | Type | | --- | --- | @@ -7205,7 +7205,7 @@ Unload samples data loaded with LoadWaveSamples() | Param | Type | | --- | --- | -| samples | number | +| samples | Float32Array | @@ -7230,7 +7230,7 @@ Load music stream from data | Param | Type | | --- | --- | | fileType | string | -| data | Buffer | +| data | UInt8Array | | dataSize | number | @@ -8146,7 +8146,7 @@ Tab Bar control, returns TAB to be closed or -1 | bounds | [Rectangle](#Rectangle) | | text | number | | count | number | -| active | number | +| active | Int32Array | @@ -8269,7 +8269,7 @@ Dropdown Box control, returns selected item | --- | --- | | bounds | [Rectangle](#Rectangle) | | text | string | -| active | number | +| active | Int32Array | | editMode | boolean | @@ -8284,7 +8284,7 @@ Spinner control, returns selected value | --- | --- | | bounds | [Rectangle](#Rectangle) | | text | string | -| value | number | +| value | Int32Array | | minValue | number | | maxValue | number | | editMode | boolean | @@ -8301,7 +8301,7 @@ Value Box control, updates input text with numbers | --- | --- | | bounds | [Rectangle](#Rectangle) | | text | string | -| value | number | +| value | Int32Array | | minValue | number | | maxValue | number | | editMode | boolean | @@ -8438,7 +8438,7 @@ List View control, returns selected list item index | --- | --- | | bounds | [Rectangle](#Rectangle) | | text | string | -| scrollIndex | number | +| scrollIndex | Int32Array | | active | number | @@ -8454,8 +8454,8 @@ List View with extended parameters | bounds | [Rectangle](#Rectangle) | | text | number | | count | number | -| focus | number | -| scrollIndex | number | +| focus | Int32Array | +| scrollIndex | Int32Array | | active | number | @@ -8489,7 +8489,7 @@ Text Input Box control, ask for text, supports secret | buttons | string | | text | string | | textMaxSize | number | -| secretViewActive | number | +| secretViewActive | Int32Array | @@ -8602,11 +8602,11 @@ Get text with icon id prepended (if supported) -## GuiGetIcons() ⇒ number +## GuiGetIcons() ⇒ UInt32Array Get raygui icons data pointer **Kind**: global function -**Returns**: number - The resulting unsigned int *. +**Returns**: UInt32Array - The resulting unsigned int *. ## GuiLoadIcons(fileName, loadIconsName) ⇒ number @@ -8709,7 +8709,7 @@ Multiply the current matrix by another matrix | Param | Type | | --- | --- | -| matf | number | +| matf | Float32Array | @@ -9335,11 +9335,11 @@ Get default shader id **Returns**: number - The resulting unsigned int. -## rlGetShaderLocsDefault() ⇒ number +## rlGetShaderLocsDefault() ⇒ Int32Array Get default shader locations **Kind**: global function -**Returns**: number - The resulting int *. +**Returns**: Int32Array - The resulting int *. ## rlLoadRenderBatch(numBuffers, bufferElements) ⇒ rlRenderBatch @@ -9563,9 +9563,9 @@ Get OpenGL internal formats | Param | Type | | --- | --- | | format | number | -| glInternalFormat | number | -| glFormat | number | -| glType | number | +| glInternalFormat | UInt32Array | +| glFormat | UInt32Array | +| glType | UInt32Array | @@ -9603,7 +9603,7 @@ Generate mipmap data for selected texture | width | number | | height | number | | format | number | -| mipmaps | number | +| mipmaps | Int32Array | @@ -9622,11 +9622,11 @@ Read texture pixel data -## rlReadScreenPixels(width, height) ⇒ Buffer +## rlReadScreenPixels(width, height) ⇒ UInt8Array Read screen pixel data (color buffer) **Kind**: global function -**Returns**: Buffer - The resulting unsigned char *. +**Returns**: UInt8Array - The resulting unsigned char *. | Param | Type | | --- | --- | @@ -9808,7 +9808,7 @@ Set shader currently active (id and locations) | Param | Type | | --- | --- | | id | number | -| locs | number | +| locs | Int32Array | diff --git a/examples/models/models_animation.js b/examples/models/models_animation.js new file mode 100644 index 0000000..d7c4545 --- /dev/null +++ b/examples/models/models_animation.js @@ -0,0 +1,108 @@ +/******************************************************************************************* +* +* raylib [models] example - Load 3d model with animations and play them +* +* Example originally created with raylib 2.5, last time updated with raylib 3.5 +* +* Example contributed by Culacant (@culacant) and reviewed by Ramon Santamaria (@raysan5) +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2019-2023 Culacant (@culacant) and Ramon Santamaria (@raysan5) +* +******************************************************************************************** +* +* NOTE: To export a model from blender, make sure it is not posed, the vertices need to be +* in the same position as they would be in edit mode and the scale of your models is +* set to 0. Scaling can be done from the export menu. +* +********************************************************************************************/ + +const r = require('raylib') +const { join } = require('path') + +// Initialization +// -------------------------------------------------------------------------------------- +const screenWidth = 800 +const screenHeight = 450 + +r.InitWindow(screenWidth, screenHeight, 'raylib [models] example - model animation') + +// Define the camera to look into our 3d world +const camera = { + position: { x: 10, y: 10, z: 10 }, // Camera position + target: { x: 0, y: 0, z: 0 }, // Camera looking at point + up: { x: 0, y: 1, z: 0 }, // Camera up vector (rotation towards target) + fovy: 45, // Camera field-of-view Y + projection: r.CAMERA_PERSPECTIVE // Camera mode type +} + +const model = r.LoadModel(join(__dirname, 'resources', 'guy', 'guy.iqm')) // Load the animated model mesh and basic data +const texture = r.LoadTexture(join(__dirname, 'resources', 'guy', 'guytex.png')) // Load model texture and set material + +// this will fail as it can't return an array of materials +const materials = r.LoadMaterials(join(__dirname, 'resources', 'guy', 'guy.iqm'), 1) +console.log('materials: ', materials) + +r.SetMaterialTexture(model.materials[0], r.MATERIAL_MAP_DIFFUSE, texture) // Set model material map texture + +const position = { x: 0, y: 0, z: 0 } // Set model position + +// Load animation data +let animsCount = 0 +const anims = r.LoadModelAnimations('resources/models/iqm/guyanim.iqm', animsCount) +animsCount = anims.length +let animFrameCounter = 0 + +r.DisableCursor() // Catch cursor +r.SetTargetFPS(60) // Set our game to run at 60 frames-per-second +// -------------------------------------------------------------------------------------- + +// Main game loop +while (!r.WindowShouldClose()) { // Detect window close button or ESC key + // Update + // ---------------------------------------------------------------------------------- + r.UpdateCamera(camera, r.CAMERA_FIRST_PERSON) + + // Play animation when spacebar is held down + if (r.IsKeyDown(r.KEY_SPACE)) { + animFrameCounter++ + r.UpdateModelAnimation(model, anims[0], animFrameCounter) + if (animFrameCounter >= anims[0].frameCount) animFrameCounter = 0 + } + // ---------------------------------------------------------------------------------- + + // Draw + // ---------------------------------------------------------------------------------- + r.BeginDrawing() + + r.ClearBackground(r.RAYWHITE) + + r.BeginMode3D(camera) + + r.DrawModelEx(model, position, { x: 0, y: 0, z: 0 }, -90, { x: 1, y: 1, z: 1 }, r.WHITE) + + for (let i = 0; i < model.boneCount; i++) { + r.DrawCube(anims[0].framePoses[animFrameCounter][i].translation, 0.2, 0.2, 0.2, r.RED) + } + + r.DrawGrid(10, 1) // Draw a grid + + r.EndMode3D() + + r.DrawText('PRESS SPACE to PLAY MODEL ANIMATION', 10, 10, 20, r.MAROON) + r.DrawText('(c) Guy IQM 3D model by @culacant', screenWidth - 200, screenHeight - 20, 10, r.GRAY) + + r.EndDrawing() + // ---------------------------------------------------------------------------------- +} + +// De-Initialization +// -------------------------------------------------------------------------------------- +r.UnloadTexture(texture) // Unload texture +r.UnloadModelAnimations(anims, animsCount) // Unload model animations data +r.UnloadModel(model) // Unload model + +r.CloseWindow() // Close window and OpenGL context +// -------------------------------------------------------------------------------------- diff --git a/examples/textures/textures_from_memory.js b/examples/textures/textures_from_memory.js index 49143ed..4caadd7 100644 --- a/examples/textures/textures_from_memory.js +++ b/examples/textures/textures_from_memory.js @@ -21,12 +21,12 @@ const screenHeight = 450 // Load the image using fs module into a `Buffer` instance. // NOTE: this `Buffer` could come from *anywhere* (statically encoded in your source code, as a // partial read from a custom resource packer file, etc.) -const raw = readFileSync(resolve(__dirname, 'resources', 'wabbit_alpha.png')) +const raw = readFileSync(resolve(__dirname, 'resources', 'raylib_logo.png')) r.InitWindow(screenWidth, screenHeight, 'raylib [textures] example - image loading from memory') // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) -const image = r.LoadImageFromMemory('png', raw, raw.length) // Loaded in CPU memory (RAM) +const image = r.LoadImageFromMemory('.png', raw, raw.length) // Loaded in CPU memory (RAM) if (!image) { console.error('image failed to load!') process.exit(1) diff --git a/package-lock.json b/package-lock.json index 6ada57a..357a1d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "raylib", - "version": "0.14.0", + "version": "0.15.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "raylib", - "version": "0.14.0", + "version": "0.15.0", "hasInstallScript": true, "license": "Zlib", "dependencies": { diff --git a/package.json b/package.json index 2ef28f4..04144b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "raylib", - "version": "0.14.0", + "version": "0.15.0", "description": "Node.js bindings for raylib.", "main": "index.js", "types": "src/generated/node-raylib.d.ts", diff --git a/src/generated/node-raylib-drm.js b/src/generated/node-raylib-drm.js index fc21812..b4c32a3 100644 --- a/src/generated/node-raylib-drm.js +++ b/src/generated/node-raylib-drm.js @@ -1381,7 +1381,7 @@ raylib.OpenURL = OpenURL * @param {string} fileName * @param {number} bytesRead * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function LoadFileData (fileName, bytesRead) { return r.BindLoadFileData( @@ -1394,7 +1394,7 @@ raylib.LoadFileData = LoadFileData /** * Unload file data allocated by LoadFileData() * - * @param {Buffer} data + * @param {UInt8Array} data * * @return {undefined} */ @@ -1426,7 +1426,7 @@ raylib.SaveFileData = SaveFileData /** * Export data to code (.h), returns true on success * - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} size * @param {string} fileName * @@ -1762,11 +1762,11 @@ raylib.GetFileModTime = GetFileModTime /** * Compress data (DEFLATE algorithm), memory must be MemFree() * - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} dataSize * @param {number} compDataSize * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function CompressData (data, dataSize, compDataSize) { return r.BindCompressData( @@ -1780,11 +1780,11 @@ raylib.CompressData = CompressData /** * Decompress data (DEFLATE algorithm), memory must be MemFree() * - * @param {Buffer} compData + * @param {UInt8Array} compData * @param {number} compDataSize * @param {number} dataSize * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function DecompressData (compData, compDataSize, dataSize) { return r.BindDecompressData( @@ -1798,7 +1798,7 @@ raylib.DecompressData = DecompressData /** * Encode data to Base64 string, memory must be MemFree() * - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} dataSize * @param {number} outputSize * @@ -1816,10 +1816,10 @@ raylib.EncodeDataBase64 = EncodeDataBase64 /** * Decode Base64 string data, memory must be MemFree() * - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} outputSize * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function DecodeDataBase64 (data, outputSize) { return r.BindDecodeDataBase64( @@ -3664,7 +3664,7 @@ raylib.LoadImageAnim = LoadImageAnim * Load image from memory buffer, fileType refers to extension: i.e. '.png' * * @param {string} fileType - * @param {Buffer} fileData + * @param {UInt8Array} fileData * @param {number} dataSize * * @return {Image} The resulting Image. @@ -5001,7 +5001,7 @@ raylib.LoadFont = LoadFont * * @param {string} fileName * @param {number} fontSize - * @param {number} fontChars + * @param {Int32Array} fontChars * @param {number} glyphCount * * @return {Font} The resulting Font. @@ -5045,10 +5045,10 @@ raylib.LoadFontFromImage = LoadFontFromImage * Load font from memory buffer, fileType refers to extension: i.e. '.ttf' * * @param {string} fileType - * @param {Buffer} fileData + * @param {UInt8Array} fileData * @param {number} dataSize * @param {number} fontSize - * @param {number} fontChars + * @param {Int32Array} fontChars * @param {number} glyphCount * * @return {Font} The resulting Font. @@ -5091,10 +5091,10 @@ raylib.IsFontReady = IsFontReady /** * Load font data for further use * - * @param {Buffer} fileData + * @param {UInt8Array} fileData * @param {number} dataSize * @param {number} fontSize - * @param {number} fontChars + * @param {Int32Array} fontChars * @param {number} glyphCount * @param {number} type * @@ -5359,7 +5359,7 @@ raylib.DrawTextCodepoint = DrawTextCodepoint * Draw multiple character (codepoint) * * @param {Font} font - * @param {number} codepoints + * @param {Int32Array} codepoints * @param {number} count * @param {Vector2} position * @param {number} fontSize @@ -5517,7 +5517,7 @@ raylib.GetGlyphAtlasRec = GetGlyphAtlasRec /** * Load UTF-8 text encoded from codepoints array * - * @param {number} codepoints + * @param {Int32Array} codepoints * @param {number} length * * @return {string} The resulting char *. @@ -5550,7 +5550,7 @@ raylib.UnloadUTF8 = UnloadUTF8 * @param {string} text * @param {number} count * - * @return {number} The resulting int *. + * @return {Int32Array} The resulting int *. */ function LoadCodepoints (text, count) { return r.BindLoadCodepoints( @@ -5563,7 +5563,7 @@ raylib.LoadCodepoints = LoadCodepoints /** * Unload codepoints data from memory * - * @param {number} codepoints + * @param {Int32Array} codepoints * * @return {undefined} */ @@ -5640,7 +5640,7 @@ raylib.GetCodepointPrevious = GetCodepointPrevious * Encode one codepoint into UTF-8 byte array (array length returned as parameter) * * @param {number} codepoint - * @param {number} utf8Size + * @param {Int32Array} utf8Size * * @return {string} The resulting const char *. */ @@ -7732,7 +7732,7 @@ raylib.LoadWave = LoadWave * Load wave from memory buffer, fileType refers to extension: i.e. '.wav' * * @param {string} fileType - * @param {Buffer} fileData + * @param {UInt8Array} fileData * @param {number} dataSize * * @return {Wave} The resulting Wave. @@ -8096,7 +8096,7 @@ raylib.WaveCopy = WaveCopy * * @param {Wave} wave * - * @return {number} The resulting float *. + * @return {Float32Array} The resulting float *. */ function LoadWaveSamples (wave) { return r.BindLoadWaveSamples( @@ -8112,7 +8112,7 @@ raylib.LoadWaveSamples = LoadWaveSamples /** * Unload samples data loaded with LoadWaveSamples() * - * @param {number} samples + * @param {Float32Array} samples * * @return {undefined} */ @@ -8141,7 +8141,7 @@ raylib.LoadMusicStream = LoadMusicStream * Load music stream from data * * @param {string} fileType - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} dataSize * * @return {Music} The resulting Music. @@ -10797,7 +10797,7 @@ raylib.GuiPanel = GuiPanel * @param {Rectangle} bounds * @param {number} text * @param {number} count - * @param {number} active + * @param {Int32Array} active * * @return {number} The resulting int. */ @@ -10986,7 +10986,7 @@ raylib.GuiComboBox = GuiComboBox * * @param {Rectangle} bounds * @param {string} text - * @param {number} active + * @param {Int32Array} active * @param {boolean} editMode * * @return {boolean} The resulting bool. @@ -11009,7 +11009,7 @@ raylib.GuiDropdownBox = GuiDropdownBox * * @param {Rectangle} bounds * @param {string} text - * @param {number} value + * @param {Int32Array} value * @param {number} minValue * @param {number} maxValue * @param {boolean} editMode @@ -11036,7 +11036,7 @@ raylib.GuiSpinner = GuiSpinner * * @param {Rectangle} bounds * @param {string} text - * @param {number} value + * @param {Int32Array} value * @param {number} minValue * @param {number} maxValue * @param {boolean} editMode @@ -11251,7 +11251,7 @@ raylib.GuiGrid = GuiGrid * * @param {Rectangle} bounds * @param {string} text - * @param {number} scrollIndex + * @param {Int32Array} scrollIndex * @param {number} active * * @return {number} The resulting int. @@ -11275,8 +11275,8 @@ raylib.GuiListView = GuiListView * @param {Rectangle} bounds * @param {number} text * @param {number} count - * @param {number} focus - * @param {number} scrollIndex + * @param {Int32Array} focus + * @param {Int32Array} scrollIndex * @param {number} active * * @return {number} The resulting int. @@ -11328,7 +11328,7 @@ raylib.GuiMessageBox = GuiMessageBox * @param {string} buttons * @param {string} text * @param {number} textMaxSize - * @param {number} secretViewActive + * @param {Int32Array} secretViewActive * * @return {number} The resulting int. */ @@ -11515,7 +11515,7 @@ raylib.GuiIconText = GuiIconText /** * Get raygui icons data pointer * - * @return {number} The resulting unsigned int *. + * @return {UInt32Array} The resulting unsigned int *. */ function GuiGetIcons () { return r.BindGuiGetIcons() @@ -11669,7 +11669,7 @@ raylib.rlScalef = rlScalef /** * Multiply the current matrix by another matrix * - * @param {number} matf + * @param {Float32Array} matf * * @return {undefined} */ @@ -12595,7 +12595,7 @@ raylib.rlGetShaderIdDefault = rlGetShaderIdDefault /** * Get default shader locations * - * @return {number} The resulting int *. + * @return {Int32Array} The resulting int *. */ function rlGetShaderLocsDefault () { return r.BindrlGetShaderLocsDefault() @@ -12967,9 +12967,9 @@ raylib.rlUpdateTexture = rlUpdateTexture * Get OpenGL internal formats * * @param {number} format - * @param {number} glInternalFormat - * @param {number} glFormat - * @param {number} glType + * @param {UInt32Array} glInternalFormat + * @param {UInt32Array} glFormat + * @param {UInt32Array} glType * * @return {undefined} */ @@ -13018,7 +13018,7 @@ raylib.rlUnloadTexture = rlUnloadTexture * @param {number} width * @param {number} height * @param {number} format - * @param {number} mipmaps + * @param {Int32Array} mipmaps * * @return {undefined} */ @@ -13059,7 +13059,7 @@ raylib.rlReadTexturePixels = rlReadTexturePixels * @param {number} width * @param {number} height * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function rlReadScreenPixels (width, height) { return r.BindrlReadScreenPixels( @@ -13300,7 +13300,7 @@ raylib.rlSetUniformSampler = rlSetUniformSampler * Set shader currently active (id and locations) * * @param {number} id - * @param {number} locs + * @param {Int32Array} locs * * @return {undefined} */ diff --git a/src/generated/node-raylib.cc b/src/generated/node-raylib.cc index b0ea9d3..07a96d6 100644 --- a/src/generated/node-raylib.cc +++ b/src/generated/node-raylib.cc @@ -58,9 +58,30 @@ inline int intFromValue(const Napi::CallbackInfo& info, int index) { inline double doubleFromValue(const Napi::CallbackInfo& info, int index) { return info[index].As().DoubleValue(); } + uintptr_t pointerFromValue(const Napi::CallbackInfo& info, int index) { return (uintptr_t) info[index].As().Int64Value(); } + +uintptr_t Float32ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t Int32ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t UInt32ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t Int16ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t UInt16ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t UInt8ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} + inline unsigned char unsignedcharFromValue(const Napi::CallbackInfo& info, int index) { return info[index].As().Uint32Value(); } @@ -250,26 +271,26 @@ inline Mesh MeshFromValue(const Napi::CallbackInfo& info, int index) { return { intFromValue(info, index + 0), intFromValue(info, index + 1), - (float *) pointerFromValue(info, index + 2), - (float *) pointerFromValue(info, index + 3), - (float *) pointerFromValue(info, index + 4), - (float *) pointerFromValue(info, index + 5), - (float *) pointerFromValue(info, index + 6), - (unsigned char *) pointerFromValue(info, index + 7), - (unsigned short *) pointerFromValue(info, index + 8), - (float *) pointerFromValue(info, index + 9), - (float *) pointerFromValue(info, index + 10), - (unsigned char *) pointerFromValue(info, index + 11), - (float *) pointerFromValue(info, index + 12), + (float *) Float32ArrayFromValue(info, index + 2), + (float *) Float32ArrayFromValue(info, index + 3), + (float *) Float32ArrayFromValue(info, index + 4), + (float *) Float32ArrayFromValue(info, index + 5), + (float *) Float32ArrayFromValue(info, index + 6), + (unsigned char *) UInt8ArrayFromValue(info, index + 7), + (unsigned short *) UInt16ArrayFromValue(info, index + 8), + (float *) Float32ArrayFromValue(info, index + 9), + (float *) Float32ArrayFromValue(info, index + 10), + (unsigned char *) UInt8ArrayFromValue(info, index + 11), + (float *) Float32ArrayFromValue(info, index + 12), unsignedintFromValue(info, index + 13), - (unsigned int *) pointerFromValue(info, index + 14) + (unsigned int *) UInt32ArrayFromValue(info, index + 14) }; } inline Shader ShaderFromValue(const Napi::CallbackInfo& info, int index) { return { unsignedintFromValue(info, index + 0), - (int *) pointerFromValue(info, index + 1) + (int *) Int32ArrayFromValue(info, index + 1) }; } @@ -303,7 +324,7 @@ inline Model ModelFromValue(const Napi::CallbackInfo& info, int index) { intFromValue(info, index + 17), (Mesh *) pointerFromValue(info, index + 18), (Material *) pointerFromValue(info, index + 19), - (int *) pointerFromValue(info, index + 20), + (int *) Int32ArrayFromValue(info, index + 20), intFromValue(info, index + 21), (BoneInfo *) pointerFromValue(info, index + 22), (Transform *) pointerFromValue(info, index + 23) @@ -1138,7 +1159,7 @@ Napi::Value BindSaveFileData(const Napi::CallbackInfo& info) { Napi::Value BindExportDataAsCode(const Napi::CallbackInfo& info) { return ToValue(info.Env(), ExportDataAsCode( - (const unsigned char *) pointerFromValue(info, 0), + (const unsigned char *) UInt8ArrayFromValue(info, 0), unsignedintFromValue(info, 1), (const char *) stringFromValue(info, 2) ) @@ -1312,7 +1333,7 @@ Napi::Value BindGetFileModTime(const Napi::CallbackInfo& info) { Napi::Value BindCompressData(const Napi::CallbackInfo& info) { return ToValue(info.Env(), CompressData( - (const unsigned char *) pointerFromValue(info, 0), + (const unsigned char *) UInt8ArrayFromValue(info, 0), intFromValue(info, 1), (int *) pointerFromValue(info, 2) ) @@ -1322,7 +1343,7 @@ Napi::Value BindCompressData(const Napi::CallbackInfo& info) { Napi::Value BindDecompressData(const Napi::CallbackInfo& info) { return ToValue(info.Env(), DecompressData( - (const unsigned char *) pointerFromValue(info, 0), + (const unsigned char *) UInt8ArrayFromValue(info, 0), intFromValue(info, 1), (int *) pointerFromValue(info, 2) ) @@ -1332,7 +1353,7 @@ Napi::Value BindDecompressData(const Napi::CallbackInfo& info) { Napi::Value BindEncodeDataBase64(const Napi::CallbackInfo& info) { return ToValue(info.Env(), EncodeDataBase64( - (const unsigned char *) pointerFromValue(info, 0), + (const unsigned char *) UInt8ArrayFromValue(info, 0), intFromValue(info, 1), (int *) pointerFromValue(info, 2) ) @@ -1342,7 +1363,7 @@ Napi::Value BindEncodeDataBase64(const Napi::CallbackInfo& info) { Napi::Value BindDecodeDataBase64(const Napi::CallbackInfo& info) { return ToValue(info.Env(), DecodeDataBase64( - (const unsigned char *) pointerFromValue(info, 0), + (const unsigned char *) UInt8ArrayFromValue(info, 0), (int *) pointerFromValue(info, 1) ) ); @@ -1792,7 +1813,7 @@ Napi::Value BindLoadImageFromMemory(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadImageFromMemory( (const char *) stringFromValue(info, 0), - (const unsigned char *) pointerFromValue(info, 1), + (const unsigned char *) UInt8ArrayFromValue(info, 1), intFromValue(info, 2) ) ); @@ -2210,7 +2231,7 @@ Napi::Value BindLoadFontEx(const Napi::CallbackInfo& info) { LoadFontEx( (const char *) stringFromValue(info, 0), intFromValue(info, 1), - (int *) pointerFromValue(info, 2), + (int *) Int32ArrayFromValue(info, 2), intFromValue(info, 3) ) ); @@ -2230,10 +2251,10 @@ Napi::Value BindLoadFontFromMemory(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadFontFromMemory( (const char *) stringFromValue(info, 0), - (const unsigned char *) pointerFromValue(info, 1), + (const unsigned char *) UInt8ArrayFromValue(info, 1), intFromValue(info, 2), intFromValue(info, 3), - (int *) pointerFromValue(info, 4), + (int *) Int32ArrayFromValue(info, 4), intFromValue(info, 5) ) ); @@ -2250,10 +2271,10 @@ Napi::Value BindIsFontReady(const Napi::CallbackInfo& info) { Napi::Value BindLoadFontData(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadFontData( - (const unsigned char *) pointerFromValue(info, 0), + (const unsigned char *) UInt8ArrayFromValue(info, 0), intFromValue(info, 1), intFromValue(info, 2), - (int *) pointerFromValue(info, 3), + (int *) Int32ArrayFromValue(info, 3), intFromValue(info, 4), intFromValue(info, 5) ) @@ -2332,7 +2353,7 @@ Napi::Value BindGetGlyphAtlasRec(const Napi::CallbackInfo& info) { Napi::Value BindLoadUTF8(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadUTF8( - (const int *) pointerFromValue(info, 0), + (const int *) Int32ArrayFromValue(info, 0), intFromValue(info, 1) ) ); @@ -2386,7 +2407,7 @@ Napi::Value BindCodepointToUTF8(const Napi::CallbackInfo& info) { return ToValue(info.Env(), CodepointToUTF8( intFromValue(info, 0), - (int *) pointerFromValue(info, 1) + (int *) Int32ArrayFromValue(info, 1) ) ); } @@ -2787,7 +2808,7 @@ Napi::Value BindLoadWaveFromMemory(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadWaveFromMemory( (const char *) stringFromValue(info, 0), - (const unsigned char *) pointerFromValue(info, 1), + (const unsigned char *) UInt8ArrayFromValue(info, 1), intFromValue(info, 2) ) ); @@ -2879,7 +2900,7 @@ Napi::Value BindLoadMusicStreamFromMemory(const Napi::CallbackInfo& info) { return ToValue(info.Env(), LoadMusicStreamFromMemory( (const char *) stringFromValue(info, 0), - (const unsigned char *) pointerFromValue(info, 1), + (const unsigned char *) UInt8ArrayFromValue(info, 1), intFromValue(info, 2) ) ); @@ -4283,7 +4304,7 @@ Napi::Value BindGuiTabBar(const Napi::CallbackInfo& info) { RectangleFromValue(info, 0), (const char **) pointerFromValue(info, 4), intFromValue(info, 5), - (int *) pointerFromValue(info, 6) + (int *) Int32ArrayFromValue(info, 6) ) ); } @@ -4362,7 +4383,7 @@ Napi::Value BindGuiDropdownBox(const Napi::CallbackInfo& info) { GuiDropdownBox( RectangleFromValue(info, 0), (const char *) stringFromValue(info, 4), - (int *) pointerFromValue(info, 5), + (int *) Int32ArrayFromValue(info, 5), boolFromValue(info, 6) ) ); @@ -4373,7 +4394,7 @@ Napi::Value BindGuiSpinner(const Napi::CallbackInfo& info) { GuiSpinner( RectangleFromValue(info, 0), (const char *) stringFromValue(info, 4), - (int *) pointerFromValue(info, 5), + (int *) Int32ArrayFromValue(info, 5), intFromValue(info, 6), intFromValue(info, 7), boolFromValue(info, 8) @@ -4386,7 +4407,7 @@ Napi::Value BindGuiValueBox(const Napi::CallbackInfo& info) { GuiValueBox( RectangleFromValue(info, 0), (const char *) stringFromValue(info, 4), - (int *) pointerFromValue(info, 5), + (int *) Int32ArrayFromValue(info, 5), intFromValue(info, 6), intFromValue(info, 7), boolFromValue(info, 8) @@ -4471,7 +4492,7 @@ Napi::Value BindGuiListView(const Napi::CallbackInfo& info) { GuiListView( RectangleFromValue(info, 0), (const char *) stringFromValue(info, 4), - (int *) pointerFromValue(info, 5), + (int *) Int32ArrayFromValue(info, 5), intFromValue(info, 6) ) ); @@ -4483,8 +4504,8 @@ Napi::Value BindGuiListViewEx(const Napi::CallbackInfo& info) { RectangleFromValue(info, 0), (const char **) pointerFromValue(info, 4), intFromValue(info, 5), - (int *) pointerFromValue(info, 6), - (int *) pointerFromValue(info, 7), + (int *) Int32ArrayFromValue(info, 6), + (int *) Int32ArrayFromValue(info, 7), intFromValue(info, 8) ) ); @@ -4510,7 +4531,7 @@ Napi::Value BindGuiTextInputBox(const Napi::CallbackInfo& info) { (const char *) stringFromValue(info, 6), (char *) pointerFromValue(info, 7), intFromValue(info, 8), - (int *) pointerFromValue(info, 9) + (int *) Int32ArrayFromValue(info, 9) ) ); } @@ -5213,7 +5234,7 @@ void BindOpenURL(const Napi::CallbackInfo& info) { void BindUnloadFileData(const Napi::CallbackInfo& info) { UnloadFileData( - (unsigned char *) pointerFromValue(info, 0) + (unsigned char *) UInt8ArrayFromValue(info, 0) ); } @@ -5858,7 +5879,7 @@ void BindDrawTextCodepoint(const Napi::CallbackInfo& info) { void BindDrawTextCodepoints(const Napi::CallbackInfo& info) { DrawTextCodepoints( FontFromValue(info, 0), - (const int *) pointerFromValue(info, 10), + (const int *) Int32ArrayFromValue(info, 10), intFromValue(info, 11), Vector2FromValue(info, 12), floatFromValue(info, 14), @@ -5875,7 +5896,7 @@ void BindUnloadUTF8(const Napi::CallbackInfo& info) { void BindUnloadCodepoints(const Napi::CallbackInfo& info) { UnloadCodepoints( - (int *) pointerFromValue(info, 0) + (int *) Int32ArrayFromValue(info, 0) ); } @@ -6291,7 +6312,7 @@ void BindSetSoundPan(const Napi::CallbackInfo& info) { void BindUnloadWaveSamples(const Napi::CallbackInfo& info) { UnloadWaveSamples( - (float *) pointerFromValue(info, 0) + (float *) Float32ArrayFromValue(info, 0) ); } @@ -6435,7 +6456,7 @@ void BindQuaternionToAxisAngle(const Napi::CallbackInfo& info) { QuaternionToAxisAngle( Vector4FromValue(info, 0), (Vector3 *) pointerFromValue(info, 1), - (float *) pointerFromValue(info, 2) + (float *) Float32ArrayFromValue(info, 2) ); } @@ -6628,7 +6649,7 @@ void BindrlScalef(const Napi::CallbackInfo& info) { void BindrlMultMatrixf(const Napi::CallbackInfo& info) { rlMultMatrixf( - (const float *) pointerFromValue(info, 0) + (const float *) Float32ArrayFromValue(info, 0) ); } @@ -7184,9 +7205,9 @@ void BindrlUpdateTexture(const Napi::CallbackInfo& info) { void BindrlGetGlTextureFormats(const Napi::CallbackInfo& info) { rlGetGlTextureFormats( intFromValue(info, 0), - (unsigned int *) pointerFromValue(info, 1), - (unsigned int *) pointerFromValue(info, 2), - (unsigned int *) pointerFromValue(info, 3) + (unsigned int *) UInt32ArrayFromValue(info, 1), + (unsigned int *) UInt32ArrayFromValue(info, 2), + (unsigned int *) UInt32ArrayFromValue(info, 3) ); } @@ -7202,7 +7223,7 @@ void BindrlGenTextureMipmaps(const Napi::CallbackInfo& info) { intFromValue(info, 1), intFromValue(info, 2), intFromValue(info, 3), - (int *) pointerFromValue(info, 4) + (int *) Int32ArrayFromValue(info, 4) ); } @@ -7254,7 +7275,7 @@ void BindrlSetUniformSampler(const Napi::CallbackInfo& info) { void BindrlSetShader(const Napi::CallbackInfo& info) { rlSetShader( unsignedintFromValue(info, 0), - (int *) pointerFromValue(info, 1) + (int *) Int32ArrayFromValue(info, 1) ); } diff --git a/src/generated/node-raylib.d.ts b/src/generated/node-raylib.d.ts index 54a9521..f4d0c93 100644 --- a/src/generated/node-raylib.d.ts +++ b/src/generated/node-raylib.d.ts @@ -193,38 +193,38 @@ declare module "raylib" { /** Number of triangles stored (indexed or not). (int) */ triangleCount: number /** Vertex position (XYZ - 3 components per vertex) (shader-location = 0). (float *) */ - vertices: number + vertices: Float32Array /** Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1). (float *) */ - texcoords: number + texcoords: Float32Array /** Vertex texture second coordinates (UV - 2 components per vertex) (shader-location = 5). (float *) */ - texcoords2: number + texcoords2: Float32Array /** Vertex normals (XYZ - 3 components per vertex) (shader-location = 2). (float *) */ - normals: number + normals: Float32Array /** Vertex tangents (XYZW - 4 components per vertex) (shader-location = 4). (float *) */ - tangents: number + tangents: Float32Array /** Vertex colors (RGBA - 4 components per vertex) (shader-location = 3). (unsigned char *) */ - colors: Buffer + colors: UInt8Array /** Vertex indices (in case vertex data comes indexed). (unsigned short *) */ - indices: number + indices: UInt16Array /** Animated vertex positions (after bones transformations). (float *) */ - animVertices: number + animVertices: Float32Array /** Animated normals (after bones transformations). (float *) */ - animNormals: number + animNormals: Float32Array /** Vertex bone ids, max 255 bone ids, up to 4 bones influence by vertex (skinning). (unsigned char *) */ - boneIds: Buffer + boneIds: UInt8Array /** Vertex bone weight, up to 4 bones influence by vertex (skinning). (float *) */ - boneWeights: number + boneWeights: Float32Array /** OpenGL Vertex Array Object id. (unsigned int) */ vaoId: number /** OpenGL Vertex Buffer Objects id (default vertex data). (unsigned int *) */ - vboId: number + vboId: UInt32Array } /** Shader */ export interface Shader { /** Shader program id. (unsigned int) */ id: number /** Shader locations array (RL_MAX_SHADER_LOCATIONS). (int *) */ - locs: number + locs: Int32Array } /** MaterialMap */ export interface MaterialMap { @@ -273,7 +273,7 @@ declare module "raylib" { /** Materials array. (Material *) */ materials: number /** Mesh material number. (int *) */ - meshMaterial: number + meshMaterial: Int32Array /** Number of bones. (int) */ boneCount: number /** Bones information (skeleton). (BoneInfo *) */ @@ -419,13 +419,13 @@ declare module "raylib" { /** Number of elements in the buffer (QUADS). (int) */ elementCount: number /** Vertex position (XYZ - 3 components per vertex) (shader-location = 0). (float *) */ - vertices: number + vertices: Float32Array /** Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1). (float *) */ - texcoords: number + texcoords: Float32Array /** Vertex colors (RGBA - 4 components per vertex) (shader-location = 3). (unsigned char *) */ - colors: Buffer + colors: UInt8Array /** Vertex indices (in case vertex data comes indexed) (6 indices per quad). (unsigned int *) */ - indices: number + indices: UInt32Array /** OpenGL Vertex Array Object id. (unsigned int) */ vaoId: number /** OpenGL Vertex Buffer Objects id (4 types of vertex data). (unsigned int[4]) */ @@ -767,16 +767,16 @@ declare module "raylib" { export function OpenURL(url: string): void /** Load file data as byte array (read) */ - export function LoadFileData(fileName: string, bytesRead: number): Buffer + export function LoadFileData(fileName: string, bytesRead: number): UInt8Array /** Unload file data allocated by LoadFileData() */ - export function UnloadFileData(data: Buffer): void + export function UnloadFileData(data: UInt8Array): void /** Save data to file from byte array (write), returns true on success */ export function SaveFileData(fileName: string, data: number, bytesToWrite: number): boolean /** Export data to code (.h), returns true on success */ - export function ExportDataAsCode(data: Buffer, size: number, fileName: string): boolean + export function ExportDataAsCode(data: UInt8Array, size: number, fileName: string): boolean /** Load text data from file (read), returns a '\0' terminated string */ export function LoadFileText(fileName: string): string @@ -848,16 +848,16 @@ declare module "raylib" { export function GetFileModTime(fileName: string): number /** Compress data (DEFLATE algorithm), memory must be MemFree() */ - export function CompressData(data: Buffer, dataSize: number, compDataSize: number): Buffer + export function CompressData(data: UInt8Array, dataSize: number, compDataSize: number): UInt8Array /** Decompress data (DEFLATE algorithm), memory must be MemFree() */ - export function DecompressData(compData: Buffer, compDataSize: number, dataSize: number): Buffer + export function DecompressData(compData: UInt8Array, compDataSize: number, dataSize: number): UInt8Array /** Encode data to Base64 string, memory must be MemFree() */ - export function EncodeDataBase64(data: Buffer, dataSize: number, outputSize: number): string + export function EncodeDataBase64(data: UInt8Array, dataSize: number, outputSize: number): string /** Decode Base64 string data, memory must be MemFree() */ - export function DecodeDataBase64(data: Buffer, outputSize: number): Buffer + export function DecodeDataBase64(data: UInt8Array, outputSize: number): UInt8Array /** Check if a key has been pressed once */ export function IsKeyPressed(key: number): boolean @@ -1151,7 +1151,7 @@ declare module "raylib" { export function LoadImageAnim(fileName: string, frames: number): Image /** Load image from memory buffer, fileType refers to extension: i.e. '.png' */ - export function LoadImageFromMemory(fileType: string, fileData: Buffer, dataSize: number): Image + export function LoadImageFromMemory(fileType: string, fileData: UInt8Array, dataSize: number): Image /** Load image from GPU texture data */ export function LoadImageFromTexture(texture: Texture): Image @@ -1454,19 +1454,19 @@ declare module "raylib" { export function LoadFont(fileName: string): Font /** Load font from file with extended parameters, use NULL for fontChars and 0 for glyphCount to load the default character set */ - export function LoadFontEx(fileName: string, fontSize: number, fontChars: number, glyphCount: number): Font + export function LoadFontEx(fileName: string, fontSize: number, fontChars: Int32Array, glyphCount: number): Font /** Load font from Image (XNA style) */ export function LoadFontFromImage(image: Image, key: Color, firstChar: number): Font /** Load font from memory buffer, fileType refers to extension: i.e. '.ttf' */ - export function LoadFontFromMemory(fileType: string, fileData: Buffer, dataSize: number, fontSize: number, fontChars: number, glyphCount: number): Font + export function LoadFontFromMemory(fileType: string, fileData: UInt8Array, dataSize: number, fontSize: number, fontChars: Int32Array, glyphCount: number): Font /** Check if a font is ready */ export function IsFontReady(font: Font): boolean /** Load font data for further use */ - export function LoadFontData(fileData: Buffer, dataSize: number, fontSize: number, fontChars: number, glyphCount: number, type: number): number + export function LoadFontData(fileData: UInt8Array, dataSize: number, fontSize: number, fontChars: Int32Array, glyphCount: number, type: number): number /** Generate image font atlas using chars info */ export function GenImageFontAtlas(chars: number, recs: number, glyphCount: number, fontSize: number, padding: number, packMethod: number): Image @@ -1496,7 +1496,7 @@ declare module "raylib" { export function DrawTextCodepoint(font: Font, codepoint: number, position: Vector2, fontSize: number, tint: Color): void /** Draw multiple character (codepoint) */ - export function DrawTextCodepoints(font: Font, codepoints: number, count: number, position: Vector2, fontSize: number, spacing: number, tint: Color): void + export function DrawTextCodepoints(font: Font, codepoints: Int32Array, count: number, position: Vector2, fontSize: number, spacing: number, tint: Color): void /** Measure string width for default font */ export function MeasureText(text: string, fontSize: number): number @@ -1514,16 +1514,16 @@ declare module "raylib" { export function GetGlyphAtlasRec(font: Font, codepoint: number): Rectangle /** Load UTF-8 text encoded from codepoints array */ - export function LoadUTF8(codepoints: number, length: number): string + export function LoadUTF8(codepoints: Int32Array, length: number): string /** Unload UTF-8 text encoded from codepoints array */ export function UnloadUTF8(text: string): void /** Load all codepoints from a UTF-8 text string, codepoints count returned by parameter */ - export function LoadCodepoints(text: string, count: number): number + export function LoadCodepoints(text: string, count: number): Int32Array /** Unload codepoints data from memory */ - export function UnloadCodepoints(codepoints: number): void + export function UnloadCodepoints(codepoints: Int32Array): void /** Get total number of codepoints in a UTF-8 encoded string */ export function GetCodepointCount(text: string): number @@ -1538,7 +1538,7 @@ declare module "raylib" { export function GetCodepointPrevious(text: string, codepointSize: number): number /** Encode one codepoint into UTF-8 byte array (array length returned as parameter) */ - export function CodepointToUTF8(codepoint: number, utf8Size: number): string + export function CodepointToUTF8(codepoint: number, utf8Size: Int32Array): string /** Copy one string to another, returns bytes copied */ export function TextCopy(dst: string, src: string): number @@ -1793,7 +1793,7 @@ declare module "raylib" { export function LoadWave(fileName: string): Wave /** Load wave from memory buffer, fileType refers to extension: i.e. '.wav' */ - export function LoadWaveFromMemory(fileType: string, fileData: Buffer, dataSize: number): Wave + export function LoadWaveFromMemory(fileType: string, fileData: UInt8Array, dataSize: number): Wave /** Checks if wave data is ready */ export function IsWaveReady(wave: Wave): boolean @@ -1856,16 +1856,16 @@ declare module "raylib" { export function WaveFormat(wave: Wave, sampleRate: number, sampleSize: number, channels: number): void /** Load samples data from wave as a 32bit float data array */ - export function LoadWaveSamples(wave: Wave): number + export function LoadWaveSamples(wave: Wave): Float32Array /** Unload samples data loaded with LoadWaveSamples() */ - export function UnloadWaveSamples(samples: number): void + export function UnloadWaveSamples(samples: Float32Array): void /** Load music stream from file */ export function LoadMusicStream(fileName: string): Music /** Load music stream from data */ - export function LoadMusicStreamFromMemory(fileType: string, data: Buffer, dataSize: number): Music + export function LoadMusicStreamFromMemory(fileType: string, data: UInt8Array, dataSize: number): Music /** Checks if a music stream is ready */ export function IsMusicReady(music: Music): boolean @@ -2351,7 +2351,7 @@ declare module "raylib" { export function QuaternionFromAxisAngle(axis: Vector3, angle: number): Quaternion /** */ - export function QuaternionToAxisAngle(q: Quaternion, outAxis: number, outAngle: number): void + export function QuaternionToAxisAngle(q: Quaternion, outAxis: number, outAngle: Float32Array): void /** */ export function QuaternionFromEuler(pitch: number, yaw: number, roll: number): Quaternion @@ -2414,7 +2414,7 @@ declare module "raylib" { export function GuiPanel(bounds: Rectangle, text: string): void /** Tab Bar control, returns TAB to be closed or -1 */ - export function GuiTabBar(bounds: Rectangle, text: number, count: number, active: number): number + export function GuiTabBar(bounds: Rectangle, text: number, count: number, active: Int32Array): number /** Scroll Panel control */ export function GuiScrollPanel(bounds: Rectangle, text: string, content: Rectangle, scroll: number): Rectangle @@ -2441,13 +2441,13 @@ declare module "raylib" { export function GuiComboBox(bounds: Rectangle, text: string, active: number): number /** Dropdown Box control, returns selected item */ - export function GuiDropdownBox(bounds: Rectangle, text: string, active: number, editMode: boolean): boolean + export function GuiDropdownBox(bounds: Rectangle, text: string, active: Int32Array, editMode: boolean): boolean /** Spinner control, returns selected value */ - export function GuiSpinner(bounds: Rectangle, text: string, value: number, minValue: number, maxValue: number, editMode: boolean): boolean + export function GuiSpinner(bounds: Rectangle, text: string, value: Int32Array, minValue: number, maxValue: number, editMode: boolean): boolean /** Value Box control, updates input text with numbers */ - export function GuiValueBox(bounds: Rectangle, text: string, value: number, minValue: number, maxValue: number, editMode: boolean): boolean + export function GuiValueBox(bounds: Rectangle, text: string, value: Int32Array, minValue: number, maxValue: number, editMode: boolean): boolean /** Text Box control, updates input text */ export function GuiTextBox(bounds: Rectangle, text: string, textSize: number, editMode: boolean): boolean @@ -2474,16 +2474,16 @@ declare module "raylib" { export function GuiGrid(bounds: Rectangle, text: string, spacing: number, subdivs: number): Vector2 /** List View control, returns selected list item index */ - export function GuiListView(bounds: Rectangle, text: string, scrollIndex: number, active: number): number + export function GuiListView(bounds: Rectangle, text: string, scrollIndex: Int32Array, active: number): number /** List View with extended parameters */ - export function GuiListViewEx(bounds: Rectangle, text: number, count: number, focus: number, scrollIndex: number, active: number): number + export function GuiListViewEx(bounds: Rectangle, text: number, count: number, focus: Int32Array, scrollIndex: Int32Array, active: number): number /** Message Box control, displays a message */ export function GuiMessageBox(bounds: Rectangle, title: string, message: string, buttons: string): number /** Text Input Box control, ask for text, supports secret */ - export function GuiTextInputBox(bounds: Rectangle, title: string, message: string, buttons: string, text: string, textMaxSize: number, secretViewActive: number): number + export function GuiTextInputBox(bounds: Rectangle, title: string, message: string, buttons: string, text: string, textMaxSize: number, secretViewActive: Int32Array): number /** Color Picker control (multiple color controls) */ export function GuiColorPicker(bounds: Rectangle, text: string, color: Color): Color @@ -2516,7 +2516,7 @@ declare module "raylib" { export function GuiIconText(iconId: number, text: string): string /** Get raygui icons data pointer */ - export function GuiGetIcons(): number + export function GuiGetIcons(): UInt32Array /** Load raygui icons file (.rgi) into internal icons data */ export function GuiLoadIcons(fileName: string, loadIconsName: boolean): number @@ -2549,7 +2549,7 @@ declare module "raylib" { export function rlScalef(x: number, y: number, z: number): void /** Multiply the current matrix by another matrix */ - export function rlMultMatrixf(matf: number): void + export function rlMultMatrixf(matf: Float32Array): void /** */ export function rlFrustum(left: number, right: number, bottom: number, top: number, znear: number, zfar: number): void @@ -2762,7 +2762,7 @@ declare module "raylib" { export function rlGetShaderIdDefault(): number /** Get default shader locations */ - export function rlGetShaderLocsDefault(): number + export function rlGetShaderLocsDefault(): Int32Array /** Load a render batch system */ export function rlLoadRenderBatch(numBuffers: number, bufferElements: number): rlRenderBatch @@ -2840,7 +2840,7 @@ declare module "raylib" { export function rlUpdateTexture(id: number, offsetX: number, offsetY: number, width: number, height: number, format: number, data: number): void /** Get OpenGL internal formats */ - export function rlGetGlTextureFormats(format: number, glInternalFormat: number, glFormat: number, glType: number): void + export function rlGetGlTextureFormats(format: number, glInternalFormat: UInt32Array, glFormat: UInt32Array, glType: UInt32Array): void /** Get name string for pixel format */ export function rlGetPixelFormatName(format: number): string @@ -2849,13 +2849,13 @@ declare module "raylib" { export function rlUnloadTexture(id: number): void /** Generate mipmap data for selected texture */ - export function rlGenTextureMipmaps(id: number, width: number, height: number, format: number, mipmaps: number): void + export function rlGenTextureMipmaps(id: number, width: number, height: number, format: number, mipmaps: Int32Array): void /** Read texture pixel data */ export function rlReadTexturePixels(id: number, width: number, height: number, format: number): number /** Read screen pixel data (color buffer) */ - export function rlReadScreenPixels(width: number, height: number): Buffer + export function rlReadScreenPixels(width: number, height: number): UInt8Array /** Load an empty framebuffer */ export function rlLoadFramebuffer(width: number, height: number): number @@ -2897,7 +2897,7 @@ declare module "raylib" { export function rlSetUniformSampler(locIndex: number, textureId: number): void /** Set shader currently active (id and locations) */ - export function rlSetShader(id: number, locs: number): void + export function rlSetShader(id: number, locs: Int32Array): void /** Load compute shader program */ export function rlLoadComputeShaderProgram(shaderId: number): number diff --git a/src/generated/node-raylib.js b/src/generated/node-raylib.js index 7b793ae..a42c94d 100644 --- a/src/generated/node-raylib.js +++ b/src/generated/node-raylib.js @@ -1381,7 +1381,7 @@ raylib.OpenURL = OpenURL * @param {string} fileName * @param {number} bytesRead * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function LoadFileData (fileName, bytesRead) { return r.BindLoadFileData( @@ -1394,7 +1394,7 @@ raylib.LoadFileData = LoadFileData /** * Unload file data allocated by LoadFileData() * - * @param {Buffer} data + * @param {UInt8Array} data * * @return {undefined} */ @@ -1426,7 +1426,7 @@ raylib.SaveFileData = SaveFileData /** * Export data to code (.h), returns true on success * - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} size * @param {string} fileName * @@ -1762,11 +1762,11 @@ raylib.GetFileModTime = GetFileModTime /** * Compress data (DEFLATE algorithm), memory must be MemFree() * - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} dataSize * @param {number} compDataSize * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function CompressData (data, dataSize, compDataSize) { return r.BindCompressData( @@ -1780,11 +1780,11 @@ raylib.CompressData = CompressData /** * Decompress data (DEFLATE algorithm), memory must be MemFree() * - * @param {Buffer} compData + * @param {UInt8Array} compData * @param {number} compDataSize * @param {number} dataSize * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function DecompressData (compData, compDataSize, dataSize) { return r.BindDecompressData( @@ -1798,7 +1798,7 @@ raylib.DecompressData = DecompressData /** * Encode data to Base64 string, memory must be MemFree() * - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} dataSize * @param {number} outputSize * @@ -1816,10 +1816,10 @@ raylib.EncodeDataBase64 = EncodeDataBase64 /** * Decode Base64 string data, memory must be MemFree() * - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} outputSize * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function DecodeDataBase64 (data, outputSize) { return r.BindDecodeDataBase64( @@ -3664,7 +3664,7 @@ raylib.LoadImageAnim = LoadImageAnim * Load image from memory buffer, fileType refers to extension: i.e. '.png' * * @param {string} fileType - * @param {Buffer} fileData + * @param {UInt8Array} fileData * @param {number} dataSize * * @return {Image} The resulting Image. @@ -5001,7 +5001,7 @@ raylib.LoadFont = LoadFont * * @param {string} fileName * @param {number} fontSize - * @param {number} fontChars + * @param {Int32Array} fontChars * @param {number} glyphCount * * @return {Font} The resulting Font. @@ -5045,10 +5045,10 @@ raylib.LoadFontFromImage = LoadFontFromImage * Load font from memory buffer, fileType refers to extension: i.e. '.ttf' * * @param {string} fileType - * @param {Buffer} fileData + * @param {UInt8Array} fileData * @param {number} dataSize * @param {number} fontSize - * @param {number} fontChars + * @param {Int32Array} fontChars * @param {number} glyphCount * * @return {Font} The resulting Font. @@ -5091,10 +5091,10 @@ raylib.IsFontReady = IsFontReady /** * Load font data for further use * - * @param {Buffer} fileData + * @param {UInt8Array} fileData * @param {number} dataSize * @param {number} fontSize - * @param {number} fontChars + * @param {Int32Array} fontChars * @param {number} glyphCount * @param {number} type * @@ -5359,7 +5359,7 @@ raylib.DrawTextCodepoint = DrawTextCodepoint * Draw multiple character (codepoint) * * @param {Font} font - * @param {number} codepoints + * @param {Int32Array} codepoints * @param {number} count * @param {Vector2} position * @param {number} fontSize @@ -5517,7 +5517,7 @@ raylib.GetGlyphAtlasRec = GetGlyphAtlasRec /** * Load UTF-8 text encoded from codepoints array * - * @param {number} codepoints + * @param {Int32Array} codepoints * @param {number} length * * @return {string} The resulting char *. @@ -5550,7 +5550,7 @@ raylib.UnloadUTF8 = UnloadUTF8 * @param {string} text * @param {number} count * - * @return {number} The resulting int *. + * @return {Int32Array} The resulting int *. */ function LoadCodepoints (text, count) { return r.BindLoadCodepoints( @@ -5563,7 +5563,7 @@ raylib.LoadCodepoints = LoadCodepoints /** * Unload codepoints data from memory * - * @param {number} codepoints + * @param {Int32Array} codepoints * * @return {undefined} */ @@ -5640,7 +5640,7 @@ raylib.GetCodepointPrevious = GetCodepointPrevious * Encode one codepoint into UTF-8 byte array (array length returned as parameter) * * @param {number} codepoint - * @param {number} utf8Size + * @param {Int32Array} utf8Size * * @return {string} The resulting const char *. */ @@ -7732,7 +7732,7 @@ raylib.LoadWave = LoadWave * Load wave from memory buffer, fileType refers to extension: i.e. '.wav' * * @param {string} fileType - * @param {Buffer} fileData + * @param {UInt8Array} fileData * @param {number} dataSize * * @return {Wave} The resulting Wave. @@ -8096,7 +8096,7 @@ raylib.WaveCopy = WaveCopy * * @param {Wave} wave * - * @return {number} The resulting float *. + * @return {Float32Array} The resulting float *. */ function LoadWaveSamples (wave) { return r.BindLoadWaveSamples( @@ -8112,7 +8112,7 @@ raylib.LoadWaveSamples = LoadWaveSamples /** * Unload samples data loaded with LoadWaveSamples() * - * @param {number} samples + * @param {Float32Array} samples * * @return {undefined} */ @@ -8141,7 +8141,7 @@ raylib.LoadMusicStream = LoadMusicStream * Load music stream from data * * @param {string} fileType - * @param {Buffer} data + * @param {UInt8Array} data * @param {number} dataSize * * @return {Music} The resulting Music. @@ -10797,7 +10797,7 @@ raylib.GuiPanel = GuiPanel * @param {Rectangle} bounds * @param {number} text * @param {number} count - * @param {number} active + * @param {Int32Array} active * * @return {number} The resulting int. */ @@ -10986,7 +10986,7 @@ raylib.GuiComboBox = GuiComboBox * * @param {Rectangle} bounds * @param {string} text - * @param {number} active + * @param {Int32Array} active * @param {boolean} editMode * * @return {boolean} The resulting bool. @@ -11009,7 +11009,7 @@ raylib.GuiDropdownBox = GuiDropdownBox * * @param {Rectangle} bounds * @param {string} text - * @param {number} value + * @param {Int32Array} value * @param {number} minValue * @param {number} maxValue * @param {boolean} editMode @@ -11036,7 +11036,7 @@ raylib.GuiSpinner = GuiSpinner * * @param {Rectangle} bounds * @param {string} text - * @param {number} value + * @param {Int32Array} value * @param {number} minValue * @param {number} maxValue * @param {boolean} editMode @@ -11251,7 +11251,7 @@ raylib.GuiGrid = GuiGrid * * @param {Rectangle} bounds * @param {string} text - * @param {number} scrollIndex + * @param {Int32Array} scrollIndex * @param {number} active * * @return {number} The resulting int. @@ -11275,8 +11275,8 @@ raylib.GuiListView = GuiListView * @param {Rectangle} bounds * @param {number} text * @param {number} count - * @param {number} focus - * @param {number} scrollIndex + * @param {Int32Array} focus + * @param {Int32Array} scrollIndex * @param {number} active * * @return {number} The resulting int. @@ -11328,7 +11328,7 @@ raylib.GuiMessageBox = GuiMessageBox * @param {string} buttons * @param {string} text * @param {number} textMaxSize - * @param {number} secretViewActive + * @param {Int32Array} secretViewActive * * @return {number} The resulting int. */ @@ -11515,7 +11515,7 @@ raylib.GuiIconText = GuiIconText /** * Get raygui icons data pointer * - * @return {number} The resulting unsigned int *. + * @return {UInt32Array} The resulting unsigned int *. */ function GuiGetIcons () { return r.BindGuiGetIcons() @@ -11669,7 +11669,7 @@ raylib.rlScalef = rlScalef /** * Multiply the current matrix by another matrix * - * @param {number} matf + * @param {Float32Array} matf * * @return {undefined} */ @@ -12595,7 +12595,7 @@ raylib.rlGetShaderIdDefault = rlGetShaderIdDefault /** * Get default shader locations * - * @return {number} The resulting int *. + * @return {Int32Array} The resulting int *. */ function rlGetShaderLocsDefault () { return r.BindrlGetShaderLocsDefault() @@ -12967,9 +12967,9 @@ raylib.rlUpdateTexture = rlUpdateTexture * Get OpenGL internal formats * * @param {number} format - * @param {number} glInternalFormat - * @param {number} glFormat - * @param {number} glType + * @param {UInt32Array} glInternalFormat + * @param {UInt32Array} glFormat + * @param {UInt32Array} glType * * @return {undefined} */ @@ -13018,7 +13018,7 @@ raylib.rlUnloadTexture = rlUnloadTexture * @param {number} width * @param {number} height * @param {number} format - * @param {number} mipmaps + * @param {Int32Array} mipmaps * * @return {undefined} */ @@ -13059,7 +13059,7 @@ raylib.rlReadTexturePixels = rlReadTexturePixels * @param {number} width * @param {number} height * - * @return {Buffer} The resulting unsigned char *. + * @return {UInt8Array} The resulting unsigned char *. */ function rlReadScreenPixels (width, height) { return r.BindrlReadScreenPixels( @@ -13300,7 +13300,7 @@ raylib.rlSetUniformSampler = rlSetUniformSampler * Set shader currently active (id and locations) * * @param {number} id - * @param {number} locs + * @param {Int32Array} locs * * @return {undefined} */ diff --git a/tools/generate_templates/ArgumentTypeConversion.js b/tools/generate_templates/ArgumentTypeConversion.js index e8ebf67..db973fa 100644 --- a/tools/generate_templates/ArgumentTypeConversion.js +++ b/tools/generate_templates/ArgumentTypeConversion.js @@ -1,6 +1,47 @@ -function ArgumentTypeConversion (arg) { - if (arg === 'const unsigned char *') { return 'Buffer' } - if (arg === 'unsigned char *') { return 'Buffer' } + +// Some raylib functions expect the last argument to be a pointer +// to a number that it will update after completing an operation, usually +// when its reading a large chunk of data. for example LoadImagePalette or CompressData +const ints = [ + 'bytesRead', // LoadFileData + 'compDataSize', // CompressData + 'dataSize', // DecompressData + 'outputSize', // En/De codeDataBase64 + 'frames', // LoadImageAnim + 'colorCount', // LoadImagePalette + 'count', // LoadCodepoints, TextSplit + 'codepointSize', // GetCodepoint, GetCodepointNext, GetCodepointPrevious + 'position', // TextAppend + 'materialCount', // LoadMaterials + 'animCount' // LoadModelAnimations +] + +function ArgumentTypeConversion (arg, name = '') { + if (arg === 'float *') { return 'Float32Array' } + if (arg === 'const float *') { return 'Float32Array' } + + // we check for when int and unsigned int * are meant to only reference one int, not an array + // so far it's based on name but I'm not sure if theres another way + if (arg === 'int *') { + if (ints.includes(name)) { return 'number' } + return 'Int32Array' + } + if (arg === 'const int *') { return 'Int32Array' } + + if (arg === 'unsigned int *') { + if (ints.includes(name)) { return 'number' } + return 'UInt32Array' + } + if (arg === 'const unsigned int *') { return 'UInt32Array' } + + if (arg === 'short *') { return 'Int16Array' } + if (arg === 'const short *') { return 'Int16Array' } + + if (arg === 'unsigned short *') { return 'UInt16Array' } + if (arg === 'const unsigned short *') { return 'UInt16Array' } + + if (arg === 'unsigned char *') { return 'UInt8Array' } + if (arg === 'const unsigned char *') { return 'UInt8Array' } if (arg === 'char') { return 'string' } if (arg === 'char *') { return 'string' } diff --git a/tools/generate_templates/node-raylib-bindings.js b/tools/generate_templates/node-raylib-bindings.js index 68f90c9..0106ff8 100644 --- a/tools/generate_templates/node-raylib-bindings.js +++ b/tools/generate_templates/node-raylib-bindings.js @@ -1,47 +1,87 @@ +// Some raylib functions expect the last argument to be a pointer +// to a number that it will update after completing an operation, usually +// when its reading a large chunk of data. for example LoadImagePalette or CompressData +const ints = [ + 'bytesRead', // LoadFileData + 'compDataSize', // CompressData + 'dataSize', // DecompressData + 'outputSize', // En/De codeDataBase64 + 'frames', // LoadImageAnim + 'colorCount', // LoadImagePalette + 'count', // LoadCodepoints, TextSplit + 'codepointSize', // GetCodepoint, GetCodepointNext, GetCodepointPrevious + 'position', // TextAppend + 'materialCount', // LoadMaterials + 'animCount' // LoadModelAnimations +] + /** * Sanitizes a type (primitive or struct) into a string that can be used as part of a function name. * Converts anything ending with '*' to 'pointer' * @param {*} name * @returns */ -const SanitizeTypeName = name => { - if (name === 'const Vector3') { +const SanitizeTypeName = (type, name = '') => { + if (type === 'const Vector3') { return 'Vector3' } - if (name === 'float[2]') { + if (type === 'float[2]') { return 'pointer' } - if (name === 'char[32]') { + if (type === 'char[32]') { return 'pointer' } - if (name === 'float[4]') { + if (type === 'float[4]') { return 'pointer' } - if (name === 'unsigned int[4]') { + if (type === 'unsigned int[4]') { return '(unsigned int) pointer' } - if (name === 'Matrix[2]') { + if (type === 'Matrix[2]') { return 'pointer' } - if (name === 'const char *') { + if (type === 'const char *') { return 'string' } - if (name.endsWith('*')) { + + if (type === 'float *') { return 'Float32Array' } + if (type === 'const float *') { return 'Float32Array' } + + if (type === 'int *' && !ints.includes(name)) { return 'Int32Array' } + if (type === 'const int *') { return 'Int32Array' } + + if (type === 'unsigned int *' && !ints.includes(name)) { return 'UInt32Array' } + if (type === 'const unsigned int *') { return 'UInt32Array' } + + if (type === 'short *') { return 'Int16Array' } + if (type === 'const short *') { return 'Int16Array' } + + if (type === 'unsigned short *') { return 'UInt16Array' } + if (type === 'const unsigned short *') { return 'UInt16Array' } + + if (type === 'const unsigned char *') { + return 'UInt8Array' + } + if (type === 'unsigned char *') { + return 'UInt8Array' + } + + if (type.endsWith('*')) { return 'pointer' } - if (name.endsWith('Callback')) { + if (type.endsWith('Callback')) { return 'function' } - if (name === 'Camera') { + if (type === 'Camera') { return 'Camera3D' } - if (name === 'Quaternion') { + if (type === 'Quaternion') { return 'Vector4' } - if (name === 'Texture2D') { + if (type === 'Texture2D') { return 'Texture' } - return name.replace(/ /g, '') + return type.replace(/ /g, '') } const TypeUnwrappedLength = (structs, type) => { @@ -82,7 +122,7 @@ const UnwrappedFuncArguments = (structs, func) => { return func.params .map(param => { - const out = `${param.type.endsWith('*') ? ` (${param.type})` : ''} ${SanitizeTypeName(param.type)}FromValue(info, ${length})` + const out = `${param.type.endsWith('*') ? ` (${param.type})` : ''} ${SanitizeTypeName(param.type, param.name)}FromValue(info, ${length})` length += TypeUnwrappedLength(structs, param.type) return out }) @@ -238,9 +278,30 @@ inline int intFromValue(const Napi::CallbackInfo& info, int index) { inline double doubleFromValue(const Napi::CallbackInfo& info, int index) { return info[index].As().DoubleValue(); } + uintptr_t pointerFromValue(const Napi::CallbackInfo& info, int index) { return (uintptr_t) info[index].As().Int64Value(); } + +uintptr_t Float32ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t Int32ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t UInt32ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t Int16ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t UInt16ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} +uintptr_t UInt8ArrayFromValue(const Napi::CallbackInfo& info, int index) { + return (uintptr_t)info[index].As().Data(); +} + inline unsigned char unsignedcharFromValue(const Napi::CallbackInfo& info, int index) { return info[index].As().Uint32Value(); } diff --git a/tools/generate_templates/node-raylib-definitions.js b/tools/generate_templates/node-raylib-definitions.js index c8b5021..d341797 100644 --- a/tools/generate_templates/node-raylib-definitions.js +++ b/tools/generate_templates/node-raylib-definitions.js @@ -5,7 +5,7 @@ const FunctionDefinition = (func) => { export function ${func.name}(${!func.params ? '' : func.params - .map(param => `${param.name}: ${ArgumentTypeConversion(param.type)}`) + .map(param => `${param.name}: ${ArgumentTypeConversion(param.type, param.name)}`) .join(', ') }): ${ArgumentTypeConversion(func.returnType)} ` diff --git a/tools/generate_templates/node-raylib-wrapper.js b/tools/generate_templates/node-raylib-wrapper.js index ee39dd9..387d1a3 100644 --- a/tools/generate_templates/node-raylib-wrapper.js +++ b/tools/generate_templates/node-raylib-wrapper.js @@ -45,7 +45,7 @@ const JSDocsForFunction = (structs, func) => { if (func.params) { params = '\n *' for (const param of func.params) { - params += `\n * @param {${ArgumentTypeConversion(param.type)}} ${param.name}` + params += `\n * @param {${ArgumentTypeConversion(param.type, param.name)}} ${param.name}` } }