raylib-wasm
Version:
Make raylib games in JS for the web
1,943 lines (1,499 loc) • 373 kB
JavaScript
import Module from './raylib_emscripten.js'
import RaylibComponent from './raylib_wc.js'
document.addEventListener('DOMContentLoaded', () => {
window.customElements.define('raylib-game', RaylibComponent)
})
const importLocation = document?.location?.toString()
// run this function before calling anything
export async function raylib_run(canvas, userInit, userUpdate, wasmBinary) {
const raylib = {}
if (!wasmBinary) {
wasmBinary = new Uint8Array(await fetch(import.meta.url.replace('raylib.js', 'raylib.wasm')).then(r => r.arrayBuffer()))
}
const mod = await Module({canvas, wasmBinary})
raylib.mod = mod
// Vector2, 2 components
raylib.Vector2 = class Vector2 {
constructor(init = {}, _address) {
this._size = 8
this._address = _address || mod._malloc(this._size)
this.x = init.x || 0
this.y = init.y || 0
}
get x () {
return mod.getValue(this._address + 0, 'float')
}
set x (x) {
mod.setValue(this._address + 0, x, 'float')
}
get y () {
return mod.getValue(this._address + 4, 'float')
}
set y (y) {
mod.setValue(this._address + 4, y, 'float')
}
}
// Vector3, 3 components
raylib.Vector3 = class Vector3 {
constructor(init = {}, _address) {
this._size = 12
this._address = _address || mod._malloc(this._size)
this.x = init.x || 0
this.y = init.y || 0
this.z = init.z || 0
}
get x () {
return mod.getValue(this._address + 0, 'float')
}
set x (x) {
mod.setValue(this._address + 0, x, 'float')
}
get y () {
return mod.getValue(this._address + 4, 'float')
}
set y (y) {
mod.setValue(this._address + 4, y, 'float')
}
get z () {
return mod.getValue(this._address + 8, 'float')
}
set z (z) {
mod.setValue(this._address + 8, z, 'float')
}
}
// Vector4, 4 components
raylib.Vector4 = class Vector4 {
constructor(init = {}, _address) {
this._size = 16
this._address = _address || mod._malloc(this._size)
this.x = init.x || 0
this.y = init.y || 0
this.z = init.z || 0
this.w = init.w || 0
}
get x () {
return mod.getValue(this._address + 0, 'float')
}
set x (x) {
mod.setValue(this._address + 0, x, 'float')
}
get y () {
return mod.getValue(this._address + 4, 'float')
}
set y (y) {
mod.setValue(this._address + 4, y, 'float')
}
get z () {
return mod.getValue(this._address + 8, 'float')
}
set z (z) {
mod.setValue(this._address + 8, z, 'float')
}
get w () {
return mod.getValue(this._address + 12, 'float')
}
set w (w) {
mod.setValue(this._address + 12, w, 'float')
}
}
// Matrix, 4x4 components, column major, OpenGL style, right-handed
raylib.Matrix = class Matrix {
constructor(init = {}, _address) {
this._size = 64
this._address = _address || mod._malloc(this._size)
this.m0 = init.m0 || 0
this.m4 = init.m4 || 0
this.m8 = init.m8 || 0
this.m12 = init.m12 || 0
this.m1 = init.m1 || 0
this.m5 = init.m5 || 0
this.m9 = init.m9 || 0
this.m13 = init.m13 || 0
this.m2 = init.m2 || 0
this.m6 = init.m6 || 0
this.m10 = init.m10 || 0
this.m14 = init.m14 || 0
this.m3 = init.m3 || 0
this.m7 = init.m7 || 0
this.m11 = init.m11 || 0
this.m15 = init.m15 || 0
}
get m0 () {
return mod.getValue(this._address + 0, 'float')
}
set m0 (m0) {
mod.setValue(this._address + 0, m0, 'float')
}
get m4 () {
return mod.getValue(this._address + 4, 'float')
}
set m4 (m4) {
mod.setValue(this._address + 4, m4, 'float')
}
get m8 () {
return mod.getValue(this._address + 8, 'float')
}
set m8 (m8) {
mod.setValue(this._address + 8, m8, 'float')
}
get m12 () {
return mod.getValue(this._address + 12, 'float')
}
set m12 (m12) {
mod.setValue(this._address + 12, m12, 'float')
}
get m1 () {
return mod.getValue(this._address + 16, 'float')
}
set m1 (m1) {
mod.setValue(this._address + 16, m1, 'float')
}
get m5 () {
return mod.getValue(this._address + 20, 'float')
}
set m5 (m5) {
mod.setValue(this._address + 20, m5, 'float')
}
get m9 () {
return mod.getValue(this._address + 24, 'float')
}
set m9 (m9) {
mod.setValue(this._address + 24, m9, 'float')
}
get m13 () {
return mod.getValue(this._address + 28, 'float')
}
set m13 (m13) {
mod.setValue(this._address + 28, m13, 'float')
}
get m2 () {
return mod.getValue(this._address + 32, 'float')
}
set m2 (m2) {
mod.setValue(this._address + 32, m2, 'float')
}
get m6 () {
return mod.getValue(this._address + 36, 'float')
}
set m6 (m6) {
mod.setValue(this._address + 36, m6, 'float')
}
get m10 () {
return mod.getValue(this._address + 40, 'float')
}
set m10 (m10) {
mod.setValue(this._address + 40, m10, 'float')
}
get m14 () {
return mod.getValue(this._address + 44, 'float')
}
set m14 (m14) {
mod.setValue(this._address + 44, m14, 'float')
}
get m3 () {
return mod.getValue(this._address + 48, 'float')
}
set m3 (m3) {
mod.setValue(this._address + 48, m3, 'float')
}
get m7 () {
return mod.getValue(this._address + 52, 'float')
}
set m7 (m7) {
mod.setValue(this._address + 52, m7, 'float')
}
get m11 () {
return mod.getValue(this._address + 56, 'float')
}
set m11 (m11) {
mod.setValue(this._address + 56, m11, 'float')
}
get m15 () {
return mod.getValue(this._address + 60, 'float')
}
set m15 (m15) {
mod.setValue(this._address + 60, m15, 'float')
}
}
// Color, 4 components, R8G8B8A8 (32bit)
raylib.Color = class Color {
constructor(init = {}, _address) {
this._size = 4
this._address = _address || mod._malloc(this._size)
this.r = init.r || 0
this.g = init.g || 0
this.b = init.b || 0
this.a = init.a || 0
}
get r () {
return mod.HEAPU8[this._address + 0]
}
set r (r) {
mod.HEAPU8[this._address + 0] = r
}
get g () {
return mod.HEAPU8[this._address + 1]
}
set g (g) {
mod.HEAPU8[this._address + 1] = g
}
get b () {
return mod.HEAPU8[this._address + 2]
}
set b (b) {
mod.HEAPU8[this._address + 2] = b
}
get a () {
return mod.HEAPU8[this._address + 3]
}
set a (a) {
mod.HEAPU8[this._address + 3] = a
}
}
// Rectangle, 4 components
raylib.Rectangle = class Rectangle {
constructor(init = {}, _address) {
this._size = 16
this._address = _address || mod._malloc(this._size)
this.x = init.x || 0
this.y = init.y || 0
this.width = init.width || 0
this.height = init.height || 0
}
get x () {
return mod.getValue(this._address + 0, 'float')
}
set x (x) {
mod.setValue(this._address + 0, x, 'float')
}
get y () {
return mod.getValue(this._address + 4, 'float')
}
set y (y) {
mod.setValue(this._address + 4, y, 'float')
}
get width () {
return mod.getValue(this._address + 8, 'float')
}
set width (width) {
mod.setValue(this._address + 8, width, 'float')
}
get height () {
return mod.getValue(this._address + 12, 'float')
}
set height (height) {
mod.setValue(this._address + 12, height, 'float')
}
}
// Image, pixel data stored in CPU memory (RAM)
raylib.Image = class Image {
constructor(init = {}, _address) {
this._size = 20
this._address = _address || mod._malloc(this._size)
this.data = init.data || 0
this.width = init.width || 0
this.height = init.height || 0
this.mipmaps = init.mipmaps || 0
this.format = init.format || 0
}
get data () {
return mod.getValue(this._address + 0, '*')
}
set data (data) {
mod.setValue(this._address + 0, data, '*')
}
get width () {
return mod.getValue(this._address + 4, 'i32')
}
set width (width) {
mod.setValue(this._address + 4, width, 'i32')
}
get height () {
return mod.getValue(this._address + 8, 'i32')
}
set height (height) {
mod.setValue(this._address + 8, height, 'i32')
}
get mipmaps () {
return mod.getValue(this._address + 12, 'i32')
}
set mipmaps (mipmaps) {
mod.setValue(this._address + 12, mipmaps, 'i32')
}
get format () {
return mod.getValue(this._address + 16, 'i32')
}
set format (format) {
mod.setValue(this._address + 16, format, 'i32')
}
}
// Texture, tex data stored in GPU memory (VRAM)
raylib.Texture = class Texture {
constructor(init = {}, _address) {
this._size = 20
this._address = _address || mod._malloc(this._size)
this.id = init.id || 0
this.width = init.width || 0
this.height = init.height || 0
this.mipmaps = init.mipmaps || 0
this.format = init.format || 0
}
get id () {
return mod.HEAPU32[this._address + 0]
}
set id (id) {
mod.HEAPU32[this._address + 0] = id
}
get width () {
return mod.getValue(this._address + 4, 'i32')
}
set width (width) {
mod.setValue(this._address + 4, width, 'i32')
}
get height () {
return mod.getValue(this._address + 8, 'i32')
}
set height (height) {
mod.setValue(this._address + 8, height, 'i32')
}
get mipmaps () {
return mod.getValue(this._address + 12, 'i32')
}
set mipmaps (mipmaps) {
mod.setValue(this._address + 12, mipmaps, 'i32')
}
get format () {
return mod.getValue(this._address + 16, 'i32')
}
set format (format) {
mod.setValue(this._address + 16, format, 'i32')
}
}
// RenderTexture, fbo for texture rendering
raylib.RenderTexture = class RenderTexture {
constructor(init = {}, _address) {
this._size = 44
this._address = _address || mod._malloc(this._size)
this.id = init.id || 0
this.texture = new raylib.Texture(init.texture || {}, this._address + 4)
this.depth = new raylib.Texture(init.depth || {}, this._address + 24)
}
get id () {
return mod.HEAPU32[this._address + 0]
}
set id (id) {
mod.HEAPU32[this._address + 0] = id
}
}
// NPatchInfo, n-patch layout info
raylib.NPatchInfo = class NPatchInfo {
constructor(init = {}, _address) {
this._size = 36
this._address = _address || mod._malloc(this._size)
this.source = new raylib.Rectangle(init.source || {}, this._address + 0)
this.left = init.left || 0
this.top = init.top || 0
this.right = init.right || 0
this.bottom = init.bottom || 0
this.layout = init.layout || 0
}
get left () {
return mod.getValue(this._address + 16, 'i32')
}
set left (left) {
mod.setValue(this._address + 16, left, 'i32')
}
get top () {
return mod.getValue(this._address + 20, 'i32')
}
set top (top) {
mod.setValue(this._address + 20, top, 'i32')
}
get right () {
return mod.getValue(this._address + 24, 'i32')
}
set right (right) {
mod.setValue(this._address + 24, right, 'i32')
}
get bottom () {
return mod.getValue(this._address + 28, 'i32')
}
set bottom (bottom) {
mod.setValue(this._address + 28, bottom, 'i32')
}
get layout () {
return mod.getValue(this._address + 32, 'i32')
}
set layout (layout) {
mod.setValue(this._address + 32, layout, 'i32')
}
}
// GlyphInfo, font characters glyphs info
raylib.GlyphInfo = class GlyphInfo {
constructor(init = {}, _address) {
this._size = 36
this._address = _address || mod._malloc(this._size)
this.value = init.value || 0
this.offsetX = init.offsetX || 0
this.offsetY = init.offsetY || 0
this.advanceX = init.advanceX || 0
this.image = new raylib.Image(init.image || {}, this._address + 16)
}
get value () {
return mod.getValue(this._address + 0, 'i32')
}
set value (value) {
mod.setValue(this._address + 0, value, 'i32')
}
get offsetX () {
return mod.getValue(this._address + 4, 'i32')
}
set offsetX (offsetX) {
mod.setValue(this._address + 4, offsetX, 'i32')
}
get offsetY () {
return mod.getValue(this._address + 8, 'i32')
}
set offsetY (offsetY) {
mod.setValue(this._address + 8, offsetY, 'i32')
}
get advanceX () {
return mod.getValue(this._address + 12, 'i32')
}
set advanceX (advanceX) {
mod.setValue(this._address + 12, advanceX, 'i32')
}
}
// Font, font texture and GlyphInfo array data
raylib.Font = class Font {
constructor(init = {}, _address) {
this._size = 40
this._address = _address || mod._malloc(this._size)
this.baseSize = init.baseSize || 0
this.glyphCount = init.glyphCount || 0
this.glyphPadding = init.glyphPadding || 0
this.texture = new raylib.Texture2D(init.texture || {}, this._address + 12)
this.recs = new raylib.Rectangle(init.recs || {}, this._address + 32)
this.glyphs = new raylib.GlyphInfo(init.glyphs || {}, this._address + 36)
}
get baseSize () {
return mod.getValue(this._address + 0, 'i32')
}
set baseSize (baseSize) {
mod.setValue(this._address + 0, baseSize, 'i32')
}
get glyphCount () {
return mod.getValue(this._address + 4, 'i32')
}
set glyphCount (glyphCount) {
mod.setValue(this._address + 4, glyphCount, 'i32')
}
get glyphPadding () {
return mod.getValue(this._address + 8, 'i32')
}
set glyphPadding (glyphPadding) {
mod.setValue(this._address + 8, glyphPadding, 'i32')
}
}
// Camera, defines position/orientation in 3d space
raylib.Camera3D = class Camera3D {
constructor(init = {}, _address) {
this._size = 44
this._address = _address || mod._malloc(this._size)
this.position = new raylib.Vector3(init.position || {}, this._address + 0)
this.target = new raylib.Vector3(init.target || {}, this._address + 12)
this.up = new raylib.Vector3(init.up || {}, this._address + 24)
this.fovy = init.fovy || 0
this.projection = init.projection || 0
}
get fovy () {
return mod.getValue(this._address + 36, 'float')
}
set fovy (fovy) {
mod.setValue(this._address + 36, fovy, 'float')
}
get projection () {
return mod.getValue(this._address + 40, 'i32')
}
set projection (projection) {
mod.setValue(this._address + 40, projection, 'i32')
}
}
// Camera2D, defines position/orientation in 2d space
raylib.Camera2D = class Camera2D {
constructor(init = {}, _address) {
this._size = 24
this._address = _address || mod._malloc(this._size)
this.offset = new raylib.Vector2(init.offset || {}, this._address + 0)
this.target = new raylib.Vector2(init.target || {}, this._address + 8)
this.rotation = init.rotation || 0
this.zoom = init.zoom || 0
}
get rotation () {
return mod.getValue(this._address + 16, 'float')
}
set rotation (rotation) {
mod.setValue(this._address + 16, rotation, 'float')
}
get zoom () {
return mod.getValue(this._address + 20, 'float')
}
set zoom (zoom) {
mod.setValue(this._address + 20, zoom, 'float')
}
}
// Mesh, vertex data and vao/vbo
raylib.Mesh = class Mesh {
constructor(init = {}, _address) {
this._size = 68
this._address = _address || mod._malloc(this._size)
this.vertexCount = init.vertexCount || 0
this.triangleCount = init.triangleCount || 0
this.vertices = init.vertices || 0
this.texcoords = init.texcoords || 0
this.texcoords2 = init.texcoords2 || 0
this.normals = init.normals || 0
this.tangents = init.tangents || 0
this.colors = init.colors || 0
this.indices = init.indices || 0
this.animVertices = init.animVertices || 0
this.animNormals = init.animNormals || 0
this.boneIds = init.boneIds || 0
this.boneWeights = init.boneWeights || 0
this.boneMatrices = new raylib.Matrix(init.boneMatrices || {}, this._address + 52)
this.boneCount = init.boneCount || 0
this.vaoId = init.vaoId || 0
this.vboId = init.vboId || 0
}
get vertexCount () {
return mod.getValue(this._address + 0, 'i32')
}
set vertexCount (vertexCount) {
mod.setValue(this._address + 0, vertexCount, 'i32')
}
get triangleCount () {
return mod.getValue(this._address + 4, 'i32')
}
set triangleCount (triangleCount) {
mod.setValue(this._address + 4, triangleCount, 'i32')
}
get vertices () {
return mod.getValue(this._address + 8, '*')
}
set vertices (vertices) {
mod.setValue(this._address + 8, vertices, '*')
}
get texcoords () {
return mod.getValue(this._address + 12, '*')
}
set texcoords (texcoords) {
mod.setValue(this._address + 12, texcoords, '*')
}
get texcoords2 () {
return mod.getValue(this._address + 16, '*')
}
set texcoords2 (texcoords2) {
mod.setValue(this._address + 16, texcoords2, '*')
}
get normals () {
return mod.getValue(this._address + 20, '*')
}
set normals (normals) {
mod.setValue(this._address + 20, normals, '*')
}
get tangents () {
return mod.getValue(this._address + 24, '*')
}
set tangents (tangents) {
mod.setValue(this._address + 24, tangents, '*')
}
get colors () {
return mod.getValue(this._address + 28, '*')
}
set colors (colors) {
mod.setValue(this._address + 28, colors, '*')
}
get indices () {
return mod.getValue(this._address + 32, '*')
}
set indices (indices) {
mod.setValue(this._address + 32, indices, '*')
}
get animVertices () {
return mod.getValue(this._address + 36, '*')
}
set animVertices (animVertices) {
mod.setValue(this._address + 36, animVertices, '*')
}
get animNormals () {
return mod.getValue(this._address + 40, '*')
}
set animNormals (animNormals) {
mod.setValue(this._address + 40, animNormals, '*')
}
get boneIds () {
return mod.getValue(this._address + 44, '*')
}
set boneIds (boneIds) {
mod.setValue(this._address + 44, boneIds, '*')
}
get boneWeights () {
return mod.getValue(this._address + 48, '*')
}
set boneWeights (boneWeights) {
mod.setValue(this._address + 48, boneWeights, '*')
}
get boneCount () {
return mod.getValue(this._address + 56, 'i32')
}
set boneCount (boneCount) {
mod.setValue(this._address + 56, boneCount, 'i32')
}
get vaoId () {
return mod.HEAPU32[this._address + 60]
}
set vaoId (vaoId) {
mod.HEAPU32[this._address + 60] = vaoId
}
get vboId () {
return mod.getValue(this._address + 64, '*')
}
set vboId (vboId) {
mod.setValue(this._address + 64, vboId, '*')
}
}
// Shader
raylib.Shader = class Shader {
constructor(init = {}, _address) {
this._size = 8
this._address = _address || mod._malloc(this._size)
this.id = init.id || 0
this.locs = init.locs || 0
}
get id () {
return mod.HEAPU32[this._address + 0]
}
set id (id) {
mod.HEAPU32[this._address + 0] = id
}
get locs () {
return mod.getValue(this._address + 4, '*')
}
set locs (locs) {
mod.setValue(this._address + 4, locs, '*')
}
}
// MaterialMap
raylib.MaterialMap = class MaterialMap {
constructor(init = {}, _address) {
this._size = 28
this._address = _address || mod._malloc(this._size)
this.texture = new raylib.Texture2D(init.texture || {}, this._address + 0)
this.color = new raylib.Color(init.color || {}, this._address + 20)
this.value = init.value || 0
}
get value () {
return mod.getValue(this._address + 24, 'float')
}
set value (value) {
mod.setValue(this._address + 24, value, 'float')
}
}
// Material, includes shader and maps
raylib.Material = class Material {
constructor(init = {}, _address) {
this._size = 28
this._address = _address || mod._malloc(this._size)
this.shader = new raylib.Shader(init.shader || {}, this._address + 0)
this.maps = new raylib.MaterialMap(init.maps || {}, this._address + 8)
this.params = init.params || [0, 0, 0, 0]
}
get params () {
return mod.getValue(this._address + 12, '*')
}
set params (params) {
mod.setValue(this._address + 12, params, '*')
}
}
// Transform, vertex transformation data
raylib.Transform = class Transform {
constructor(init = {}, _address) {
this._size = 40
this._address = _address || mod._malloc(this._size)
this.translation = new raylib.Vector3(init.translation || {}, this._address + 0)
this.rotation = new raylib.Quaternion(init.rotation || {}, this._address + 12)
this.scale = new raylib.Vector3(init.scale || {}, this._address + 28)
}
}
// Bone, skeletal animation bone
raylib.BoneInfo = class BoneInfo {
constructor(init = {}, _address) {
this._size = 36
this._address = _address || mod._malloc(this._size)
this.name = init.name || ''
this.parent = init.parent || 0
}
get name () {
return mod.UTF8ToString(this._address + 0)
}
set name (name) {
mod.stringToUTF8(this._address + 0, name)
}
get parent () {
return mod.getValue(this._address + 32, 'i32')
}
set parent (parent) {
mod.setValue(this._address + 32, parent, 'i32')
}
}
// Model, meshes, materials and animation data
raylib.Model = class Model {
constructor(init = {}, _address) {
this._size = 96
this._address = _address || mod._malloc(this._size)
this.transform = new raylib.Matrix(init.transform || {}, this._address + 0)
this.meshCount = init.meshCount || 0
this.materialCount = init.materialCount || 0
this.meshes = new raylib.Mesh(init.meshes || {}, this._address + 72)
this.materials = new raylib.Material(init.materials || {}, this._address + 76)
this.meshMaterial = init.meshMaterial || 0
this.boneCount = init.boneCount || 0
this.bones = new raylib.BoneInfo(init.bones || {}, this._address + 88)
this.bindPose = new raylib.Transform(init.bindPose || {}, this._address + 92)
}
get meshCount () {
return mod.getValue(this._address + 64, 'i32')
}
set meshCount (meshCount) {
mod.setValue(this._address + 64, meshCount, 'i32')
}
get materialCount () {
return mod.getValue(this._address + 68, 'i32')
}
set materialCount (materialCount) {
mod.setValue(this._address + 68, materialCount, 'i32')
}
get meshMaterial () {
return mod.getValue(this._address + 80, '*')
}
set meshMaterial (meshMaterial) {
mod.setValue(this._address + 80, meshMaterial, '*')
}
get boneCount () {
return mod.getValue(this._address + 84, 'i32')
}
set boneCount (boneCount) {
mod.setValue(this._address + 84, boneCount, 'i32')
}
}
// ModelAnimation
raylib.ModelAnimation = class ModelAnimation {
constructor(init = {}, _address) {
this._size = 48
this._address = _address || mod._malloc(this._size)
this.boneCount = init.boneCount || 0
this.frameCount = init.frameCount || 0
this.bones = new raylib.BoneInfo(init.bones || {}, this._address + 8)
this.framePoses = init.framePoses || new raylib.Transform()
this.name = init.name || ''
}
get boneCount () {
return mod.getValue(this._address + 0, 'i32')
}
set boneCount (boneCount) {
mod.setValue(this._address + 0, boneCount, 'i32')
}
get frameCount () {
return mod.getValue(this._address + 4, 'i32')
}
set frameCount (frameCount) {
mod.setValue(this._address + 4, frameCount, 'i32')
}
get framePoses () {
return mod.getValue(this._address + 12, '*')
}
set framePoses (framePoses) {
mod.setValue(this._address + 12, framePoses, '*')
}
get name () {
return mod.UTF8ToString(this._address + 16)
}
set name (name) {
mod.stringToUTF8(this._address + 16, name)
}
}
// Ray, ray for raycasting
raylib.Ray = class Ray {
constructor(init = {}, _address) {
this._size = 24
this._address = _address || mod._malloc(this._size)
this.position = new raylib.Vector3(init.position || {}, this._address + 0)
this.direction = new raylib.Vector3(init.direction || {}, this._address + 12)
}
}
// RayCollision, ray hit information
raylib.RayCollision = class RayCollision {
constructor(init = {}, _address) {
this._size = 29
this._address = _address || mod._malloc(this._size)
this.hit = init.hit || 0
this.distance = init.distance || 0
this.point = new raylib.Vector3(init.point || {}, this._address + 5)
this.normal = new raylib.Vector3(init.normal || {}, this._address + 17)
}
get hit () {
return mod.getValue(this._address + 0, 'i1')
}
set hit (hit) {
mod.setValue(this._address + 0, hit, 'i1')
}
get distance () {
return mod.getValue(this._address + 1, 'float')
}
set distance (distance) {
mod.setValue(this._address + 1, distance, 'float')
}
}
// BoundingBox
raylib.BoundingBox = class BoundingBox {
constructor(init = {}, _address) {
this._size = 24
this._address = _address || mod._malloc(this._size)
this.min = new raylib.Vector3(init.min || {}, this._address + 0)
this.max = new raylib.Vector3(init.max || {}, this._address + 12)
}
}
// Wave, audio wave data
raylib.Wave = class Wave {
constructor(init = {}, _address) {
this._size = 20
this._address = _address || mod._malloc(this._size)
this.frameCount = init.frameCount || 0
this.sampleRate = init.sampleRate || 0
this.sampleSize = init.sampleSize || 0
this.channels = init.channels || 0
this.data = init.data || 0
}
get frameCount () {
return mod.HEAPU32[this._address + 0]
}
set frameCount (frameCount) {
mod.HEAPU32[this._address + 0] = frameCount
}
get sampleRate () {
return mod.HEAPU32[this._address + 4]
}
set sampleRate (sampleRate) {
mod.HEAPU32[this._address + 4] = sampleRate
}
get sampleSize () {
return mod.HEAPU32[this._address + 8]
}
set sampleSize (sampleSize) {
mod.HEAPU32[this._address + 8] = sampleSize
}
get channels () {
return mod.HEAPU32[this._address + 12]
}
set channels (channels) {
mod.HEAPU32[this._address + 12] = channels
}
get data () {
return mod.getValue(this._address + 16, '*')
}
set data (data) {
mod.setValue(this._address + 16, data, '*')
}
}
// AudioStream, custom audio stream
raylib.AudioStream = class AudioStream {
constructor(init = {}, _address) {
this._size = 20
this._address = _address || mod._malloc(this._size)
this.buffer = init.buffer || 0
this.processor = init.processor || 0
this.sampleRate = init.sampleRate || 0
this.sampleSize = init.sampleSize || 0
this.channels = init.channels || 0
}
get buffer () {
return mod.getValue(this._address + 0, '*')
}
set buffer (buffer) {
mod.setValue(this._address + 0, buffer, '*')
}
get processor () {
return mod.getValue(this._address + 4, '*')
}
set processor (processor) {
mod.setValue(this._address + 4, processor, '*')
}
get sampleRate () {
return mod.HEAPU32[this._address + 8]
}
set sampleRate (sampleRate) {
mod.HEAPU32[this._address + 8] = sampleRate
}
get sampleSize () {
return mod.HEAPU32[this._address + 12]
}
set sampleSize (sampleSize) {
mod.HEAPU32[this._address + 12] = sampleSize
}
get channels () {
return mod.HEAPU32[this._address + 16]
}
set channels (channels) {
mod.HEAPU32[this._address + 16] = channels
}
}
// Sound
raylib.Sound = class Sound {
constructor(init = {}, _address) {
this._size = 24
this._address = _address || mod._malloc(this._size)
this.stream = new raylib.AudioStream(init.stream || {}, this._address + 0)
this.frameCount = init.frameCount || 0
}
get frameCount () {
return mod.HEAPU32[this._address + 20]
}
set frameCount (frameCount) {
mod.HEAPU32[this._address + 20] = frameCount
}
}
// Music, audio stream, anything longer than ~10 seconds should be streamed
raylib.Music = class Music {
constructor(init = {}, _address) {
this._size = 33
this._address = _address || mod._malloc(this._size)
this.stream = new raylib.AudioStream(init.stream || {}, this._address + 0)
this.frameCount = init.frameCount || 0
this.looping = init.looping || 0
this.ctxType = init.ctxType || 0
this.ctxData = init.ctxData || 0
}
get frameCount () {
return mod.HEAPU32[this._address + 20]
}
set frameCount (frameCount) {
mod.HEAPU32[this._address + 20] = frameCount
}
get looping () {
return mod.getValue(this._address + 24, 'i1')
}
set looping (looping) {
mod.setValue(this._address + 24, looping, 'i1')
}
get ctxType () {
return mod.getValue(this._address + 25, 'i32')
}
set ctxType (ctxType) {
mod.setValue(this._address + 25, ctxType, 'i32')
}
get ctxData () {
return mod.getValue(this._address + 29, '*')
}
set ctxData (ctxData) {
mod.setValue(this._address + 29, ctxData, '*')
}
}
// VrDeviceInfo, Head-Mounted-Display device parameters
raylib.VrDeviceInfo = class VrDeviceInfo {
constructor(init = {}, _address) {
this._size = 60
this._address = _address || mod._malloc(this._size)
this.hResolution = init.hResolution || 0
this.vResolution = init.vResolution || 0
this.hScreenSize = init.hScreenSize || 0
this.vScreenSize = init.vScreenSize || 0
this.eyeToScreenDistance = init.eyeToScreenDistance || 0
this.lensSeparationDistance = init.lensSeparationDistance || 0
this.interpupillaryDistance = init.interpupillaryDistance || 0
this.lensDistortionValues = init.lensDistortionValues || [0, 0, 0, 0]
this.chromaAbCorrection = init.chromaAbCorrection || [0, 0, 0, 0]
}
get hResolution () {
return mod.getValue(this._address + 0, 'i32')
}
set hResolution (hResolution) {
mod.setValue(this._address + 0, hResolution, 'i32')
}
get vResolution () {
return mod.getValue(this._address + 4, 'i32')
}
set vResolution (vResolution) {
mod.setValue(this._address + 4, vResolution, 'i32')
}
get hScreenSize () {
return mod.getValue(this._address + 8, 'float')
}
set hScreenSize (hScreenSize) {
mod.setValue(this._address + 8, hScreenSize, 'float')
}
get vScreenSize () {
return mod.getValue(this._address + 12, 'float')
}
set vScreenSize (vScreenSize) {
mod.setValue(this._address + 12, vScreenSize, 'float')
}
get eyeToScreenDistance () {
return mod.getValue(this._address + 16, 'float')
}
set eyeToScreenDistance (eyeToScreenDistance) {
mod.setValue(this._address + 16, eyeToScreenDistance, 'float')
}
get lensSeparationDistance () {
return mod.getValue(this._address + 20, 'float')
}
set lensSeparationDistance (lensSeparationDistance) {
mod.setValue(this._address + 20, lensSeparationDistance, 'float')
}
get interpupillaryDistance () {
return mod.getValue(this._address + 24, 'float')
}
set interpupillaryDistance (interpupillaryDistance) {
mod.setValue(this._address + 24, interpupillaryDistance, 'float')
}
get lensDistortionValues () {
return mod.getValue(this._address + 28, '*')
}
set lensDistortionValues (lensDistortionValues) {
mod.setValue(this._address + 28, lensDistortionValues, '*')
}
get chromaAbCorrection () {
return mod.getValue(this._address + 44, '*')
}
set chromaAbCorrection (chromaAbCorrection) {
mod.setValue(this._address + 44, chromaAbCorrection, '*')
}
}
// VrStereoConfig, VR stereo rendering configuration for simulator
raylib.VrStereoConfig = class VrStereoConfig {
constructor(init = {}, _address) {
this._size = 304
this._address = _address || mod._malloc(this._size)
this.projection = init.projection || [new raylib.Matrix(), new raylib.Matrix()]
this.viewOffset = init.viewOffset || [new raylib.Matrix(), new raylib.Matrix()]
this.leftLensCenter = init.leftLensCenter || [0, 0]
this.rightLensCenter = init.rightLensCenter || [0, 0]
this.leftScreenCenter = init.leftScreenCenter || [0, 0]
this.rightScreenCenter = init.rightScreenCenter || [0, 0]
this.scale = init.scale || [0, 0]
this.scaleIn = init.scaleIn || [0, 0]
}
get projection () {
return mod.getValue(this._address + 0, '*')
}
set projection (projection) {
mod.setValue(this._address + 0, projection, '*')
}
get viewOffset () {
return mod.getValue(this._address + 128, '*')
}
set viewOffset (viewOffset) {
mod.setValue(this._address + 128, viewOffset, '*')
}
get leftLensCenter () {
return mod.getValue(this._address + 256, '*')
}
set leftLensCenter (leftLensCenter) {
mod.setValue(this._address + 256, leftLensCenter, '*')
}
get rightLensCenter () {
return mod.getValue(this._address + 264, '*')
}
set rightLensCenter (rightLensCenter) {
mod.setValue(this._address + 264, rightLensCenter, '*')
}
get leftScreenCenter () {
return mod.getValue(this._address + 272, '*')
}
set leftScreenCenter (leftScreenCenter) {
mod.setValue(this._address + 272, leftScreenCenter, '*')
}
get rightScreenCenter () {
return mod.getValue(this._address + 280, '*')
}
set rightScreenCenter (rightScreenCenter) {
mod.setValue(this._address + 280, rightScreenCenter, '*')
}
get scale () {
return mod.getValue(this._address + 288, '*')
}
set scale (scale) {
mod.setValue(this._address + 288, scale, '*')
}
get scaleIn () {
return mod.getValue(this._address + 296, '*')
}
set scaleIn (scaleIn) {
mod.setValue(this._address + 296, scaleIn, '*')
}
}
// File path list
raylib.FilePathList = class FilePathList {
constructor(init = {}, _address) {
this._size = 12
this._address = _address || mod._malloc(this._size)
this.capacity = init.capacity || 0
this.count = init.count || 0
this.paths = init.paths || 0
}
get capacity () {
return mod.HEAPU32[this._address + 0]
}
set capacity (capacity) {
mod.HEAPU32[this._address + 0] = capacity
}
get count () {
return mod.HEAPU32[this._address + 4]
}
set count (count) {
mod.HEAPU32[this._address + 4] = count
}
get paths () {
return mod.getValue(this._address + 8, '*')
}
set paths (paths) {
mod.setValue(this._address + 8, paths, '*')
}
}
// Automation event
raylib.AutomationEvent = class AutomationEvent {
constructor(init = {}, _address) {
this._size = 24
this._address = _address || mod._malloc(this._size)
this.frame = init.frame || 0
this.type = init.type || 0
this.params = init.params || [0, 0, 0, 0]
}
get frame () {
return mod.HEAPU32[this._address + 0]
}
set frame (frame) {
mod.HEAPU32[this._address + 0] = frame
}
get type () {
return mod.HEAPU32[this._address + 4]
}
set type (type) {
mod.HEAPU32[this._address + 4] = type
}
get params () {
return mod.getValue(this._address + 8, '*')
}
set params (params) {
mod.setValue(this._address + 8, params, '*')
}
}
// Automation event list
raylib.AutomationEventList = class AutomationEventList {
constructor(init = {}, _address) {
this._size = 12
this._address = _address || mod._malloc(this._size)
this.capacity = init.capacity || 0
this.count = init.count || 0
this.events = new raylib.AutomationEvent(init.events || {}, this._address + 8)
}
get capacity () {
return mod.HEAPU32[this._address + 0]
}
set capacity (capacity) {
mod.HEAPU32[this._address + 0] = capacity
}
get count () {
return mod.HEAPU32[this._address + 4]
}
set count (count) {
mod.HEAPU32[this._address + 4] = count
}
}
// Texture2D, same as Texture
raylib.Texture2D = class Texture2D {
constructor(init = {}, _address) {
this._size = 20
this._address = _address || mod._malloc(this._size)
this.id = init.id || 0
this.width = init.width || 0
this.height = init.height || 0
this.mipmaps = init.mipmaps || 0
this.format = init.format || 0
}
get id () {
return mod.HEAPU32[this._address + 0]
}
set id (id) {
mod.HEAPU32[this._address + 0] = id
}
get width () {
return mod.getValue(this._address + 4, 'i32')
}
set width (width) {
mod.setValue(this._address + 4, width, 'i32')
}
get height () {
return mod.getValue(this._address + 8, 'i32')
}
set height (height) {
mod.setValue(this._address + 8, height, 'i32')
}
get mipmaps () {
return mod.getValue(this._address + 12, 'i32')
}
set mipmaps (mipmaps) {
mod.setValue(this._address + 12, mipmaps, 'i32')
}
get format () {
return mod.getValue(this._address + 16, 'i32')
}
set format (format) {
mod.setValue(this._address + 16, format, 'i32')
}
}
// NOTE: Used when exporting style as code for convenience
raylib.GuiStyleProp = class GuiStyleProp {
constructor(init = {}, _address) {
this._size = 4
this._address = _address || mod._malloc(this._size)
this.controlId = init.controlId || 0
this.propertyId = init.propertyId || 0
this.propertyValue = init.propertyValue || 0
}
get controlId () {
return mod.getValue(this._address + 0, '*')
}
set controlId (controlId) {
mod.setValue(this._address + 0, controlId, '*')
}
get propertyId () {
return mod.getValue(this._address + 0, '*')
}
set propertyId (propertyId) {
mod.setValue(this._address + 0, propertyId, '*')
}
get propertyValue () {
return mod.getValue(this._address + 0, 'i32')
}
set propertyValue (propertyValue) {
mod.setValue(this._address + 0, propertyValue, 'i32')
}
}
// NOTE: Text style is defined by control
raylib.GuiTextStyle = class GuiTextStyle {
constructor(init = {}, _address) {
this._size = 24
this._address = _address || mod._malloc(this._size)
this.size = init.size || 0
this.charSpacing = init.charSpacing || 0
this.lineSpacing = init.lineSpacing || 0
this.alignmentH = init.alignmentH || 0
this.alignmentV = init.alignmentV || 0
this.padding = init.padding || 0
}
get size () {
return mod.HEAPU32[this._address + 0]
}
set size (size) {
mod.HEAPU32[this._address + 0] = size
}
get charSpacing () {
return mod.getValue(this._address + 4, 'i32')
}
set charSpacing (charSpacing) {
mod.setValue(this._address + 4, charSpacing, 'i32')
}
get lineSpacing () {
return mod.getValue(this._address + 8, 'i32')
}
set lineSpacing (lineSpacing) {
mod.setValue(this._address + 8, lineSpacing, 'i32')
}
get alignmentH () {
return mod.getValue(this._address + 12, 'i32')
}
set alignmentH (alignmentH) {
mod.setValue(this._address + 12, alignmentH, 'i32')
}
get alignmentV () {
return mod.getValue(this._address + 16, 'i32')
}
set alignmentV (alignmentV) {
mod.setValue(this._address + 16, alignmentV, 'i32')
}
get padding () {
return mod.getValue(this._address + 20, 'i32')
}
set padding (padding) {
mod.setValue(this._address + 20, padding, 'i32')
}
}
// Quaternion, 4 components (Vector4 alias)
raylib.Quaternion = class Quaternion {
constructor(init = {}, _address) {
this._size = 16
this._address = _address || mod._malloc(this._size)
this.x = init.x || 0
this.y = init.y || 0
this.z = init.z || 0
this.w = init.w || 0
}
get x () {
return mod.getValue(this._address + 0, 'float')
}
set x (x) {
mod.setValue(this._address + 0, x, 'float')
}
get y () {
return mod.getValue(this._address + 4, 'float')
}
set y (y) {
mod.setValue(this._address + 4, y, 'float')
}
get z () {
return mod.getValue(this._address + 8, 'float')
}
set z (z) {
mod.setValue(this._address + 8, z, 'float')
}
get w () {
return mod.getValue(this._address + 12, 'float')
}
set w (w) {
mod.setValue(this._address + 12, w, 'float')
}
}
// TextureCubemap, same as Texture
raylib.TextureCubemap = class TextureCubemap {
constructor(init = {}, _address) {
this._size = 20
this._address = _address || mod._malloc(this._size)
this.id = init.id || 0
this.width = init.width || 0
this.height = init.height || 0
this.mipmaps = init.mipmaps || 0
this.format = init.format || 0
}
get id () {
return mod.HEAPU32[this._address + 0]
}
set id (id) {
mod.HEAPU32[this._address + 0] = id
}
get width () {
return mod.getValue(this._address + 4, 'i32')
}
set width (width) {
mod.setValue(this._address + 4, width, 'i32')
}
get height () {
return mod.getValue(this._address + 8, 'i32')
}
set height (height) {
mod.setValue(this._address + 8, height, 'i32')
}
get mipmaps () {
return mod.getValue(this._address + 12, 'i32')
}
set mipmaps (mipmaps) {
mod.setValue(this._address + 12, mipmaps, 'i32')
}
get format () {
return mod.getValue(this._address + 16, 'i32')
}
set format (format) {
mod.setValue(this._address + 16, format, 'i32')
}
}
// RenderTexture2D, same as RenderTexture
raylib.RenderTexture2D = class RenderTexture2D {
constructor(init = {}, _address) {
this._size = 44
this._address = _address || mod._malloc(this._size)
this.id = init.id || 0
this.texture = new raylib.Texture(init.texture || {}, this._address + 4)
this.depth = new raylib.Texture(init.depth || {}, this._address + 24)
}
get id () {
return mod.HEAPU32[this._address + 0]
}
set id (id) {
mod.HEAPU32[this._address + 0] = id
}
}
// Camera type fallback, defaults to Camera3D
raylib.Camera = class Camera {
constructor(init = {}, _address) {
this._size = 44
this._address = _address || mod._malloc(this._size)
this.position = new raylib.Vector3(init.position || {}, this._address + 0)
this.target = new raylib.Vector3(init.target || {}, this._address + 12)
this.up = new raylib.Vector3(init.up || {}, this._address + 24)
this.fovy = init.fovy || 0
this.projection = init.projection || 0
}
get fovy () {
return mod.getValue(this._address + 36, 'float')
}
set fovy (fovy) {
mod.setValue(this._address + 36, fovy, 'float')
}
get projection () {
return mod.getValue(this._address + 40, 'i32')
}
set projection (projection) {
mod.setValue(this._address + 40, projection, 'i32')
}
}
// ENUM ConfigFlags
// System/Window config flags
raylib.FLAG_VSYNC_HINT = 64 // Set to try enabling V-Sync on GPU
raylib.FLAG_FULLSCREEN_MODE = 2 // Set to run program in fullscreen
raylib.FLAG_WINDOW_RESIZABLE = 4 // Set to allow resizable window
raylib.FLAG_WINDOW_UNDECORATED = 8 // Set to disable window decoration (frame and buttons)
raylib.FLAG_WINDOW_HIDDEN = 128 // Set to hide window
raylib.FLAG_WINDOW_MINIMIZED = 512 // Set to minimize window (iconify)
raylib.FLAG_WINDOW_MAXIMIZED = 1024 // Set to maximize window (expanded to monitor)
raylib.FLAG_WINDOW_UNFOCUSED = 2048 // Set to window non focused
raylib.FLAG_WINDOW_TOPMOST = 4096 // Set to window always on top
raylib.FLAG_WINDOW_ALWAYS_RUN = 256 // Set to allow windows running while minimized
raylib.FLAG_WINDOW_TRANSPARENT = 16 // Set to allow transparent framebuffer
raylib.FLAG_WINDOW_HIGHDPI = 8192 // Set to support HighDPI
raylib.FLAG_WINDOW_MOUSE_PASSTHROUGH = 16384 // Set to support mouse passthrough, only supported when FLAG_WINDOW_UNDECORATED
raylib.FLAG_BORDERLESS_WINDOWED_MODE = 32768 // Set to run program in borderless windowed mode
raylib.FLAG_MSAA_4X_HINT = 32 // Set to try enabling MSAA 4X
raylib.FLAG_INTERLACED_HINT = 65536 // Set to try enabling interlaced video format (for V3D)
// ENUM TraceLogLevel
// Trace log level
raylib.LOG_ALL = 0 // Display all logs
raylib.LOG_TRACE = 1 // Trace logging, intended for internal use only
raylib.LOG_DEBUG = 2 // Debug logging, used for internal debugging, it should be disabled on release builds
raylib.LOG_INFO = 3 // Info logging, used for program execution info
raylib.LOG_WARNING = 4 // Warning logging, used on recoverable failures
raylib.LOG_ERROR = 5 // Error logging, used on unrecoverable failures
raylib.LOG_FATAL = 6 // Fatal logging, used to abort program: exit(EXIT_FAILURE)
raylib.LOG_NONE = 7 // Disable logging
// ENUM KeyboardKey
// Keyboard keys (US keyboard layout)
raylib.KEY_NULL = 0 // Key: NULL, used for no key pressed
raylib.KEY_APOSTROPHE = 39 // Key: '
raylib.KEY_COMMA = 44 // Key: ,
raylib.KEY_MINUS = 45 // Key: -
raylib.KEY_PERIOD = 46 // Key: .
raylib.KEY_SLASH = 47 // Key: /
raylib.KEY_ZERO = 48 // Key: 0
raylib.KEY_ONE = 49 // Key: 1
raylib.KEY_TWO = 50 // Key: 2
raylib.KEY_THREE = 51 // Key: 3
raylib.KEY_FOUR = 52 // Key: 4
raylib.KEY_FIVE = 53 // Key: 5
raylib.KEY_SIX = 54 // Key: 6
raylib.KEY_SEVEN = 55 // Key: 7
raylib.KEY_EIGHT = 56 // Key: 8
raylib.KEY_NINE = 57 // Key: 9
raylib.KEY_SEMICOLON = 59 // Key: ;
raylib.KEY_EQUAL = 61 // Key: =
raylib.KEY_A = 65 // Key: A | a
raylib.KEY_B = 66 // Key: B | b
raylib.KEY_C = 67 // Key: C | c
raylib.KEY_D = 68 // Key: D