diff --git a/assets/wabbit_alpha.png b/assets/wabbit_alpha.png new file mode 100644 index 0000000..db4081f Binary files /dev/null and b/assets/wabbit_alpha.png differ diff --git a/bindings/raylib_math_api.json b/bindings/raylib_math_api.json new file mode 100644 index 0000000..cbf9f7e --- /dev/null +++ b/bindings/raylib_math_api.json @@ -0,0 +1,1664 @@ +[ + { + "name": "Clamp", + "returnType": "float", + "params": [ + { + "name": "value", + "type": "float" + }, + { + "name": "min", + "type": "float" + }, + { + "name": "max", + "type": "float" + } + ], + "description": "" + }, + { + "name": "Lerp", + "returnType": "float", + "params": [ + { + "name": "start", + "type": "float" + }, + { + "name": "end", + "type": "float" + }, + { + "name": "amount", + "type": "float" + } + ], + "description": "" + }, + { + "name": "Normalize", + "returnType": "float", + "params": [ + { + "name": "value", + "type": "float" + }, + { + "name": "start", + "type": "float" + }, + { + "name": "end", + "type": "float" + } + ], + "description": "" + }, + { + "name": "Remap", + "returnType": "float", + "params": [ + { + "name": "value", + "type": "float" + }, + { + "name": "inputStart", + "type": "float" + }, + { + "name": "inputEnd", + "type": "float" + }, + { + "name": "outputStart", + "type": "float" + }, + { + "name": "outputEnd", + "type": "float" + } + ], + "description": "" + }, + { + "name": "Wrap", + "returnType": "float", + "params": [ + { + "name": "value", + "type": "float" + }, + { + "name": "min", + "type": "float" + }, + { + "name": "max", + "type": "float" + } + ], + "description": "" + }, + { + "name": "FloatEquals", + "returnType": "int", + "params": [ + { + "name": "x", + "type": "float" + }, + { + "name": "y", + "type": "float" + } + ], + "description": "" + }, + { + "name": "Vector2Zero", + "returnType": "Vector2", + "params": [], + "description": "" + }, + { + "name": "Vector2One", + "returnType": "Vector2", + "params": [], + "description": "" + }, + { + "name": "Vector2Add", + "returnType": "Vector2", + "params": [ + { + "name": "v1", + "type": "Vector2" + }, + { + "name": "v2", + "type": "Vector2" + } + ], + "description": "" + }, + { + "name": "Vector2AddValue", + "returnType": "Vector2", + "params": [ + { + "name": "v", + "type": "Vector2" + }, + { + "name": "add", + "type": "float" + } + ], + "description": "" + }, + { + "name": "Vector2Subtract", + "returnType": "Vector2", + "params": [ + { + "name": "v1", + "type": "Vector2" + }, + { + "name": "v2", + "type": "Vector2" + } + ], + "description": "" + }, + { + "name": "Vector2SubtractValue", + "returnType": "Vector2", + "params": [ + { + "name": "v", + "type": "Vector2" + }, + { + "name": "sub", + "type": "float" + } + ], + "description": "" + }, + { + "name": "Vector2Length", + "returnType": "float", + "params": [ + { + "name": "v", + "type": "Vector2" + } + ], + "description": "" + }, + { + "name": "Vector2LengthSqr", + "returnType": "float", + "params": [ + { + "name": "v", + "type": "Vector2" + } + ], + "description": "" + }, + { + "name": "Vector2DotProduct", + "returnType": "float", + "params": [ + { + "name": "v1", + "type": "Vector2" + }, + { + "name": "v2", + "type": "Vector2" + } + ], + "description": "" + }, + { + "name": "Vector2Distance", + "returnType": "float", + "params": [ + { + "name": "v1", + "type": "Vector2" + }, + { + "name": "v2", + "type": "Vector2" + } + ], + "description": "" + }, + { + "name": "Vector2DistanceSqr", + "returnType": "float", + "params": [ + { + "name": "v1", + "type": "Vector2" + }, + { + "name": "v2", + "type": "Vector2" + } + ], + "description": "" + }, + { + "name": "Vector2Angle", + "returnType": "float", + "params": [ + { + "name": "v1", + "type": "Vector2" + }, + { + "name": "v2", + "type": "Vector2" + } + ], + "description": "" + }, + { + "name": "Vector2LineAngle", + "returnType": "float", + "params": [ + { + "name": "start", + "type": "Vector2" + }, + { + "name": "end", + "type": "Vector2" + } + ], + "description": "" + }, + { + "name": "Vector2Scale", + "returnType": "Vector2", + "params": [ + { + "name": "v", + "type": "Vector2" + }, + { + "name": "scale", + "type": "float" + } + ], + "description": "" + }, + { + "name": "Vector2Multiply", + "returnType": "Vector2", + "params": [ + { + "name": "v1", + "type": "Vector2" + }, + { + "name": "v2", + "type": "Vector2" + } + ], + "description": "" + }, + { + "name": "Vector2Negate", + "returnType": "Vector2", + "params": [ + { + "name": "v", + "type": "Vector2" + } + ], + "description": "" + }, + { + "name": "Vector2Divide", + "returnType": "Vector2", + "params": [ + { + "name": "v1", + "type": "Vector2" + }, + { + "name": "v2", + "type": "Vector2" + } + ], + "description": "" + }, + { + "name": "Vector2Normalize", + "returnType": "Vector2", + "params": [ + { + "name": "v", + "type": "Vector2" + } + ], + "description": "" + }, + { + "name": "Vector2Transform", + "returnType": "Vector2", + "params": [ + { + "name": "v", + "type": "Vector2" + }, + { + "name": "mat", + "type": "Matrix" + } + ], + "description": "" + }, + { + "name": "Vector2Lerp", + "returnType": "Vector2", + "params": [ + { + "name": "v1", + "type": "Vector2" + }, + { + "name": "v2", + "type": "Vector2" + }, + { + "name": "amount", + "type": "float" + } + ], + "description": "" + }, + { + "name": "Vector2Reflect", + "returnType": "Vector2", + "params": [ + { + "name": "v", + "type": "Vector2" + }, + { + "name": "normal", + "type": "Vector2" + } + ], + "description": "" + }, + { + "name": "Vector2Rotate", + "returnType": "Vector2", + "params": [ + { + "name": "v", + "type": "Vector2" + }, + { + "name": "angle", + "type": "float" + } + ], + "description": "" + }, + { + "name": "Vector2MoveTowards", + "returnType": "Vector2", + "params": [ + { + "name": "v", + "type": "Vector2" + }, + { + "name": "target", + "type": "Vector2" + }, + { + "name": "maxDistance", + "type": "float" + } + ], + "description": "" + }, + { + "name": "Vector2Invert", + "returnType": "Vector2", + "params": [ + { + "name": "v", + "type": "Vector2" + } + ], + "description": "" + }, + { + "name": "Vector2Clamp", + "returnType": "Vector2", + "params": [ + { + "name": "v", + "type": "Vector2" + }, + { + "name": "min", + "type": "Vector2" + }, + { + "name": "max", + "type": "Vector2" + } + ], + "description": "" + }, + { + "name": "Vector2ClampValue", + "returnType": "Vector2", + "params": [ + { + "name": "v", + "type": "Vector2" + }, + { + "name": "min", + "type": "float" + }, + { + "name": "max", + "type": "float" + } + ], + "description": "" + }, + { + "name": "Vector2Equals", + "returnType": "int", + "params": [ + { + "name": "p", + "type": "Vector2" + }, + { + "name": "q", + "type": "Vector2" + } + ], + "description": "" + }, + { + "name": "Vector3Zero", + "returnType": "Vector3", + "params": [], + "description": "" + }, + { + "name": "Vector3One", + "returnType": "Vector3", + "params": [], + "description": "" + }, + { + "name": "Vector3Add", + "returnType": "Vector3", + "params": [ + { + "name": "v1", + "type": "Vector3" + }, + { + "name": "v2", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3AddValue", + "returnType": "Vector3", + "params": [ + { + "name": "v", + "type": "Vector3" + }, + { + "name": "add", + "type": "float" + } + ], + "description": "" + }, + { + "name": "Vector3Subtract", + "returnType": "Vector3", + "params": [ + { + "name": "v1", + "type": "Vector3" + }, + { + "name": "v2", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3SubtractValue", + "returnType": "Vector3", + "params": [ + { + "name": "v", + "type": "Vector3" + }, + { + "name": "sub", + "type": "float" + } + ], + "description": "" + }, + { + "name": "Vector3Scale", + "returnType": "Vector3", + "params": [ + { + "name": "v", + "type": "Vector3" + }, + { + "name": "scalar", + "type": "float" + } + ], + "description": "" + }, + { + "name": "Vector3Multiply", + "returnType": "Vector3", + "params": [ + { + "name": "v1", + "type": "Vector3" + }, + { + "name": "v2", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3CrossProduct", + "returnType": "Vector3", + "params": [ + { + "name": "v1", + "type": "Vector3" + }, + { + "name": "v2", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3Perpendicular", + "returnType": "Vector3", + "params": [ + { + "name": "v", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3Length", + "returnType": "float", + "params": [ + { + "name": "v", + "type": "const Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3LengthSqr", + "returnType": "float", + "params": [ + { + "name": "v", + "type": "const Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3DotProduct", + "returnType": "float", + "params": [ + { + "name": "v1", + "type": "Vector3" + }, + { + "name": "v2", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3Distance", + "returnType": "float", + "params": [ + { + "name": "v1", + "type": "Vector3" + }, + { + "name": "v2", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3DistanceSqr", + "returnType": "float", + "params": [ + { + "name": "v1", + "type": "Vector3" + }, + { + "name": "v2", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3Angle", + "returnType": "float", + "params": [ + { + "name": "v1", + "type": "Vector3" + }, + { + "name": "v2", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3Negate", + "returnType": "Vector3", + "params": [ + { + "name": "v", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3Divide", + "returnType": "Vector3", + "params": [ + { + "name": "v1", + "type": "Vector3" + }, + { + "name": "v2", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3Normalize", + "returnType": "Vector3", + "params": [ + { + "name": "v", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3OrthoNormalize", + "returnType": "void", + "params": [ + { + "name": "v1", + "type": "Vector3 *" + }, + { + "name": "v2", + "type": "Vector3 *" + } + ], + "description": "" + }, + { + "name": "Vector3Transform", + "returnType": "Vector3", + "params": [ + { + "name": "v", + "type": "Vector3" + }, + { + "name": "mat", + "type": "Matrix" + } + ], + "description": "" + }, + { + "name": "Vector3RotateByQuaternion", + "returnType": "Vector3", + "params": [ + { + "name": "v", + "type": "Vector3" + }, + { + "name": "q", + "type": "Quaternion" + } + ], + "description": "" + }, + { + "name": "Vector3RotateByAxisAngle", + "returnType": "Vector3", + "params": [ + { + "name": "v", + "type": "Vector3" + }, + { + "name": "axis", + "type": "Vector3" + }, + { + "name": "angle", + "type": "float" + } + ], + "description": "" + }, + { + "name": "Vector3Lerp", + "returnType": "Vector3", + "params": [ + { + "name": "v1", + "type": "Vector3" + }, + { + "name": "v2", + "type": "Vector3" + }, + { + "name": "amount", + "type": "float" + } + ], + "description": "" + }, + { + "name": "Vector3Reflect", + "returnType": "Vector3", + "params": [ + { + "name": "v", + "type": "Vector3" + }, + { + "name": "normal", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3Min", + "returnType": "Vector3", + "params": [ + { + "name": "v1", + "type": "Vector3" + }, + { + "name": "v2", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3Max", + "returnType": "Vector3", + "params": [ + { + "name": "v1", + "type": "Vector3" + }, + { + "name": "v2", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3Barycenter", + "returnType": "Vector3", + "params": [ + { + "name": "p", + "type": "Vector3" + }, + { + "name": "a", + "type": "Vector3" + }, + { + "name": "b", + "type": "Vector3" + }, + { + "name": "c", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3Unproject", + "returnType": "Vector3", + "params": [ + { + "name": "source", + "type": "Vector3" + }, + { + "name": "projection", + "type": "Matrix" + }, + { + "name": "view", + "type": "Matrix" + } + ], + "description": "" + }, + { + "name": "Vector3ToFloatV", + "returnType": "float3", + "params": [ + { + "name": "v", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3Invert", + "returnType": "Vector3", + "params": [ + { + "name": "v", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3Clamp", + "returnType": "Vector3", + "params": [ + { + "name": "v", + "type": "Vector3" + }, + { + "name": "min", + "type": "Vector3" + }, + { + "name": "max", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3ClampValue", + "returnType": "Vector3", + "params": [ + { + "name": "v", + "type": "Vector3" + }, + { + "name": "min", + "type": "float" + }, + { + "name": "max", + "type": "float" + } + ], + "description": "" + }, + { + "name": "Vector3Equals", + "returnType": "int", + "params": [ + { + "name": "p", + "type": "Vector3" + }, + { + "name": "q", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "Vector3Refract", + "returnType": "Vector3", + "params": [ + { + "name": "v", + "type": "Vector3" + }, + { + "name": "n", + "type": "Vector3" + }, + { + "name": "r", + "type": "float" + } + ], + "description": "" + }, + { + "name": "MatrixDeterminant", + "returnType": "float", + "params": [ + { + "name": "mat", + "type": "Matrix" + } + ], + "description": "" + }, + { + "name": "MatrixTrace", + "returnType": "float", + "params": [ + { + "name": "mat", + "type": "Matrix" + } + ], + "description": "" + }, + { + "name": "MatrixTranspose", + "returnType": "Matrix", + "params": [ + { + "name": "mat", + "type": "Matrix" + } + ], + "description": "" + }, + { + "name": "MatrixInvert", + "returnType": "Matrix", + "params": [ + { + "name": "mat", + "type": "Matrix" + } + ], + "description": "" + }, + { + "name": "MatrixIdentity", + "returnType": "Matrix", + "params": [], + "description": "" + }, + { + "name": "MatrixAdd", + "returnType": "Matrix", + "params": [ + { + "name": "left", + "type": "Matrix" + }, + { + "name": "right", + "type": "Matrix" + } + ], + "description": "" + }, + { + "name": "MatrixSubtract", + "returnType": "Matrix", + "params": [ + { + "name": "left", + "type": "Matrix" + }, + { + "name": "right", + "type": "Matrix" + } + ], + "description": "" + }, + { + "name": "MatrixMultiply", + "returnType": "Matrix", + "params": [ + { + "name": "left", + "type": "Matrix" + }, + { + "name": "right", + "type": "Matrix" + } + ], + "description": "" + }, + { + "name": "MatrixTranslate", + "returnType": "Matrix", + "params": [ + { + "name": "x", + "type": "float" + }, + { + "name": "y", + "type": "float" + }, + { + "name": "z", + "type": "float" + } + ], + "description": "" + }, + { + "name": "MatrixRotate", + "returnType": "Matrix", + "params": [ + { + "name": "axis", + "type": "Vector3" + }, + { + "name": "angle", + "type": "float" + } + ], + "description": "" + }, + { + "name": "MatrixRotateX", + "returnType": "Matrix", + "params": [ + { + "name": "angle", + "type": "float" + } + ], + "description": "" + }, + { + "name": "MatrixRotateY", + "returnType": "Matrix", + "params": [ + { + "name": "angle", + "type": "float" + } + ], + "description": "" + }, + { + "name": "MatrixRotateZ", + "returnType": "Matrix", + "params": [ + { + "name": "angle", + "type": "float" + } + ], + "description": "" + }, + { + "name": "MatrixRotateXYZ", + "returnType": "Matrix", + "params": [ + { + "name": "angle", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "MatrixRotateZYX", + "returnType": "Matrix", + "params": [ + { + "name": "angle", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "MatrixScale", + "returnType": "Matrix", + "params": [ + { + "name": "x", + "type": "float" + }, + { + "name": "y", + "type": "float" + }, + { + "name": "z", + "type": "float" + } + ], + "description": "" + }, + { + "name": "MatrixFrustum", + "returnType": "Matrix", + "params": [ + { + "name": "left", + "type": "double" + }, + { + "name": "right", + "type": "double" + }, + { + "name": "bottom", + "type": "double" + }, + { + "name": "top", + "type": "double" + }, + { + "name": "near", + "type": "double" + }, + { + "name": "far", + "type": "double" + } + ], + "description": "" + }, + { + "name": "MatrixPerspective", + "returnType": "Matrix", + "params": [ + { + "name": "fovy", + "type": "double" + }, + { + "name": "aspect", + "type": "double" + }, + { + "name": "near", + "type": "double" + }, + { + "name": "far", + "type": "double" + } + ], + "description": "" + }, + { + "name": "MatrixOrtho", + "returnType": "Matrix", + "params": [ + { + "name": "left", + "type": "double" + }, + { + "name": "right", + "type": "double" + }, + { + "name": "bottom", + "type": "double" + }, + { + "name": "top", + "type": "double" + }, + { + "name": "near", + "type": "double" + }, + { + "name": "far", + "type": "double" + } + ], + "description": "" + }, + { + "name": "MatrixLookAt", + "returnType": "Matrix", + "params": [ + { + "name": "eye", + "type": "Vector3" + }, + { + "name": "target", + "type": "Vector3" + }, + { + "name": "up", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "MatrixToFloatV", + "returnType": "float16", + "params": [ + { + "name": "mat", + "type": "Matrix" + } + ], + "description": "" + }, + { + "name": "QuaternionAdd", + "returnType": "Quaternion", + "params": [ + { + "name": "q1", + "type": "Quaternion" + }, + { + "name": "q2", + "type": "Quaternion" + } + ], + "description": "" + }, + { + "name": "QuaternionAddValue", + "returnType": "Quaternion", + "params": [ + { + "name": "q", + "type": "Quaternion" + }, + { + "name": "add", + "type": "float" + } + ], + "description": "" + }, + { + "name": "QuaternionSubtract", + "returnType": "Quaternion", + "params": [ + { + "name": "q1", + "type": "Quaternion" + }, + { + "name": "q2", + "type": "Quaternion" + } + ], + "description": "" + }, + { + "name": "QuaternionSubtractValue", + "returnType": "Quaternion", + "params": [ + { + "name": "q", + "type": "Quaternion" + }, + { + "name": "sub", + "type": "float" + } + ], + "description": "" + }, + { + "name": "QuaternionIdentity", + "returnType": "Quaternion", + "params": [], + "description": "" + }, + { + "name": "QuaternionLength", + "returnType": "float", + "params": [ + { + "name": "q", + "type": "Quaternion" + } + ], + "description": "" + }, + { + "name": "QuaternionNormalize", + "returnType": "Quaternion", + "params": [ + { + "name": "q", + "type": "Quaternion" + } + ], + "description": "" + }, + { + "name": "QuaternionInvert", + "returnType": "Quaternion", + "params": [ + { + "name": "q", + "type": "Quaternion" + } + ], + "description": "" + }, + { + "name": "QuaternionMultiply", + "returnType": "Quaternion", + "params": [ + { + "name": "q1", + "type": "Quaternion" + }, + { + "name": "q2", + "type": "Quaternion" + } + ], + "description": "" + }, + { + "name": "QuaternionScale", + "returnType": "Quaternion", + "params": [ + { + "name": "q", + "type": "Quaternion" + }, + { + "name": "mul", + "type": "float" + } + ], + "description": "" + }, + { + "name": "QuaternionDivide", + "returnType": "Quaternion", + "params": [ + { + "name": "q1", + "type": "Quaternion" + }, + { + "name": "q2", + "type": "Quaternion" + } + ], + "description": "" + }, + { + "name": "QuaternionLerp", + "returnType": "Quaternion", + "params": [ + { + "name": "q1", + "type": "Quaternion" + }, + { + "name": "q2", + "type": "Quaternion" + }, + { + "name": "amount", + "type": "float" + } + ], + "description": "" + }, + { + "name": "QuaternionNlerp", + "returnType": "Quaternion", + "params": [ + { + "name": "q1", + "type": "Quaternion" + }, + { + "name": "q2", + "type": "Quaternion" + }, + { + "name": "amount", + "type": "float" + } + ], + "description": "" + }, + { + "name": "QuaternionSlerp", + "returnType": "Quaternion", + "params": [ + { + "name": "q1", + "type": "Quaternion" + }, + { + "name": "q2", + "type": "Quaternion" + }, + { + "name": "amount", + "type": "float" + } + ], + "description": "" + }, + { + "name": "QuaternionFromVector3ToVector3", + "returnType": "Quaternion", + "params": [ + { + "name": "from", + "type": "Vector3" + }, + { + "name": "to", + "type": "Vector3" + } + ], + "description": "" + }, + { + "name": "QuaternionFromMatrix", + "returnType": "Quaternion", + "params": [ + { + "name": "mat", + "type": "Matrix" + } + ], + "description": "" + }, + { + "name": "QuaternionToMatrix", + "returnType": "Matrix", + "params": [ + { + "name": "q", + "type": "Quaternion" + } + ], + "description": "" + }, + { + "name": "QuaternionFromAxisAngle", + "returnType": "Quaternion", + "params": [ + { + "name": "axis", + "type": "Vector3" + }, + { + "name": "angle", + "type": "float" + } + ], + "description": "" + }, + { + "name": "QuaternionToAxisAngle", + "returnType": "void", + "params": [ + { + "name": "q", + "type": "Quaternion" + }, + { + "name": "outAxis", + "type": "Vector3 *" + }, + { + "name": "outAngle", + "type": "float *" + } + ], + "description": "" + }, + { + "name": "QuaternionFromEuler", + "returnType": "Quaternion", + "params": [ + { + "name": "pitch", + "type": "float" + }, + { + "name": "yaw", + "type": "float" + }, + { + "name": "roll", + "type": "float" + } + ], + "description": "" + }, + { + "name": "QuaternionToEuler", + "returnType": "Vector3", + "params": [ + { + "name": "q", + "type": "Quaternion" + } + ], + "description": "" + }, + { + "name": "QuaternionTransform", + "returnType": "Quaternion", + "params": [ + { + "name": "q", + "type": "Quaternion" + }, + { + "name": "mat", + "type": "Matrix" + } + ], + "description": "" + }, + { + "name": "QuaternionEquals", + "returnType": "int", + "params": [ + { + "name": "p", + "type": "Quaternion" + }, + { + "name": "q", + "type": "Quaternion" + } + ], + "description": "" + } +] \ No newline at end of file diff --git a/bindings/src/api.ts b/bindings/src/api.ts index e92be0b..49944fd 100644 --- a/bindings/src/api.ts +++ b/bindings/src/api.ts @@ -9,6 +9,7 @@ export class ApiFunction{ get argc() { return this.api.params?.length || 0 } get params() { return this.api.params || [] } get returnType() { return this.api.returnType } + get description() { return this.api.description } } export class ApiStruct{ @@ -21,8 +22,12 @@ export class ApiStruct{ } export class ApiDescription{ + constructor(private api: RayLibApi){ + } + getAliases(name: string) { + return this.api.aliases.filter(x => x.type === name).map(x => x.name) } getFunction(name: string){ diff --git a/bindings/src/generation.ts b/bindings/src/generation.ts index 8b05651..af9cbd3 100644 --- a/bindings/src/generation.ts +++ b/bindings/src/generation.ts @@ -65,7 +65,8 @@ enum Token { export interface FunctionArgument { type: string, - name: string + name: string, + description?: string } diff --git a/bindings/src/index.ts b/bindings/src/index.ts index 05d287a..ac2ae84 100644 --- a/bindings/src/index.ts +++ b/bindings/src/index.ts @@ -1,14 +1,41 @@ import { readFileSync, writeFileSync } from "fs"; -import { RayLibApi } from "./interfaces"; -import { ApiDescription } from "./api"; +import { RayLibApi, RayLibFunction, RayLibType } from "./interfaces"; +import { ApiDescription, ApiFunction } from "./api"; import { RayLibHeader } from "./raylib-header"; +function parseMathHeader(): RayLibFunction[] { + return readFileSync("thirdparty/raylib/src/raymath.h", 'utf8') + .split("\n") + .filter(x => x.startsWith("RMAPI")) + .map(inputString => { + const matches = inputString.match(/^RMAPI\s+([\w<>]+)\s+([\w<>]+)\((.*)\)$/); + if(!matches) throw new Error("Unable to match " + inputString) + const args = matches[3].split(',').filter(x => x !== 'void').map(arg => { + arg = arg.trim().replace(" *", "* ") + const frags = arg.split(' ') + const name = frags.pop() + const type = frags.join(' ').replace("*", " *") + console.log({ name: name || "", type: type }) + return { name: name || "", type: type } + }) + return { + name: matches[2], + returnType: matches[1], + params: args, + description: "" + } + }); +} + function main(){ + + const mathApi = parseMathHeader(); + writeFileSync("bindings/raylib_math_api.json", JSON.stringify(mathApi)) + const api = JSON.parse(readFileSync("thirdparty/raylib/parser/output/raylib_api.json", 'utf8')) const apiDesc = new ApiDescription(api) - - const core_gen = new RayLibHeader("raylib_core", apiDesc) - core_gen.addApiStructByName("Color", { + const core = new RayLibHeader("raylib_core", apiDesc) + core.addApiStructByName("Color", { properties: { r: { get: true, set: true }, g: { get: true, set: true }, @@ -17,7 +44,7 @@ function main(){ }, createConstructor: true }) - core_gen.addApiStructByName("Rectangle", { + core.addApiStructByName("Rectangle", { properties: { x: { get: true, set: true }, y: { get: true, set: true }, @@ -26,14 +53,14 @@ function main(){ }, createConstructor: true }) - core_gen.addApiStructByName("Vector2", { + core.addApiStructByName("Vector2", { properties: { x: { get: true, set: true }, y: { get: true, set: true }, }, createConstructor: true }) - core_gen.addApiStructByName("Vector3", { + core.addApiStructByName("Vector3", { properties: { x: { get: true, set: true }, y: { get: true, set: true }, @@ -41,14 +68,32 @@ function main(){ }, createConstructor: true }) - core_gen.addApiStructByName("Ray", { + core.addApiStructByName("Vector4", { + properties: { + x: { get: true, set: true }, + y: { get: true, set: true }, + z: { get: true, set: true }, + w: { get: true, set: true }, + }, + createConstructor: true + }) + core.addApiStructByName("Ray", { properties: { position: { get: false, set: true }, direction: { get: false, set: true }, }, createConstructor: true }) - core_gen.addApiStructByName("Camera2D",{ + core.addApiStructByName("RayCollision", { + properties: { + hit: { get: true, set: false }, + distance: { get: true, set: false }, + //point: { get: true, set: false }, + //normal: { get: true, set: false }, + }, + createConstructor: false + }) + core.addApiStructByName("Camera2D",{ properties: { offset: { get: false, set: true }, target: { get: false, set: true }, @@ -57,220 +102,718 @@ function main(){ }, createConstructor: true }) - core_gen.addApiStructByName("Matrix",{ + core.addApiStructByName("Camera3D",{ + properties: { + position: { get: false, set: true }, + target: { get: false, set: true }, + up: { get: false, set: true }, + fovy: { get: true, set: true }, + projection: { get: true, set: true }, + }, + createConstructor: true + }) + core.addApiStructByName("BoundingBox",{ + properties: {}, + createConstructor: true + }) + core.addApiStructByName("Matrix",{ properties: {}, createConstructor: false }) + core.addApiStructByName("Image", { + properties: { + width: { get: true }, + height: { get: true }, + mipmaps: { get: true }, + format: { get: true } + }, + destructor: "UnloadImage" + }) + core.addApiStructByName("Wave", { + properties: { + frameCount: { get: true }, + sampleRate: { get: true }, + sampleSize: { get: true }, + channels: { get: true } + }, + destructor: "UnloadWave" + }) + core.addApiStructByName("Sound", { + properties: { + frameCount: { get: true } + }, + destructor: "UnloadSound" + }) + core.addApiStructByName("Music", { + properties: { + frameCount: { get: true }, + looping: { get: true, set: true } + }, + destructor: "UnloadMusicStream" + }) + core.addApiStructByName("Model", { + properties: {}, + destructor: "UnloadModel" + }) + core.addApiStructByName("Mesh", { + properties: {}, + destructor: "UnloadMesh" + }) + core.addApiStructByName("Shader", { + properties: {}, + destructor: "UnloadShader" + }) + core.addApiStructByName("Texture", { + properties: { + width: { get: true }, + height: { get: true } + }, + destructor: "UnloadTexture" + }) + core.addApiStructByName("Font", { + properties: { + baseSize: { get: true } + }, + destructor: "UnloadFont" + }) + // Window-related functions - core_gen.addApiFunctionByName("InitWindow") - core_gen.addApiFunctionByName("WindowShouldClose") - core_gen.addApiFunctionByName("CloseWindow") - core_gen.addApiFunctionByName("IsWindowReady") - core_gen.addApiFunctionByName("IsWindowFullscreen") - core_gen.addApiFunctionByName("IsWindowHidden") - core_gen.addApiFunctionByName("IsWindowMinimized") - core_gen.addApiFunctionByName("IsWindowMaximized") - core_gen.addApiFunctionByName("IsWindowFocused") - core_gen.addApiFunctionByName("IsWindowResized") - core_gen.addApiFunctionByName("IsWindowState") - core_gen.addApiFunctionByName("SetWindowState") - core_gen.addApiFunctionByName("ClearWindowState") - core_gen.addApiFunctionByName("ToggleFullscreen") - core_gen.addApiFunctionByName("MaximizeWindow") - core_gen.addApiFunctionByName("MinimizeWindow") - core_gen.addApiFunctionByName("RestoreWindow") + core.addApiFunctionByName("InitWindow") + core.addApiFunctionByName("WindowShouldClose") + core.addApiFunctionByName("CloseWindow") + core.addApiFunctionByName("IsWindowReady") + core.addApiFunctionByName("IsWindowFullscreen") + core.addApiFunctionByName("IsWindowHidden") + core.addApiFunctionByName("IsWindowMinimized") + core.addApiFunctionByName("IsWindowMaximized") + core.addApiFunctionByName("IsWindowFocused") + core.addApiFunctionByName("IsWindowResized") + core.addApiFunctionByName("IsWindowState") + core.addApiFunctionByName("SetWindowState") + core.addApiFunctionByName("ClearWindowState") + core.addApiFunctionByName("ToggleFullscreen") + core.addApiFunctionByName("MaximizeWindow") + core.addApiFunctionByName("MinimizeWindow") + core.addApiFunctionByName("RestoreWindow") // SetWindowIcon // SetWindowIcons - core_gen.addApiFunctionByName("SetWindowTitle") - core_gen.addApiFunctionByName("SetWindowPosition") - core_gen.addApiFunctionByName("SetWindowMonitor") - core_gen.addApiFunctionByName("SetWindowMinSize") - core_gen.addApiFunctionByName("SetWindowSize") - core_gen.addApiFunctionByName("SetWindowOpacity") + core.addApiFunctionByName("SetWindowTitle") + core.addApiFunctionByName("SetWindowPosition") + core.addApiFunctionByName("SetWindowMonitor") + core.addApiFunctionByName("SetWindowMinSize") + core.addApiFunctionByName("SetWindowSize") + core.addApiFunctionByName("SetWindowOpacity") // GetWindowHandle - core_gen.addApiFunctionByName("GetScreenWidth") - core_gen.addApiFunctionByName("GetScreenHeight") - core_gen.addApiFunctionByName("GetRenderWidth") - core_gen.addApiFunctionByName("GetRenderHeight") - core_gen.addApiFunctionByName("GetMonitorCount") - core_gen.addApiFunctionByName("GetCurrentMonitor") - core_gen.addApiFunctionByName("GetMonitorPosition") - core_gen.addApiFunctionByName("GetMonitorWidth") - core_gen.addApiFunctionByName("GetMonitorHeight") - core_gen.addApiFunctionByName("GetMonitorPhysicalWidth") - core_gen.addApiFunctionByName("GetMonitorPhysicalHeight") - core_gen.addApiFunctionByName("GetMonitorRefreshRate") - core_gen.addApiFunctionByName("GetWindowPosition") - core_gen.addApiFunctionByName("GetWindowScaleDPI") - core_gen.addApiFunctionByName("GetMonitorName") - core_gen.addApiFunctionByName("SetClipboardText") - core_gen.addApiFunctionByName("GetClipboardText") - core_gen.addApiFunctionByName("EnableEventWaiting") - core_gen.addApiFunctionByName("DisableEventWaiting") + core.addApiFunctionByName("GetScreenWidth") + core.addApiFunctionByName("GetScreenHeight") + core.addApiFunctionByName("GetRenderWidth") + core.addApiFunctionByName("GetRenderHeight") + core.addApiFunctionByName("GetMonitorCount") + core.addApiFunctionByName("GetCurrentMonitor") + core.addApiFunctionByName("GetMonitorPosition") + core.addApiFunctionByName("GetMonitorWidth") + core.addApiFunctionByName("GetMonitorHeight") + core.addApiFunctionByName("GetMonitorPhysicalWidth") + core.addApiFunctionByName("GetMonitorPhysicalHeight") + core.addApiFunctionByName("GetMonitorRefreshRate") + core.addApiFunctionByName("GetWindowPosition") + core.addApiFunctionByName("GetWindowScaleDPI") + core.addApiFunctionByName("GetMonitorName") + core.addApiFunctionByName("SetClipboardText") + core.addApiFunctionByName("GetClipboardText") + core.addApiFunctionByName("EnableEventWaiting") + core.addApiFunctionByName("DisableEventWaiting") // Custom frame control functions // NOT SUPPORTED BECAUSE NEEDS COMPILER FLAG // Cursor-related functions - core_gen.addApiFunctionByName("ShowCursor") - core_gen.addApiFunctionByName("HideCursor") - core_gen.addApiFunctionByName("IsCursorHidden") - core_gen.addApiFunctionByName("EnableCursor") - core_gen.addApiFunctionByName("DisableCursor") - core_gen.addApiFunctionByName("IsCursorOnScreen") + core.addApiFunctionByName("ShowCursor") + core.addApiFunctionByName("HideCursor") + core.addApiFunctionByName("IsCursorHidden") + core.addApiFunctionByName("EnableCursor") + core.addApiFunctionByName("DisableCursor") + core.addApiFunctionByName("IsCursorOnScreen") // Drawing related functions - core_gen.addApiFunctionByName("ClearBackground") - core_gen.addApiFunctionByName("BeginDrawing") - core_gen.addApiFunctionByName("EndDrawing", null, { before: fun => fun.call("app_update_quickjs", []) }) - core_gen.addApiFunctionByName("BeginMode2D") - core_gen.addApiFunctionByName("EndMode2D") - //core_gen.addApiFunctionByName("BeginMode3D") - //core_gen.addApiFunctionByName("EndMode3D") - //core_gen.addApiFunctionByName("BeginTextureMode") - //core_gen.addApiFunctionByName("EndTextureMode") - //core_gen.addApiFunctionByName("BeginShaderMode") - //core_gen.addApiFunctionByName("EndShaderMode") - core_gen.addApiFunctionByName("BeginBlendMode") - core_gen.addApiFunctionByName("EndBlendMode") - core_gen.addApiFunctionByName("BeginScissorMode") - core_gen.addApiFunctionByName("EndScissorMode") - //core_gen.addApiFunctionByName("BeginVrStereoMode") - //core_gen.addApiFunctionByName("EndVrStereoMode") + core.addApiFunctionByName("ClearBackground") + core.addApiFunctionByName("BeginDrawing") + core.addApiFunctionByName("EndDrawing", null, { before: fun => fun.call("app_update_quickjs", []) }) + core.addApiFunctionByName("BeginMode2D") + core.addApiFunctionByName("EndMode2D") + core.addApiFunctionByName("BeginMode3D") + core.addApiFunctionByName("EndMode3D") + //core.addApiFunctionByName("BeginTextureMode") + //core.addApiFunctionByName("EndTextureMode") + //core.addApiFunctionByName("BeginShaderMode") + //core.addApiFunctionByName("EndShaderMode") + core.addApiFunctionByName("BeginBlendMode") + core.addApiFunctionByName("EndBlendMode") + core.addApiFunctionByName("BeginScissorMode") + core.addApiFunctionByName("EndScissorMode") + //core.addApiFunctionByName("BeginVrStereoMode") + //core.addApiFunctionByName("EndVrStereoMode") // VR Stereo config options - //core_gen.addApiFunctionByName("LoadVrStereoConfig") - //core_gen.addApiFunctionByName("UnloadVrStereoConfig") + //core.addApiFunctionByName("LoadVrStereoConfig") + //core.addApiFunctionByName("UnloadVrStereoConfig") // Shader Management - // core_gen.addApiFunctionByName("LoadShader") - // core_gen.addApiFunctionByName("LoadShaderFromMemory") - // core_gen.addApiFunctionByName("IsShaderReady") - // core_gen.addApiFunctionByName("GetShaderLocation") - // core_gen.addApiFunctionByName("GetShaderLocationAttrib") - // core_gen.addApiFunctionByName("SetShaderValue") - // core_gen.addApiFunctionByName("SetShaderValueV") - // core_gen.addApiFunctionByName("SetShaderValueMatrix") - // core_gen.addApiFunctionByName("SetShaderValueTexture") + // core.addApiFunctionByName("LoadShader") + // core.addApiFunctionByName("LoadShaderFromMemory") + // core.addApiFunctionByName("IsShaderReady") + // core.addApiFunctionByName("GetShaderLocation") + // core.addApiFunctionByName("GetShaderLocationAttrib") + // core.addApiFunctionByName("SetShaderValue") + // core.addApiFunctionByName("SetShaderValueV") + // core.addApiFunctionByName("SetShaderValueMatrix") + // core.addApiFunctionByName("SetShaderValueTexture") // // "UnloadShader" is destructor // ScreenSpaceRelatedFunctions - //core_gen.addApiFunctionByName("GetMouseRay") - //core_gen.addApiFunctionByName("GetCameraMatrix") - core_gen.addApiFunctionByName("GetCameraMatrix2D") - //core_gen.addApiFunctionByName("GetWorldToScreen") - core_gen.addApiFunctionByName("GetScreenToWorld2D") - //core_gen.addApiFunctionByName("GetScreenToWorldEx") - core_gen.addApiFunctionByName("GetWorldToScreen2D") + //core.addApiFunctionByName("GetMouseRay") + //core.addApiFunctionByName("GetCameraMatrix") + core.addApiFunctionByName("GetCameraMatrix2D") + //core.addApiFunctionByName("GetWorldToScreen") + core.addApiFunctionByName("GetScreenToWorld2D") + //core.addApiFunctionByName("GetScreenToWorldEx") + core.addApiFunctionByName("GetWorldToScreen2D") // Timing related functions - core_gen.addApiFunctionByName("SetTargetFPS") - core_gen.addApiFunctionByName("GetFPS") - core_gen.addApiFunctionByName("GetFrameTime") - core_gen.addApiFunctionByName("GetTime") + core.addApiFunctionByName("SetTargetFPS") + core.addApiFunctionByName("GetFPS") + core.addApiFunctionByName("GetFrameTime") + core.addApiFunctionByName("GetTime") // Misc functions - core_gen.addApiFunctionByName("GetRandomValue") - core_gen.addApiFunctionByName("SetRandomSeed") - core_gen.addApiFunctionByName("TakeScreenshot") - core_gen.addApiFunctionByName("SetConfigFlags") + core.addApiFunctionByName("GetRandomValue") + core.addApiFunctionByName("SetRandomSeed") + core.addApiFunctionByName("TakeScreenshot") + core.addApiFunctionByName("SetConfigFlags") const traceLog = apiDesc.getFunction("TraceLog") if(!traceLog) throw new Error("TraceLog not found") traceLog.params.pop() - core_gen.addApiFunction(traceLog) - core_gen.addApiFunctionByName("SetTraceLogLevel") + core.addApiFunction(traceLog) + core.addApiFunctionByName("SetTraceLogLevel") // Memory functions not supported on JS - core_gen.addApiFunctionByName("OpenURL") + core.addApiFunctionByName("OpenURL") // Callbacks not supported on JS // Files management functions - //core_gen.addApiFunctionByName("LoadFileData") - //core_gen.addApiFunctionByName("UnloadLoadFileData") - //core_gen.addApiFunctionByName("SaveFileData") + //core.addApiFunctionByName("LoadFileData") + //core.addApiFunctionByName("UnloadLoadFileData") + //core.addApiFunctionByName("SaveFileData") // Export data as code not needed - core_gen.addApiFunctionByName("LoadFileText", null, { after: gen => gen.call("UnloadFileText", ["returnVal"]) }) - core_gen.addApiFunctionByName("SaveFileText") - core_gen.addApiFunctionByName("FileExists") - core_gen.addApiFunctionByName("DirectoryExists") - core_gen.addApiFunctionByName("IsFileExtension") + core.addApiFunctionByName("LoadFileText", null, { after: gen => gen.call("UnloadFileText", ["returnVal"]) }) + core.addApiFunctionByName("SaveFileText") + core.addApiFunctionByName("FileExists") + core.addApiFunctionByName("DirectoryExists") + core.addApiFunctionByName("IsFileExtension") // TODO: Who needs to clean memory here? - core_gen.addApiFunctionByName("GetFileLength") - core_gen.addApiFunctionByName("GetFileExtension") - core_gen.addApiFunctionByName("GetFileName") - core_gen.addApiFunctionByName("GetFileNameWithoutExt") - core_gen.addApiFunctionByName("GetDirectoryPath") - core_gen.addApiFunctionByName("GetPrevDirectoryPath") - core_gen.addApiFunctionByName("GetWorkingDirectory") - core_gen.addApiFunctionByName("GetApplicationDirectory") - core_gen.addApiFunctionByName("ChangeDirectory") - core_gen.addApiFunctionByName("IsPathFile") - //core_gen.addApiFunctionByName("LoadPathFiles") - //core_gen.addApiFunctionByName("LoadPathFilesEx") + core.addApiFunctionByName("GetFileLength") + core.addApiFunctionByName("GetFileExtension") + core.addApiFunctionByName("GetFileName") + core.addApiFunctionByName("GetFileNameWithoutExt") + core.addApiFunctionByName("GetDirectoryPath") + core.addApiFunctionByName("GetPrevDirectoryPath") + core.addApiFunctionByName("GetWorkingDirectory") + core.addApiFunctionByName("GetApplicationDirectory") + core.addApiFunctionByName("ChangeDirectory") + core.addApiFunctionByName("IsPathFile") + //core.addApiFunctionByName("LoadPathFiles") + //core.addApiFunctionByName("LoadPathFilesEx") // UnloadDirectoryFiles - core_gen.addApiFunctionByName("IsFileDropped") - //core_gen.addApiFunctionByName("LoadDroppedFiles") + core.addApiFunctionByName("IsFileDropped") + //core.addApiFunctionByName("LoadDroppedFiles") // UnloadDroppedFiles - core_gen.addApiFunctionByName("GetFileModTime") + core.addApiFunctionByName("GetFileModTime") // Compression/encodeing functionality - //core_gen.addApiFunctionByName("CompressData") - //core_gen.addApiFunctionByName("DecompressData") - //core_gen.addApiFunctionByName("EncodeDataBase64") - //core_gen.addApiFunctionByName("DecodeDataBase64") + //core.addApiFunctionByName("CompressData") + //core.addApiFunctionByName("DecompressData") + //core.addApiFunctionByName("EncodeDataBase64") + //core.addApiFunctionByName("DecodeDataBase64") // input handling functions - core_gen.addApiFunctionByName("IsKeyPressed") - core_gen.addApiFunctionByName("IsKeyDown") - core_gen.addApiFunctionByName("IsKeyReleased") - core_gen.addApiFunctionByName("IsKeyUp") - core_gen.addApiFunctionByName("SetExitKey") - core_gen.addApiFunctionByName("GetKeyPressed") - core_gen.addApiFunctionByName("GetCharPressed") + core.addApiFunctionByName("IsKeyPressed") + core.addApiFunctionByName("IsKeyDown") + core.addApiFunctionByName("IsKeyReleased") + core.addApiFunctionByName("IsKeyUp") + core.addApiFunctionByName("SetExitKey") + core.addApiFunctionByName("GetKeyPressed") + core.addApiFunctionByName("GetCharPressed") - // input-related functions - core_gen.addApiFunctionByName("IsGamepadAvailable") - core_gen.addApiFunctionByName("GetGamepadName") - core_gen.addApiFunctionByName("IsGamepadButtonPressed") - core_gen.addApiFunctionByName("IsGamepadButtonDown") - core_gen.addApiFunctionByName("IsGamepadButtonReleased") - core_gen.addApiFunctionByName("IsGamepadButtonUp") - core_gen.addApiFunctionByName("GetGamepadButtonPressed") - core_gen.addApiFunctionByName("GetGamepadAxisCount") - core_gen.addApiFunctionByName("GetGamepadAxisMovement") - core_gen.addApiFunctionByName("SetGamepadMappings") + // input-related functions: gamepads + core.addApiFunctionByName("IsGamepadAvailable") + core.addApiFunctionByName("GetGamepadName") + core.addApiFunctionByName("IsGamepadButtonPressed") + core.addApiFunctionByName("IsGamepadButtonDown") + core.addApiFunctionByName("IsGamepadButtonReleased") + core.addApiFunctionByName("IsGamepadButtonUp") + core.addApiFunctionByName("GetGamepadButtonPressed") + core.addApiFunctionByName("GetGamepadAxisCount") + core.addApiFunctionByName("GetGamepadAxisMovement") + core.addApiFunctionByName("SetGamepadMappings") - core_gen.addApiFunctionByName("DrawText") - core_gen.addApiFunctionByName("DrawLine") - core_gen.addApiFunctionByName("DrawCircleV") - core_gen.addApiFunctionByName("GetMousePosition") - core_gen.addApiFunctionByName("IsMouseButtonPressed") - core_gen.addApiFunctionByName("GetMouseWheelMove") - core_gen.addApiFunctionByName("DrawRectangle") - core_gen.addApiFunctionByName("DrawRectangleRec") - core_gen.addApiFunctionByName("DrawRectangleLines") - core_gen.addApiFunctionByName("Fade") - api.defines.filter(x => x.type === "COLOR").map(x => ({ name: x.name, values: (x.value.match(/\{([^}]+)\}/) || "")[1].split(',').map(x => x.trim()) })).forEach(x => { - core_gen.exportGlobalStruct("Color", x.name, x.values) + // input-related functions: mouse + core.addApiFunctionByName("IsMouseButtonPressed") + core.addApiFunctionByName("IsMouseButtonDown") + core.addApiFunctionByName("IsMouseButtonReleased") + core.addApiFunctionByName("IsMouseButtonUp") + core.addApiFunctionByName("GetMouseX") + core.addApiFunctionByName("GetMouseY") + core.addApiFunctionByName("GetMousePosition") + core.addApiFunctionByName("GetMouseDelta") + core.addApiFunctionByName("SetMousePosition") + core.addApiFunctionByName("SetMouseOffset") + core.addApiFunctionByName("SetMouseScale") + core.addApiFunctionByName("GetMouseWheelMove") + core.addApiFunctionByName("GetMouseWheelMoveV") + core.addApiFunctionByName("SetMouseCursor") + + // input-related functions: touch + core.addApiFunctionByName("GetTouchX") + core.addApiFunctionByName("GetTouchY") + core.addApiFunctionByName("GetTouchPosition") + core.addApiFunctionByName("GetTouchPointId") + core.addApiFunctionByName("GetTouchPointCount") + + // Gesture and touch handling functions + core.addApiFunctionByName("SetGesturesEnabled") + core.addApiFunctionByName("IsGestureDetected") + core.addApiFunctionByName("GetGestureDetected") + core.addApiFunctionByName("GetGestureHoldDuration") + core.addApiFunctionByName("GetGestureDragVector") + core.addApiFunctionByName("GetGestureDragAngle") + core.addApiFunctionByName("GetGesturePinchVector") + core.addApiFunctionByName("GetGesturePinchAngle") + + // Camera system functions + // core.addApiFunctionByName("UpdateCamera") + // core.addApiFunctionByName("UpdateCameraPro") + + //api.functions.forEach(x => console.log(`core.addApiFunctionByName("${x.name}")`)) + + // module: rshapes + // TODO: Do we need ref-counting here? + //core.addApiFunctionByName("SetShapesTexture") + + // Basic shapes drawing functions + core.addApiFunctionByName("DrawPixel") + core.addApiFunctionByName("DrawPixelV") + core.addApiFunctionByName("DrawLine") + core.addApiFunctionByName("DrawLineV") + core.addApiFunctionByName("DrawLineEx") + core.addApiFunctionByName("DrawLineBezier") + core.addApiFunctionByName("DrawLineBezierQuad") + core.addApiFunctionByName("DrawLineBezierCubic") + // core.addApiFunctionByName("DrawLineStrip") + core.addApiFunctionByName("DrawCircle") + core.addApiFunctionByName("DrawCircleSector") + core.addApiFunctionByName("DrawCircleSectorLines") + core.addApiFunctionByName("DrawCircleGradient") + core.addApiFunctionByName("DrawCircleV") + core.addApiFunctionByName("DrawCircleLines") + core.addApiFunctionByName("DrawEllipse") + core.addApiFunctionByName("DrawEllipseLines") + core.addApiFunctionByName("DrawRing") + core.addApiFunctionByName("DrawRingLines") + core.addApiFunctionByName("DrawRectangle") + core.addApiFunctionByName("DrawRectangleV") + core.addApiFunctionByName("DrawRectangleRec") + core.addApiFunctionByName("DrawRectanglePro") + core.addApiFunctionByName("DrawRectangleGradientV") + core.addApiFunctionByName("DrawRectangleGradientH") + core.addApiFunctionByName("DrawRectangleGradientEx") + core.addApiFunctionByName("DrawRectangleLines") + core.addApiFunctionByName("DrawRectangleLinesEx") + core.addApiFunctionByName("DrawRectangleRounded") + core.addApiFunctionByName("DrawRectangleRoundedLines") + core.addApiFunctionByName("DrawTriangle") + core.addApiFunctionByName("DrawTriangleLines") + //core.addApiFunctionByName("DrawTriangleFan") + //core.addApiFunctionByName("DrawTriangleStrip") + core.addApiFunctionByName("DrawPoly") + core.addApiFunctionByName("DrawPolyLines") + core.addApiFunctionByName("DrawPolyLinesEx") + + // Basic shapes collision detection functions + core.addApiFunctionByName("CheckCollisionRecs") + core.addApiFunctionByName("CheckCollisionCircles") + core.addApiFunctionByName("CheckCollisionCircleRec") + core.addApiFunctionByName("CheckCollisionPointRec") + core.addApiFunctionByName("CheckCollisionPointCircle") + core.addApiFunctionByName("CheckCollisionPointTriangle") + // core.addApiFunctionByName("CheckCollisionPointPoly") + // core.addApiFunctionByName("CheckCollisionLines") + core.addApiFunctionByName("CheckCollisionPointLine") + core.addApiFunctionByName("GetCollisionRec") + + // Image loading functions + core.addApiFunctionByName("LoadImage") + core.addApiFunctionByName("LoadImageRaw") + // core.addApiFunctionByName("LoadImageAnim") + // core.addApiFunctionByName("LoadImageFromMemory") + core.addApiFunctionByName("LoadImageFromTexture") + core.addApiFunctionByName("LoadImageFromScreen") + core.addApiFunctionByName("IsImageReady") + // UnloadImage called by destructor + core.addApiFunctionByName("ExportImage") + // needed? + // core.addApiFunctionByName("ExportImageAsCode") + + // Image generation functions + core.addApiFunctionByName("GenImageColor") + core.addApiFunctionByName("GenImageGradientV") + core.addApiFunctionByName("GenImageGradientH") + core.addApiFunctionByName("GenImageGradientRadial") + core.addApiFunctionByName("GenImageChecked") + core.addApiFunctionByName("GenImageWhiteNoise") + core.addApiFunctionByName("GenImagePerlinNoise") + core.addApiFunctionByName("GenImageCellular") + core.addApiFunctionByName("GenImageText") + + // Image manipulations functions + core.addApiFunctionByName("ImageCopy") + core.addApiFunctionByName("ImageFromImage") + core.addApiFunctionByName("ImageText") + // core.addApiFunctionByName("ImageTextEx") + // core.addApiFunctionByName("ImageFormat") + // core.addApiFunctionByName("ImageToPOT") + // core.addApiFunctionByName("ImageCrop") + // core.addApiFunctionByName("ImageAlphaCrop") + // core.addApiFunctionByName("ImageAlphaClear") + // core.addApiFunctionByName("ImageAlphaMask") + // core.addApiFunctionByName("ImageAlphaPremultiply") + // core.addApiFunctionByName("ImageBlurGaussian") + // core.addApiFunctionByName("ImageResize") + // core.addApiFunctionByName("ImageResizeNN") + // core.addApiFunctionByName("ImageResizeCanvas") + // core.addApiFunctionByName("ImageMipmaps") + // core.addApiFunctionByName("ImageDither") + // core.addApiFunctionByName("ImageFlipVertical") + // core.addApiFunctionByName("ImageFlipHorizontal") + // core.addApiFunctionByName("ImageRotateCW") + // core.addApiFunctionByName("ImageRotateCCW") + // core.addApiFunctionByName("ImageColorTint") + // core.addApiFunctionByName("ImageColorInvert") + // core.addApiFunctionByName("ImageColorGrayscale") + // core.addApiFunctionByName("ImageColorContrast") + // core.addApiFunctionByName("ImageColorBrightness") + // core.addApiFunctionByName("ImageColorReplace") + // core.addApiFunctionByName("LoadImageColors") + // core.addApiFunctionByName("LoadImagePalette") + // core.addApiFunctionByName("UnloadImageColors") + // core.addApiFunctionByName("UnloadImagePalette") + core.addApiFunctionByName("GetImageAlphaBorder") + core.addApiFunctionByName("GetImageColor") + + // Image drawing functions + // core.addApiFunctionByName("ImageClearBackground") + // core.addApiFunctionByName("ImageDrawPixel") + // core.addApiFunctionByName("ImageDrawPixelV") + // core.addApiFunctionByName("ImageDrawLine") + // core.addApiFunctionByName("ImageDrawLineV") + // core.addApiFunctionByName("ImageDrawCircle") + // core.addApiFunctionByName("ImageDrawCircleV") + // core.addApiFunctionByName("ImageDrawCircleLines") + // core.addApiFunctionByName("ImageDrawCircleLinesV") + // core.addApiFunctionByName("ImageDrawRectangle") + // core.addApiFunctionByName("ImageDrawRectangleV") + // core.addApiFunctionByName("ImageDrawRectangleRec") + // core.addApiFunctionByName("ImageDrawRectangleLines") + // core.addApiFunctionByName("ImageDraw") + // core.addApiFunctionByName("ImageDrawText") + // core.addApiFunctionByName("ImageDrawTextEx") + + // Texture loading functions + core.addApiFunctionByName("LoadTexture") + core.addApiFunctionByName("LoadTextureFromImage") + core.addApiFunctionByName("LoadTextureCubemap") + // core.addApiFunctionByName("LoadRenderTexture") + core.addApiFunctionByName("IsTextureReady") + // "UnloadTexture" called by finalizer + // core.addApiFunctionByName("IsRenderTextureReady") + // core.addApiFunctionByName("UnloadRenderTexture") + // core.addApiFunctionByName("UpdateTexture") + // core.addApiFunctionByName("UpdateTextureRec") + + // Texture configuration functions + // core.addApiFunctionByName("GenTextureMipmaps") + core.addApiFunctionByName("SetTextureFilter") + core.addApiFunctionByName("SetTextureWrap") + + // Texture drawing functions + core.addApiFunctionByName("DrawTexture") + core.addApiFunctionByName("DrawTextureV") + core.addApiFunctionByName("DrawTextureEx") + core.addApiFunctionByName("DrawTextureRec") + core.addApiFunctionByName("DrawTexturePro") + // core.addApiFunctionByName("DrawTextureNPatch") + + // Color/pixel related functions + core.addApiFunctionByName("Fade") + core.addApiFunctionByName("ColorToInt") + core.addApiFunctionByName("ColorNormalize") + core.addApiFunctionByName("ColorFromNormalized") + core.addApiFunctionByName("ColorToHSV") + core.addApiFunctionByName("ColorFromHSV") + core.addApiFunctionByName("ColorTint") + core.addApiFunctionByName("ColorBrightness") + core.addApiFunctionByName("ColorContrast") + core.addApiFunctionByName("ColorAlpha") + core.addApiFunctionByName("ColorAlphaBlend") + core.addApiFunctionByName("GetColor") + // core.addApiFunctionByName("GetPixelColor") + // core.addApiFunctionByName("SetPixelColor") + core.addApiFunctionByName("GetPixelDataSize") + + // module: rtext + + // Font loading/unloading + core.addApiFunctionByName("GetFontDefault") + core.addApiFunctionByName("LoadFont") + // core.addApiFunctionByName("LoadFontEx") + core.addApiFunctionByName("LoadFontFromImage") + // core.addApiFunctionByName("LoadFontFromMemory") + core.addApiFunctionByName("IsFontReady") + // core.addApiFunctionByName("LoadFontData") + // core.addApiFunctionByName("GenImageFontAtlas") + // core.addApiFunctionByName("UnloadFontData") + // "UnloadFont" called by finalizer + // core.addApiFunctionByName("ExportFontAsCode") + + // Text drawing functions + core.addApiFunctionByName("DrawFPS") + core.addApiFunctionByName("DrawText") + core.addApiFunctionByName("DrawTextEx") + core.addApiFunctionByName("DrawTextPro") + core.addApiFunctionByName("DrawTextCodepoint") + //core.addApiFunctionByName("DrawTextCodepoints") + + // Text font info functions + core.addApiFunctionByName("MeasureText") + core.addApiFunctionByName("MeasureTextEx") + core.addApiFunctionByName("GetGlyphIndex") + // core.addApiFunctionByName("GetGlyphInfo") + core.addApiFunctionByName("GetGlyphAtlasRec") + + // Text codepoints management functions (unicode characters) + // Is this needed? + // core.addApiFunctionByName("LoadUTF8") + // core.addApiFunctionByName("UnloadUTF8") + // core.addApiFunctionByName("LoadCodepoints") + // core.addApiFunctionByName("UnloadCodepoints") + // core.addApiFunctionByName("GetCodepointCount") + // core.addApiFunctionByName("GetCodepoint") + // core.addApiFunctionByName("GetCodepointNext") + // core.addApiFunctionByName("GetCodepointPrevious") + // core.addApiFunctionByName("CodepointToUTF8") + + // Text strings management functions (no UTF-8 strings, only byte chars) + // Probably not needed + // core.addApiFunctionByName("TextCopy") + // core.addApiFunctionByName("TextIsEqual") + // core.addApiFunctionByName("TextLength") + // core.addApiFunctionByName("TextFormat") + // core.addApiFunctionByName("TextSubtext") + // core.addApiFunctionByName("TextReplace") + // core.addApiFunctionByName("TextInsert") + // core.addApiFunctionByName("TextJoin") + // core.addApiFunctionByName("TextSplit") + // core.addApiFunctionByName("TextAppend") + // core.addApiFunctionByName("TextFindIndex") + // core.addApiFunctionByName("TextToUpper") + // core.addApiFunctionByName("TextToLower") + // core.addApiFunctionByName("TextToPascal") + // core.addApiFunctionByName("TextToInteger") + + // module: rmodels + + // Basic geometric 3D shapes drawing functions + core.addApiFunctionByName("DrawLine3D") + core.addApiFunctionByName("DrawPoint3D") + core.addApiFunctionByName("DrawCircle3D") + core.addApiFunctionByName("DrawTriangle3D") + //core.addApiFunctionByName("DrawTriangleStrip3D") + core.addApiFunctionByName("DrawCube") + core.addApiFunctionByName("DrawCubeV") + core.addApiFunctionByName("DrawCubeWires") + core.addApiFunctionByName("DrawCubeWiresV") + core.addApiFunctionByName("DrawSphere") + core.addApiFunctionByName("DrawSphereEx") + core.addApiFunctionByName("DrawSphereWires") + core.addApiFunctionByName("DrawCylinder") + core.addApiFunctionByName("DrawCylinderEx") + core.addApiFunctionByName("DrawCylinderWires") + core.addApiFunctionByName("DrawCylinderWiresEx") + core.addApiFunctionByName("DrawCapsule") + core.addApiFunctionByName("DrawCapsuleWires") + core.addApiFunctionByName("DrawPlane") + core.addApiFunctionByName("DrawRay") + core.addApiFunctionByName("DrawGrid") + + // model management functions + core.addApiFunctionByName("LoadModel") + core.addApiFunctionByName("LoadModelFromMesh") + core.addApiFunctionByName("IsModelReady") + // "UnloadModel" called by finalizer + core.addApiFunctionByName("GetModelBoundingBox") + + // model drawing functions + core.addApiFunctionByName("DrawModel") + core.addApiFunctionByName("DrawModelEx") + core.addApiFunctionByName("DrawModelWires") + core.addApiFunctionByName("DrawModelWiresEx") + core.addApiFunctionByName("DrawBoundingBox") + core.addApiFunctionByName("DrawBillboard") + core.addApiFunctionByName("DrawBillboardRec") + core.addApiFunctionByName("DrawBillboardPro") + + // Mesh management functions + // core.addApiFunctionByName("UploadMesh") + // core.addApiFunctionByName("UpdateMeshBuffer") + // "UnloadMesh" called by finalizer + //core.addApiFunctionByName("DrawMesh") + // core.addApiFunctionByName("DrawMeshInstanced") + core.addApiFunctionByName("ExportMesh") + core.addApiFunctionByName("GetMeshBoundingBox") + // core.addApiFunctionByName("GenMeshTangents") + + // Mesh generation functions + core.addApiFunctionByName("GenMeshPoly") + core.addApiFunctionByName("GenMeshPlane") + core.addApiFunctionByName("GenMeshCube") + core.addApiFunctionByName("GenMeshSphere") + core.addApiFunctionByName("GenMeshHemiSphere") + core.addApiFunctionByName("GenMeshCylinder") + core.addApiFunctionByName("GenMeshCone") + core.addApiFunctionByName("GenMeshTorus") + core.addApiFunctionByName("GenMeshKnot") + core.addApiFunctionByName("GenMeshHeightmap") + core.addApiFunctionByName("GenMeshCubicmap") + + // Material loading/unloading functions + // core.addApiFunctionByName("LoadMaterials") + // core.addApiFunctionByName("LoadMaterialDefault") + // core.addApiFunctionByName("IsMaterialReady") + // core.addApiFunctionByName("UnloadMaterial") + // core.addApiFunctionByName("SetMaterialTexture") + // core.addApiFunctionByName("SetModelMeshMaterial") + + // Model animations loading/unloading functions + // core.addApiFunctionByName("LoadModelAnimations") + // core.addApiFunctionByName("UpdateModelAnimation") + // core.addApiFunctionByName("UnloadModelAnimation") + // core.addApiFunctionByName("UnloadModelAnimations") + // core.addApiFunctionByName("IsModelAnimationValid") + + // Collision detection functions + core.addApiFunctionByName("CheckCollisionSpheres") + core.addApiFunctionByName("CheckCollisionBoxes") + core.addApiFunctionByName("CheckCollisionBoxSphere") + core.addApiFunctionByName("GetRayCollisionSphere") + core.addApiFunctionByName("GetRayCollisionBox") + core.addApiFunctionByName("GetRayCollisionMesh") + core.addApiFunctionByName("GetRayCollisionTriangle") + core.addApiFunctionByName("GetRayCollisionQuad") + + // module: raudio + + // Audio device management functions + core.addApiFunctionByName("InitAudioDevice") + core.addApiFunctionByName("CloseAudioDevice") + core.addApiFunctionByName("IsAudioDeviceReady") + core.addApiFunctionByName("SetMasterVolume") + + // Wave/Sound loading/unloading functions + core.addApiFunctionByName("LoadWave") + // core.addApiFunctionByName("LoadWaveFromMemory") + core.addApiFunctionByName("IsWaveReady") + core.addApiFunctionByName("LoadSound") + core.addApiFunctionByName("LoadSoundFromWave") + core.addApiFunctionByName("IsSoundReady") + // core.addApiFunctionByName("UpdateSound") + // "UnloadWave" called by finalizer + // "UnloadSound" called by finalizer + core.addApiFunctionByName("ExportWave") + // core.addApiFunctionByName("ExportWaveAsCode") + + // Wave/Sound management functions + core.addApiFunctionByName("PlaySound") + core.addApiFunctionByName("StopSound") + core.addApiFunctionByName("PauseSound") + core.addApiFunctionByName("ResumeSound") + core.addApiFunctionByName("IsSoundPlaying") + core.addApiFunctionByName("SetSoundVolume") + core.addApiFunctionByName("SetSoundPitch") + core.addApiFunctionByName("SetSoundPan") + core.addApiFunctionByName("WaveCopy") + // core.addApiFunctionByName("WaveCrop") + // core.addApiFunctionByName("WaveFormat") + // core.addApiFunctionByName("LoadWaveSamples") + // core.addApiFunctionByName("UnloadWaveSamples") + + // Music management functions + core.addApiFunctionByName("LoadMusicStream") + // core.addApiFunctionByName("LoadMusicStreamFromMemory") + core.addApiFunctionByName("IsMusicReady") + // "UnloadMusicStream" called by finalizer + core.addApiFunctionByName("PlayMusicStream") + core.addApiFunctionByName("IsMusicStreamPlaying") + core.addApiFunctionByName("UpdateMusicStream") + core.addApiFunctionByName("StopMusicStream") + core.addApiFunctionByName("PauseMusicStream") + core.addApiFunctionByName("ResumeMusicStream") + core.addApiFunctionByName("SeekMusicStream") + core.addApiFunctionByName("SetMusicVolume") + core.addApiFunctionByName("SetMusicPitch") + core.addApiFunctionByName("SetMusicPan") + core.addApiFunctionByName("GetMusicTimeLength") + core.addApiFunctionByName("GetMusicTimePlayed") + + // AudioStream management functions + // core.addApiFunctionByName("LoadAudioStream") + // core.addApiFunctionByName("IsAudioStreamReady") + // core.addApiFunctionByName("UnloadAudioStream") + // core.addApiFunctionByName("UpdateAudioStream") + // core.addApiFunctionByName("IsAudioStreamProcessed") + // core.addApiFunctionByName("PlayAudioStream") + // core.addApiFunctionByName("PauseAudioStream") + // core.addApiFunctionByName("ResumeAudioStream") + // core.addApiFunctionByName("IsAudioStreamPlaying") + // core.addApiFunctionByName("StopAudioStream") + // core.addApiFunctionByName("SetAudioStreamVolume") + // core.addApiFunctionByName("SetAudioStreamPitch") + // core.addApiFunctionByName("SetAudioStreamPan") + // core.addApiFunctionByName("SetAudioStreamBufferSizeDefault") + // core.addApiFunctionByName("SetAudioStreamCallback") + + // core.addApiFunctionByName("AttachAudioStreamProcessor") + // core.addApiFunctionByName("DetachAudioStreamProcessor") + + // core.addApiFunctionByName("AttachAudioMixedProcessor") + // core.addApiFunctionByName("DetachAudioMixedProcessor") + + // module: raymath + + //mathApi.forEach(x => console.log(`core.addApi`)) + + api.defines.filter(x => x.type === "COLOR").map(x => ({ name: x.name, description: x.description, values: (x.value.match(/\{([^}]+)\}/) || "")[1].split(',').map(x => x.trim()) })).forEach(x => { + core.exportGlobalStruct("Color", x.name, x.values, x.description) }) - api.enums.find(x => x.name === "KeyboardKey")?.values.forEach(x => core_gen.exportGlobalConstant(x.name)) - api.enums.find(x => x.name === "MouseButton")?.values.forEach(x => core_gen.exportGlobalConstant(x.name)) - api.enums.find(x => x.name === "ConfigFlags")?.values.forEach(x => core_gen.exportGlobalConstant(x.name)) - api.enums.find(x => x.name === "BlendMode")?.values.forEach(x => core_gen.exportGlobalConstant(x.name)) - api.enums.find(x => x.name === "TraceLogLevel")?.values.forEach(x => core_gen.exportGlobalConstant(x.name)) - core_gen.writeTo("src/bindings/js_raylib_core.h") - - const texture_gen = new RayLibHeader("raylib_texture", apiDesc) - texture_gen.addApiStructByName("Image", { - properties: { - width: { get: true }, - height: { get: true } - }, - destructor: "UnloadImage" - }) - texture_gen.addApiFunctionByName("LoadImage") - texture_gen.writeTo("src/bindings/js_raylib_texture.h") + api.enums.find(x => x.name === "KeyboardKey")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)) + api.enums.find(x => x.name === "MouseButton")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)) + api.enums.find(x => x.name === "ConfigFlags")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)) + api.enums.find(x => x.name === "BlendMode")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)) + api.enums.find(x => x.name === "TraceLogLevel")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)) + api.enums.find(x => x.name === "MouseCursor")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)) + api.enums.find(x => x.name === "PixelFormat")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)) + api.enums.find(x => x.name === "CameraProjection")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)) + core.writeTo("src/bindings/js_raylib_core.h") + core.typings.writeTo("examples/lib.raylib.d.ts") } main() diff --git a/bindings/src/interfaces.ts b/bindings/src/interfaces.ts index 60b82a2..d74362a 100644 --- a/bindings/src/interfaces.ts +++ b/bindings/src/interfaces.ts @@ -32,18 +32,25 @@ export interface RayLibEnum { } export interface RayLibParamDescription { - type: RayLibType, + type: RayLibType | string, name: string } export interface RayLibFunction { name: string, description: string, - returnType: RayLibType, + returnType: RayLibType | string, params?: RayLibParamDescription[] } +export interface RayLibAlias { + type: string + name: string, + description: string, +} + export interface RayLibApi { + aliases: RayLibAlias[], defines: RayLibDefine[], structs: RayLibStruct[], enums: RayLibEnum[], diff --git a/bindings/src/quickjs.ts b/bindings/src/quickjs.ts index 244565c..6649915 100644 --- a/bindings/src/quickjs.ts +++ b/bindings/src/quickjs.ts @@ -12,7 +12,7 @@ export class QuickJsHeader { public readonly functions: QuickJsGenerator public readonly moduleInit: QuickJsGenerator public readonly moduleEntry: QuickJsGenerator - public readonly declarations: QuickJsGenerator + public readonly definitions: QuickJsGenerator public readonly body: QuickJsGenerator public readonly includes: QuickJsGenerator private readonly root: QuickJsGenerator @@ -31,7 +31,7 @@ export class QuickJsHeader { body.line("#define countof(x) (sizeof(x) / sizeof((x)[0]))") body.line("#endif") body.breakLine() - this.declarations = body.child() + this.definitions = body.child() body.breakLine() this.structs = body.child() this.functions = body.child() @@ -83,23 +83,34 @@ export abstract class GenericQuickJsGenerator extend this.statement(`${type} ${name} = (${type})JS_ToCString(ctx, ${src})`) this.statement(`if(${name} == NULL) return JS_EXCEPTION`) break; + case "double": + this.statement(`${type} ${name}`) + this.statement(`JS_ToFloat64(ctx, &${name}, ${src})`) + break; case "float": this.statement("double _double_"+name) this.statement(`JS_ToFloat64(ctx, &_double_${name}, ${src})`) this.statement(`${type} ${name} = (${type})_double_${name}`) break; case "int": + this.statement(`${type} ${name}`) + this.statement(`JS_ToInt32(ctx, &${name}, ${src})`) + break; case "unsigned int": this.statement(`${type} ${name}`) - this.statement(`JS_ToInt32(ctx, (int *)&${name}, ${src})`) + this.statement(`JS_ToUint32(ctx, &${name}, ${src})`) break; case "unsigned char": - this.statement("int _int_"+name) - this.statement(`JS_ToInt32(ctx, &_int_${name}, ${src})`) + this.statement("unsigned int _int_"+name) + this.statement(`JS_ToUint32(ctx, &_int_${name}, ${src})`) this.statement(`${type} ${name} = (${type})_int_${name}`) break; + case "bool": + this.statement(`${type} ${name} = JS_ToBool(ctx, ${src})`) + break; default: - const classId = classIds[type] + const isConst = type.startsWith('const') + const classId = classIds[type.replace("const ", "")] if(!classId) throw new Error("Cannot convert into parameter type: " + type) this.jsOpqToStructPtr(type, name+"_ptr", src, classId) this.statement(`if(${name}_ptr == NULL) return JS_EXCEPTION`) @@ -110,10 +121,16 @@ export abstract class GenericQuickJsGenerator extend jsToJs(type: string, name: string, src: string, classIds: StructLookup = {}){ switch (type) { case "int": - case "unsigned char": case "long": this.declare(name,'JSValue', false, `JS_NewInt32(ctx, ${src})`) break; + case "long": + this.declare(name,'JSValue', false, `JS_NewInt64(ctx, ${src})`) + break; + case "unsigned int": + case "unsigned char": + this.declare(name,'JSValue', false, `JS_NewUint32(ctx, ${src})`) + break; case "bool": this.declare(name, 'JSValue', false, `JS_NewBool(ctx, ${src})`) break; diff --git a/bindings/src/raylib-header.ts b/bindings/src/raylib-header.ts index 664921b..d9208a9 100644 --- a/bindings/src/raylib-header.ts +++ b/bindings/src/raylib-header.ts @@ -1,6 +1,7 @@ import { ApiDescription, ApiFunction, ApiStruct } from "./api" import { CodeGenerator } from "./generation" import { QuickJsGenerator, QuickJsHeader } from "./quickjs" +import { TypeScriptDeclaration } from "./typescript" export interface StructBindingOptions { properties?: { [key:string]: { get?:boolean, set?:boolean } }, @@ -17,6 +18,8 @@ export interface FuncBindingOptions { export class RayLibHeader extends QuickJsHeader { + typings = new TypeScriptDeclaration() + constructor(name: string, private api: ApiDescription){ super(name) this.includes.include("raylib.h") @@ -49,6 +52,7 @@ export class RayLibHeader extends QuickJsHeader { // add binding to function declaration this.moduleFunctionList.jsFuncDef(jName, api.argc, fun.getTag("_name")) + this.typings.addFunction(jName,api) } addApiFunctionByName(name: string, jsName: string | null = null, options: FuncBindingOptions = {}){ @@ -58,8 +62,9 @@ export class RayLibHeader extends QuickJsHeader { } addApiStruct(struct: ApiStruct, destructor: ApiFunction | null, options?: StructBindingOptions){ - const classId = this.declarations.jsClassId(`js_${struct.name}_class_id`) + const classId = this.definitions.jsClassId(`js_${struct.name}_class_id`) this.registerStruct(struct.name, classId) + this.api.getAliases(struct.name).forEach(x => this.registerStruct(x, classId)) const finalizer = this.structs.jsStructFinalizer(classId, struct.name, (gen,ptr) => destructor && gen.call(destructor.name, ["*"+ptr])) const propDeclarations = this.structs.createGenerator() @@ -91,20 +96,23 @@ export class RayLibHeader extends QuickJsHeader { this.moduleEntry.call("JS_AddModuleExport", ["ctx","m",'"'+struct.name+'"']) } + this.typings.addStruct(struct, options || {}) } - exportGlobalStruct(structName: string, exportName: string, values: string[]){ + exportGlobalStruct(structName: string, exportName: string, values: string[], description: string){ this.moduleInit.declareStruct(structName,exportName+"_struct", values) const classId = this.structLookup[structName] if(!classId) throw new Error("Struct "+structName+" not found in register") this.moduleInit.jsStructToOpq(structName, exportName+"_js", exportName+"_struct", classId) this.moduleInit.call("JS_SetModuleExport", ["ctx","m",`"${exportName}"`, exportName+"_js"]) this.moduleEntry.call("JS_AddModuleExport", ["ctx","m",`"${exportName}"`]) + this.typings.constants.tsDeclareConstant(exportName, structName, description) } - exportGlobalConstant(name: string){ + exportGlobalConstant(name: string, description: string){ this.moduleInit.statement(`JS_SetModuleExport(ctx, m, "${name}", JS_NewInt32(ctx, ${name}))`) this.moduleEntry.statement(`JS_AddModuleExport(ctx, m, "${name}")`) + this.typings.constants.tsDeclareConstant(name, "number", description) } addApiStructByName(structName: string, options?: StructBindingOptions){ diff --git a/bindings/src/typescript.ts b/bindings/src/typescript.ts new file mode 100644 index 0000000..6ce3ae9 --- /dev/null +++ b/bindings/src/typescript.ts @@ -0,0 +1,100 @@ +import { ApiFunction, ApiStruct } from "./api"; +import { GenericCodeGenerator, FunctionArgument, CodeWriter } from "./generation" +import { writeFileSync } from "fs"; +import { StructBindingOptions } from "./raylib-header"; + +export class TypeScriptDeclaration { + root = new TypescriptGenerator() + structs: TypescriptGenerator; + functions: TypescriptGenerator; + constants: TypescriptGenerator; + + constructor(){ + this.structs = this.root.child() + this.functions = this.root.child() + this.constants = this.root.child() + } + + + + addFunction(name: string, api: ApiFunction){ + const para = api.params.map(x => ({ name: x.name, type: this.toJsType(x.type)})) + const returnType = this.toJsType(api.returnType) + this.functions.tsDeclareFunction(name, para, returnType, api.description) + } + + addStruct(api: ApiStruct, options: StructBindingOptions){ + var fields = api.fields.filter(x => !!(options.properties || {})[x.name]).map(x => ({name: x.name, description: x.description, type: this.toJsType(x.type)})) + this.structs.tsDeclareInterface(api.name, fields) + this.structs.tsDeclareType(api.name, !!options.createConstructor, fields) + } + + private toJsType(type: string){ + switch(type){ + case "int": + case "long": + case "unsigned int": + case "unsigned char": + case "float": + case "double": + return "number" + case "bool": + return "boolean" + case "const char *": + case "char *": + return "string" + default: + return type + } + } + + public writeTo(filename: string){ + const writer = new CodeWriter() + writer.writeGenerator(this.root) + writeFileSync(filename, writer.toString()) + } +} + +export abstract class GenericTypescriptGenerator extends GenericCodeGenerator { + + tsDeclareFunction(name: string, parameters: FunctionArgument[], returnType: string, description: string){ + this.tsDocComment(description) + this.statement(`declare function ${name}(${parameters.map(x => x.name + ': '+x.type).join(', ')}): ${returnType}`) + } + + tsDeclareConstant(name: string, type: string, description: string){ + this.tsDocComment(description) + this.statement(`declare var ${name}: ${type}`) + } + + tsDeclareType(name: string, hasConstructor: boolean, parameters: FunctionArgument[]){ + this.line(`declare var ${name}: {`) + this.indent() + this.statement("prototype: "+name) + if(hasConstructor) this.statement(`new(${parameters.map(x => x.name+": "+x.type).join(', ')}): ${name}`) + this.unindent() + this.line("}") + } + + tsDeclareInterface(name: string, fields: FunctionArgument[]){ + this.line(`interface ${name} {`) + this.indent() + for (const field of fields) { + if(field.description) this.tsDocComment(field.description) + this.line(field.name + ": "+field.type+",") + } + this.unindent() + this.line("}") + } + + tsDocComment(comment: string){ + this.line(`/** ${comment} */`) + } +} + +export class TypescriptGenerator extends GenericTypescriptGenerator { + createGenerator(): TypescriptGenerator { + return new TypescriptGenerator() + } +} + diff --git a/examples/2d_camera.js b/examples/2d_camera.js index e8c5451..a1e7ce2 100644 --- a/examples/2d_camera.js +++ b/examples/2d_camera.js @@ -1,14 +1,12 @@ -import * as rlc from "raylib.core" - // Initialization //-------------------------------------------------------------------------------------- const screenWidth = 800; const screenHeight = 450; const MAX_BUILDINGS = 100 -rlc.initWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera"); +initWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera"); -const player = new rlc.Rectangle(400, 280, 40, 40); +const player = new Rectangle(400, 280, 40, 40); const buildings = new Array(MAX_BUILDINGS); const buildColors = new Array(MAX_BUILDINGS); @@ -16,52 +14,52 @@ let spacing = 0; for (let i = 0; i < MAX_BUILDINGS; i++) { - const height = rlc.getRandomValue(100, 800) - buildings[i] = new rlc.Rectangle( + const height = getRandomValue(100, 800) + buildings[i] = new Rectangle( -6000.0 + spacing, screenHeight - 130.0 - height, - rlc.getRandomValue(50, 200), + getRandomValue(50, 200), height) spacing += buildings[i].width; - buildColors[i] = new rlc.Color(rlc.getRandomValue(200, 240), rlc.getRandomValue(200, 240), rlc.getRandomValue(200, 250), 255); + buildColors[i] = new Color(getRandomValue(200, 240), getRandomValue(200, 240), getRandomValue(200, 250), 255); } -const camera = new rlc.Camera2D(new rlc.Vector2(screenWidth/2.0, screenHeight/2.0),new rlc.Vector2(player.x + 20.0, player.y + 20.0), 0, 1) +const camera = new Camera2D(new Vector2(screenWidth/2.0, screenHeight/2.0),new Vector2(player.x + 20.0, player.y + 20.0), 0, 1) -rlc.setTargetFPS(60); // Set our game to run at 60 frames-per-second +setTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop -while (!rlc.windowShouldClose()) // Detect window close button or ESC key +while (!windowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- // Player movement - if (rlc.isKeyDown(rlc.KEY_RIGHT)) player.x += 2; - else if (rlc.isKeyDown(rlc.KEY_LEFT)) player.x -= 2; + if (isKeyDown(KEY_RIGHT)) player.x += 2; + else if (isKeyDown(KEY_LEFT)) player.x -= 2; // Camera target follows player - const cameraTarget = new rlc.Vector2(player.x + 20, player.y + 20); + const cameraTarget = new Vector2(player.x + 20, player.y + 20); camera.target = cameraTarget; // Camera rotation controls - if (rlc.isKeyDown(rlc.KEY_A)) camera.rotation--; - else if (rlc.isKeyDown(rlc.KEY_S)) camera.rotation++; + if (isKeyDown(KEY_A)) camera.rotation--; + else if (isKeyDown(KEY_S)) camera.rotation++; // Limit camera rotation to 80 degrees (-40 to 40) if (camera.rotation > 40) camera.rotation = 40; else if (camera.rotation < -40) camera.rotation = -40; // Camera zoom controls - camera.zoom += (rlc.getMouseWheelMove()*0.05); + camera.zoom += (getMouseWheelMove()*0.05); if (camera.zoom > 3.0) camera.zoom = 3.0; else if (camera.zoom < 0.1) camera.zoom = 0.1; // Camera reset (zoom and rotation) - if (rlc.isKeyPressed(rlc.KEY_R)) + if (isKeyPressed(KEY_R)) { camera.zoom = 1.0; camera.rotation = 0.0; @@ -70,44 +68,44 @@ while (!rlc.windowShouldClose()) // Detect window close button or ESC key // Draw //---------------------------------------------------------------------------------- - rlc.beginDrawing(); + beginDrawing(); - rlc.clearBackground(rlc.RAYWHITE); + clearBackground(RAYWHITE); - rlc.beginMode2D(camera); + beginMode2D(camera); - rlc.drawRectangle(-6000, 320, 13000, 8000, rlc.DARKGRAY); + drawRectangle(-6000, 320, 13000, 8000, DARKGRAY); - for (let i = 0; i < MAX_BUILDINGS; i++) rlc.drawRectangleRec(buildings[i], buildColors[i]); + for (let i = 0; i < MAX_BUILDINGS; i++) drawRectangleRec(buildings[i], buildColors[i]); - rlc.drawRectangleRec(player, rlc.RED); + drawRectangleRec(player, RED); - rlc.drawLine(cameraTarget.x, -screenHeight*10, cameraTarget.x, screenHeight*10, rlc.GREEN); - rlc.drawLine(-screenWidth*10, cameraTarget.y, screenWidth*10, cameraTarget.y, rlc.GREEN); + drawLine(cameraTarget.x, -screenHeight*10, cameraTarget.x, screenHeight*10, GREEN); + drawLine(-screenWidth*10, cameraTarget.y, screenWidth*10, cameraTarget.y, GREEN); - rlc.endMode2D(); + endMode2D(); - rlc.drawText("SCREEN AREA", 640, 10, 20, rlc.RED); + drawText("SCREEN AREA", 640, 10, 20, RED); - rlc.drawRectangle(0, 0, screenWidth, 5, rlc.RED); - rlc.drawRectangle(0, 5, 5, screenHeight - 10, rlc.RED); - rlc.drawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, rlc.RED); - rlc.drawRectangle(0, screenHeight - 5, screenWidth, 5, rlc.RED); + drawRectangle(0, 0, screenWidth, 5, RED); + drawRectangle(0, 5, 5, screenHeight - 10, RED); + drawRectangle(screenWidth - 5, 5, 5, screenHeight - 10, RED); + drawRectangle(0, screenHeight - 5, screenWidth, 5, RED); - rlc.drawRectangle( 10, 10, 250, 113, rlc.fade(rlc.SKYBLUE, 0.5)); - rlc.drawRectangleLines( 10, 10, 250, 113, rlc.BLUE); + drawRectangle( 10, 10, 250, 113, fade(SKYBLUE, 0.5)); + drawRectangleLines( 10, 10, 250, 113, BLUE); - rlc.drawText("Free 2d camera controls:", 20, 20, 10, rlc.BLACK); - rlc.drawText("- Right/Left to move Offset", 40, 40, 10, rlc.DARKGRAY); - rlc.drawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, rlc.DARKGRAY); - rlc.drawText("- A / S to Rotate", 40, 80, 10, rlc.DARKGRAY); - rlc.drawText("- R to reset Zoom and Rotation", 40, 100, 10, rlc.DARKGRAY); + drawText("Free 2d camera controls:", 20, 20, 10, BLACK); + drawText("- Right/Left to move Offset", 40, 40, 10, DARKGRAY); + drawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, DARKGRAY); + drawText("- A / S to Rotate", 40, 80, 10, DARKGRAY); + drawText("- R to reset Zoom and Rotation", 40, 100, 10, DARKGRAY); - rlc.endDrawing(); + endDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- -rlc.closeWindow(); // Close window and OpenGL context +closeWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/2d_camera_mouse_zoom.js b/examples/2d_camera_mouse_zoom.js new file mode 100644 index 0000000..c8a25c6 --- /dev/null +++ b/examples/2d_camera_mouse_zoom.js @@ -0,0 +1,86 @@ +import * as rl from "raylib" + +for (const key in rl) { + globalThis[key] = rl[key] +} + + +// Initialization + //-------------------------------------------------------------------------------------- + const screenWidth = 800; + const screenHeight = 450; + + initWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera mouse zoom"); + + const camera = new Camera2D(new Vector2(), new Vector2(), 0, 1); + + setTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!windowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // Translate based on mouse right click + if (isMouseButtonDown(MOUSE_BUTTON_RIGHT)) + { + const delta = getMouseDelta(); + delta = vector2Scale(delta, -1.0/camera.zoom); + + camera.target = vector2Add(camera.target, delta); + } + + // Zoom based on mouse wheel + let wheel = getMouseWheelMove(); + if (wheel != 0) + { + // Get the world point that is under the mouse + const mouseWorldPos = getScreenToWorld2D(getMousePosition(), camera); + + // Set the offset to where the mouse is + camera.offset = getMousePosition(); + + // Set the target to match, so that the camera maps the world space point + // under the cursor to the screen space point under the cursor at any zoom + camera.target = mouseWorldPos; + + // Zoom increment + const zoomIncrement = 0.125; + + camera.zoom += (wheel*zoomIncrement); + if (camera.zoom < zoomIncrement) camera.zoom = zoomIncrement; + } + + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + beginDrawing(); + clearBackground(BLACK); + + beginMode2D(camera); + + // Draw the 3d grid, rotated 90 degrees and centered around 0,0 + // just so we have something in the XY plane + rlPushMatrix(); + rlTranslatef(0, 25*50, 0); + rlRotatef(90, 1, 0, 0); + drawGrid(100, 50); + rlPopMatrix(); + + // Draw a reference circle + drawCircle(100, 100, 50, YELLOW); + + endMode2D(); + + drawText("Mouse right button drag to move, mouse wheel to zoom", 10, 10, 20, WHITE); + + endDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + closeWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- diff --git a/examples/3d_camera_mode.js b/examples/3d_camera_mode.js new file mode 100644 index 0000000..6a8c8da --- /dev/null +++ b/examples/3d_camera_mode.js @@ -0,0 +1,53 @@ +// Initialization + //-------------------------------------------------------------------------------------- + const screenWidth = 800; + const screenHeight = 450; + + initWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera mode"); + + // Define the camera to look into our 3d world + const position = new Vector3(0,10,10); + const target = new Vector3(0,0,0); + const up = new Vector3(0,1,0); + const camera = new Camera3D(position,target,up, 45, CAMERA_PERSPECTIVE); + + const cubePosition = new Vector3(0,0,0); + + setTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!windowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + beginDrawing(); + + clearBackground(RAYWHITE); + + beginMode3D(camera); + + drawCube(cubePosition, 2.0, 2.0, 2.0, RED); + drawCubeWires(cubePosition, 2.0, 2.0, 2.0, MAROON); + + drawGrid(10, 1.0); + + endMode3D(); + + drawText("Welcome to the third dimension!", 10, 40, 20, DARKGRAY); + + drawFPS(10, 10); + + endDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + closeWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/examples/basic_window.js b/examples/basic_window.js index 0155dd4..0e3ce67 100644 --- a/examples/basic_window.js +++ b/examples/basic_window.js @@ -1,18 +1,16 @@ -import * as rlc from "raylib.core" - // Initialization //-------------------------------------------------------------------------------------- const screenWidth = 800; const screenHeight = 450; -rlc.initWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); +initWindow(screenWidth, screenHeight, "raylib [core] example - basic window"); -rlc.setTargetFPS(60); // Set our game to run at 60 frames-per-second +setTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop -while (!rlc.windowShouldClose()) // Detect window close button or ESC key +while (!windowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- @@ -21,13 +19,13 @@ while (!rlc.windowShouldClose()) // Detect window close button or ESC key // Draw //---------------------------------------------------------------------------------- - rlc.beginDrawing(); + beginDrawing(); - rlc.clearBackground(rlc.RAYWHITE); + clearBackground(RAYWHITE); - rlc.drawText("Congrats! You created your first window!", 190, 200, 20, rlc.LIGHTGRAY); + drawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); - rlc.endDrawing(); + endDrawing(); //---------------------------------------------------------------------------------- } diff --git a/examples/bunnymark.js b/examples/bunnymark.js new file mode 100644 index 0000000..5ee90a1 --- /dev/null +++ b/examples/bunnymark.js @@ -0,0 +1,87 @@ +// Initialization +//-------------------------------------------------------------------------------------- +const screenWidth = 800; +const screenHeight = 450; +const MAX_BUNNIES = 50000 +const MAX_BATCH_ELEMENTS = 8192 + +initWindow(screenWidth, screenHeight, "raylib [textures] example - bunnymark"); + +// Load bunny texture +const texBunny = loadTexture("assets/wabbit_alpha.png"); + +const bunnies = new Array(MAX_BUNNIES) + + +let bunniesCount = 0; // Bunnies counter + +setTargetFPS(60); // Set our game to run at 60 frames-per-second +//-------------------------------------------------------------------------------------- + +// Main game loop +while (!windowShouldClose()) // Detect window close button or ESC key +{ + // Update + //---------------------------------------------------------------------------------- + if (isMouseButtonDown(MOUSE_BUTTON_LEFT)) + { + // Create more bunnies + for (let i = 0; i < 100; i++) + { + if (bunniesCount < MAX_BUNNIES) + { + const bunny = { + position: getMousePosition(), + speed: new Vector2(getRandomValue(-250, 250)/60.0, getRandomValue(-250, 250)/60.0), + color: new Color(getRandomValue(50, 240), getRandomValue(80, 240), getRandomValue(100, 240), 255) + } + bunnies[bunniesCount] = bunny + bunniesCount++; + } + } + } + + // Update bunnies + for (let i = 0; i < bunniesCount; i++) + { + bunnies[i].position.x += bunnies[i].speed.x; + bunnies[i].position.y += bunnies[i].speed.y; + + if (((bunnies[i].position.x + texBunny.width/2) > getScreenWidth()) || + ((bunnies[i].position.x + texBunny.width/2) < 0)) bunnies[i].speed.x *= -1; + if (((bunnies[i].position.y + texBunny.height/2) > getScreenHeight()) || + ((bunnies[i].position.y + texBunny.height/2 - 40) < 0)) bunnies[i].speed.y *= -1; + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + beginDrawing(); + + clearBackground(RAYWHITE); + + for (let i = 0; i < bunniesCount; i++) + { + // NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS), + // a draw call is launched and buffer starts being filled again; + // before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU... + // Process of sending data is costly and it could happen that GPU data has not been completely + // processed for drawing while new data is tried to be sent (updating current in-use buffers) + // it could generates a stall and consequently a frame drop, limiting the number of drawn bunnies + drawTexture(texBunny, bunnies[i].position.x, bunnies[i].position.y, bunnies[i].color); + } + + drawRectangle(0, 0, screenWidth, 40, BLACK); + drawText("bunnies: " + bunniesCount, 120, 10, 20, GREEN); + drawText("batched draw calls: " + (1 + bunniesCount/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON); + + drawFPS(10, 10); + + endDrawing(); + //---------------------------------------------------------------------------------- +} + +// De-Initialization +//-------------------------------------------------------------------------------------- +closeWindow(); // Close window and OpenGL context +//-------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/examples/common/timers.js b/examples/common/timers.js new file mode 100644 index 0000000..fe4d4cb --- /dev/null +++ b/examples/common/timers.js @@ -0,0 +1,23 @@ +export class Timers { + + _timeouts_ = {} + _timeout_ctr_ = 0 + _time = 0 + + setTimeout(cb, ms){ + var ctr = this._timeout_ctr_++ + this._timeouts_[ctr] = [this._time+ms,cb] + return ctr + } + + update(deltaTime){ + this._time += (deltaTime*1000) + for (var key in this._timeouts_) { + var to = this._timeouts_[key] + if(to[0] <= this._time){ + delete this._timeouts_[key] + to[1]() + } + } + } +} diff --git a/examples/input_keys.js b/examples/input_keys.js index 69d414d..749dca6 100644 --- a/examples/input_keys.js +++ b/examples/input_keys.js @@ -1,43 +1,41 @@ -import * as rlc from "raylib.core" - // Initialization //-------------------------------------------------------------------------------------- const screenWidth = 800; const screenHeight = 450; -rlc.initWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input"); +initWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input"); -const ballPosition = new rlc.Vector2(screenWidth/2, screenHeight/2); +const ballPosition = new Vector2(screenWidth/2, screenHeight/2); -rlc.setTargetFPS(60); // Set our game to run at 60 frames-per-second +setTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop -while (!rlc.windowShouldClose()) // Detect window close button or ESC key +while (!windowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- - if (rlc.isKeyDown(rlc.KEY_RIGHT)) ballPosition.x += 2; - if (rlc.isKeyDown(rlc.KEY_LEFT)) ballPosition.x -= 2; - if (rlc.isKeyDown(rlc.KEY_UP)) ballPosition.y -= 2; - if (rlc.isKeyDown(rlc.KEY_DOWN)) ballPosition.y += 2; + if (isKeyDown(KEY_RIGHT)) ballPosition.x += 2; + if (isKeyDown(KEY_LEFT)) ballPosition.x -= 2; + if (isKeyDown(KEY_UP)) ballPosition.y -= 2; + if (isKeyDown(KEY_DOWN)) ballPosition.y += 2; //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- - rlc.beginDrawing(); + beginDrawing(); - rlc.clearBackground(rlc.RAYWHITE); + clearBackground(RAYWHITE); - rlc.drawText("move the ball with arrow keys", 10, 10, 20, rlc.DARKGRAY); + drawText("move the ball with arrow keys", 10, 10, 20, DARKGRAY); - rlc.drawCircleV(ballPosition, 50, rlc.MAROON); + drawCircleV(ballPosition, 50, MAROON); - rlc.endDrawing(); + endDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- -rlc.closeWindow(); // Close window and OpenGL context +closeWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/input_mouse.js b/examples/input_mouse.js index 98e028b..d764511 100644 --- a/examples/input_mouse.js +++ b/examples/input_mouse.js @@ -1,49 +1,47 @@ -import * as rlc from "raylib.core" - // Initialization //-------------------------------------------------------------------------------------- const screenWidth = 800; const screenHeight = 450; -rlc.initWindow(screenWidth, screenHeight, "raylib [core] example - mouse input"); +initWindow(screenWidth, screenHeight, "raylib [core] example - mouse input"); -let ballPosition = new rlc.Vector2(-100.0, -100.0); -let ballColor = rlc.DARKBLUE; +let ballPosition = new Vector2(-100.0, -100.0); +let ballColor = DARKBLUE; -rlc.setTargetFPS(60); // Set our game to run at 60 frames-per-second +setTargetFPS(60); // Set our game to run at 60 frames-per-second //--------------------------------------------------------------------------------------- // Main game loop -while (!rlc.windowShouldClose()) // Detect window close button or ESC key +while (!windowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- - ballPosition = rlc.getMousePosition(); + ballPosition = getMousePosition(); - if (rlc.isMouseButtonPressed(rlc.MOUSE_BUTTON_LEFT)) ballColor = rlc.MAROON; - else if (rlc.isMouseButtonPressed(rlc.MOUSE_BUTTON_MIDDLE)) ballColor = rlc.LIME; - else if (rlc.isMouseButtonPressed(rlc.MOUSE_BUTTON_RIGHT)) ballColor = rlc.DARKBLUE; - else if (rlc.isMouseButtonPressed(rlc.MOUSE_BUTTON_SIDE)) ballColor = rlc.PURPLE; - else if (rlc.isMouseButtonPressed(rlc.MOUSE_BUTTON_EXTRA)) ballColor = rlc.YELLOW; - else if (rlc.isMouseButtonPressed(rlc.MOUSE_BUTTON_FORWARD)) ballColor = rlc.ORANGE; - else if (rlc.isMouseButtonPressed(rlc.MOUSE_BUTTON_BACK)) ballColor = rlc.BEIGE; + if (isMouseButtonPressed(MOUSE_BUTTON_LEFT)) ballColor = MAROON; + else if (isMouseButtonPressed(MOUSE_BUTTON_MIDDLE)) ballColor = LIME; + else if (isMouseButtonPressed(MOUSE_BUTTON_RIGHT)) ballColor = DARKBLUE; + else if (isMouseButtonPressed(MOUSE_BUTTON_SIDE)) ballColor = PURPLE; + else if (isMouseButtonPressed(MOUSE_BUTTON_EXTRA)) ballColor = YELLOW; + else if (isMouseButtonPressed(MOUSE_BUTTON_FORWARD)) ballColor = ORANGE; + else if (isMouseButtonPressed(MOUSE_BUTTON_BACK)) ballColor = BEIGE; //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- - rlc.beginDrawing(); + beginDrawing(); - rlc.clearBackground(rlc.RAYWHITE); + clearBackground(RAYWHITE); - rlc.drawCircleV(ballPosition, 40, ballColor); + drawCircleV(ballPosition, 40, ballColor); - rlc.drawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rlc.DARKGRAY); + drawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY); - rlc.endDrawing(); + endDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- -rlc.closeWindow(); // Close window and OpenGL context +closeWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/input_mouse_wheel.js b/examples/input_mouse_wheel.js index 3bfcb88..73199ce 100644 --- a/examples/input_mouse_wheel.js +++ b/examples/input_mouse_wheel.js @@ -1,42 +1,40 @@ -import * as rlc from "raylib.core" - // Initialization //-------------------------------------------------------------------------------------- const screenWidth = 800; const screenHeight = 450; -rlc.initWindow(screenWidth, screenHeight, "raylib [core] example - input mouse wheel"); +initWindow(screenWidth, screenHeight, "raylib [core] example - input mouse wheel"); let boxPositionY = screenHeight/2 - 40; let scrollSpeed = 4; // Scrolling speed in pixels -rlc.setTargetFPS(60); // Set our game to run at 60 frames-per-second +setTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop -while (!rlc.windowShouldClose()) // Detect window close button or ESC key +while (!windowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- - boxPositionY -= (rlc.getMouseWheelMove()*scrollSpeed); + boxPositionY -= (getMouseWheelMove()*scrollSpeed); //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- - rlc.beginDrawing(); + beginDrawing(); - rlc.clearBackground(rlc.RAYWHITE); + clearBackground(RAYWHITE); - rlc.drawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, rlc.MAROON); + drawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, MAROON); - rlc.drawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, rlc.GRAY); - rlc.drawText("Box position Y: " + boxPositionY, 10, 40, 20, rlc.LIGHTGRAY); + drawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, GRAY); + drawText("Box position Y: " + boxPositionY, 10, 40, 20, LIGHTGRAY); - rlc.endDrawing(); + endDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- -rlc.closeWindow(); // Close window and OpenGL context +closeWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/js_example.js b/examples/js_example.js new file mode 100644 index 0000000..9c190c0 --- /dev/null +++ b/examples/js_example.js @@ -0,0 +1,20 @@ +import { Timers } from "./examples/common/timers.js" + +const timers = new Timers() + +initWindow(640, 480, "Javascript Tests") + +const pos = new Vector2(getScreenWidth()/2,getScreenHeight()/2) +const radius = 100 + +timers.setTimeout(() => pos.x += 200, 2000) + +while(!windowShouldClose()){ + timers.update(getFrameTime()) + beginDrawing() + clearBackground(RAYWHITE) + drawCircle(pos.x,pos.y, radius, LIME) + endDrawing() +} + +closeWindow() \ No newline at end of file diff --git a/examples/lib.raylib.d.ts b/examples/lib.raylib.d.ts new file mode 100644 index 0000000..3aed2ec --- /dev/null +++ b/examples/lib.raylib.d.ts @@ -0,0 +1,1251 @@ +interface Color { + /** Color red value */ + r: number, + /** Color green value */ + g: number, + /** Color blue value */ + b: number, + /** Color alpha value */ + a: number, +} +declare var Color: { + prototype: Color; + new(r: number, g: number, b: number, a: number): Color; +} +interface Rectangle { + /** Rectangle top-left corner position x */ + x: number, + /** Rectangle top-left corner position y */ + y: number, + /** Rectangle width */ + width: number, + /** Rectangle height */ + height: number, +} +declare var Rectangle: { + prototype: Rectangle; + new(x: number, y: number, width: number, height: number): Rectangle; +} +interface Vector2 { + /** Vector x component */ + x: number, + /** Vector y component */ + y: number, +} +declare var Vector2: { + prototype: Vector2; + new(x: number, y: number): Vector2; +} +interface Vector3 { + /** Vector x component */ + x: number, + /** Vector y component */ + y: number, + /** Vector z component */ + z: number, +} +declare var Vector3: { + prototype: Vector3; + new(x: number, y: number, z: number): Vector3; +} +interface Vector4 { + /** Vector x component */ + x: number, + /** Vector y component */ + y: number, + /** Vector z component */ + z: number, + /** Vector w component */ + w: number, +} +declare var Vector4: { + prototype: Vector4; + new(x: number, y: number, z: number, w: number): Vector4; +} +interface Ray { + /** Ray position (origin) */ + position: Vector3, + /** Ray direction */ + direction: Vector3, +} +declare var Ray: { + prototype: Ray; + new(position: Vector3, direction: Vector3): Ray; +} +interface RayCollision { + /** Did the ray hit something? */ + hit: boolean, + /** Distance to the nearest hit */ + distance: number, +} +declare var RayCollision: { + prototype: RayCollision; +} +interface Camera2D { + /** Camera offset (displacement from target) */ + offset: Vector2, + /** Camera target (rotation and zoom origin) */ + target: Vector2, + /** Camera rotation in degrees */ + rotation: number, + /** Camera zoom (scaling), should be 1.0f by default */ + zoom: number, +} +declare var Camera2D: { + prototype: Camera2D; + new(offset: Vector2, target: Vector2, rotation: number, zoom: number): Camera2D; +} +interface Camera3D { + /** Camera position */ + position: Vector3, + /** Camera target it looks-at */ + target: Vector3, + /** Camera up vector (rotation over its axis) */ + up: Vector3, + /** Camera field-of-view aperture in Y (degrees) in perspective, used as near plane width in orthographic */ + fovy: number, + /** Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC */ + projection: number, +} +declare var Camera3D: { + prototype: Camera3D; + new(position: Vector3, target: Vector3, up: Vector3, fovy: number, projection: number): Camera3D; +} +interface BoundingBox { +} +declare var BoundingBox: { + prototype: BoundingBox; + new(): BoundingBox; +} +interface Matrix { +} +declare var Matrix: { + prototype: Matrix; +} +interface Image { + /** Image base width */ + width: number, + /** Image base height */ + height: number, + /** Mipmap levels, 1 by default */ + mipmaps: number, + /** Data format (PixelFormat type) */ + format: number, +} +declare var Image: { + prototype: Image; +} +interface Wave { + /** Total number of frames (considering channels) */ + frameCount: number, + /** Frequency (samples per second) */ + sampleRate: number, + /** Bit depth (bits per sample): 8, 16, 32 (24 not supported) */ + sampleSize: number, + /** Number of channels (1-mono, 2-stereo, ...) */ + channels: number, +} +declare var Wave: { + prototype: Wave; +} +interface Sound { + /** Total number of frames (considering channels) */ + frameCount: number, +} +declare var Sound: { + prototype: Sound; +} +interface Music { + /** Total number of frames (considering channels) */ + frameCount: number, + /** Music looping enable */ + looping: boolean, +} +declare var Music: { + prototype: Music; +} +interface Model { +} +declare var Model: { + prototype: Model; +} +interface Mesh { +} +declare var Mesh: { + prototype: Mesh; +} +interface Shader { +} +declare var Shader: { + prototype: Shader; +} +interface Texture { + /** Texture base width */ + width: number, + /** Texture base height */ + height: number, +} +declare var Texture: { + prototype: Texture; +} +interface Font { + /** Base size (default chars height) */ + baseSize: number, +} +declare var Font: { + prototype: Font; +} +/** Initialize window and OpenGL context */ +declare function initWindow(width: number, height: number, title: string): void; +/** Check if KEY_ESCAPE pressed or Close icon pressed */ +declare function windowShouldClose(): boolean; +/** Close window and unload OpenGL context */ +declare function closeWindow(): void; +/** Check if window has been initialized successfully */ +declare function isWindowReady(): boolean; +/** Check if window is currently fullscreen */ +declare function isWindowFullscreen(): boolean; +/** Check if window is currently hidden (only PLATFORM_DESKTOP) */ +declare function isWindowHidden(): boolean; +/** Check if window is currently minimized (only PLATFORM_DESKTOP) */ +declare function isWindowMinimized(): boolean; +/** Check if window is currently maximized (only PLATFORM_DESKTOP) */ +declare function isWindowMaximized(): boolean; +/** Check if window is currently focused (only PLATFORM_DESKTOP) */ +declare function isWindowFocused(): boolean; +/** Check if window has been resized last frame */ +declare function isWindowResized(): boolean; +/** Check if one specific window flag is enabled */ +declare function isWindowState(flag: number): boolean; +/** Set window configuration state using flags (only PLATFORM_DESKTOP) */ +declare function setWindowState(flags: number): void; +/** Clear window configuration state flags */ +declare function clearWindowState(flags: number): void; +/** Toggle window state: fullscreen/windowed (only PLATFORM_DESKTOP) */ +declare function toggleFullscreen(): void; +/** Set window state: maximized, if resizable (only PLATFORM_DESKTOP) */ +declare function maximizeWindow(): void; +/** Set window state: minimized, if resizable (only PLATFORM_DESKTOP) */ +declare function minimizeWindow(): void; +/** Set window state: not minimized/maximized (only PLATFORM_DESKTOP) */ +declare function restoreWindow(): void; +/** Set title for window (only PLATFORM_DESKTOP) */ +declare function setWindowTitle(title: string): void; +/** Set window position on screen (only PLATFORM_DESKTOP) */ +declare function setWindowPosition(x: number, y: number): void; +/** Set monitor for the current window (fullscreen mode) */ +declare function setWindowMonitor(monitor: number): void; +/** Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE) */ +declare function setWindowMinSize(width: number, height: number): void; +/** Set window dimensions */ +declare function setWindowSize(width: number, height: number): void; +/** Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP) */ +declare function setWindowOpacity(opacity: number): void; +/** Get current screen width */ +declare function getScreenWidth(): number; +/** Get current screen height */ +declare function getScreenHeight(): number; +/** Get current render width (it considers HiDPI) */ +declare function getRenderWidth(): number; +/** Get current render height (it considers HiDPI) */ +declare function getRenderHeight(): number; +/** Get number of connected monitors */ +declare function getMonitorCount(): number; +/** Get current connected monitor */ +declare function getCurrentMonitor(): number; +/** Get specified monitor position */ +declare function getMonitorPosition(monitor: number): Vector2; +/** Get specified monitor width (current video mode used by monitor) */ +declare function getMonitorWidth(monitor: number): number; +/** Get specified monitor height (current video mode used by monitor) */ +declare function getMonitorHeight(monitor: number): number; +/** Get specified monitor physical width in millimetres */ +declare function getMonitorPhysicalWidth(monitor: number): number; +/** Get specified monitor physical height in millimetres */ +declare function getMonitorPhysicalHeight(monitor: number): number; +/** Get specified monitor refresh rate */ +declare function getMonitorRefreshRate(monitor: number): number; +/** Get window position XY on monitor */ +declare function getWindowPosition(): Vector2; +/** Get window scale DPI factor */ +declare function getWindowScaleDPI(): Vector2; +/** Get the human-readable, UTF-8 encoded name of the primary monitor */ +declare function getMonitorName(monitor: number): string; +/** Set clipboard text content */ +declare function setClipboardText(text: string): void; +/** Get clipboard text content */ +declare function getClipboardText(): string; +/** Enable waiting for events on EndDrawing(), no automatic event polling */ +declare function enableEventWaiting(): void; +/** Disable waiting for events on EndDrawing(), automatic events polling */ +declare function disableEventWaiting(): void; +/** Shows cursor */ +declare function showCursor(): void; +/** Hides cursor */ +declare function hideCursor(): void; +/** Check if cursor is not visible */ +declare function isCursorHidden(): boolean; +/** Enables cursor (unlock cursor) */ +declare function enableCursor(): void; +/** Disables cursor (lock cursor) */ +declare function disableCursor(): void; +/** Check if cursor is on the screen */ +declare function isCursorOnScreen(): boolean; +/** Set background color (framebuffer clear color) */ +declare function clearBackground(color: Color): void; +/** Setup canvas (framebuffer) to start drawing */ +declare function beginDrawing(): void; +/** End canvas drawing and swap buffers (double buffering) */ +declare function endDrawing(): void; +/** Begin 2D mode with custom camera (2D) */ +declare function beginMode2D(camera: Camera2D): void; +/** Ends 2D mode with custom camera */ +declare function endMode2D(): void; +/** Begin 3D mode with custom camera (3D) */ +declare function beginMode3D(camera: Camera3D): void; +/** Ends 3D mode and returns to default 2D orthographic mode */ +declare function endMode3D(): void; +/** Begin blending mode (alpha, additive, multiplied, subtract, custom) */ +declare function beginBlendMode(mode: number): void; +/** End blending mode (reset to default: alpha blending) */ +declare function endBlendMode(): void; +/** Begin scissor mode (define screen area for following drawing) */ +declare function beginScissorMode(x: number, y: number, width: number, height: number): void; +/** End scissor mode */ +declare function endScissorMode(): void; +/** Get camera 2d transform matrix */ +declare function getCameraMatrix2D(camera: Camera2D): Matrix; +/** Get the world space position for a 2d camera screen space position */ +declare function getScreenToWorld2D(position: Vector2, camera: Camera2D): Vector2; +/** Get the screen space position for a 2d camera world space position */ +declare function getWorldToScreen2D(position: Vector2, camera: Camera2D): Vector2; +/** Set target FPS (maximum) */ +declare function setTargetFPS(fps: number): void; +/** Get current FPS */ +declare function getFPS(): number; +/** Get time in seconds for last frame drawn (delta time) */ +declare function getFrameTime(): number; +/** Get elapsed time in seconds since InitWindow() */ +declare function getTime(): number; +/** Get a random value between min and max (both included) */ +declare function getRandomValue(min: number, max: number): number; +/** Set the seed for the random number generator */ +declare function setRandomSeed(seed: number): void; +/** Takes a screenshot of current screen (filename extension defines format) */ +declare function takeScreenshot(fileName: string): void; +/** Setup init configuration flags (view FLAGS) */ +declare function setConfigFlags(flags: number): void; +/** Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR...) */ +declare function traceLog(logLevel: number, text: string): void; +/** Set the current threshold (minimum) log level */ +declare function setTraceLogLevel(logLevel: number): void; +/** Open URL with default system browser (if available) */ +declare function openURL(url: string): void; +/** Load text data from file (read), returns a '\0' terminated string */ +declare function loadFileText(fileName: string): string; +/** Save text data to file (write), string must be '\0' terminated, returns true on success */ +declare function saveFileText(fileName: string, text: string): boolean; +/** Check if file exists */ +declare function fileExists(fileName: string): boolean; +/** Check if a directory path exists */ +declare function directoryExists(dirPath: string): boolean; +/** Check file extension (including point: .png, .wav) */ +declare function isFileExtension(fileName: string, ext: string): boolean; +/** Get file length in bytes (NOTE: GetFileSize() conflicts with windows.h) */ +declare function getFileLength(fileName: string): number; +/** Get pointer to extension for a filename string (includes dot: '.png') */ +declare function getFileExtension(fileName: string): string; +/** Get pointer to filename for a path string */ +declare function getFileName(filePath: string): string; +/** Get filename string without extension (uses static string) */ +declare function getFileNameWithoutExt(filePath: string): string; +/** Get full path for a given fileName with path (uses static string) */ +declare function getDirectoryPath(filePath: string): string; +/** Get previous directory path for a given path (uses static string) */ +declare function getPrevDirectoryPath(dirPath: string): string; +/** Get current working directory (uses static string) */ +declare function getWorkingDirectory(): string; +/** Get the directory if the running application (uses static string) */ +declare function getApplicationDirectory(): string; +/** Change working directory, return true on success */ +declare function changeDirectory(dir: string): boolean; +/** Check if a given path is a file or a directory */ +declare function isPathFile(path: string): boolean; +/** Check if a file has been dropped into window */ +declare function isFileDropped(): boolean; +/** Get file modification time (last write time) */ +declare function getFileModTime(fileName: string): number; +/** Check if a key has been pressed once */ +declare function isKeyPressed(key: number): boolean; +/** Check if a key is being pressed */ +declare function isKeyDown(key: number): boolean; +/** Check if a key has been released once */ +declare function isKeyReleased(key: number): boolean; +/** Check if a key is NOT being pressed */ +declare function isKeyUp(key: number): boolean; +/** Set a custom key to exit program (default is ESC) */ +declare function setExitKey(key: number): void; +/** Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty */ +declare function getKeyPressed(): number; +/** Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty */ +declare function getCharPressed(): number; +/** Check if a gamepad is available */ +declare function isGamepadAvailable(gamepad: number): boolean; +/** Get gamepad internal name id */ +declare function getGamepadName(gamepad: number): string; +/** Check if a gamepad button has been pressed once */ +declare function isGamepadButtonPressed(gamepad: number, button: number): boolean; +/** Check if a gamepad button is being pressed */ +declare function isGamepadButtonDown(gamepad: number, button: number): boolean; +/** Check if a gamepad button has been released once */ +declare function isGamepadButtonReleased(gamepad: number, button: number): boolean; +/** Check if a gamepad button is NOT being pressed */ +declare function isGamepadButtonUp(gamepad: number, button: number): boolean; +/** Get the last gamepad button pressed */ +declare function getGamepadButtonPressed(): number; +/** Get gamepad axis count for a gamepad */ +declare function getGamepadAxisCount(gamepad: number): number; +/** Get axis movement value for a gamepad axis */ +declare function getGamepadAxisMovement(gamepad: number, axis: number): number; +/** Set internal gamepad mappings (SDL_GameControllerDB) */ +declare function setGamepadMappings(mappings: string): number; +/** Check if a mouse button has been pressed once */ +declare function isMouseButtonPressed(button: number): boolean; +/** Check if a mouse button is being pressed */ +declare function isMouseButtonDown(button: number): boolean; +/** Check if a mouse button has been released once */ +declare function isMouseButtonReleased(button: number): boolean; +/** Check if a mouse button is NOT being pressed */ +declare function isMouseButtonUp(button: number): boolean; +/** Get mouse position X */ +declare function getMouseX(): number; +/** Get mouse position Y */ +declare function getMouseY(): number; +/** Get mouse position XY */ +declare function getMousePosition(): Vector2; +/** Get mouse delta between frames */ +declare function getMouseDelta(): Vector2; +/** Set mouse position XY */ +declare function setMousePosition(x: number, y: number): void; +/** Set mouse offset */ +declare function setMouseOffset(offsetX: number, offsetY: number): void; +/** Set mouse scaling */ +declare function setMouseScale(scaleX: number, scaleY: number): void; +/** Get mouse wheel movement for X or Y, whichever is larger */ +declare function getMouseWheelMove(): number; +/** Get mouse wheel movement for both X and Y */ +declare function getMouseWheelMoveV(): Vector2; +/** Set mouse cursor */ +declare function setMouseCursor(cursor: number): void; +/** Get touch position X for touch point 0 (relative to screen size) */ +declare function getTouchX(): number; +/** Get touch position Y for touch point 0 (relative to screen size) */ +declare function getTouchY(): number; +/** Get touch position XY for a touch point index (relative to screen size) */ +declare function getTouchPosition(index: number): Vector2; +/** Get touch point identifier for given index */ +declare function getTouchPointId(index: number): number; +/** Get number of touch points */ +declare function getTouchPointCount(): number; +/** Enable a set of gestures using flags */ +declare function setGesturesEnabled(flags: number): void; +/** Check if a gesture have been detected */ +declare function isGestureDetected(gesture: number): boolean; +/** Get latest detected gesture */ +declare function getGestureDetected(): number; +/** Get gesture hold time in milliseconds */ +declare function getGestureHoldDuration(): number; +/** Get gesture drag vector */ +declare function getGestureDragVector(): Vector2; +/** Get gesture drag angle */ +declare function getGestureDragAngle(): number; +/** Get gesture pinch delta */ +declare function getGesturePinchVector(): Vector2; +/** Get gesture pinch angle */ +declare function getGesturePinchAngle(): number; +/** Draw a pixel */ +declare function drawPixel(posX: number, posY: number, color: Color): void; +/** Draw a pixel (Vector version) */ +declare function drawPixelV(position: Vector2, color: Color): void; +/** Draw a line */ +declare function drawLine(startPosX: number, startPosY: number, endPosX: number, endPosY: number, color: Color): void; +/** Draw a line (Vector version) */ +declare function drawLineV(startPos: Vector2, endPos: Vector2, color: Color): void; +/** Draw a line defining thickness */ +declare function drawLineEx(startPos: Vector2, endPos: Vector2, thick: number, color: Color): void; +/** Draw a line using cubic-bezier curves in-out */ +declare function drawLineBezier(startPos: Vector2, endPos: Vector2, thick: number, color: Color): void; +/** Draw line using quadratic bezier curves with a control point */ +declare function drawLineBezierQuad(startPos: Vector2, endPos: Vector2, controlPos: Vector2, thick: number, color: Color): void; +/** Draw line using cubic bezier curves with 2 control points */ +declare function drawLineBezierCubic(startPos: Vector2, endPos: Vector2, startControlPos: Vector2, endControlPos: Vector2, thick: number, color: Color): void; +/** Draw a color-filled circle */ +declare function drawCircle(centerX: number, centerY: number, radius: number, color: Color): void; +/** Draw a piece of a circle */ +declare function drawCircleSector(center: Vector2, radius: number, startAngle: number, endAngle: number, segments: number, color: Color): void; +/** Draw circle sector outline */ +declare function drawCircleSectorLines(center: Vector2, radius: number, startAngle: number, endAngle: number, segments: number, color: Color): void; +/** Draw a gradient-filled circle */ +declare function drawCircleGradient(centerX: number, centerY: number, radius: number, color1: Color, color2: Color): void; +/** Draw a color-filled circle (Vector version) */ +declare function drawCircleV(center: Vector2, radius: number, color: Color): void; +/** Draw circle outline */ +declare function drawCircleLines(centerX: number, centerY: number, radius: number, color: Color): void; +/** Draw ellipse */ +declare function drawEllipse(centerX: number, centerY: number, radiusH: number, radiusV: number, color: Color): void; +/** Draw ellipse outline */ +declare function drawEllipseLines(centerX: number, centerY: number, radiusH: number, radiusV: number, color: Color): void; +/** Draw ring */ +declare function drawRing(center: Vector2, innerRadius: number, outerRadius: number, startAngle: number, endAngle: number, segments: number, color: Color): void; +/** Draw ring outline */ +declare function drawRingLines(center: Vector2, innerRadius: number, outerRadius: number, startAngle: number, endAngle: number, segments: number, color: Color): void; +/** Draw a color-filled rectangle */ +declare function drawRectangle(posX: number, posY: number, width: number, height: number, color: Color): void; +/** Draw a color-filled rectangle (Vector version) */ +declare function drawRectangleV(position: Vector2, size: Vector2, color: Color): void; +/** Draw a color-filled rectangle */ +declare function drawRectangleRec(rec: Rectangle, color: Color): void; +/** Draw a color-filled rectangle with pro parameters */ +declare function drawRectanglePro(rec: Rectangle, origin: Vector2, rotation: number, color: Color): void; +/** Draw a vertical-gradient-filled rectangle */ +declare function drawRectangleGradientV(posX: number, posY: number, width: number, height: number, color1: Color, color2: Color): void; +/** Draw a horizontal-gradient-filled rectangle */ +declare function drawRectangleGradientH(posX: number, posY: number, width: number, height: number, color1: Color, color2: Color): void; +/** Draw a gradient-filled rectangle with custom vertex colors */ +declare function drawRectangleGradientEx(rec: Rectangle, col1: Color, col2: Color, col3: Color, col4: Color): void; +/** Draw rectangle outline */ +declare function drawRectangleLines(posX: number, posY: number, width: number, height: number, color: Color): void; +/** Draw rectangle outline with extended parameters */ +declare function drawRectangleLinesEx(rec: Rectangle, lineThick: number, color: Color): void; +/** Draw rectangle with rounded edges */ +declare function drawRectangleRounded(rec: Rectangle, roundness: number, segments: number, color: Color): void; +/** Draw rectangle with rounded edges outline */ +declare function drawRectangleRoundedLines(rec: Rectangle, roundness: number, segments: number, lineThick: number, color: Color): void; +/** Draw a color-filled triangle (vertex in counter-clockwise order!) */ +declare function drawTriangle(v1: Vector2, v2: Vector2, v3: Vector2, color: Color): void; +/** Draw triangle outline (vertex in counter-clockwise order!) */ +declare function drawTriangleLines(v1: Vector2, v2: Vector2, v3: Vector2, color: Color): void; +/** Draw a regular polygon (Vector version) */ +declare function drawPoly(center: Vector2, sides: number, radius: number, rotation: number, color: Color): void; +/** Draw a polygon outline of n sides */ +declare function drawPolyLines(center: Vector2, sides: number, radius: number, rotation: number, color: Color): void; +/** Draw a polygon outline of n sides with extended parameters */ +declare function drawPolyLinesEx(center: Vector2, sides: number, radius: number, rotation: number, lineThick: number, color: Color): void; +/** Check collision between two rectangles */ +declare function checkCollisionRecs(rec1: Rectangle, rec2: Rectangle): boolean; +/** Check collision between two circles */ +declare function checkCollisionCircles(center1: Vector2, radius1: number, center2: Vector2, radius2: number): boolean; +/** Check collision between circle and rectangle */ +declare function checkCollisionCircleRec(center: Vector2, radius: number, rec: Rectangle): boolean; +/** Check if point is inside rectangle */ +declare function checkCollisionPointRec(point: Vector2, rec: Rectangle): boolean; +/** Check if point is inside circle */ +declare function checkCollisionPointCircle(point: Vector2, center: Vector2, radius: number): boolean; +/** Check if point is inside a triangle */ +declare function checkCollisionPointTriangle(point: Vector2, p1: Vector2, p2: Vector2, p3: Vector2): boolean; +/** Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold] */ +declare function checkCollisionPointLine(point: Vector2, p1: Vector2, p2: Vector2, threshold: number): boolean; +/** Get collision rectangle for two rectangles collision */ +declare function getCollisionRec(rec1: Rectangle, rec2: Rectangle): Rectangle; +/** Load image from file into CPU memory (RAM) */ +declare function loadImage(fileName: string): Image; +/** Load image from RAW file data */ +declare function loadImageRaw(fileName: string, width: number, height: number, format: number, headerSize: number): Image; +/** Load image from GPU texture data */ +declare function loadImageFromTexture(texture: Texture2D): Image; +/** Load image from screen buffer and (screenshot) */ +declare function loadImageFromScreen(): Image; +/** Check if an image is ready */ +declare function isImageReady(image: Image): boolean; +/** Export image data to file, returns true on success */ +declare function exportImage(image: Image, fileName: string): boolean; +/** Generate image: plain color */ +declare function genImageColor(width: number, height: number, color: Color): Image; +/** Generate image: vertical gradient */ +declare function genImageGradientV(width: number, height: number, top: Color, bottom: Color): Image; +/** Generate image: horizontal gradient */ +declare function genImageGradientH(width: number, height: number, left: Color, right: Color): Image; +/** Generate image: radial gradient */ +declare function genImageGradientRadial(width: number, height: number, density: number, inner: Color, outer: Color): Image; +/** Generate image: checked */ +declare function genImageChecked(width: number, height: number, checksX: number, checksY: number, col1: Color, col2: Color): Image; +/** Generate image: white noise */ +declare function genImageWhiteNoise(width: number, height: number, factor: number): Image; +/** Generate image: perlin noise */ +declare function genImagePerlinNoise(width: number, height: number, offsetX: number, offsetY: number, scale: number): Image; +/** Generate image: cellular algorithm, bigger tileSize means bigger cells */ +declare function genImageCellular(width: number, height: number, tileSize: number): Image; +/** Generate image: grayscale image from text data */ +declare function genImageText(width: number, height: number, text: string): Image; +/** Create an image duplicate (useful for transformations) */ +declare function imageCopy(image: Image): Image; +/** Create an image from another image piece */ +declare function imageFromImage(image: Image, rec: Rectangle): Image; +/** Create an image from text (default font) */ +declare function imageText(text: string, fontSize: number, color: Color): Image; +/** Get image alpha border rectangle */ +declare function getImageAlphaBorder(image: Image, threshold: number): Rectangle; +/** Get image pixel color at (x, y) position */ +declare function getImageColor(image: Image, x: number, y: number): Color; +/** Load texture from file into GPU memory (VRAM) */ +declare function loadTexture(fileName: string): Texture2D; +/** Load texture from image data */ +declare function loadTextureFromImage(image: Image): Texture2D; +/** Load cubemap from image, multiple image cubemap layouts supported */ +declare function loadTextureCubemap(image: Image, layout: number): TextureCubemap; +/** Check if a texture is ready */ +declare function isTextureReady(texture: Texture2D): boolean; +/** Set texture scaling filter mode */ +declare function setTextureFilter(texture: Texture2D, filter: number): void; +/** Set texture wrapping mode */ +declare function setTextureWrap(texture: Texture2D, wrap: number): void; +/** Draw a Texture2D */ +declare function drawTexture(texture: Texture2D, posX: number, posY: number, tint: Color): void; +/** Draw a Texture2D with position defined as Vector2 */ +declare function drawTextureV(texture: Texture2D, position: Vector2, tint: Color): void; +/** Draw a Texture2D with extended parameters */ +declare function drawTextureEx(texture: Texture2D, position: Vector2, rotation: number, scale: number, tint: Color): void; +/** Draw a part of a texture defined by a rectangle */ +declare function drawTextureRec(texture: Texture2D, source: Rectangle, position: Vector2, tint: Color): void; +/** Draw a part of a texture defined by a rectangle with 'pro' parameters */ +declare function drawTexturePro(texture: Texture2D, source: Rectangle, dest: Rectangle, origin: Vector2, rotation: number, tint: Color): void; +/** Get color with alpha applied, alpha goes from 0.0f to 1.0f */ +declare function fade(color: Color, alpha: number): Color; +/** Get hexadecimal value for a Color */ +declare function colorToInt(color: Color): number; +/** Get Color normalized as float [0..1] */ +declare function colorNormalize(color: Color): Vector4; +/** Get Color from normalized values [0..1] */ +declare function colorFromNormalized(normalized: Vector4): Color; +/** Get HSV values for a Color, hue [0..360], saturation/value [0..1] */ +declare function colorToHSV(color: Color): Vector3; +/** Get a Color from HSV values, hue [0..360], saturation/value [0..1] */ +declare function colorFromHSV(hue: number, saturation: number, value: number): Color; +/** Get color multiplied with another color */ +declare function colorTint(color: Color, tint: Color): Color; +/** Get color with brightness correction, brightness factor goes from -1.0f to 1.0f */ +declare function colorBrightness(color: Color, factor: number): Color; +/** Get color with contrast correction, contrast values between -1.0f and 1.0f */ +declare function colorContrast(color: Color, contrast: number): Color; +/** Get color with alpha applied, alpha goes from 0.0f to 1.0f */ +declare function colorAlpha(color: Color, alpha: number): Color; +/** Get src alpha-blended into dst color with tint */ +declare function colorAlphaBlend(dst: Color, src: Color, tint: Color): Color; +/** Get Color structure from hexadecimal value */ +declare function getColor(hexValue: number): Color; +/** Get pixel data size in bytes for certain format */ +declare function getPixelDataSize(width: number, height: number, format: number): number; +/** Get the default Font */ +declare function getFontDefault(): Font; +/** Load font from file into GPU memory (VRAM) */ +declare function loadFont(fileName: string): Font; +/** Load font from Image (XNA style) */ +declare function loadFontFromImage(image: Image, key: Color, firstChar: number): Font; +/** Check if a font is ready */ +declare function isFontReady(font: Font): boolean; +/** Draw current FPS */ +declare function drawFPS(posX: number, posY: number): void; +/** Draw text (using default font) */ +declare function drawText(text: string, posX: number, posY: number, fontSize: number, color: Color): void; +/** Draw text using font and additional parameters */ +declare function drawTextEx(font: Font, text: string, position: Vector2, fontSize: number, spacing: number, tint: Color): void; +/** Draw text using Font and pro parameters (rotation) */ +declare function drawTextPro(font: Font, text: string, position: Vector2, origin: Vector2, rotation: number, fontSize: number, spacing: number, tint: Color): void; +/** Draw one character (codepoint) */ +declare function drawTextCodepoint(font: Font, codepoint: number, position: Vector2, fontSize: number, tint: Color): void; +/** Measure string width for default font */ +declare function measureText(text: string, fontSize: number): number; +/** Measure string size for Font */ +declare function measureTextEx(font: Font, text: string, fontSize: number, spacing: number): Vector2; +/** Get glyph index position in font for a codepoint (unicode character), fallback to '?' if not found */ +declare function getGlyphIndex(font: Font, codepoint: number): number; +/** Get glyph rectangle in font atlas for a codepoint (unicode character), fallback to '?' if not found */ +declare function getGlyphAtlasRec(font: Font, codepoint: number): Rectangle; +/** Draw a line in 3D world space */ +declare function drawLine3D(startPos: Vector3, endPos: Vector3, color: Color): void; +/** Draw a point in 3D space, actually a small line */ +declare function drawPoint3D(position: Vector3, color: Color): void; +/** Draw a circle in 3D world space */ +declare function drawCircle3D(center: Vector3, radius: number, rotationAxis: Vector3, rotationAngle: number, color: Color): void; +/** Draw a color-filled triangle (vertex in counter-clockwise order!) */ +declare function drawTriangle3D(v1: Vector3, v2: Vector3, v3: Vector3, color: Color): void; +/** Draw cube */ +declare function drawCube(position: Vector3, width: number, height: number, length: number, color: Color): void; +/** Draw cube (Vector version) */ +declare function drawCubeV(position: Vector3, size: Vector3, color: Color): void; +/** Draw cube wires */ +declare function drawCubeWires(position: Vector3, width: number, height: number, length: number, color: Color): void; +/** Draw cube wires (Vector version) */ +declare function drawCubeWiresV(position: Vector3, size: Vector3, color: Color): void; +/** Draw sphere */ +declare function drawSphere(centerPos: Vector3, radius: number, color: Color): void; +/** Draw sphere with extended parameters */ +declare function drawSphereEx(centerPos: Vector3, radius: number, rings: number, slices: number, color: Color): void; +/** Draw sphere wires */ +declare function drawSphereWires(centerPos: Vector3, radius: number, rings: number, slices: number, color: Color): void; +/** Draw a cylinder/cone */ +declare function drawCylinder(position: Vector3, radiusTop: number, radiusBottom: number, height: number, slices: number, color: Color): void; +/** Draw a cylinder with base at startPos and top at endPos */ +declare function drawCylinderEx(startPos: Vector3, endPos: Vector3, startRadius: number, endRadius: number, sides: number, color: Color): void; +/** Draw a cylinder/cone wires */ +declare function drawCylinderWires(position: Vector3, radiusTop: number, radiusBottom: number, height: number, slices: number, color: Color): void; +/** Draw a cylinder wires with base at startPos and top at endPos */ +declare function drawCylinderWiresEx(startPos: Vector3, endPos: Vector3, startRadius: number, endRadius: number, sides: number, color: Color): void; +/** Draw a capsule with the center of its sphere caps at startPos and endPos */ +declare function drawCapsule(startPos: Vector3, endPos: Vector3, radius: number, slices: number, rings: number, color: Color): void; +/** Draw capsule wireframe with the center of its sphere caps at startPos and endPos */ +declare function drawCapsuleWires(startPos: Vector3, endPos: Vector3, radius: number, slices: number, rings: number, color: Color): void; +/** Draw a plane XZ */ +declare function drawPlane(centerPos: Vector3, size: Vector2, color: Color): void; +/** Draw a ray line */ +declare function drawRay(ray: Ray, color: Color): void; +/** Draw a grid (centered at (0, 0, 0)) */ +declare function drawGrid(slices: number, spacing: number): void; +/** Load model from files (meshes and materials) */ +declare function loadModel(fileName: string): Model; +/** Load model from generated mesh (default material) */ +declare function loadModelFromMesh(mesh: Mesh): Model; +/** Check if a model is ready */ +declare function isModelReady(model: Model): boolean; +/** Compute model bounding box limits (considers all meshes) */ +declare function getModelBoundingBox(model: Model): BoundingBox; +/** Draw a model (with texture if set) */ +declare function drawModel(model: Model, position: Vector3, scale: number, tint: Color): void; +/** Draw a model with extended parameters */ +declare function drawModelEx(model: Model, position: Vector3, rotationAxis: Vector3, rotationAngle: number, scale: Vector3, tint: Color): void; +/** Draw a model wires (with texture if set) */ +declare function drawModelWires(model: Model, position: Vector3, scale: number, tint: Color): void; +/** Draw a model wires (with texture if set) with extended parameters */ +declare function drawModelWiresEx(model: Model, position: Vector3, rotationAxis: Vector3, rotationAngle: number, scale: Vector3, tint: Color): void; +/** Draw bounding box (wires) */ +declare function drawBoundingBox(box: BoundingBox, color: Color): void; +/** Draw a billboard texture */ +declare function drawBillboard(camera: Camera, texture: Texture2D, position: Vector3, size: number, tint: Color): void; +/** Draw a billboard texture defined by source */ +declare function drawBillboardRec(camera: Camera, texture: Texture2D, source: Rectangle, position: Vector3, size: Vector2, tint: Color): void; +/** Draw a billboard texture defined by source and rotation */ +declare function drawBillboardPro(camera: Camera, texture: Texture2D, source: Rectangle, position: Vector3, up: Vector3, size: Vector2, origin: Vector2, rotation: number, tint: Color): void; +/** Export mesh data to file, returns true on success */ +declare function exportMesh(mesh: Mesh, fileName: string): boolean; +/** Compute mesh bounding box limits */ +declare function getMeshBoundingBox(mesh: Mesh): BoundingBox; +/** Generate polygonal mesh */ +declare function genMeshPoly(sides: number, radius: number): Mesh; +/** Generate plane mesh (with subdivisions) */ +declare function genMeshPlane(width: number, length: number, resX: number, resZ: number): Mesh; +/** Generate cuboid mesh */ +declare function genMeshCube(width: number, height: number, length: number): Mesh; +/** Generate sphere mesh (standard sphere) */ +declare function genMeshSphere(radius: number, rings: number, slices: number): Mesh; +/** Generate half-sphere mesh (no bottom cap) */ +declare function genMeshHemiSphere(radius: number, rings: number, slices: number): Mesh; +/** Generate cylinder mesh */ +declare function genMeshCylinder(radius: number, height: number, slices: number): Mesh; +/** Generate cone/pyramid mesh */ +declare function genMeshCone(radius: number, height: number, slices: number): Mesh; +/** Generate torus mesh */ +declare function genMeshTorus(radius: number, size: number, radSeg: number, sides: number): Mesh; +/** Generate trefoil knot mesh */ +declare function genMeshKnot(radius: number, size: number, radSeg: number, sides: number): Mesh; +/** Generate heightmap mesh from image data */ +declare function genMeshHeightmap(heightmap: Image, size: Vector3): Mesh; +/** Generate cubes-based map mesh from image data */ +declare function genMeshCubicmap(cubicmap: Image, cubeSize: Vector3): Mesh; +/** Check collision between two spheres */ +declare function checkCollisionSpheres(center1: Vector3, radius1: number, center2: Vector3, radius2: number): boolean; +/** Check collision between two bounding boxes */ +declare function checkCollisionBoxes(box1: BoundingBox, box2: BoundingBox): boolean; +/** Check collision between box and sphere */ +declare function checkCollisionBoxSphere(box: BoundingBox, center: Vector3, radius: number): boolean; +/** Get collision info between ray and sphere */ +declare function getRayCollisionSphere(ray: Ray, center: Vector3, radius: number): RayCollision; +/** Get collision info between ray and box */ +declare function getRayCollisionBox(ray: Ray, box: BoundingBox): RayCollision; +/** Get collision info between ray and mesh */ +declare function getRayCollisionMesh(ray: Ray, mesh: Mesh, transform: Matrix): RayCollision; +/** Get collision info between ray and triangle */ +declare function getRayCollisionTriangle(ray: Ray, p1: Vector3, p2: Vector3, p3: Vector3): RayCollision; +/** Get collision info between ray and quad */ +declare function getRayCollisionQuad(ray: Ray, p1: Vector3, p2: Vector3, p3: Vector3, p4: Vector3): RayCollision; +/** Initialize audio device and context */ +declare function initAudioDevice(): void; +/** Close the audio device and context */ +declare function closeAudioDevice(): void; +/** Check if audio device has been initialized successfully */ +declare function isAudioDeviceReady(): boolean; +/** Set master volume (listener) */ +declare function setMasterVolume(volume: number): void; +/** Load wave data from file */ +declare function loadWave(fileName: string): Wave; +/** Checks if wave data is ready */ +declare function isWaveReady(wave: Wave): boolean; +/** Load sound from file */ +declare function loadSound(fileName: string): Sound; +/** Load sound from wave data */ +declare function loadSoundFromWave(wave: Wave): Sound; +/** Checks if a sound is ready */ +declare function isSoundReady(sound: Sound): boolean; +/** Export wave data to file, returns true on success */ +declare function exportWave(wave: Wave, fileName: string): boolean; +/** Play a sound */ +declare function playSound(sound: Sound): void; +/** Stop playing a sound */ +declare function stopSound(sound: Sound): void; +/** Pause a sound */ +declare function pauseSound(sound: Sound): void; +/** Resume a paused sound */ +declare function resumeSound(sound: Sound): void; +/** Check if a sound is currently playing */ +declare function isSoundPlaying(sound: Sound): boolean; +/** Set volume for a sound (1.0 is max level) */ +declare function setSoundVolume(sound: Sound, volume: number): void; +/** Set pitch for a sound (1.0 is base level) */ +declare function setSoundPitch(sound: Sound, pitch: number): void; +/** Set pan for a sound (0.5 is center) */ +declare function setSoundPan(sound: Sound, pan: number): void; +/** Copy a wave to a new wave */ +declare function waveCopy(wave: Wave): Wave; +/** Load music stream from file */ +declare function loadMusicStream(fileName: string): Music; +/** Checks if a music stream is ready */ +declare function isMusicReady(music: Music): boolean; +/** Start music playing */ +declare function playMusicStream(music: Music): void; +/** Check if music is playing */ +declare function isMusicStreamPlaying(music: Music): boolean; +/** Updates buffers for music streaming */ +declare function updateMusicStream(music: Music): void; +/** Stop music playing */ +declare function stopMusicStream(music: Music): void; +/** Pause music playing */ +declare function pauseMusicStream(music: Music): void; +/** Resume playing paused music */ +declare function resumeMusicStream(music: Music): void; +/** Seek music to a position (in seconds) */ +declare function seekMusicStream(music: Music, position: number): void; +/** Set volume for music (1.0 is max level) */ +declare function setMusicVolume(music: Music, volume: number): void; +/** Set pitch for a music (1.0 is base level) */ +declare function setMusicPitch(music: Music, pitch: number): void; +/** Set pan for a music (0.5 is center) */ +declare function setMusicPan(music: Music, pan: number): void; +/** Get music time length (in seconds) */ +declare function getMusicTimeLength(music: Music): number; +/** Get current music time played (in seconds) */ +declare function getMusicTimePlayed(music: Music): number; +/** Light Gray */ +declare var LIGHTGRAY: Color; +/** Gray */ +declare var GRAY: Color; +/** Dark Gray */ +declare var DARKGRAY: Color; +/** Yellow */ +declare var YELLOW: Color; +/** Gold */ +declare var GOLD: Color; +/** Orange */ +declare var ORANGE: Color; +/** Pink */ +declare var PINK: Color; +/** Red */ +declare var RED: Color; +/** Maroon */ +declare var MAROON: Color; +/** Green */ +declare var GREEN: Color; +/** Lime */ +declare var LIME: Color; +/** Dark Green */ +declare var DARKGREEN: Color; +/** Sky Blue */ +declare var SKYBLUE: Color; +/** Blue */ +declare var BLUE: Color; +/** Dark Blue */ +declare var DARKBLUE: Color; +/** Purple */ +declare var PURPLE: Color; +/** Violet */ +declare var VIOLET: Color; +/** Dark Purple */ +declare var DARKPURPLE: Color; +/** Beige */ +declare var BEIGE: Color; +/** Brown */ +declare var BROWN: Color; +/** Dark Brown */ +declare var DARKBROWN: Color; +/** White */ +declare var WHITE: Color; +/** Black */ +declare var BLACK: Color; +/** Blank (Transparent) */ +declare var BLANK: Color; +/** Magenta */ +declare var MAGENTA: Color; +/** My own White (raylib logo) */ +declare var RAYWHITE: Color; +/** Key: NULL, used for no key pressed */ +declare var KEY_NULL: number; +/** Key: ' */ +declare var KEY_APOSTROPHE: number; +/** Key: , */ +declare var KEY_COMMA: number; +/** Key: - */ +declare var KEY_MINUS: number; +/** Key: . */ +declare var KEY_PERIOD: number; +/** Key: / */ +declare var KEY_SLASH: number; +/** Key: 0 */ +declare var KEY_ZERO: number; +/** Key: 1 */ +declare var KEY_ONE: number; +/** Key: 2 */ +declare var KEY_TWO: number; +/** Key: 3 */ +declare var KEY_THREE: number; +/** Key: 4 */ +declare var KEY_FOUR: number; +/** Key: 5 */ +declare var KEY_FIVE: number; +/** Key: 6 */ +declare var KEY_SIX: number; +/** Key: 7 */ +declare var KEY_SEVEN: number; +/** Key: 8 */ +declare var KEY_EIGHT: number; +/** Key: 9 */ +declare var KEY_NINE: number; +/** Key: ; */ +declare var KEY_SEMICOLON: number; +/** Key: = */ +declare var KEY_EQUAL: number; +/** Key: A | a */ +declare var KEY_A: number; +/** Key: B | b */ +declare var KEY_B: number; +/** Key: C | c */ +declare var KEY_C: number; +/** Key: D | d */ +declare var KEY_D: number; +/** Key: E | e */ +declare var KEY_E: number; +/** Key: F | f */ +declare var KEY_F: number; +/** Key: G | g */ +declare var KEY_G: number; +/** Key: H | h */ +declare var KEY_H: number; +/** Key: I | i */ +declare var KEY_I: number; +/** Key: J | j */ +declare var KEY_J: number; +/** Key: K | k */ +declare var KEY_K: number; +/** Key: L | l */ +declare var KEY_L: number; +/** Key: M | m */ +declare var KEY_M: number; +/** Key: N | n */ +declare var KEY_N: number; +/** Key: O | o */ +declare var KEY_O: number; +/** Key: P | p */ +declare var KEY_P: number; +/** Key: Q | q */ +declare var KEY_Q: number; +/** Key: R | r */ +declare var KEY_R: number; +/** Key: S | s */ +declare var KEY_S: number; +/** Key: T | t */ +declare var KEY_T: number; +/** Key: U | u */ +declare var KEY_U: number; +/** Key: V | v */ +declare var KEY_V: number; +/** Key: W | w */ +declare var KEY_W: number; +/** Key: X | x */ +declare var KEY_X: number; +/** Key: Y | y */ +declare var KEY_Y: number; +/** Key: Z | z */ +declare var KEY_Z: number; +/** Key: [ */ +declare var KEY_LEFT_BRACKET: number; +/** Key: '\' */ +declare var KEY_BACKSLASH: number; +/** Key: ] */ +declare var KEY_RIGHT_BRACKET: number; +/** Key: ` */ +declare var KEY_GRAVE: number; +/** Key: Space */ +declare var KEY_SPACE: number; +/** Key: Esc */ +declare var KEY_ESCAPE: number; +/** Key: Enter */ +declare var KEY_ENTER: number; +/** Key: Tab */ +declare var KEY_TAB: number; +/** Key: Backspace */ +declare var KEY_BACKSPACE: number; +/** Key: Ins */ +declare var KEY_INSERT: number; +/** Key: Del */ +declare var KEY_DELETE: number; +/** Key: Cursor right */ +declare var KEY_RIGHT: number; +/** Key: Cursor left */ +declare var KEY_LEFT: number; +/** Key: Cursor down */ +declare var KEY_DOWN: number; +/** Key: Cursor up */ +declare var KEY_UP: number; +/** Key: Page up */ +declare var KEY_PAGE_UP: number; +/** Key: Page down */ +declare var KEY_PAGE_DOWN: number; +/** Key: Home */ +declare var KEY_HOME: number; +/** Key: End */ +declare var KEY_END: number; +/** Key: Caps lock */ +declare var KEY_CAPS_LOCK: number; +/** Key: Scroll down */ +declare var KEY_SCROLL_LOCK: number; +/** Key: Num lock */ +declare var KEY_NUM_LOCK: number; +/** Key: Print screen */ +declare var KEY_PRINT_SCREEN: number; +/** Key: Pause */ +declare var KEY_PAUSE: number; +/** Key: F1 */ +declare var KEY_F1: number; +/** Key: F2 */ +declare var KEY_F2: number; +/** Key: F3 */ +declare var KEY_F3: number; +/** Key: F4 */ +declare var KEY_F4: number; +/** Key: F5 */ +declare var KEY_F5: number; +/** Key: F6 */ +declare var KEY_F6: number; +/** Key: F7 */ +declare var KEY_F7: number; +/** Key: F8 */ +declare var KEY_F8: number; +/** Key: F9 */ +declare var KEY_F9: number; +/** Key: F10 */ +declare var KEY_F10: number; +/** Key: F11 */ +declare var KEY_F11: number; +/** Key: F12 */ +declare var KEY_F12: number; +/** Key: Shift left */ +declare var KEY_LEFT_SHIFT: number; +/** Key: Control left */ +declare var KEY_LEFT_CONTROL: number; +/** Key: Alt left */ +declare var KEY_LEFT_ALT: number; +/** Key: Super left */ +declare var KEY_LEFT_SUPER: number; +/** Key: Shift right */ +declare var KEY_RIGHT_SHIFT: number; +/** Key: Control right */ +declare var KEY_RIGHT_CONTROL: number; +/** Key: Alt right */ +declare var KEY_RIGHT_ALT: number; +/** Key: Super right */ +declare var KEY_RIGHT_SUPER: number; +/** Key: KB menu */ +declare var KEY_KB_MENU: number; +/** Key: Keypad 0 */ +declare var KEY_KP_0: number; +/** Key: Keypad 1 */ +declare var KEY_KP_1: number; +/** Key: Keypad 2 */ +declare var KEY_KP_2: number; +/** Key: Keypad 3 */ +declare var KEY_KP_3: number; +/** Key: Keypad 4 */ +declare var KEY_KP_4: number; +/** Key: Keypad 5 */ +declare var KEY_KP_5: number; +/** Key: Keypad 6 */ +declare var KEY_KP_6: number; +/** Key: Keypad 7 */ +declare var KEY_KP_7: number; +/** Key: Keypad 8 */ +declare var KEY_KP_8: number; +/** Key: Keypad 9 */ +declare var KEY_KP_9: number; +/** Key: Keypad . */ +declare var KEY_KP_DECIMAL: number; +/** Key: Keypad / */ +declare var KEY_KP_DIVIDE: number; +/** Key: Keypad * */ +declare var KEY_KP_MULTIPLY: number; +/** Key: Keypad - */ +declare var KEY_KP_SUBTRACT: number; +/** Key: Keypad + */ +declare var KEY_KP_ADD: number; +/** Key: Keypad Enter */ +declare var KEY_KP_ENTER: number; +/** Key: Keypad = */ +declare var KEY_KP_EQUAL: number; +/** Key: Android back button */ +declare var KEY_BACK: number; +/** Key: Android menu button */ +declare var KEY_MENU: number; +/** Key: Android volume up button */ +declare var KEY_VOLUME_UP: number; +/** Key: Android volume down button */ +declare var KEY_VOLUME_DOWN: number; +/** Mouse button left */ +declare var MOUSE_BUTTON_LEFT: number; +/** Mouse button right */ +declare var MOUSE_BUTTON_RIGHT: number; +/** Mouse button middle (pressed wheel) */ +declare var MOUSE_BUTTON_MIDDLE: number; +/** Mouse button side (advanced mouse device) */ +declare var MOUSE_BUTTON_SIDE: number; +/** Mouse button extra (advanced mouse device) */ +declare var MOUSE_BUTTON_EXTRA: number; +/** Mouse button forward (advanced mouse device) */ +declare var MOUSE_BUTTON_FORWARD: number; +/** Mouse button back (advanced mouse device) */ +declare var MOUSE_BUTTON_BACK: number; +/** Set to try enabling V-Sync on GPU */ +declare var FLAG_VSYNC_HINT: number; +/** Set to run program in fullscreen */ +declare var FLAG_FULLSCREEN_MODE: number; +/** Set to allow resizable window */ +declare var FLAG_WINDOW_RESIZABLE: number; +/** Set to disable window decoration (frame and buttons) */ +declare var FLAG_WINDOW_UNDECORATED: number; +/** Set to hide window */ +declare var FLAG_WINDOW_HIDDEN: number; +/** Set to minimize window (iconify) */ +declare var FLAG_WINDOW_MINIMIZED: number; +/** Set to maximize window (expanded to monitor) */ +declare var FLAG_WINDOW_MAXIMIZED: number; +/** Set to window non focused */ +declare var FLAG_WINDOW_UNFOCUSED: number; +/** Set to window always on top */ +declare var FLAG_WINDOW_TOPMOST: number; +/** Set to allow windows running while minimized */ +declare var FLAG_WINDOW_ALWAYS_RUN: number; +/** Set to allow transparent framebuffer */ +declare var FLAG_WINDOW_TRANSPARENT: number; +/** Set to support HighDPI */ +declare var FLAG_WINDOW_HIGHDPI: number; +/** Set to support mouse passthrough, only supported when FLAG_WINDOW_UNDECORATED */ +declare var FLAG_WINDOW_MOUSE_PASSTHROUGH: number; +/** Set to try enabling MSAA 4X */ +declare var FLAG_MSAA_4X_HINT: number; +/** Set to try enabling interlaced video format (for V3D) */ +declare var FLAG_INTERLACED_HINT: number; +/** Blend textures considering alpha (default) */ +declare var BLEND_ALPHA: number; +/** Blend textures adding colors */ +declare var BLEND_ADDITIVE: number; +/** Blend textures multiplying colors */ +declare var BLEND_MULTIPLIED: number; +/** Blend textures adding colors (alternative) */ +declare var BLEND_ADD_COLORS: number; +/** Blend textures subtracting colors (alternative) */ +declare var BLEND_SUBTRACT_COLORS: number; +/** Blend premultiplied textures considering alpha */ +declare var BLEND_ALPHA_PREMULTIPLY: number; +/** Blend textures using custom src/dst factors (use rlSetBlendFactors()) */ +declare var BLEND_CUSTOM: number; +/** Blend textures using custom rgb/alpha separate src/dst factors (use rlSetBlendFactorsSeparate()) */ +declare var BLEND_CUSTOM_SEPARATE: number; +/** Display all logs */ +declare var LOG_ALL: number; +/** Trace logging, intended for internal use only */ +declare var LOG_TRACE: number; +/** Debug logging, used for internal debugging, it should be disabled on release builds */ +declare var LOG_DEBUG: number; +/** Info logging, used for program execution info */ +declare var LOG_INFO: number; +/** Warning logging, used on recoverable failures */ +declare var LOG_WARNING: number; +/** Error logging, used on unrecoverable failures */ +declare var LOG_ERROR: number; +/** Fatal logging, used to abort program: exit(EXIT_FAILURE) */ +declare var LOG_FATAL: number; +/** Disable logging */ +declare var LOG_NONE: number; +/** Default pointer shape */ +declare var MOUSE_CURSOR_DEFAULT: number; +/** Arrow shape */ +declare var MOUSE_CURSOR_ARROW: number; +/** Text writing cursor shape */ +declare var MOUSE_CURSOR_IBEAM: number; +/** Cross shape */ +declare var MOUSE_CURSOR_CROSSHAIR: number; +/** Pointing hand cursor */ +declare var MOUSE_CURSOR_POINTING_HAND: number; +/** Horizontal resize/move arrow shape */ +declare var MOUSE_CURSOR_RESIZE_EW: number; +/** Vertical resize/move arrow shape */ +declare var MOUSE_CURSOR_RESIZE_NS: number; +/** Top-left to bottom-right diagonal resize/move arrow shape */ +declare var MOUSE_CURSOR_RESIZE_NWSE: number; +/** The top-right to bottom-left diagonal resize/move arrow shape */ +declare var MOUSE_CURSOR_RESIZE_NESW: number; +/** The omnidirectional resize/move cursor shape */ +declare var MOUSE_CURSOR_RESIZE_ALL: number; +/** The operation-not-allowed shape */ +declare var MOUSE_CURSOR_NOT_ALLOWED: number; +/** 8 bit per pixel (no alpha) */ +declare var PIXELFORMAT_UNCOMPRESSED_GRAYSCALE: number; +/** 8*2 bpp (2 channels) */ +declare var PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA: number; +/** 16 bpp */ +declare var PIXELFORMAT_UNCOMPRESSED_R5G6B5: number; +/** 24 bpp */ +declare var PIXELFORMAT_UNCOMPRESSED_R8G8B8: number; +/** 16 bpp (1 bit alpha) */ +declare var PIXELFORMAT_UNCOMPRESSED_R5G5B5A1: number; +/** 16 bpp (4 bit alpha) */ +declare var PIXELFORMAT_UNCOMPRESSED_R4G4B4A4: number; +/** 32 bpp */ +declare var PIXELFORMAT_UNCOMPRESSED_R8G8B8A8: number; +/** 32 bpp (1 channel - float) */ +declare var PIXELFORMAT_UNCOMPRESSED_R32: number; +/** 32*3 bpp (3 channels - float) */ +declare var PIXELFORMAT_UNCOMPRESSED_R32G32B32: number; +/** 32*4 bpp (4 channels - float) */ +declare var PIXELFORMAT_UNCOMPRESSED_R32G32B32A32: number; +/** 4 bpp (no alpha) */ +declare var PIXELFORMAT_COMPRESSED_DXT1_RGB: number; +/** 4 bpp (1 bit alpha) */ +declare var PIXELFORMAT_COMPRESSED_DXT1_RGBA: number; +/** 8 bpp */ +declare var PIXELFORMAT_COMPRESSED_DXT3_RGBA: number; +/** 8 bpp */ +declare var PIXELFORMAT_COMPRESSED_DXT5_RGBA: number; +/** 4 bpp */ +declare var PIXELFORMAT_COMPRESSED_ETC1_RGB: number; +/** 4 bpp */ +declare var PIXELFORMAT_COMPRESSED_ETC2_RGB: number; +/** 8 bpp */ +declare var PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA: number; +/** 4 bpp */ +declare var PIXELFORMAT_COMPRESSED_PVRT_RGB: number; +/** 4 bpp */ +declare var PIXELFORMAT_COMPRESSED_PVRT_RGBA: number; +/** 8 bpp */ +declare var PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA: number; +/** 2 bpp */ +declare var PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA: number; +/** Perspective projection */ +declare var CAMERA_PERSPECTIVE: number; +/** Orthographic projection */ +declare var CAMERA_ORTHOGRAPHIC: number; diff --git a/examples/tsconfig.json b/examples/tsconfig.json new file mode 100644 index 0000000..4f408c1 --- /dev/null +++ b/examples/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "allowJs": true, + "target": "es2020", + "lib": ["ES2020"] + } + } + \ No newline at end of file diff --git a/generate-bindings.js b/generate-bindings.js index 4b5e193..1ac2c59 100644 --- a/generate-bindings.js +++ b/generate-bindings.js @@ -20,6 +20,7 @@ class ApiFunction { get argc() { return this.api.params?.length || 0; } get params() { return this.api.params || []; } get returnType() { return this.api.returnType; } + get description() { return this.api.description; } } exports.ApiFunction = ApiFunction; class ApiStruct { @@ -34,6 +35,9 @@ class ApiDescription { constructor(api) { this.api = api; } + getAliases(name) { + return this.api.aliases.filter(x => x.type === name).map(x => x.name); + } getFunction(name) { const f = this.api.functions.find(x => x.name === name); if (!f) @@ -303,7 +307,7 @@ class QuickJsHeader { body.line("#define countof(x) (sizeof(x) / sizeof((x)[0]))"); body.line("#endif"); body.breakLine(); - this.declarations = body.child(); + this.definitions = body.child(); body.breakLine(); this.structs = body.child(); this.functions = body.child(); @@ -348,23 +352,34 @@ class GenericQuickJsGenerator extends generation_1.GenericCodeGenerator { this.statement(`${type} ${name} = (${type})JS_ToCString(ctx, ${src})`); this.statement(`if(${name} == NULL) return JS_EXCEPTION`); break; + case "double": + this.statement(`${type} ${name}`); + this.statement(`JS_ToFloat64(ctx, &${name}, ${src})`); + break; case "float": this.statement("double _double_" + name); this.statement(`JS_ToFloat64(ctx, &_double_${name}, ${src})`); this.statement(`${type} ${name} = (${type})_double_${name}`); break; case "int": + this.statement(`${type} ${name}`); + this.statement(`JS_ToInt32(ctx, &${name}, ${src})`); + break; case "unsigned int": this.statement(`${type} ${name}`); - this.statement(`JS_ToInt32(ctx, (int *)&${name}, ${src})`); + this.statement(`JS_ToUint32(ctx, &${name}, ${src})`); break; case "unsigned char": - this.statement("int _int_" + name); - this.statement(`JS_ToInt32(ctx, &_int_${name}, ${src})`); + this.statement("unsigned int _int_" + name); + this.statement(`JS_ToUint32(ctx, &_int_${name}, ${src})`); this.statement(`${type} ${name} = (${type})_int_${name}`); break; + case "bool": + this.statement(`${type} ${name} = JS_ToBool(ctx, ${src})`); + break; default: - const classId = classIds[type]; + const isConst = type.startsWith('const'); + const classId = classIds[type.replace("const ", "")]; if (!classId) throw new Error("Cannot convert into parameter type: " + type); this.jsOpqToStructPtr(type, name + "_ptr", src, classId); @@ -375,10 +390,16 @@ class GenericQuickJsGenerator extends generation_1.GenericCodeGenerator { jsToJs(type, name, src, classIds = {}) { switch (type) { case "int": - case "unsigned char": case "long": this.declare(name, 'JSValue', false, `JS_NewInt32(ctx, ${src})`); break; + case "long": + this.declare(name, 'JSValue', false, `JS_NewInt64(ctx, ${src})`); + break; + case "unsigned int": + case "unsigned char": + this.declare(name, 'JSValue', false, `JS_NewUint32(ctx, ${src})`); + break; case "bool": this.declare(name, 'JSValue', false, `JS_NewBool(ctx, ${src})`); break; @@ -521,10 +542,12 @@ exports.QuickJsGenerator = QuickJsGenerator; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.RayLibHeader = void 0; const quickjs_1 = __webpack_require__(/*! ./quickjs */ "./src/quickjs.ts"); +const typescript_1 = __webpack_require__(/*! ./typescript */ "./src/typescript.ts"); class RayLibHeader extends quickjs_1.QuickJsHeader { constructor(name, api) { super(name); this.api = api; + this.typings = new typescript_1.TypeScriptDeclaration(); this.includes.include("raylib.h"); } addApiFunction(api, jsName = null, options = {}) { @@ -555,6 +578,7 @@ class RayLibHeader extends quickjs_1.QuickJsHeader { } // add binding to function declaration this.moduleFunctionList.jsFuncDef(jName, api.argc, fun.getTag("_name")); + this.typings.addFunction(jName, api); } addApiFunctionByName(name, jsName = null, options = {}) { const func = this.api.getFunction(name); @@ -563,8 +587,9 @@ class RayLibHeader extends quickjs_1.QuickJsHeader { this.addApiFunction(func, jsName, options); } addApiStruct(struct, destructor, options) { - const classId = this.declarations.jsClassId(`js_${struct.name}_class_id`); + const classId = this.definitions.jsClassId(`js_${struct.name}_class_id`); this.registerStruct(struct.name, classId); + this.api.getAliases(struct.name).forEach(x => this.registerStruct(x, classId)); const finalizer = this.structs.jsStructFinalizer(classId, struct.name, (gen, ptr) => destructor && gen.call(destructor.name, ["*" + ptr])); const propDeclarations = this.structs.createGenerator(); if (options && options.properties) { @@ -593,8 +618,9 @@ class RayLibHeader extends quickjs_1.QuickJsHeader { this.moduleInit.call("JS_SetModuleExport", ["ctx", "m", `"${struct.name}"`, struct.name + "_constr"]); this.moduleEntry.call("JS_AddModuleExport", ["ctx", "m", '"' + struct.name + '"']); } + this.typings.addStruct(struct, options || {}); } - exportGlobalStruct(structName, exportName, values) { + exportGlobalStruct(structName, exportName, values, description) { this.moduleInit.declareStruct(structName, exportName + "_struct", values); const classId = this.structLookup[structName]; if (!classId) @@ -602,10 +628,12 @@ class RayLibHeader extends quickjs_1.QuickJsHeader { this.moduleInit.jsStructToOpq(structName, exportName + "_js", exportName + "_struct", classId); this.moduleInit.call("JS_SetModuleExport", ["ctx", "m", `"${exportName}"`, exportName + "_js"]); this.moduleEntry.call("JS_AddModuleExport", ["ctx", "m", `"${exportName}"`]); + this.typings.constants.tsDeclareConstant(exportName, structName, description); } - exportGlobalConstant(name) { + exportGlobalConstant(name, description) { this.moduleInit.statement(`JS_SetModuleExport(ctx, m, "${name}", JS_NewInt32(ctx, ${name}))`); this.moduleEntry.statement(`JS_AddModuleExport(ctx, m, "${name}")`); + this.typings.constants.tsDeclareConstant(name, "number", description); } addApiStructByName(structName, options) { const struct = this.api.getStruct(structName); @@ -623,6 +651,103 @@ class RayLibHeader extends quickjs_1.QuickJsHeader { exports.RayLibHeader = RayLibHeader; +/***/ }), + +/***/ "./src/typescript.ts": +/*!***************************!*\ + !*** ./src/typescript.ts ***! + \***************************/ +/***/ ((__unused_webpack_module, exports, __webpack_require__) => { + + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.TypescriptGenerator = exports.GenericTypescriptGenerator = exports.TypeScriptDeclaration = void 0; +const generation_1 = __webpack_require__(/*! ./generation */ "./src/generation.ts"); +const fs_1 = __webpack_require__(/*! fs */ "fs"); +class TypeScriptDeclaration { + constructor() { + this.root = new TypescriptGenerator(); + this.structs = this.root.child(); + this.functions = this.root.child(); + this.constants = this.root.child(); + } + addFunction(name, api) { + const para = api.params.map(x => ({ name: x.name, type: this.toJsType(x.type) })); + const returnType = this.toJsType(api.returnType); + this.functions.tsDeclareFunction(name, para, returnType, api.description); + } + addStruct(api, options) { + var fields = api.fields.filter(x => !!(options.properties || {})[x.name]).map(x => ({ name: x.name, description: x.description, type: this.toJsType(x.type) })); + this.structs.tsDeclareInterface(api.name, fields); + this.structs.tsDeclareType(api.name, !!options.createConstructor, fields); + } + toJsType(type) { + switch (type) { + case "int": + case "long": + case "unsigned int": + case "unsigned char": + case "float": + case "double": + return "number"; + case "bool": + return "boolean"; + case "const char *": + case "char *": + return "string"; + default: + return type; + } + } + writeTo(filename) { + const writer = new generation_1.CodeWriter(); + writer.writeGenerator(this.root); + (0, fs_1.writeFileSync)(filename, writer.toString()); + } +} +exports.TypeScriptDeclaration = TypeScriptDeclaration; +class GenericTypescriptGenerator extends generation_1.GenericCodeGenerator { + tsDeclareFunction(name, parameters, returnType, description) { + this.tsDocComment(description); + this.statement(`declare function ${name}(${parameters.map(x => x.name + ': ' + x.type).join(', ')}): ${returnType}`); + } + tsDeclareConstant(name, type, description) { + this.tsDocComment(description); + this.statement(`declare var ${name}: ${type}`); + } + tsDeclareType(name, hasConstructor, parameters) { + this.line(`declare var ${name}: {`); + this.indent(); + this.statement("prototype: " + name); + if (hasConstructor) + this.statement(`new(${parameters.map(x => x.name + ": " + x.type).join(', ')}): ${name}`); + this.unindent(); + this.line("}"); + } + tsDeclareInterface(name, fields) { + this.line(`interface ${name} {`); + this.indent(); + for (const field of fields) { + if (field.description) + this.tsDocComment(field.description); + this.line(field.name + ": " + field.type + ","); + } + this.unindent(); + this.line("}"); + } + tsDocComment(comment) { + this.line(`/** ${comment} */`); + } +} +exports.GenericTypescriptGenerator = GenericTypescriptGenerator; +class TypescriptGenerator extends GenericTypescriptGenerator { + createGenerator() { + return new TypescriptGenerator(); + } +} +exports.TypescriptGenerator = TypescriptGenerator; + + /***/ }), /***/ "fs": @@ -674,11 +799,37 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); const fs_1 = __webpack_require__(/*! fs */ "fs"); const api_1 = __webpack_require__(/*! ./api */ "./src/api.ts"); const raylib_header_1 = __webpack_require__(/*! ./raylib-header */ "./src/raylib-header.ts"); +function parseMathHeader() { + return (0, fs_1.readFileSync)("thirdparty/raylib/src/raymath.h", 'utf8') + .split("\n") + .filter(x => x.startsWith("RMAPI")) + .map(inputString => { + const matches = inputString.match(/^RMAPI\s+([\w<>]+)\s+([\w<>]+)\((.*)\)$/); + if (!matches) + throw new Error("Unable to match " + inputString); + const args = matches[3].split(',').filter(x => x !== 'void').map(arg => { + arg = arg.trim().replace(" *", "* "); + const frags = arg.split(' '); + const name = frags.pop(); + const type = frags.join(' ').replace("*", " *"); + console.log({ name: name || "", type: type }); + return { name: name || "", type: type }; + }); + return { + name: matches[2], + returnType: matches[1], + params: args, + description: "" + }; + }); +} function main() { + const mathApi = parseMathHeader(); + (0, fs_1.writeFileSync)("bindings/raylib_math_api.json", JSON.stringify(mathApi)); const api = JSON.parse((0, fs_1.readFileSync)("thirdparty/raylib/parser/output/raylib_api.json", 'utf8')); const apiDesc = new api_1.ApiDescription(api); - const core_gen = new raylib_header_1.RayLibHeader("raylib_core", apiDesc); - core_gen.addApiStructByName("Color", { + const core = new raylib_header_1.RayLibHeader("raylib_core", apiDesc); + core.addApiStructByName("Color", { properties: { r: { get: true, set: true }, g: { get: true, set: true }, @@ -687,7 +838,7 @@ function main() { }, createConstructor: true }); - core_gen.addApiStructByName("Rectangle", { + core.addApiStructByName("Rectangle", { properties: { x: { get: true, set: true }, y: { get: true, set: true }, @@ -696,14 +847,14 @@ function main() { }, createConstructor: true }); - core_gen.addApiStructByName("Vector2", { + core.addApiStructByName("Vector2", { properties: { x: { get: true, set: true }, y: { get: true, set: true }, }, createConstructor: true }); - core_gen.addApiStructByName("Vector3", { + core.addApiStructByName("Vector3", { properties: { x: { get: true, set: true }, y: { get: true, set: true }, @@ -711,14 +862,32 @@ function main() { }, createConstructor: true }); - core_gen.addApiStructByName("Ray", { + core.addApiStructByName("Vector4", { + properties: { + x: { get: true, set: true }, + y: { get: true, set: true }, + z: { get: true, set: true }, + w: { get: true, set: true }, + }, + createConstructor: true + }); + core.addApiStructByName("Ray", { properties: { position: { get: false, set: true }, direction: { get: false, set: true }, }, createConstructor: true }); - core_gen.addApiStructByName("Camera2D", { + core.addApiStructByName("RayCollision", { + properties: { + hit: { get: true, set: false }, + distance: { get: true, set: false }, + //point: { get: true, set: false }, + //normal: { get: true, set: false }, + }, + createConstructor: false + }); + core.addApiStructByName("Camera2D", { properties: { offset: { get: false, set: true }, target: { get: false, set: true }, @@ -727,205 +896,662 @@ function main() { }, createConstructor: true }); - core_gen.addApiStructByName("Matrix", { + core.addApiStructByName("Camera3D", { + properties: { + position: { get: false, set: true }, + target: { get: false, set: true }, + up: { get: false, set: true }, + fovy: { get: true, set: true }, + projection: { get: true, set: true }, + }, + createConstructor: true + }); + core.addApiStructByName("BoundingBox", { + properties: {}, + createConstructor: true + }); + core.addApiStructByName("Matrix", { properties: {}, createConstructor: false }); - // Window-related functions - core_gen.addApiFunctionByName("InitWindow"); - core_gen.addApiFunctionByName("WindowShouldClose"); - core_gen.addApiFunctionByName("CloseWindow"); - core_gen.addApiFunctionByName("IsWindowReady"); - core_gen.addApiFunctionByName("IsWindowFullscreen"); - core_gen.addApiFunctionByName("IsWindowHidden"); - core_gen.addApiFunctionByName("IsWindowMinimized"); - core_gen.addApiFunctionByName("IsWindowMaximized"); - core_gen.addApiFunctionByName("IsWindowFocused"); - core_gen.addApiFunctionByName("IsWindowResized"); - core_gen.addApiFunctionByName("IsWindowState"); - core_gen.addApiFunctionByName("SetWindowState"); - core_gen.addApiFunctionByName("ClearWindowState"); - core_gen.addApiFunctionByName("ToggleFullscreen"); - core_gen.addApiFunctionByName("MaximizeWindow"); - core_gen.addApiFunctionByName("MinimizeWindow"); - core_gen.addApiFunctionByName("RestoreWindow"); - // SetWindowIcon - // SetWindowIcons - core_gen.addApiFunctionByName("SetWindowTitle"); - core_gen.addApiFunctionByName("SetWindowPosition"); - core_gen.addApiFunctionByName("SetWindowMonitor"); - core_gen.addApiFunctionByName("SetWindowMinSize"); - core_gen.addApiFunctionByName("SetWindowSize"); - core_gen.addApiFunctionByName("SetWindowOpacity"); - // GetWindowHandle - core_gen.addApiFunctionByName("GetScreenWidth"); - core_gen.addApiFunctionByName("GetScreenHeight"); - core_gen.addApiFunctionByName("GetRenderWidth"); - core_gen.addApiFunctionByName("GetRenderHeight"); - core_gen.addApiFunctionByName("GetMonitorCount"); - core_gen.addApiFunctionByName("GetCurrentMonitor"); - core_gen.addApiFunctionByName("GetMonitorPosition"); - core_gen.addApiFunctionByName("GetMonitorWidth"); - core_gen.addApiFunctionByName("GetMonitorHeight"); - core_gen.addApiFunctionByName("GetMonitorPhysicalWidth"); - core_gen.addApiFunctionByName("GetMonitorPhysicalHeight"); - core_gen.addApiFunctionByName("GetMonitorRefreshRate"); - core_gen.addApiFunctionByName("GetWindowPosition"); - core_gen.addApiFunctionByName("GetWindowScaleDPI"); - core_gen.addApiFunctionByName("GetMonitorName"); - core_gen.addApiFunctionByName("SetClipboardText"); - core_gen.addApiFunctionByName("GetClipboardText"); - core_gen.addApiFunctionByName("EnableEventWaiting"); - core_gen.addApiFunctionByName("DisableEventWaiting"); - // Custom frame control functions - // NOT SUPPORTED BECAUSE NEEDS COMPILER FLAG - // Cursor-related functions - core_gen.addApiFunctionByName("ShowCursor"); - core_gen.addApiFunctionByName("HideCursor"); - core_gen.addApiFunctionByName("IsCursorHidden"); - core_gen.addApiFunctionByName("EnableCursor"); - core_gen.addApiFunctionByName("DisableCursor"); - core_gen.addApiFunctionByName("IsCursorOnScreen"); - // Drawing related functions - core_gen.addApiFunctionByName("ClearBackground"); - core_gen.addApiFunctionByName("BeginDrawing"); - core_gen.addApiFunctionByName("EndDrawing", null, { before: fun => fun.call("app_update_quickjs", []) }); - core_gen.addApiFunctionByName("BeginMode2D"); - core_gen.addApiFunctionByName("EndMode2D"); - //core_gen.addApiFunctionByName("BeginMode3D") - //core_gen.addApiFunctionByName("EndMode3D") - //core_gen.addApiFunctionByName("BeginTextureMode") - //core_gen.addApiFunctionByName("EndTextureMode") - //core_gen.addApiFunctionByName("BeginShaderMode") - //core_gen.addApiFunctionByName("EndShaderMode") - core_gen.addApiFunctionByName("BeginBlendMode"); - core_gen.addApiFunctionByName("EndBlendMode"); - core_gen.addApiFunctionByName("BeginScissorMode"); - core_gen.addApiFunctionByName("EndScissorMode"); - //core_gen.addApiFunctionByName("BeginVrStereoMode") - //core_gen.addApiFunctionByName("EndVrStereoMode") - // VR Stereo config options - //core_gen.addApiFunctionByName("LoadVrStereoConfig") - //core_gen.addApiFunctionByName("UnloadVrStereoConfig") - // Shader Management - // core_gen.addApiFunctionByName("LoadShader") - // core_gen.addApiFunctionByName("LoadShaderFromMemory") - // core_gen.addApiFunctionByName("IsShaderReady") - // core_gen.addApiFunctionByName("GetShaderLocation") - // core_gen.addApiFunctionByName("GetShaderLocationAttrib") - // core_gen.addApiFunctionByName("SetShaderValue") - // core_gen.addApiFunctionByName("SetShaderValueV") - // core_gen.addApiFunctionByName("SetShaderValueMatrix") - // core_gen.addApiFunctionByName("SetShaderValueTexture") - // // "UnloadShader" is destructor - // ScreenSpaceRelatedFunctions - //core_gen.addApiFunctionByName("GetMouseRay") - //core_gen.addApiFunctionByName("GetCameraMatrix") - core_gen.addApiFunctionByName("GetCameraMatrix2D"); - //core_gen.addApiFunctionByName("GetWorldToScreen") - core_gen.addApiFunctionByName("GetScreenToWorld2D"); - //core_gen.addApiFunctionByName("GetScreenToWorldEx") - core_gen.addApiFunctionByName("GetWorldToScreen2D"); - // Timing related functions - core_gen.addApiFunctionByName("SetTargetFPS"); - core_gen.addApiFunctionByName("GetFPS"); - core_gen.addApiFunctionByName("GetFrameTime"); - core_gen.addApiFunctionByName("GetTime"); - // Misc functions - core_gen.addApiFunctionByName("GetRandomValue"); - core_gen.addApiFunctionByName("SetRandomSeed"); - core_gen.addApiFunctionByName("TakeScreenshot"); - core_gen.addApiFunctionByName("SetConfigFlags"); - const traceLog = apiDesc.getFunction("TraceLog"); - if (!traceLog) - throw new Error("TraceLog not found"); - traceLog.params.pop(); - core_gen.addApiFunction(traceLog); - core_gen.addApiFunctionByName("SetTraceLogLevel"); - // Memory functions not supported on JS - core_gen.addApiFunctionByName("OpenURL"); - // Callbacks not supported on JS - // Files management functions - //core_gen.addApiFunctionByName("LoadFileData") - //core_gen.addApiFunctionByName("UnloadLoadFileData") - //core_gen.addApiFunctionByName("SaveFileData") - // Export data as code not needed - core_gen.addApiFunctionByName("LoadFileText", null, { after: gen => gen.call("UnloadFileText", ["returnVal"]) }); - core_gen.addApiFunctionByName("SaveFileText"); - core_gen.addApiFunctionByName("FileExists"); - core_gen.addApiFunctionByName("DirectoryExists"); - core_gen.addApiFunctionByName("IsFileExtension"); - // TODO: Who needs to clean memory here? - core_gen.addApiFunctionByName("GetFileLength"); - core_gen.addApiFunctionByName("GetFileExtension"); - core_gen.addApiFunctionByName("GetFileName"); - core_gen.addApiFunctionByName("GetFileNameWithoutExt"); - core_gen.addApiFunctionByName("GetDirectoryPath"); - core_gen.addApiFunctionByName("GetPrevDirectoryPath"); - core_gen.addApiFunctionByName("GetWorkingDirectory"); - core_gen.addApiFunctionByName("GetApplicationDirectory"); - core_gen.addApiFunctionByName("ChangeDirectory"); - core_gen.addApiFunctionByName("IsPathFile"); - //core_gen.addApiFunctionByName("LoadPathFiles") - //core_gen.addApiFunctionByName("LoadPathFilesEx") - // UnloadDirectoryFiles - core_gen.addApiFunctionByName("IsFileDropped"); - //core_gen.addApiFunctionByName("LoadDroppedFiles") - // UnloadDroppedFiles - core_gen.addApiFunctionByName("GetFileModTime"); - // Compression/encodeing functionality - //core_gen.addApiFunctionByName("CompressData") - //core_gen.addApiFunctionByName("DecompressData") - //core_gen.addApiFunctionByName("EncodeDataBase64") - //core_gen.addApiFunctionByName("DecodeDataBase64") - // input handling functions - core_gen.addApiFunctionByName("IsKeyPressed"); - core_gen.addApiFunctionByName("IsKeyDown"); - core_gen.addApiFunctionByName("IsKeyReleased"); - core_gen.addApiFunctionByName("IsKeyUp"); - core_gen.addApiFunctionByName("SetExitKey"); - core_gen.addApiFunctionByName("GetKeyPressed"); - core_gen.addApiFunctionByName("GetCharPressed"); - // input-related functions - core_gen.addApiFunctionByName("IsGamepadAvailable"); - core_gen.addApiFunctionByName("GetGamepadName"); - core_gen.addApiFunctionByName("IsGamepadButtonPressed"); - core_gen.addApiFunctionByName("IsGamepadButtonDown"); - core_gen.addApiFunctionByName("IsGamepadButtonReleased"); - core_gen.addApiFunctionByName("IsGamepadButtonUp"); - core_gen.addApiFunctionByName("GetGamepadButtonPressed"); - core_gen.addApiFunctionByName("GetGamepadAxisCount"); - core_gen.addApiFunctionByName("GetGamepadAxisMovement"); - core_gen.addApiFunctionByName("SetGamepadMappings"); - core_gen.addApiFunctionByName("DrawText"); - core_gen.addApiFunctionByName("DrawLine"); - core_gen.addApiFunctionByName("DrawCircleV"); - core_gen.addApiFunctionByName("GetMousePosition"); - core_gen.addApiFunctionByName("IsMouseButtonPressed"); - core_gen.addApiFunctionByName("GetMouseWheelMove"); - core_gen.addApiFunctionByName("DrawRectangle"); - core_gen.addApiFunctionByName("DrawRectangleRec"); - core_gen.addApiFunctionByName("DrawRectangleLines"); - core_gen.addApiFunctionByName("Fade"); - api.defines.filter(x => x.type === "COLOR").map(x => ({ name: x.name, values: (x.value.match(/\{([^}]+)\}/) || "")[1].split(',').map(x => x.trim()) })).forEach(x => { - core_gen.exportGlobalStruct("Color", x.name, x.values); + core.addApiStructByName("Image", { + properties: { + width: { get: true }, + height: { get: true }, + mipmaps: { get: true }, + format: { get: true } + }, + destructor: "UnloadImage" }); - api.enums.find(x => x.name === "KeyboardKey")?.values.forEach(x => core_gen.exportGlobalConstant(x.name)); - api.enums.find(x => x.name === "MouseButton")?.values.forEach(x => core_gen.exportGlobalConstant(x.name)); - api.enums.find(x => x.name === "ConfigFlags")?.values.forEach(x => core_gen.exportGlobalConstant(x.name)); - api.enums.find(x => x.name === "BlendMode")?.values.forEach(x => core_gen.exportGlobalConstant(x.name)); - api.enums.find(x => x.name === "TraceLogLevel")?.values.forEach(x => core_gen.exportGlobalConstant(x.name)); - core_gen.writeTo("src/bindings/js_raylib_core.h"); - const texture_gen = new raylib_header_1.RayLibHeader("raylib_texture", apiDesc); - texture_gen.addApiStructByName("Image", { + core.addApiStructByName("Wave", { + properties: { + frameCount: { get: true }, + sampleRate: { get: true }, + sampleSize: { get: true }, + channels: { get: true } + }, + destructor: "UnloadWave" + }); + core.addApiStructByName("Sound", { + properties: { + frameCount: { get: true } + }, + destructor: "UnloadSound" + }); + core.addApiStructByName("Music", { + properties: { + frameCount: { get: true }, + looping: { get: true, set: true } + }, + destructor: "UnloadMusicStream" + }); + core.addApiStructByName("Model", { + properties: {}, + destructor: "UnloadModel" + }); + core.addApiStructByName("Mesh", { + properties: {}, + destructor: "UnloadMesh" + }); + core.addApiStructByName("Shader", { + properties: {}, + destructor: "UnloadShader" + }); + core.addApiStructByName("Texture", { properties: { width: { get: true }, height: { get: true } }, - destructor: "UnloadImage" + destructor: "UnloadTexture" }); - texture_gen.addApiFunctionByName("LoadImage"); - texture_gen.writeTo("src/bindings/js_raylib_texture.h"); + core.addApiStructByName("Font", { + properties: { + baseSize: { get: true } + }, + destructor: "UnloadFont" + }); + // Window-related functions + core.addApiFunctionByName("InitWindow"); + core.addApiFunctionByName("WindowShouldClose"); + core.addApiFunctionByName("CloseWindow"); + core.addApiFunctionByName("IsWindowReady"); + core.addApiFunctionByName("IsWindowFullscreen"); + core.addApiFunctionByName("IsWindowHidden"); + core.addApiFunctionByName("IsWindowMinimized"); + core.addApiFunctionByName("IsWindowMaximized"); + core.addApiFunctionByName("IsWindowFocused"); + core.addApiFunctionByName("IsWindowResized"); + core.addApiFunctionByName("IsWindowState"); + core.addApiFunctionByName("SetWindowState"); + core.addApiFunctionByName("ClearWindowState"); + core.addApiFunctionByName("ToggleFullscreen"); + core.addApiFunctionByName("MaximizeWindow"); + core.addApiFunctionByName("MinimizeWindow"); + core.addApiFunctionByName("RestoreWindow"); + // SetWindowIcon + // SetWindowIcons + core.addApiFunctionByName("SetWindowTitle"); + core.addApiFunctionByName("SetWindowPosition"); + core.addApiFunctionByName("SetWindowMonitor"); + core.addApiFunctionByName("SetWindowMinSize"); + core.addApiFunctionByName("SetWindowSize"); + core.addApiFunctionByName("SetWindowOpacity"); + // GetWindowHandle + core.addApiFunctionByName("GetScreenWidth"); + core.addApiFunctionByName("GetScreenHeight"); + core.addApiFunctionByName("GetRenderWidth"); + core.addApiFunctionByName("GetRenderHeight"); + core.addApiFunctionByName("GetMonitorCount"); + core.addApiFunctionByName("GetCurrentMonitor"); + core.addApiFunctionByName("GetMonitorPosition"); + core.addApiFunctionByName("GetMonitorWidth"); + core.addApiFunctionByName("GetMonitorHeight"); + core.addApiFunctionByName("GetMonitorPhysicalWidth"); + core.addApiFunctionByName("GetMonitorPhysicalHeight"); + core.addApiFunctionByName("GetMonitorRefreshRate"); + core.addApiFunctionByName("GetWindowPosition"); + core.addApiFunctionByName("GetWindowScaleDPI"); + core.addApiFunctionByName("GetMonitorName"); + core.addApiFunctionByName("SetClipboardText"); + core.addApiFunctionByName("GetClipboardText"); + core.addApiFunctionByName("EnableEventWaiting"); + core.addApiFunctionByName("DisableEventWaiting"); + // Custom frame control functions + // NOT SUPPORTED BECAUSE NEEDS COMPILER FLAG + // Cursor-related functions + core.addApiFunctionByName("ShowCursor"); + core.addApiFunctionByName("HideCursor"); + core.addApiFunctionByName("IsCursorHidden"); + core.addApiFunctionByName("EnableCursor"); + core.addApiFunctionByName("DisableCursor"); + core.addApiFunctionByName("IsCursorOnScreen"); + // Drawing related functions + core.addApiFunctionByName("ClearBackground"); + core.addApiFunctionByName("BeginDrawing"); + core.addApiFunctionByName("EndDrawing", null, { before: fun => fun.call("app_update_quickjs", []) }); + core.addApiFunctionByName("BeginMode2D"); + core.addApiFunctionByName("EndMode2D"); + core.addApiFunctionByName("BeginMode3D"); + core.addApiFunctionByName("EndMode3D"); + //core.addApiFunctionByName("BeginTextureMode") + //core.addApiFunctionByName("EndTextureMode") + //core.addApiFunctionByName("BeginShaderMode") + //core.addApiFunctionByName("EndShaderMode") + core.addApiFunctionByName("BeginBlendMode"); + core.addApiFunctionByName("EndBlendMode"); + core.addApiFunctionByName("BeginScissorMode"); + core.addApiFunctionByName("EndScissorMode"); + //core.addApiFunctionByName("BeginVrStereoMode") + //core.addApiFunctionByName("EndVrStereoMode") + // VR Stereo config options + //core.addApiFunctionByName("LoadVrStereoConfig") + //core.addApiFunctionByName("UnloadVrStereoConfig") + // Shader Management + // core.addApiFunctionByName("LoadShader") + // core.addApiFunctionByName("LoadShaderFromMemory") + // core.addApiFunctionByName("IsShaderReady") + // core.addApiFunctionByName("GetShaderLocation") + // core.addApiFunctionByName("GetShaderLocationAttrib") + // core.addApiFunctionByName("SetShaderValue") + // core.addApiFunctionByName("SetShaderValueV") + // core.addApiFunctionByName("SetShaderValueMatrix") + // core.addApiFunctionByName("SetShaderValueTexture") + // // "UnloadShader" is destructor + // ScreenSpaceRelatedFunctions + //core.addApiFunctionByName("GetMouseRay") + //core.addApiFunctionByName("GetCameraMatrix") + core.addApiFunctionByName("GetCameraMatrix2D"); + //core.addApiFunctionByName("GetWorldToScreen") + core.addApiFunctionByName("GetScreenToWorld2D"); + //core.addApiFunctionByName("GetScreenToWorldEx") + core.addApiFunctionByName("GetWorldToScreen2D"); + // Timing related functions + core.addApiFunctionByName("SetTargetFPS"); + core.addApiFunctionByName("GetFPS"); + core.addApiFunctionByName("GetFrameTime"); + core.addApiFunctionByName("GetTime"); + // Misc functions + core.addApiFunctionByName("GetRandomValue"); + core.addApiFunctionByName("SetRandomSeed"); + core.addApiFunctionByName("TakeScreenshot"); + core.addApiFunctionByName("SetConfigFlags"); + const traceLog = apiDesc.getFunction("TraceLog"); + if (!traceLog) + throw new Error("TraceLog not found"); + traceLog.params.pop(); + core.addApiFunction(traceLog); + core.addApiFunctionByName("SetTraceLogLevel"); + // Memory functions not supported on JS + core.addApiFunctionByName("OpenURL"); + // Callbacks not supported on JS + // Files management functions + //core.addApiFunctionByName("LoadFileData") + //core.addApiFunctionByName("UnloadLoadFileData") + //core.addApiFunctionByName("SaveFileData") + // Export data as code not needed + core.addApiFunctionByName("LoadFileText", null, { after: gen => gen.call("UnloadFileText", ["returnVal"]) }); + core.addApiFunctionByName("SaveFileText"); + core.addApiFunctionByName("FileExists"); + core.addApiFunctionByName("DirectoryExists"); + core.addApiFunctionByName("IsFileExtension"); + // TODO: Who needs to clean memory here? + core.addApiFunctionByName("GetFileLength"); + core.addApiFunctionByName("GetFileExtension"); + core.addApiFunctionByName("GetFileName"); + core.addApiFunctionByName("GetFileNameWithoutExt"); + core.addApiFunctionByName("GetDirectoryPath"); + core.addApiFunctionByName("GetPrevDirectoryPath"); + core.addApiFunctionByName("GetWorkingDirectory"); + core.addApiFunctionByName("GetApplicationDirectory"); + core.addApiFunctionByName("ChangeDirectory"); + core.addApiFunctionByName("IsPathFile"); + //core.addApiFunctionByName("LoadPathFiles") + //core.addApiFunctionByName("LoadPathFilesEx") + // UnloadDirectoryFiles + core.addApiFunctionByName("IsFileDropped"); + //core.addApiFunctionByName("LoadDroppedFiles") + // UnloadDroppedFiles + core.addApiFunctionByName("GetFileModTime"); + // Compression/encodeing functionality + //core.addApiFunctionByName("CompressData") + //core.addApiFunctionByName("DecompressData") + //core.addApiFunctionByName("EncodeDataBase64") + //core.addApiFunctionByName("DecodeDataBase64") + // input handling functions + core.addApiFunctionByName("IsKeyPressed"); + core.addApiFunctionByName("IsKeyDown"); + core.addApiFunctionByName("IsKeyReleased"); + core.addApiFunctionByName("IsKeyUp"); + core.addApiFunctionByName("SetExitKey"); + core.addApiFunctionByName("GetKeyPressed"); + core.addApiFunctionByName("GetCharPressed"); + // input-related functions: gamepads + core.addApiFunctionByName("IsGamepadAvailable"); + core.addApiFunctionByName("GetGamepadName"); + core.addApiFunctionByName("IsGamepadButtonPressed"); + core.addApiFunctionByName("IsGamepadButtonDown"); + core.addApiFunctionByName("IsGamepadButtonReleased"); + core.addApiFunctionByName("IsGamepadButtonUp"); + core.addApiFunctionByName("GetGamepadButtonPressed"); + core.addApiFunctionByName("GetGamepadAxisCount"); + core.addApiFunctionByName("GetGamepadAxisMovement"); + core.addApiFunctionByName("SetGamepadMappings"); + // input-related functions: mouse + core.addApiFunctionByName("IsMouseButtonPressed"); + core.addApiFunctionByName("IsMouseButtonDown"); + core.addApiFunctionByName("IsMouseButtonReleased"); + core.addApiFunctionByName("IsMouseButtonUp"); + core.addApiFunctionByName("GetMouseX"); + core.addApiFunctionByName("GetMouseY"); + core.addApiFunctionByName("GetMousePosition"); + core.addApiFunctionByName("GetMouseDelta"); + core.addApiFunctionByName("SetMousePosition"); + core.addApiFunctionByName("SetMouseOffset"); + core.addApiFunctionByName("SetMouseScale"); + core.addApiFunctionByName("GetMouseWheelMove"); + core.addApiFunctionByName("GetMouseWheelMoveV"); + core.addApiFunctionByName("SetMouseCursor"); + // input-related functions: touch + core.addApiFunctionByName("GetTouchX"); + core.addApiFunctionByName("GetTouchY"); + core.addApiFunctionByName("GetTouchPosition"); + core.addApiFunctionByName("GetTouchPointId"); + core.addApiFunctionByName("GetTouchPointCount"); + // Gesture and touch handling functions + core.addApiFunctionByName("SetGesturesEnabled"); + core.addApiFunctionByName("IsGestureDetected"); + core.addApiFunctionByName("GetGestureDetected"); + core.addApiFunctionByName("GetGestureHoldDuration"); + core.addApiFunctionByName("GetGestureDragVector"); + core.addApiFunctionByName("GetGestureDragAngle"); + core.addApiFunctionByName("GetGesturePinchVector"); + core.addApiFunctionByName("GetGesturePinchAngle"); + // Camera system functions + // core.addApiFunctionByName("UpdateCamera") + // core.addApiFunctionByName("UpdateCameraPro") + //api.functions.forEach(x => console.log(`core.addApiFunctionByName("${x.name}")`)) + // module: rshapes + // TODO: Do we need ref-counting here? + //core.addApiFunctionByName("SetShapesTexture") + // Basic shapes drawing functions + core.addApiFunctionByName("DrawPixel"); + core.addApiFunctionByName("DrawPixelV"); + core.addApiFunctionByName("DrawLine"); + core.addApiFunctionByName("DrawLineV"); + core.addApiFunctionByName("DrawLineEx"); + core.addApiFunctionByName("DrawLineBezier"); + core.addApiFunctionByName("DrawLineBezierQuad"); + core.addApiFunctionByName("DrawLineBezierCubic"); + // core.addApiFunctionByName("DrawLineStrip") + core.addApiFunctionByName("DrawCircle"); + core.addApiFunctionByName("DrawCircleSector"); + core.addApiFunctionByName("DrawCircleSectorLines"); + core.addApiFunctionByName("DrawCircleGradient"); + core.addApiFunctionByName("DrawCircleV"); + core.addApiFunctionByName("DrawCircleLines"); + core.addApiFunctionByName("DrawEllipse"); + core.addApiFunctionByName("DrawEllipseLines"); + core.addApiFunctionByName("DrawRing"); + core.addApiFunctionByName("DrawRingLines"); + core.addApiFunctionByName("DrawRectangle"); + core.addApiFunctionByName("DrawRectangleV"); + core.addApiFunctionByName("DrawRectangleRec"); + core.addApiFunctionByName("DrawRectanglePro"); + core.addApiFunctionByName("DrawRectangleGradientV"); + core.addApiFunctionByName("DrawRectangleGradientH"); + core.addApiFunctionByName("DrawRectangleGradientEx"); + core.addApiFunctionByName("DrawRectangleLines"); + core.addApiFunctionByName("DrawRectangleLinesEx"); + core.addApiFunctionByName("DrawRectangleRounded"); + core.addApiFunctionByName("DrawRectangleRoundedLines"); + core.addApiFunctionByName("DrawTriangle"); + core.addApiFunctionByName("DrawTriangleLines"); + //core.addApiFunctionByName("DrawTriangleFan") + //core.addApiFunctionByName("DrawTriangleStrip") + core.addApiFunctionByName("DrawPoly"); + core.addApiFunctionByName("DrawPolyLines"); + core.addApiFunctionByName("DrawPolyLinesEx"); + // Basic shapes collision detection functions + core.addApiFunctionByName("CheckCollisionRecs"); + core.addApiFunctionByName("CheckCollisionCircles"); + core.addApiFunctionByName("CheckCollisionCircleRec"); + core.addApiFunctionByName("CheckCollisionPointRec"); + core.addApiFunctionByName("CheckCollisionPointCircle"); + core.addApiFunctionByName("CheckCollisionPointTriangle"); + // core.addApiFunctionByName("CheckCollisionPointPoly") + // core.addApiFunctionByName("CheckCollisionLines") + core.addApiFunctionByName("CheckCollisionPointLine"); + core.addApiFunctionByName("GetCollisionRec"); + // Image loading functions + core.addApiFunctionByName("LoadImage"); + core.addApiFunctionByName("LoadImageRaw"); + // core.addApiFunctionByName("LoadImageAnim") + // core.addApiFunctionByName("LoadImageFromMemory") + core.addApiFunctionByName("LoadImageFromTexture"); + core.addApiFunctionByName("LoadImageFromScreen"); + core.addApiFunctionByName("IsImageReady"); + // UnloadImage called by destructor + core.addApiFunctionByName("ExportImage"); + // needed? + // core.addApiFunctionByName("ExportImageAsCode") + // Image generation functions + core.addApiFunctionByName("GenImageColor"); + core.addApiFunctionByName("GenImageGradientV"); + core.addApiFunctionByName("GenImageGradientH"); + core.addApiFunctionByName("GenImageGradientRadial"); + core.addApiFunctionByName("GenImageChecked"); + core.addApiFunctionByName("GenImageWhiteNoise"); + core.addApiFunctionByName("GenImagePerlinNoise"); + core.addApiFunctionByName("GenImageCellular"); + core.addApiFunctionByName("GenImageText"); + // Image manipulations functions + core.addApiFunctionByName("ImageCopy"); + core.addApiFunctionByName("ImageFromImage"); + core.addApiFunctionByName("ImageText"); + // core.addApiFunctionByName("ImageTextEx") + // core.addApiFunctionByName("ImageFormat") + // core.addApiFunctionByName("ImageToPOT") + // core.addApiFunctionByName("ImageCrop") + // core.addApiFunctionByName("ImageAlphaCrop") + // core.addApiFunctionByName("ImageAlphaClear") + // core.addApiFunctionByName("ImageAlphaMask") + // core.addApiFunctionByName("ImageAlphaPremultiply") + // core.addApiFunctionByName("ImageBlurGaussian") + // core.addApiFunctionByName("ImageResize") + // core.addApiFunctionByName("ImageResizeNN") + // core.addApiFunctionByName("ImageResizeCanvas") + // core.addApiFunctionByName("ImageMipmaps") + // core.addApiFunctionByName("ImageDither") + // core.addApiFunctionByName("ImageFlipVertical") + // core.addApiFunctionByName("ImageFlipHorizontal") + // core.addApiFunctionByName("ImageRotateCW") + // core.addApiFunctionByName("ImageRotateCCW") + // core.addApiFunctionByName("ImageColorTint") + // core.addApiFunctionByName("ImageColorInvert") + // core.addApiFunctionByName("ImageColorGrayscale") + // core.addApiFunctionByName("ImageColorContrast") + // core.addApiFunctionByName("ImageColorBrightness") + // core.addApiFunctionByName("ImageColorReplace") + // core.addApiFunctionByName("LoadImageColors") + // core.addApiFunctionByName("LoadImagePalette") + // core.addApiFunctionByName("UnloadImageColors") + // core.addApiFunctionByName("UnloadImagePalette") + core.addApiFunctionByName("GetImageAlphaBorder"); + core.addApiFunctionByName("GetImageColor"); + // Image drawing functions + // core.addApiFunctionByName("ImageClearBackground") + // core.addApiFunctionByName("ImageDrawPixel") + // core.addApiFunctionByName("ImageDrawPixelV") + // core.addApiFunctionByName("ImageDrawLine") + // core.addApiFunctionByName("ImageDrawLineV") + // core.addApiFunctionByName("ImageDrawCircle") + // core.addApiFunctionByName("ImageDrawCircleV") + // core.addApiFunctionByName("ImageDrawCircleLines") + // core.addApiFunctionByName("ImageDrawCircleLinesV") + // core.addApiFunctionByName("ImageDrawRectangle") + // core.addApiFunctionByName("ImageDrawRectangleV") + // core.addApiFunctionByName("ImageDrawRectangleRec") + // core.addApiFunctionByName("ImageDrawRectangleLines") + // core.addApiFunctionByName("ImageDraw") + // core.addApiFunctionByName("ImageDrawText") + // core.addApiFunctionByName("ImageDrawTextEx") + // Texture loading functions + core.addApiFunctionByName("LoadTexture"); + core.addApiFunctionByName("LoadTextureFromImage"); + core.addApiFunctionByName("LoadTextureCubemap"); + // core.addApiFunctionByName("LoadRenderTexture") + core.addApiFunctionByName("IsTextureReady"); + // "UnloadTexture" called by finalizer + // core.addApiFunctionByName("IsRenderTextureReady") + // core.addApiFunctionByName("UnloadRenderTexture") + // core.addApiFunctionByName("UpdateTexture") + // core.addApiFunctionByName("UpdateTextureRec") + // Texture configuration functions + // core.addApiFunctionByName("GenTextureMipmaps") + core.addApiFunctionByName("SetTextureFilter"); + core.addApiFunctionByName("SetTextureWrap"); + // Texture drawing functions + core.addApiFunctionByName("DrawTexture"); + core.addApiFunctionByName("DrawTextureV"); + core.addApiFunctionByName("DrawTextureEx"); + core.addApiFunctionByName("DrawTextureRec"); + core.addApiFunctionByName("DrawTexturePro"); + // core.addApiFunctionByName("DrawTextureNPatch") + // Color/pixel related functions + core.addApiFunctionByName("Fade"); + core.addApiFunctionByName("ColorToInt"); + core.addApiFunctionByName("ColorNormalize"); + core.addApiFunctionByName("ColorFromNormalized"); + core.addApiFunctionByName("ColorToHSV"); + core.addApiFunctionByName("ColorFromHSV"); + core.addApiFunctionByName("ColorTint"); + core.addApiFunctionByName("ColorBrightness"); + core.addApiFunctionByName("ColorContrast"); + core.addApiFunctionByName("ColorAlpha"); + core.addApiFunctionByName("ColorAlphaBlend"); + core.addApiFunctionByName("GetColor"); + // core.addApiFunctionByName("GetPixelColor") + // core.addApiFunctionByName("SetPixelColor") + core.addApiFunctionByName("GetPixelDataSize"); + // module: rtext + // Font loading/unloading + core.addApiFunctionByName("GetFontDefault"); + core.addApiFunctionByName("LoadFont"); + // core.addApiFunctionByName("LoadFontEx") + core.addApiFunctionByName("LoadFontFromImage"); + // core.addApiFunctionByName("LoadFontFromMemory") + core.addApiFunctionByName("IsFontReady"); + // core.addApiFunctionByName("LoadFontData") + // core.addApiFunctionByName("GenImageFontAtlas") + // core.addApiFunctionByName("UnloadFontData") + // "UnloadFont" called by finalizer + // core.addApiFunctionByName("ExportFontAsCode") + // Text drawing functions + core.addApiFunctionByName("DrawFPS"); + core.addApiFunctionByName("DrawText"); + core.addApiFunctionByName("DrawTextEx"); + core.addApiFunctionByName("DrawTextPro"); + core.addApiFunctionByName("DrawTextCodepoint"); + //core.addApiFunctionByName("DrawTextCodepoints") + // Text font info functions + core.addApiFunctionByName("MeasureText"); + core.addApiFunctionByName("MeasureTextEx"); + core.addApiFunctionByName("GetGlyphIndex"); + // core.addApiFunctionByName("GetGlyphInfo") + core.addApiFunctionByName("GetGlyphAtlasRec"); + // Text codepoints management functions (unicode characters) + // Is this needed? + // core.addApiFunctionByName("LoadUTF8") + // core.addApiFunctionByName("UnloadUTF8") + // core.addApiFunctionByName("LoadCodepoints") + // core.addApiFunctionByName("UnloadCodepoints") + // core.addApiFunctionByName("GetCodepointCount") + // core.addApiFunctionByName("GetCodepoint") + // core.addApiFunctionByName("GetCodepointNext") + // core.addApiFunctionByName("GetCodepointPrevious") + // core.addApiFunctionByName("CodepointToUTF8") + // Text strings management functions (no UTF-8 strings, only byte chars) + // Probably not needed + // core.addApiFunctionByName("TextCopy") + // core.addApiFunctionByName("TextIsEqual") + // core.addApiFunctionByName("TextLength") + // core.addApiFunctionByName("TextFormat") + // core.addApiFunctionByName("TextSubtext") + // core.addApiFunctionByName("TextReplace") + // core.addApiFunctionByName("TextInsert") + // core.addApiFunctionByName("TextJoin") + // core.addApiFunctionByName("TextSplit") + // core.addApiFunctionByName("TextAppend") + // core.addApiFunctionByName("TextFindIndex") + // core.addApiFunctionByName("TextToUpper") + // core.addApiFunctionByName("TextToLower") + // core.addApiFunctionByName("TextToPascal") + // core.addApiFunctionByName("TextToInteger") + // module: rmodels + // Basic geometric 3D shapes drawing functions + core.addApiFunctionByName("DrawLine3D"); + core.addApiFunctionByName("DrawPoint3D"); + core.addApiFunctionByName("DrawCircle3D"); + core.addApiFunctionByName("DrawTriangle3D"); + //core.addApiFunctionByName("DrawTriangleStrip3D") + core.addApiFunctionByName("DrawCube"); + core.addApiFunctionByName("DrawCubeV"); + core.addApiFunctionByName("DrawCubeWires"); + core.addApiFunctionByName("DrawCubeWiresV"); + core.addApiFunctionByName("DrawSphere"); + core.addApiFunctionByName("DrawSphereEx"); + core.addApiFunctionByName("DrawSphereWires"); + core.addApiFunctionByName("DrawCylinder"); + core.addApiFunctionByName("DrawCylinderEx"); + core.addApiFunctionByName("DrawCylinderWires"); + core.addApiFunctionByName("DrawCylinderWiresEx"); + core.addApiFunctionByName("DrawCapsule"); + core.addApiFunctionByName("DrawCapsuleWires"); + core.addApiFunctionByName("DrawPlane"); + core.addApiFunctionByName("DrawRay"); + core.addApiFunctionByName("DrawGrid"); + // model management functions + core.addApiFunctionByName("LoadModel"); + core.addApiFunctionByName("LoadModelFromMesh"); + core.addApiFunctionByName("IsModelReady"); + // "UnloadModel" called by finalizer + core.addApiFunctionByName("GetModelBoundingBox"); + // model drawing functions + core.addApiFunctionByName("DrawModel"); + core.addApiFunctionByName("DrawModelEx"); + core.addApiFunctionByName("DrawModelWires"); + core.addApiFunctionByName("DrawModelWiresEx"); + core.addApiFunctionByName("DrawBoundingBox"); + core.addApiFunctionByName("DrawBillboard"); + core.addApiFunctionByName("DrawBillboardRec"); + core.addApiFunctionByName("DrawBillboardPro"); + // Mesh management functions + // core.addApiFunctionByName("UploadMesh") + // core.addApiFunctionByName("UpdateMeshBuffer") + // "UnloadMesh" called by finalizer + //core.addApiFunctionByName("DrawMesh") + // core.addApiFunctionByName("DrawMeshInstanced") + core.addApiFunctionByName("ExportMesh"); + core.addApiFunctionByName("GetMeshBoundingBox"); + // core.addApiFunctionByName("GenMeshTangents") + // Mesh generation functions + core.addApiFunctionByName("GenMeshPoly"); + core.addApiFunctionByName("GenMeshPlane"); + core.addApiFunctionByName("GenMeshCube"); + core.addApiFunctionByName("GenMeshSphere"); + core.addApiFunctionByName("GenMeshHemiSphere"); + core.addApiFunctionByName("GenMeshCylinder"); + core.addApiFunctionByName("GenMeshCone"); + core.addApiFunctionByName("GenMeshTorus"); + core.addApiFunctionByName("GenMeshKnot"); + core.addApiFunctionByName("GenMeshHeightmap"); + core.addApiFunctionByName("GenMeshCubicmap"); + // Material loading/unloading functions + // core.addApiFunctionByName("LoadMaterials") + // core.addApiFunctionByName("LoadMaterialDefault") + // core.addApiFunctionByName("IsMaterialReady") + // core.addApiFunctionByName("UnloadMaterial") + // core.addApiFunctionByName("SetMaterialTexture") + // core.addApiFunctionByName("SetModelMeshMaterial") + // Model animations loading/unloading functions + // core.addApiFunctionByName("LoadModelAnimations") + // core.addApiFunctionByName("UpdateModelAnimation") + // core.addApiFunctionByName("UnloadModelAnimation") + // core.addApiFunctionByName("UnloadModelAnimations") + // core.addApiFunctionByName("IsModelAnimationValid") + // Collision detection functions + core.addApiFunctionByName("CheckCollisionSpheres"); + core.addApiFunctionByName("CheckCollisionBoxes"); + core.addApiFunctionByName("CheckCollisionBoxSphere"); + core.addApiFunctionByName("GetRayCollisionSphere"); + core.addApiFunctionByName("GetRayCollisionBox"); + core.addApiFunctionByName("GetRayCollisionMesh"); + core.addApiFunctionByName("GetRayCollisionTriangle"); + core.addApiFunctionByName("GetRayCollisionQuad"); + // module: raudio + // Audio device management functions + core.addApiFunctionByName("InitAudioDevice"); + core.addApiFunctionByName("CloseAudioDevice"); + core.addApiFunctionByName("IsAudioDeviceReady"); + core.addApiFunctionByName("SetMasterVolume"); + // Wave/Sound loading/unloading functions + core.addApiFunctionByName("LoadWave"); + // core.addApiFunctionByName("LoadWaveFromMemory") + core.addApiFunctionByName("IsWaveReady"); + core.addApiFunctionByName("LoadSound"); + core.addApiFunctionByName("LoadSoundFromWave"); + core.addApiFunctionByName("IsSoundReady"); + // core.addApiFunctionByName("UpdateSound") + // "UnloadWave" called by finalizer + // "UnloadSound" called by finalizer + core.addApiFunctionByName("ExportWave"); + // core.addApiFunctionByName("ExportWaveAsCode") + // Wave/Sound management functions + core.addApiFunctionByName("PlaySound"); + core.addApiFunctionByName("StopSound"); + core.addApiFunctionByName("PauseSound"); + core.addApiFunctionByName("ResumeSound"); + core.addApiFunctionByName("IsSoundPlaying"); + core.addApiFunctionByName("SetSoundVolume"); + core.addApiFunctionByName("SetSoundPitch"); + core.addApiFunctionByName("SetSoundPan"); + core.addApiFunctionByName("WaveCopy"); + // core.addApiFunctionByName("WaveCrop") + // core.addApiFunctionByName("WaveFormat") + // core.addApiFunctionByName("LoadWaveSamples") + // core.addApiFunctionByName("UnloadWaveSamples") + // Music management functions + core.addApiFunctionByName("LoadMusicStream"); + // core.addApiFunctionByName("LoadMusicStreamFromMemory") + core.addApiFunctionByName("IsMusicReady"); + // "UnloadMusicStream" called by finalizer + core.addApiFunctionByName("PlayMusicStream"); + core.addApiFunctionByName("IsMusicStreamPlaying"); + core.addApiFunctionByName("UpdateMusicStream"); + core.addApiFunctionByName("StopMusicStream"); + core.addApiFunctionByName("PauseMusicStream"); + core.addApiFunctionByName("ResumeMusicStream"); + core.addApiFunctionByName("SeekMusicStream"); + core.addApiFunctionByName("SetMusicVolume"); + core.addApiFunctionByName("SetMusicPitch"); + core.addApiFunctionByName("SetMusicPan"); + core.addApiFunctionByName("GetMusicTimeLength"); + core.addApiFunctionByName("GetMusicTimePlayed"); + // AudioStream management functions + // core.addApiFunctionByName("LoadAudioStream") + // core.addApiFunctionByName("IsAudioStreamReady") + // core.addApiFunctionByName("UnloadAudioStream") + // core.addApiFunctionByName("UpdateAudioStream") + // core.addApiFunctionByName("IsAudioStreamProcessed") + // core.addApiFunctionByName("PlayAudioStream") + // core.addApiFunctionByName("PauseAudioStream") + // core.addApiFunctionByName("ResumeAudioStream") + // core.addApiFunctionByName("IsAudioStreamPlaying") + // core.addApiFunctionByName("StopAudioStream") + // core.addApiFunctionByName("SetAudioStreamVolume") + // core.addApiFunctionByName("SetAudioStreamPitch") + // core.addApiFunctionByName("SetAudioStreamPan") + // core.addApiFunctionByName("SetAudioStreamBufferSizeDefault") + // core.addApiFunctionByName("SetAudioStreamCallback") + // core.addApiFunctionByName("AttachAudioStreamProcessor") + // core.addApiFunctionByName("DetachAudioStreamProcessor") + // core.addApiFunctionByName("AttachAudioMixedProcessor") + // core.addApiFunctionByName("DetachAudioMixedProcessor") + // module: raymath + //mathApi.forEach(x => console.log(`core.addApi`)) + api.defines.filter(x => x.type === "COLOR").map(x => ({ name: x.name, description: x.description, values: (x.value.match(/\{([^}]+)\}/) || "")[1].split(',').map(x => x.trim()) })).forEach(x => { + core.exportGlobalStruct("Color", x.name, x.values, x.description); + }); + api.enums.find(x => x.name === "KeyboardKey")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)); + api.enums.find(x => x.name === "MouseButton")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)); + api.enums.find(x => x.name === "ConfigFlags")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)); + api.enums.find(x => x.name === "BlendMode")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)); + api.enums.find(x => x.name === "TraceLogLevel")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)); + api.enums.find(x => x.name === "MouseCursor")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)); + api.enums.find(x => x.name === "PixelFormat")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)); + api.enums.find(x => x.name === "CameraProjection")?.values.forEach(x => core.exportGlobalConstant(x.name, x.description)); + core.writeTo("src/bindings/js_raylib_core.h"); + core.typings.writeTo("examples/lib.raylib.d.ts"); } main(); diff --git a/src/bindings/js_raylib_core.h b/src/bindings/js_raylib_core.h index f053cc3..5b8ce5e 100644 --- a/src/bindings/js_raylib_core.h +++ b/src/bindings/js_raylib_core.h @@ -16,9 +16,22 @@ static JSClassID js_Color_class_id; static JSClassID js_Rectangle_class_id; static JSClassID js_Vector2_class_id; static JSClassID js_Vector3_class_id; +static JSClassID js_Vector4_class_id; static JSClassID js_Ray_class_id; +static JSClassID js_RayCollision_class_id; static JSClassID js_Camera2D_class_id; +static JSClassID js_Camera3D_class_id; +static JSClassID js_BoundingBox_class_id; static JSClassID js_Matrix_class_id; +static JSClassID js_Image_class_id; +static JSClassID js_Wave_class_id; +static JSClassID js_Sound_class_id; +static JSClassID js_Music_class_id; +static JSClassID js_Model_class_id; +static JSClassID js_Mesh_class_id; +static JSClassID js_Shader_class_id; +static JSClassID js_Texture_class_id; +static JSClassID js_Font_class_id; static void js_Color_finalizer(JSRuntime * rt, JSValue val) { Color* ptr = JS_GetOpaque(val, js_Color_class_id); @@ -33,7 +46,7 @@ static JSValue js_Color_get_r(JSContext* ctx, JSValueConst this_val) { return JS_EXCEPTION; } unsigned char r = ptr->r; - JSValue ret = JS_NewInt32(ctx, r); + JSValue ret = JS_NewUint32(ctx, r); return ret; } @@ -42,8 +55,8 @@ static JSValue js_Color_set_r(JSContext* ctx, JSValueConst this_val, JSValueCons if(!ptr) { return JS_EXCEPTION; } - int _int_value; - JS_ToInt32(ctx, &_int_value, v); + unsigned int _int_value; + JS_ToUint32(ctx, &_int_value, v); unsigned char value = (unsigned char)_int_value; ptr->r = value; return JS_UNDEFINED; @@ -55,7 +68,7 @@ static JSValue js_Color_get_g(JSContext* ctx, JSValueConst this_val) { return JS_EXCEPTION; } unsigned char g = ptr->g; - JSValue ret = JS_NewInt32(ctx, g); + JSValue ret = JS_NewUint32(ctx, g); return ret; } @@ -64,8 +77,8 @@ static JSValue js_Color_set_g(JSContext* ctx, JSValueConst this_val, JSValueCons if(!ptr) { return JS_EXCEPTION; } - int _int_value; - JS_ToInt32(ctx, &_int_value, v); + unsigned int _int_value; + JS_ToUint32(ctx, &_int_value, v); unsigned char value = (unsigned char)_int_value; ptr->g = value; return JS_UNDEFINED; @@ -77,7 +90,7 @@ static JSValue js_Color_get_b(JSContext* ctx, JSValueConst this_val) { return JS_EXCEPTION; } unsigned char b = ptr->b; - JSValue ret = JS_NewInt32(ctx, b); + JSValue ret = JS_NewUint32(ctx, b); return ret; } @@ -86,8 +99,8 @@ static JSValue js_Color_set_b(JSContext* ctx, JSValueConst this_val, JSValueCons if(!ptr) { return JS_EXCEPTION; } - int _int_value; - JS_ToInt32(ctx, &_int_value, v); + unsigned int _int_value; + JS_ToUint32(ctx, &_int_value, v); unsigned char value = (unsigned char)_int_value; ptr->b = value; return JS_UNDEFINED; @@ -99,7 +112,7 @@ static JSValue js_Color_get_a(JSContext* ctx, JSValueConst this_val) { return JS_EXCEPTION; } unsigned char a = ptr->a; - JSValue ret = JS_NewInt32(ctx, a); + JSValue ret = JS_NewUint32(ctx, a); return ret; } @@ -108,8 +121,8 @@ static JSValue js_Color_set_a(JSContext* ctx, JSValueConst this_val, JSValueCons if(!ptr) { return JS_EXCEPTION; } - int _int_value; - JS_ToInt32(ctx, &_int_value, v); + unsigned int _int_value; + JS_ToUint32(ctx, &_int_value, v); unsigned char value = (unsigned char)_int_value; ptr->a = value; return JS_UNDEFINED; @@ -403,6 +416,119 @@ static int js_declare_Vector3(JSContext * ctx, JSModuleDef * m) { return 0; } +static void js_Vector4_finalizer(JSRuntime * rt, JSValue val) { + Vector4* ptr = JS_GetOpaque(val, js_Vector4_class_id); + if(ptr) { + js_free_rt(rt, ptr); + } +} + +static JSValue js_Vector4_get_x(JSContext* ctx, JSValueConst this_val) { + Vector4* ptr = JS_GetOpaque2(ctx, this_val, js_Vector4_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + float x = ptr->x; + JSValue ret = JS_NewFloat64(ctx, x); + return ret; +} + +static JSValue js_Vector4_set_x(JSContext* ctx, JSValueConst this_val, JSValueConst v) { + Vector4* ptr = JS_GetOpaque2(ctx, this_val, js_Vector4_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + double _double_value; + JS_ToFloat64(ctx, &_double_value, v); + float value = (float)_double_value; + ptr->x = value; + return JS_UNDEFINED; +} + +static JSValue js_Vector4_get_y(JSContext* ctx, JSValueConst this_val) { + Vector4* ptr = JS_GetOpaque2(ctx, this_val, js_Vector4_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + float y = ptr->y; + JSValue ret = JS_NewFloat64(ctx, y); + return ret; +} + +static JSValue js_Vector4_set_y(JSContext* ctx, JSValueConst this_val, JSValueConst v) { + Vector4* ptr = JS_GetOpaque2(ctx, this_val, js_Vector4_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + double _double_value; + JS_ToFloat64(ctx, &_double_value, v); + float value = (float)_double_value; + ptr->y = value; + return JS_UNDEFINED; +} + +static JSValue js_Vector4_get_z(JSContext* ctx, JSValueConst this_val) { + Vector4* ptr = JS_GetOpaque2(ctx, this_val, js_Vector4_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + float z = ptr->z; + JSValue ret = JS_NewFloat64(ctx, z); + return ret; +} + +static JSValue js_Vector4_set_z(JSContext* ctx, JSValueConst this_val, JSValueConst v) { + Vector4* ptr = JS_GetOpaque2(ctx, this_val, js_Vector4_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + double _double_value; + JS_ToFloat64(ctx, &_double_value, v); + float value = (float)_double_value; + ptr->z = value; + return JS_UNDEFINED; +} + +static JSValue js_Vector4_get_w(JSContext* ctx, JSValueConst this_val) { + Vector4* ptr = JS_GetOpaque2(ctx, this_val, js_Vector4_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + float w = ptr->w; + JSValue ret = JS_NewFloat64(ctx, w); + return ret; +} + +static JSValue js_Vector4_set_w(JSContext* ctx, JSValueConst this_val, JSValueConst v) { + Vector4* ptr = JS_GetOpaque2(ctx, this_val, js_Vector4_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + double _double_value; + JS_ToFloat64(ctx, &_double_value, v); + float value = (float)_double_value; + ptr->w = value; + return JS_UNDEFINED; +} + +static const JSCFunctionListEntry js_Vector4_proto_funcs[] = { + JS_CGETSET_DEF("x",js_Vector4_get_x,js_Vector4_set_x), + JS_CGETSET_DEF("y",js_Vector4_get_y,js_Vector4_set_y), + JS_CGETSET_DEF("z",js_Vector4_get_z,js_Vector4_set_z), + JS_CGETSET_DEF("w",js_Vector4_get_w,js_Vector4_set_w), + JS_PROP_STRING_DEF("[Symbol.toStringTag]","Vector4", JS_PROP_CONFIGURABLE), +}; + +static int js_declare_Vector4(JSContext * ctx, JSModuleDef * m) { + JS_NewClassID(&js_Vector4_class_id); + JSClassDef js_Vector4_def = { .class_name = "Vector4", .finalizer = js_Vector4_finalizer }; + JS_NewClass(JS_GetRuntime(ctx), js_Vector4_class_id, &js_Vector4_def); + JSValue proto = JS_NewObject(ctx); + JS_SetPropertyFunctionList(ctx, proto, js_Vector4_proto_funcs, countof(js_Vector4_proto_funcs)); + JS_SetClassProto(ctx, js_Vector4_class_id, proto); + return 0; +} + static void js_Ray_finalizer(JSRuntime * rt, JSValue val) { Ray* ptr = JS_GetOpaque(val, js_Ray_class_id); if(ptr) { @@ -450,6 +576,49 @@ static int js_declare_Ray(JSContext * ctx, JSModuleDef * m) { return 0; } +static void js_RayCollision_finalizer(JSRuntime * rt, JSValue val) { + RayCollision* ptr = JS_GetOpaque(val, js_RayCollision_class_id); + if(ptr) { + js_free_rt(rt, ptr); + } +} + +static JSValue js_RayCollision_get_hit(JSContext* ctx, JSValueConst this_val) { + RayCollision* ptr = JS_GetOpaque2(ctx, this_val, js_RayCollision_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + bool hit = ptr->hit; + JSValue ret = JS_NewBool(ctx, hit); + return ret; +} + +static JSValue js_RayCollision_get_distance(JSContext* ctx, JSValueConst this_val) { + RayCollision* ptr = JS_GetOpaque2(ctx, this_val, js_RayCollision_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + float distance = ptr->distance; + JSValue ret = JS_NewFloat64(ctx, distance); + return ret; +} + +static const JSCFunctionListEntry js_RayCollision_proto_funcs[] = { + JS_CGETSET_DEF("hit",js_RayCollision_get_hit,NULL), + JS_CGETSET_DEF("distance",js_RayCollision_get_distance,NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]","RayCollision", JS_PROP_CONFIGURABLE), +}; + +static int js_declare_RayCollision(JSContext * ctx, JSModuleDef * m) { + JS_NewClassID(&js_RayCollision_class_id); + JSClassDef js_RayCollision_def = { .class_name = "RayCollision", .finalizer = js_RayCollision_finalizer }; + JS_NewClass(JS_GetRuntime(ctx), js_RayCollision_class_id, &js_RayCollision_def); + JSValue proto = JS_NewObject(ctx); + JS_SetPropertyFunctionList(ctx, proto, js_RayCollision_proto_funcs, countof(js_RayCollision_proto_funcs)); + JS_SetClassProto(ctx, js_RayCollision_class_id, proto); + return 0; +} + static void js_Camera2D_finalizer(JSRuntime * rt, JSValue val) { Camera2D* ptr = JS_GetOpaque(val, js_Camera2D_class_id); if(ptr) { @@ -543,6 +712,132 @@ static int js_declare_Camera2D(JSContext * ctx, JSModuleDef * m) { return 0; } +static void js_Camera3D_finalizer(JSRuntime * rt, JSValue val) { + Camera3D* ptr = JS_GetOpaque(val, js_Camera3D_class_id); + if(ptr) { + js_free_rt(rt, ptr); + } +} + +static JSValue js_Camera3D_set_position(JSContext* ctx, JSValueConst this_val, JSValueConst v) { + Camera3D* ptr = JS_GetOpaque2(ctx, this_val, js_Camera3D_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + Vector3* value_ptr = (Vector3*)JS_GetOpaque2(ctx, v, js_Vector3_class_id); + if(value_ptr == NULL) return JS_EXCEPTION; + Vector3 value = *value_ptr; + ptr->position = value; + return JS_UNDEFINED; +} + +static JSValue js_Camera3D_set_target(JSContext* ctx, JSValueConst this_val, JSValueConst v) { + Camera3D* ptr = JS_GetOpaque2(ctx, this_val, js_Camera3D_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + Vector3* value_ptr = (Vector3*)JS_GetOpaque2(ctx, v, js_Vector3_class_id); + if(value_ptr == NULL) return JS_EXCEPTION; + Vector3 value = *value_ptr; + ptr->target = value; + return JS_UNDEFINED; +} + +static JSValue js_Camera3D_set_up(JSContext* ctx, JSValueConst this_val, JSValueConst v) { + Camera3D* ptr = JS_GetOpaque2(ctx, this_val, js_Camera3D_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + Vector3* value_ptr = (Vector3*)JS_GetOpaque2(ctx, v, js_Vector3_class_id); + if(value_ptr == NULL) return JS_EXCEPTION; + Vector3 value = *value_ptr; + ptr->up = value; + return JS_UNDEFINED; +} + +static JSValue js_Camera3D_get_fovy(JSContext* ctx, JSValueConst this_val) { + Camera3D* ptr = JS_GetOpaque2(ctx, this_val, js_Camera3D_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + float fovy = ptr->fovy; + JSValue ret = JS_NewFloat64(ctx, fovy); + return ret; +} + +static JSValue js_Camera3D_set_fovy(JSContext* ctx, JSValueConst this_val, JSValueConst v) { + Camera3D* ptr = JS_GetOpaque2(ctx, this_val, js_Camera3D_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + double _double_value; + JS_ToFloat64(ctx, &_double_value, v); + float value = (float)_double_value; + ptr->fovy = value; + return JS_UNDEFINED; +} + +static JSValue js_Camera3D_get_projection(JSContext* ctx, JSValueConst this_val) { + Camera3D* ptr = JS_GetOpaque2(ctx, this_val, js_Camera3D_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + int projection = ptr->projection; + JSValue ret = JS_NewInt32(ctx, projection); + return ret; +} + +static JSValue js_Camera3D_set_projection(JSContext* ctx, JSValueConst this_val, JSValueConst v) { + Camera3D* ptr = JS_GetOpaque2(ctx, this_val, js_Camera3D_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + int value; + JS_ToInt32(ctx, &value, v); + ptr->projection = value; + return JS_UNDEFINED; +} + +static const JSCFunctionListEntry js_Camera3D_proto_funcs[] = { + JS_CGETSET_DEF("position",NULL,js_Camera3D_set_position), + JS_CGETSET_DEF("target",NULL,js_Camera3D_set_target), + JS_CGETSET_DEF("up",NULL,js_Camera3D_set_up), + JS_CGETSET_DEF("fovy",js_Camera3D_get_fovy,js_Camera3D_set_fovy), + JS_CGETSET_DEF("projection",js_Camera3D_get_projection,js_Camera3D_set_projection), + JS_PROP_STRING_DEF("[Symbol.toStringTag]","Camera3D", JS_PROP_CONFIGURABLE), +}; + +static int js_declare_Camera3D(JSContext * ctx, JSModuleDef * m) { + JS_NewClassID(&js_Camera3D_class_id); + JSClassDef js_Camera3D_def = { .class_name = "Camera3D", .finalizer = js_Camera3D_finalizer }; + JS_NewClass(JS_GetRuntime(ctx), js_Camera3D_class_id, &js_Camera3D_def); + JSValue proto = JS_NewObject(ctx); + JS_SetPropertyFunctionList(ctx, proto, js_Camera3D_proto_funcs, countof(js_Camera3D_proto_funcs)); + JS_SetClassProto(ctx, js_Camera3D_class_id, proto); + return 0; +} + +static void js_BoundingBox_finalizer(JSRuntime * rt, JSValue val) { + BoundingBox* ptr = JS_GetOpaque(val, js_BoundingBox_class_id); + if(ptr) { + js_free_rt(rt, ptr); + } +} + +static const JSCFunctionListEntry js_BoundingBox_proto_funcs[] = { + JS_PROP_STRING_DEF("[Symbol.toStringTag]","BoundingBox", JS_PROP_CONFIGURABLE), +}; + +static int js_declare_BoundingBox(JSContext * ctx, JSModuleDef * m) { + JS_NewClassID(&js_BoundingBox_class_id); + JSClassDef js_BoundingBox_def = { .class_name = "BoundingBox", .finalizer = js_BoundingBox_finalizer }; + JS_NewClass(JS_GetRuntime(ctx), js_BoundingBox_class_id, &js_BoundingBox_def); + JSValue proto = JS_NewObject(ctx); + JS_SetPropertyFunctionList(ctx, proto, js_BoundingBox_proto_funcs, countof(js_BoundingBox_proto_funcs)); + JS_SetClassProto(ctx, js_BoundingBox_class_id, proto); + return 0; +} + static void js_Matrix_finalizer(JSRuntime * rt, JSValue val) { Matrix* ptr = JS_GetOpaque(val, js_Matrix_class_id); if(ptr) { @@ -564,18 +859,380 @@ static int js_declare_Matrix(JSContext * ctx, JSModuleDef * m) { return 0; } +static void js_Image_finalizer(JSRuntime * rt, JSValue val) { + Image* ptr = JS_GetOpaque(val, js_Image_class_id); + if(ptr) { + UnloadImage(*ptr); + js_free_rt(rt, ptr); + } +} + +static JSValue js_Image_get_width(JSContext* ctx, JSValueConst this_val) { + Image* ptr = JS_GetOpaque2(ctx, this_val, js_Image_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + int width = ptr->width; + JSValue ret = JS_NewInt32(ctx, width); + return ret; +} + +static JSValue js_Image_get_height(JSContext* ctx, JSValueConst this_val) { + Image* ptr = JS_GetOpaque2(ctx, this_val, js_Image_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + int height = ptr->height; + JSValue ret = JS_NewInt32(ctx, height); + return ret; +} + +static JSValue js_Image_get_mipmaps(JSContext* ctx, JSValueConst this_val) { + Image* ptr = JS_GetOpaque2(ctx, this_val, js_Image_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + int mipmaps = ptr->mipmaps; + JSValue ret = JS_NewInt32(ctx, mipmaps); + return ret; +} + +static JSValue js_Image_get_format(JSContext* ctx, JSValueConst this_val) { + Image* ptr = JS_GetOpaque2(ctx, this_val, js_Image_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + int format = ptr->format; + JSValue ret = JS_NewInt32(ctx, format); + return ret; +} + +static const JSCFunctionListEntry js_Image_proto_funcs[] = { + JS_CGETSET_DEF("width",js_Image_get_width,NULL), + JS_CGETSET_DEF("height",js_Image_get_height,NULL), + JS_CGETSET_DEF("mipmaps",js_Image_get_mipmaps,NULL), + JS_CGETSET_DEF("format",js_Image_get_format,NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]","Image", JS_PROP_CONFIGURABLE), +}; + +static int js_declare_Image(JSContext * ctx, JSModuleDef * m) { + JS_NewClassID(&js_Image_class_id); + JSClassDef js_Image_def = { .class_name = "Image", .finalizer = js_Image_finalizer }; + JS_NewClass(JS_GetRuntime(ctx), js_Image_class_id, &js_Image_def); + JSValue proto = JS_NewObject(ctx); + JS_SetPropertyFunctionList(ctx, proto, js_Image_proto_funcs, countof(js_Image_proto_funcs)); + JS_SetClassProto(ctx, js_Image_class_id, proto); + return 0; +} + +static void js_Wave_finalizer(JSRuntime * rt, JSValue val) { + Wave* ptr = JS_GetOpaque(val, js_Wave_class_id); + if(ptr) { + UnloadWave(*ptr); + js_free_rt(rt, ptr); + } +} + +static JSValue js_Wave_get_frameCount(JSContext* ctx, JSValueConst this_val) { + Wave* ptr = JS_GetOpaque2(ctx, this_val, js_Wave_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + unsigned int frameCount = ptr->frameCount; + JSValue ret = JS_NewUint32(ctx, frameCount); + return ret; +} + +static JSValue js_Wave_get_sampleRate(JSContext* ctx, JSValueConst this_val) { + Wave* ptr = JS_GetOpaque2(ctx, this_val, js_Wave_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + unsigned int sampleRate = ptr->sampleRate; + JSValue ret = JS_NewUint32(ctx, sampleRate); + return ret; +} + +static JSValue js_Wave_get_sampleSize(JSContext* ctx, JSValueConst this_val) { + Wave* ptr = JS_GetOpaque2(ctx, this_val, js_Wave_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + unsigned int sampleSize = ptr->sampleSize; + JSValue ret = JS_NewUint32(ctx, sampleSize); + return ret; +} + +static JSValue js_Wave_get_channels(JSContext* ctx, JSValueConst this_val) { + Wave* ptr = JS_GetOpaque2(ctx, this_val, js_Wave_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + unsigned int channels = ptr->channels; + JSValue ret = JS_NewUint32(ctx, channels); + return ret; +} + +static const JSCFunctionListEntry js_Wave_proto_funcs[] = { + JS_CGETSET_DEF("frameCount",js_Wave_get_frameCount,NULL), + JS_CGETSET_DEF("sampleRate",js_Wave_get_sampleRate,NULL), + JS_CGETSET_DEF("sampleSize",js_Wave_get_sampleSize,NULL), + JS_CGETSET_DEF("channels",js_Wave_get_channels,NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]","Wave", JS_PROP_CONFIGURABLE), +}; + +static int js_declare_Wave(JSContext * ctx, JSModuleDef * m) { + JS_NewClassID(&js_Wave_class_id); + JSClassDef js_Wave_def = { .class_name = "Wave", .finalizer = js_Wave_finalizer }; + JS_NewClass(JS_GetRuntime(ctx), js_Wave_class_id, &js_Wave_def); + JSValue proto = JS_NewObject(ctx); + JS_SetPropertyFunctionList(ctx, proto, js_Wave_proto_funcs, countof(js_Wave_proto_funcs)); + JS_SetClassProto(ctx, js_Wave_class_id, proto); + return 0; +} + +static void js_Sound_finalizer(JSRuntime * rt, JSValue val) { + Sound* ptr = JS_GetOpaque(val, js_Sound_class_id); + if(ptr) { + UnloadSound(*ptr); + js_free_rt(rt, ptr); + } +} + +static JSValue js_Sound_get_frameCount(JSContext* ctx, JSValueConst this_val) { + Sound* ptr = JS_GetOpaque2(ctx, this_val, js_Sound_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + unsigned int frameCount = ptr->frameCount; + JSValue ret = JS_NewUint32(ctx, frameCount); + return ret; +} + +static const JSCFunctionListEntry js_Sound_proto_funcs[] = { + JS_CGETSET_DEF("frameCount",js_Sound_get_frameCount,NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]","Sound", JS_PROP_CONFIGURABLE), +}; + +static int js_declare_Sound(JSContext * ctx, JSModuleDef * m) { + JS_NewClassID(&js_Sound_class_id); + JSClassDef js_Sound_def = { .class_name = "Sound", .finalizer = js_Sound_finalizer }; + JS_NewClass(JS_GetRuntime(ctx), js_Sound_class_id, &js_Sound_def); + JSValue proto = JS_NewObject(ctx); + JS_SetPropertyFunctionList(ctx, proto, js_Sound_proto_funcs, countof(js_Sound_proto_funcs)); + JS_SetClassProto(ctx, js_Sound_class_id, proto); + return 0; +} + +static void js_Music_finalizer(JSRuntime * rt, JSValue val) { + Music* ptr = JS_GetOpaque(val, js_Music_class_id); + if(ptr) { + UnloadMusicStream(*ptr); + js_free_rt(rt, ptr); + } +} + +static JSValue js_Music_get_frameCount(JSContext* ctx, JSValueConst this_val) { + Music* ptr = JS_GetOpaque2(ctx, this_val, js_Music_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + unsigned int frameCount = ptr->frameCount; + JSValue ret = JS_NewUint32(ctx, frameCount); + return ret; +} + +static JSValue js_Music_get_looping(JSContext* ctx, JSValueConst this_val) { + Music* ptr = JS_GetOpaque2(ctx, this_val, js_Music_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + bool looping = ptr->looping; + JSValue ret = JS_NewBool(ctx, looping); + return ret; +} + +static JSValue js_Music_set_looping(JSContext* ctx, JSValueConst this_val, JSValueConst v) { + Music* ptr = JS_GetOpaque2(ctx, this_val, js_Music_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + bool value = JS_ToBool(ctx, v); + ptr->looping = value; + return JS_UNDEFINED; +} + +static const JSCFunctionListEntry js_Music_proto_funcs[] = { + JS_CGETSET_DEF("frameCount",js_Music_get_frameCount,NULL), + JS_CGETSET_DEF("looping",js_Music_get_looping,js_Music_set_looping), + JS_PROP_STRING_DEF("[Symbol.toStringTag]","Music", JS_PROP_CONFIGURABLE), +}; + +static int js_declare_Music(JSContext * ctx, JSModuleDef * m) { + JS_NewClassID(&js_Music_class_id); + JSClassDef js_Music_def = { .class_name = "Music", .finalizer = js_Music_finalizer }; + JS_NewClass(JS_GetRuntime(ctx), js_Music_class_id, &js_Music_def); + JSValue proto = JS_NewObject(ctx); + JS_SetPropertyFunctionList(ctx, proto, js_Music_proto_funcs, countof(js_Music_proto_funcs)); + JS_SetClassProto(ctx, js_Music_class_id, proto); + return 0; +} + +static void js_Model_finalizer(JSRuntime * rt, JSValue val) { + Model* ptr = JS_GetOpaque(val, js_Model_class_id); + if(ptr) { + UnloadModel(*ptr); + js_free_rt(rt, ptr); + } +} + +static const JSCFunctionListEntry js_Model_proto_funcs[] = { + JS_PROP_STRING_DEF("[Symbol.toStringTag]","Model", JS_PROP_CONFIGURABLE), +}; + +static int js_declare_Model(JSContext * ctx, JSModuleDef * m) { + JS_NewClassID(&js_Model_class_id); + JSClassDef js_Model_def = { .class_name = "Model", .finalizer = js_Model_finalizer }; + JS_NewClass(JS_GetRuntime(ctx), js_Model_class_id, &js_Model_def); + JSValue proto = JS_NewObject(ctx); + JS_SetPropertyFunctionList(ctx, proto, js_Model_proto_funcs, countof(js_Model_proto_funcs)); + JS_SetClassProto(ctx, js_Model_class_id, proto); + return 0; +} + +static void js_Mesh_finalizer(JSRuntime * rt, JSValue val) { + Mesh* ptr = JS_GetOpaque(val, js_Mesh_class_id); + if(ptr) { + UnloadMesh(*ptr); + js_free_rt(rt, ptr); + } +} + +static const JSCFunctionListEntry js_Mesh_proto_funcs[] = { + JS_PROP_STRING_DEF("[Symbol.toStringTag]","Mesh", JS_PROP_CONFIGURABLE), +}; + +static int js_declare_Mesh(JSContext * ctx, JSModuleDef * m) { + JS_NewClassID(&js_Mesh_class_id); + JSClassDef js_Mesh_def = { .class_name = "Mesh", .finalizer = js_Mesh_finalizer }; + JS_NewClass(JS_GetRuntime(ctx), js_Mesh_class_id, &js_Mesh_def); + JSValue proto = JS_NewObject(ctx); + JS_SetPropertyFunctionList(ctx, proto, js_Mesh_proto_funcs, countof(js_Mesh_proto_funcs)); + JS_SetClassProto(ctx, js_Mesh_class_id, proto); + return 0; +} + +static void js_Shader_finalizer(JSRuntime * rt, JSValue val) { + Shader* ptr = JS_GetOpaque(val, js_Shader_class_id); + if(ptr) { + UnloadShader(*ptr); + js_free_rt(rt, ptr); + } +} + +static const JSCFunctionListEntry js_Shader_proto_funcs[] = { + JS_PROP_STRING_DEF("[Symbol.toStringTag]","Shader", JS_PROP_CONFIGURABLE), +}; + +static int js_declare_Shader(JSContext * ctx, JSModuleDef * m) { + JS_NewClassID(&js_Shader_class_id); + JSClassDef js_Shader_def = { .class_name = "Shader", .finalizer = js_Shader_finalizer }; + JS_NewClass(JS_GetRuntime(ctx), js_Shader_class_id, &js_Shader_def); + JSValue proto = JS_NewObject(ctx); + JS_SetPropertyFunctionList(ctx, proto, js_Shader_proto_funcs, countof(js_Shader_proto_funcs)); + JS_SetClassProto(ctx, js_Shader_class_id, proto); + return 0; +} + +static void js_Texture_finalizer(JSRuntime * rt, JSValue val) { + Texture* ptr = JS_GetOpaque(val, js_Texture_class_id); + if(ptr) { + UnloadTexture(*ptr); + js_free_rt(rt, ptr); + } +} + +static JSValue js_Texture_get_width(JSContext* ctx, JSValueConst this_val) { + Texture* ptr = JS_GetOpaque2(ctx, this_val, js_Texture_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + int width = ptr->width; + JSValue ret = JS_NewInt32(ctx, width); + return ret; +} + +static JSValue js_Texture_get_height(JSContext* ctx, JSValueConst this_val) { + Texture* ptr = JS_GetOpaque2(ctx, this_val, js_Texture_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + int height = ptr->height; + JSValue ret = JS_NewInt32(ctx, height); + return ret; +} + +static const JSCFunctionListEntry js_Texture_proto_funcs[] = { + JS_CGETSET_DEF("width",js_Texture_get_width,NULL), + JS_CGETSET_DEF("height",js_Texture_get_height,NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]","Texture", JS_PROP_CONFIGURABLE), +}; + +static int js_declare_Texture(JSContext * ctx, JSModuleDef * m) { + JS_NewClassID(&js_Texture_class_id); + JSClassDef js_Texture_def = { .class_name = "Texture", .finalizer = js_Texture_finalizer }; + JS_NewClass(JS_GetRuntime(ctx), js_Texture_class_id, &js_Texture_def); + JSValue proto = JS_NewObject(ctx); + JS_SetPropertyFunctionList(ctx, proto, js_Texture_proto_funcs, countof(js_Texture_proto_funcs)); + JS_SetClassProto(ctx, js_Texture_class_id, proto); + return 0; +} + +static void js_Font_finalizer(JSRuntime * rt, JSValue val) { + Font* ptr = JS_GetOpaque(val, js_Font_class_id); + if(ptr) { + UnloadFont(*ptr); + js_free_rt(rt, ptr); + } +} + +static JSValue js_Font_get_baseSize(JSContext* ctx, JSValueConst this_val) { + Font* ptr = JS_GetOpaque2(ctx, this_val, js_Font_class_id); + if(!ptr) { + return JS_EXCEPTION; + } + int baseSize = ptr->baseSize; + JSValue ret = JS_NewInt32(ctx, baseSize); + return ret; +} + +static const JSCFunctionListEntry js_Font_proto_funcs[] = { + JS_CGETSET_DEF("baseSize",js_Font_get_baseSize,NULL), + JS_PROP_STRING_DEF("[Symbol.toStringTag]","Font", JS_PROP_CONFIGURABLE), +}; + +static int js_declare_Font(JSContext * ctx, JSModuleDef * m) { + JS_NewClassID(&js_Font_class_id); + JSClassDef js_Font_def = { .class_name = "Font", .finalizer = js_Font_finalizer }; + JS_NewClass(JS_GetRuntime(ctx), js_Font_class_id, &js_Font_def); + JSValue proto = JS_NewObject(ctx); + JS_SetPropertyFunctionList(ctx, proto, js_Font_proto_funcs, countof(js_Font_proto_funcs)); + JS_SetClassProto(ctx, js_Font_class_id, proto); + return 0; +} + static JSValue js_Color_constructor(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { - int _int_r; - JS_ToInt32(ctx, &_int_r, argv[0]); + unsigned int _int_r; + JS_ToUint32(ctx, &_int_r, argv[0]); unsigned char r = (unsigned char)_int_r; - int _int_g; - JS_ToInt32(ctx, &_int_g, argv[1]); + unsigned int _int_g; + JS_ToUint32(ctx, &_int_g, argv[1]); unsigned char g = (unsigned char)_int_g; - int _int_b; - JS_ToInt32(ctx, &_int_b, argv[2]); + unsigned int _int_b; + JS_ToUint32(ctx, &_int_b, argv[2]); unsigned char b = (unsigned char)_int_b; - int _int_a; - JS_ToInt32(ctx, &_int_a, argv[3]); + unsigned int _int_a; + JS_ToUint32(ctx, &_int_a, argv[3]); unsigned char a = (unsigned char)_int_a; Color _struct = { r, g, b, a }; Color* _return_ptr = (Color*)js_malloc(ctx, sizeof(Color)); @@ -639,6 +1296,27 @@ static JSValue js_Vector3_constructor(JSContext * ctx, JSValueConst this_val, in return _return; } +static JSValue js_Vector4_constructor(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + double _double_x; + JS_ToFloat64(ctx, &_double_x, argv[0]); + float x = (float)_double_x; + double _double_y; + JS_ToFloat64(ctx, &_double_y, argv[1]); + float y = (float)_double_y; + double _double_z; + JS_ToFloat64(ctx, &_double_z, argv[2]); + float z = (float)_double_z; + double _double_w; + JS_ToFloat64(ctx, &_double_w, argv[3]); + float w = (float)_double_w; + Vector4 _struct = { x, y, z, w }; + Vector4* _return_ptr = (Vector4*)js_malloc(ctx, sizeof(Vector4)); + *_return_ptr = _struct; + JSValue _return = JS_NewObjectClass(ctx, js_Vector4_class_id); + JS_SetOpaque(_return, _return_ptr); + return _return; +} + static JSValue js_Ray_constructor(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { Vector3* position_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); if(position_ptr == NULL) return JS_EXCEPTION; @@ -675,11 +1353,49 @@ static JSValue js_Camera2D_constructor(JSContext * ctx, JSValueConst this_val, i return _return; } +static JSValue js_Camera3D_constructor(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* position_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector3 position = *position_ptr; + Vector3* target_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(target_ptr == NULL) return JS_EXCEPTION; + Vector3 target = *target_ptr; + Vector3* up_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[2], js_Vector3_class_id); + if(up_ptr == NULL) return JS_EXCEPTION; + Vector3 up = *up_ptr; + double _double_fovy; + JS_ToFloat64(ctx, &_double_fovy, argv[3]); + float fovy = (float)_double_fovy; + int projection; + JS_ToInt32(ctx, &projection, argv[4]); + Camera3D _struct = { position, target, up, fovy, projection }; + Camera3D* _return_ptr = (Camera3D*)js_malloc(ctx, sizeof(Camera3D)); + *_return_ptr = _struct; + JSValue _return = JS_NewObjectClass(ctx, js_Camera3D_class_id); + JS_SetOpaque(_return, _return_ptr); + return _return; +} + +static JSValue js_BoundingBox_constructor(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* min_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(min_ptr == NULL) return JS_EXCEPTION; + Vector3 min = *min_ptr; + Vector3* max_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(max_ptr == NULL) return JS_EXCEPTION; + Vector3 max = *max_ptr; + BoundingBox _struct = { min, max }; + BoundingBox* _return_ptr = (BoundingBox*)js_malloc(ctx, sizeof(BoundingBox)); + *_return_ptr = _struct; + JSValue _return = JS_NewObjectClass(ctx, js_BoundingBox_class_id); + JS_SetOpaque(_return, _return_ptr); + return _return; +} + static JSValue js_initWindow(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int width; - JS_ToInt32(ctx, (int *)&width, argv[0]); + JS_ToInt32(ctx, &width, argv[0]); int height; - JS_ToInt32(ctx, (int *)&height, argv[1]); + JS_ToInt32(ctx, &height, argv[1]); const char * title = (const char *)JS_ToCString(ctx, argv[2]); if(title == NULL) return JS_EXCEPTION; InitWindow(width, height, title); @@ -742,7 +1458,7 @@ static JSValue js_isWindowResized(JSContext * ctx, JSValueConst this_val, int ar static JSValue js_isWindowState(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { unsigned int flag; - JS_ToInt32(ctx, (int *)&flag, argv[0]); + JS_ToUint32(ctx, &flag, argv[0]); bool returnVal = IsWindowState(flag); JSValue ret = JS_NewBool(ctx, returnVal); return ret; @@ -750,14 +1466,14 @@ static JSValue js_isWindowState(JSContext * ctx, JSValueConst this_val, int argc static JSValue js_setWindowState(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { unsigned int flags; - JS_ToInt32(ctx, (int *)&flags, argv[0]); + JS_ToUint32(ctx, &flags, argv[0]); SetWindowState(flags); return JS_UNDEFINED; } static JSValue js_clearWindowState(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { unsigned int flags; - JS_ToInt32(ctx, (int *)&flags, argv[0]); + JS_ToUint32(ctx, &flags, argv[0]); ClearWindowState(flags); return JS_UNDEFINED; } @@ -792,34 +1508,34 @@ static JSValue js_setWindowTitle(JSContext * ctx, JSValueConst this_val, int arg static JSValue js_setWindowPosition(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int x; - JS_ToInt32(ctx, (int *)&x, argv[0]); + JS_ToInt32(ctx, &x, argv[0]); int y; - JS_ToInt32(ctx, (int *)&y, argv[1]); + JS_ToInt32(ctx, &y, argv[1]); SetWindowPosition(x, y); return JS_UNDEFINED; } static JSValue js_setWindowMonitor(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int monitor; - JS_ToInt32(ctx, (int *)&monitor, argv[0]); + JS_ToInt32(ctx, &monitor, argv[0]); SetWindowMonitor(monitor); return JS_UNDEFINED; } static JSValue js_setWindowMinSize(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int width; - JS_ToInt32(ctx, (int *)&width, argv[0]); + JS_ToInt32(ctx, &width, argv[0]); int height; - JS_ToInt32(ctx, (int *)&height, argv[1]); + JS_ToInt32(ctx, &height, argv[1]); SetWindowMinSize(width, height); return JS_UNDEFINED; } static JSValue js_setWindowSize(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int width; - JS_ToInt32(ctx, (int *)&width, argv[0]); + JS_ToInt32(ctx, &width, argv[0]); int height; - JS_ToInt32(ctx, (int *)&height, argv[1]); + JS_ToInt32(ctx, &height, argv[1]); SetWindowSize(width, height); return JS_UNDEFINED; } @@ -870,7 +1586,7 @@ static JSValue js_getCurrentMonitor(JSContext * ctx, JSValueConst this_val, int static JSValue js_getMonitorPosition(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int monitor; - JS_ToInt32(ctx, (int *)&monitor, argv[0]); + JS_ToInt32(ctx, &monitor, argv[0]); Vector2 returnVal = GetMonitorPosition(monitor); Vector2* ret_ptr = (Vector2*)js_malloc(ctx, sizeof(Vector2)); *ret_ptr = returnVal; @@ -881,7 +1597,7 @@ static JSValue js_getMonitorPosition(JSContext * ctx, JSValueConst this_val, int static JSValue js_getMonitorWidth(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int monitor; - JS_ToInt32(ctx, (int *)&monitor, argv[0]); + JS_ToInt32(ctx, &monitor, argv[0]); int returnVal = GetMonitorWidth(monitor); JSValue ret = JS_NewInt32(ctx, returnVal); return ret; @@ -889,7 +1605,7 @@ static JSValue js_getMonitorWidth(JSContext * ctx, JSValueConst this_val, int ar static JSValue js_getMonitorHeight(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int monitor; - JS_ToInt32(ctx, (int *)&monitor, argv[0]); + JS_ToInt32(ctx, &monitor, argv[0]); int returnVal = GetMonitorHeight(monitor); JSValue ret = JS_NewInt32(ctx, returnVal); return ret; @@ -897,7 +1613,7 @@ static JSValue js_getMonitorHeight(JSContext * ctx, JSValueConst this_val, int a static JSValue js_getMonitorPhysicalWidth(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int monitor; - JS_ToInt32(ctx, (int *)&monitor, argv[0]); + JS_ToInt32(ctx, &monitor, argv[0]); int returnVal = GetMonitorPhysicalWidth(monitor); JSValue ret = JS_NewInt32(ctx, returnVal); return ret; @@ -905,7 +1621,7 @@ static JSValue js_getMonitorPhysicalWidth(JSContext * ctx, JSValueConst this_val static JSValue js_getMonitorPhysicalHeight(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int monitor; - JS_ToInt32(ctx, (int *)&monitor, argv[0]); + JS_ToInt32(ctx, &monitor, argv[0]); int returnVal = GetMonitorPhysicalHeight(monitor); JSValue ret = JS_NewInt32(ctx, returnVal); return ret; @@ -913,7 +1629,7 @@ static JSValue js_getMonitorPhysicalHeight(JSContext * ctx, JSValueConst this_va static JSValue js_getMonitorRefreshRate(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int monitor; - JS_ToInt32(ctx, (int *)&monitor, argv[0]); + JS_ToInt32(ctx, &monitor, argv[0]); int returnVal = GetMonitorRefreshRate(monitor); JSValue ret = JS_NewInt32(ctx, returnVal); return ret; @@ -939,7 +1655,7 @@ static JSValue js_getWindowScaleDPI(JSContext * ctx, JSValueConst this_val, int static JSValue js_getMonitorName(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int monitor; - JS_ToInt32(ctx, (int *)&monitor, argv[0]); + JS_ToInt32(ctx, &monitor, argv[0]); const char * returnVal = GetMonitorName(monitor); JSValue ret = JS_NewString(ctx, returnVal); return ret; @@ -1033,9 +1749,22 @@ static JSValue js_endMode2D(JSContext * ctx, JSValueConst this_val, int argc, JS return JS_UNDEFINED; } +static JSValue js_beginMode3D(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Camera3D* camera_ptr = (Camera3D*)JS_GetOpaque2(ctx, argv[0], js_Camera3D_class_id); + if(camera_ptr == NULL) return JS_EXCEPTION; + Camera3D camera = *camera_ptr; + BeginMode3D(camera); + return JS_UNDEFINED; +} + +static JSValue js_endMode3D(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + EndMode3D(); + return JS_UNDEFINED; +} + static JSValue js_beginBlendMode(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int mode; - JS_ToInt32(ctx, (int *)&mode, argv[0]); + JS_ToInt32(ctx, &mode, argv[0]); BeginBlendMode(mode); return JS_UNDEFINED; } @@ -1047,13 +1776,13 @@ static JSValue js_endBlendMode(JSContext * ctx, JSValueConst this_val, int argc, static JSValue js_beginScissorMode(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int x; - JS_ToInt32(ctx, (int *)&x, argv[0]); + JS_ToInt32(ctx, &x, argv[0]); int y; - JS_ToInt32(ctx, (int *)&y, argv[1]); + JS_ToInt32(ctx, &y, argv[1]); int width; - JS_ToInt32(ctx, (int *)&width, argv[2]); + JS_ToInt32(ctx, &width, argv[2]); int height; - JS_ToInt32(ctx, (int *)&height, argv[3]); + JS_ToInt32(ctx, &height, argv[3]); BeginScissorMode(x, y, width, height); return JS_UNDEFINED; } @@ -1107,7 +1836,7 @@ static JSValue js_getWorldToScreen2D(JSContext * ctx, JSValueConst this_val, int static JSValue js_setTargetFPS(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int fps; - JS_ToInt32(ctx, (int *)&fps, argv[0]); + JS_ToInt32(ctx, &fps, argv[0]); SetTargetFPS(fps); return JS_UNDEFINED; } @@ -1132,9 +1861,9 @@ static JSValue js_getTime(JSContext * ctx, JSValueConst this_val, int argc, JSVa static JSValue js_getRandomValue(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int min; - JS_ToInt32(ctx, (int *)&min, argv[0]); + JS_ToInt32(ctx, &min, argv[0]); int max; - JS_ToInt32(ctx, (int *)&max, argv[1]); + JS_ToInt32(ctx, &max, argv[1]); int returnVal = GetRandomValue(min, max); JSValue ret = JS_NewInt32(ctx, returnVal); return ret; @@ -1142,7 +1871,7 @@ static JSValue js_getRandomValue(JSContext * ctx, JSValueConst this_val, int arg static JSValue js_setRandomSeed(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { unsigned int seed; - JS_ToInt32(ctx, (int *)&seed, argv[0]); + JS_ToUint32(ctx, &seed, argv[0]); SetRandomSeed(seed); return JS_UNDEFINED; } @@ -1157,14 +1886,14 @@ static JSValue js_takeScreenshot(JSContext * ctx, JSValueConst this_val, int arg static JSValue js_setConfigFlags(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { unsigned int flags; - JS_ToInt32(ctx, (int *)&flags, argv[0]); + JS_ToUint32(ctx, &flags, argv[0]); SetConfigFlags(flags); return JS_UNDEFINED; } static JSValue js_traceLog(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int logLevel; - JS_ToInt32(ctx, (int *)&logLevel, argv[0]); + JS_ToInt32(ctx, &logLevel, argv[0]); const char * text = (const char *)JS_ToCString(ctx, argv[1]); if(text == NULL) return JS_EXCEPTION; TraceLog(logLevel, text); @@ -1174,7 +1903,7 @@ static JSValue js_traceLog(JSContext * ctx, JSValueConst this_val, int argc, JSV static JSValue js_setTraceLogLevel(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int logLevel; - JS_ToInt32(ctx, (int *)&logLevel, argv[0]); + JS_ToInt32(ctx, &logLevel, argv[0]); SetTraceLogLevel(logLevel); return JS_UNDEFINED; } @@ -1339,7 +2068,7 @@ static JSValue js_getFileModTime(JSContext * ctx, JSValueConst this_val, int arg static JSValue js_isKeyPressed(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int key; - JS_ToInt32(ctx, (int *)&key, argv[0]); + JS_ToInt32(ctx, &key, argv[0]); bool returnVal = IsKeyPressed(key); JSValue ret = JS_NewBool(ctx, returnVal); return ret; @@ -1347,7 +2076,7 @@ static JSValue js_isKeyPressed(JSContext * ctx, JSValueConst this_val, int argc, static JSValue js_isKeyDown(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int key; - JS_ToInt32(ctx, (int *)&key, argv[0]); + JS_ToInt32(ctx, &key, argv[0]); bool returnVal = IsKeyDown(key); JSValue ret = JS_NewBool(ctx, returnVal); return ret; @@ -1355,7 +2084,7 @@ static JSValue js_isKeyDown(JSContext * ctx, JSValueConst this_val, int argc, JS static JSValue js_isKeyReleased(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int key; - JS_ToInt32(ctx, (int *)&key, argv[0]); + JS_ToInt32(ctx, &key, argv[0]); bool returnVal = IsKeyReleased(key); JSValue ret = JS_NewBool(ctx, returnVal); return ret; @@ -1363,7 +2092,7 @@ static JSValue js_isKeyReleased(JSContext * ctx, JSValueConst this_val, int argc static JSValue js_isKeyUp(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int key; - JS_ToInt32(ctx, (int *)&key, argv[0]); + JS_ToInt32(ctx, &key, argv[0]); bool returnVal = IsKeyUp(key); JSValue ret = JS_NewBool(ctx, returnVal); return ret; @@ -1371,7 +2100,7 @@ static JSValue js_isKeyUp(JSContext * ctx, JSValueConst this_val, int argc, JSVa static JSValue js_setExitKey(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int key; - JS_ToInt32(ctx, (int *)&key, argv[0]); + JS_ToInt32(ctx, &key, argv[0]); SetExitKey(key); return JS_UNDEFINED; } @@ -1390,7 +2119,7 @@ static JSValue js_getCharPressed(JSContext * ctx, JSValueConst this_val, int arg static JSValue js_isGamepadAvailable(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int gamepad; - JS_ToInt32(ctx, (int *)&gamepad, argv[0]); + JS_ToInt32(ctx, &gamepad, argv[0]); bool returnVal = IsGamepadAvailable(gamepad); JSValue ret = JS_NewBool(ctx, returnVal); return ret; @@ -1398,7 +2127,7 @@ static JSValue js_isGamepadAvailable(JSContext * ctx, JSValueConst this_val, int static JSValue js_getGamepadName(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int gamepad; - JS_ToInt32(ctx, (int *)&gamepad, argv[0]); + JS_ToInt32(ctx, &gamepad, argv[0]); const char * returnVal = GetGamepadName(gamepad); JSValue ret = JS_NewString(ctx, returnVal); return ret; @@ -1406,9 +2135,9 @@ static JSValue js_getGamepadName(JSContext * ctx, JSValueConst this_val, int arg static JSValue js_isGamepadButtonPressed(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int gamepad; - JS_ToInt32(ctx, (int *)&gamepad, argv[0]); + JS_ToInt32(ctx, &gamepad, argv[0]); int button; - JS_ToInt32(ctx, (int *)&button, argv[1]); + JS_ToInt32(ctx, &button, argv[1]); bool returnVal = IsGamepadButtonPressed(gamepad, button); JSValue ret = JS_NewBool(ctx, returnVal); return ret; @@ -1416,9 +2145,9 @@ static JSValue js_isGamepadButtonPressed(JSContext * ctx, JSValueConst this_val, static JSValue js_isGamepadButtonDown(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int gamepad; - JS_ToInt32(ctx, (int *)&gamepad, argv[0]); + JS_ToInt32(ctx, &gamepad, argv[0]); int button; - JS_ToInt32(ctx, (int *)&button, argv[1]); + JS_ToInt32(ctx, &button, argv[1]); bool returnVal = IsGamepadButtonDown(gamepad, button); JSValue ret = JS_NewBool(ctx, returnVal); return ret; @@ -1426,9 +2155,9 @@ static JSValue js_isGamepadButtonDown(JSContext * ctx, JSValueConst this_val, in static JSValue js_isGamepadButtonReleased(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int gamepad; - JS_ToInt32(ctx, (int *)&gamepad, argv[0]); + JS_ToInt32(ctx, &gamepad, argv[0]); int button; - JS_ToInt32(ctx, (int *)&button, argv[1]); + JS_ToInt32(ctx, &button, argv[1]); bool returnVal = IsGamepadButtonReleased(gamepad, button); JSValue ret = JS_NewBool(ctx, returnVal); return ret; @@ -1436,9 +2165,9 @@ static JSValue js_isGamepadButtonReleased(JSContext * ctx, JSValueConst this_val static JSValue js_isGamepadButtonUp(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int gamepad; - JS_ToInt32(ctx, (int *)&gamepad, argv[0]); + JS_ToInt32(ctx, &gamepad, argv[0]); int button; - JS_ToInt32(ctx, (int *)&button, argv[1]); + JS_ToInt32(ctx, &button, argv[1]); bool returnVal = IsGamepadButtonUp(gamepad, button); JSValue ret = JS_NewBool(ctx, returnVal); return ret; @@ -1452,7 +2181,7 @@ static JSValue js_getGamepadButtonPressed(JSContext * ctx, JSValueConst this_val static JSValue js_getGamepadAxisCount(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int gamepad; - JS_ToInt32(ctx, (int *)&gamepad, argv[0]); + JS_ToInt32(ctx, &gamepad, argv[0]); int returnVal = GetGamepadAxisCount(gamepad); JSValue ret = JS_NewInt32(ctx, returnVal); return ret; @@ -1460,9 +2189,9 @@ static JSValue js_getGamepadAxisCount(JSContext * ctx, JSValueConst this_val, in static JSValue js_getGamepadAxisMovement(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int gamepad; - JS_ToInt32(ctx, (int *)&gamepad, argv[0]); + JS_ToInt32(ctx, &gamepad, argv[0]); int axis; - JS_ToInt32(ctx, (int *)&axis, argv[1]); + JS_ToInt32(ctx, &axis, argv[1]); float returnVal = GetGamepadAxisMovement(gamepad, axis); JSValue ret = JS_NewFloat64(ctx, returnVal); return ret; @@ -1477,32 +2206,245 @@ static JSValue js_setGamepadMappings(JSContext * ctx, JSValueConst this_val, int return ret; } -static JSValue js_drawText(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { - const char * text = (const char *)JS_ToCString(ctx, argv[0]); - if(text == NULL) return JS_EXCEPTION; +static JSValue js_isMouseButtonPressed(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int button; + JS_ToInt32(ctx, &button, argv[0]); + bool returnVal = IsMouseButtonPressed(button); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_isMouseButtonDown(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int button; + JS_ToInt32(ctx, &button, argv[0]); + bool returnVal = IsMouseButtonDown(button); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_isMouseButtonReleased(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int button; + JS_ToInt32(ctx, &button, argv[0]); + bool returnVal = IsMouseButtonReleased(button); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_isMouseButtonUp(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int button; + JS_ToInt32(ctx, &button, argv[0]); + bool returnVal = IsMouseButtonUp(button); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_getMouseX(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int returnVal = GetMouseX(); + JSValue ret = JS_NewInt32(ctx, returnVal); + return ret; +} + +static JSValue js_getMouseY(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int returnVal = GetMouseY(); + JSValue ret = JS_NewInt32(ctx, returnVal); + return ret; +} + +static JSValue js_getMousePosition(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2 returnVal = GetMousePosition(); + Vector2* ret_ptr = (Vector2*)js_malloc(ctx, sizeof(Vector2)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Vector2_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_getMouseDelta(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2 returnVal = GetMouseDelta(); + Vector2* ret_ptr = (Vector2*)js_malloc(ctx, sizeof(Vector2)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Vector2_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_setMousePosition(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int x; + JS_ToInt32(ctx, &x, argv[0]); + int y; + JS_ToInt32(ctx, &y, argv[1]); + SetMousePosition(x, y); + return JS_UNDEFINED; +} + +static JSValue js_setMouseOffset(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int offsetX; + JS_ToInt32(ctx, &offsetX, argv[0]); + int offsetY; + JS_ToInt32(ctx, &offsetY, argv[1]); + SetMouseOffset(offsetX, offsetY); + return JS_UNDEFINED; +} + +static JSValue js_setMouseScale(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + double _double_scaleX; + JS_ToFloat64(ctx, &_double_scaleX, argv[0]); + float scaleX = (float)_double_scaleX; + double _double_scaleY; + JS_ToFloat64(ctx, &_double_scaleY, argv[1]); + float scaleY = (float)_double_scaleY; + SetMouseScale(scaleX, scaleY); + return JS_UNDEFINED; +} + +static JSValue js_getMouseWheelMove(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + float returnVal = GetMouseWheelMove(); + JSValue ret = JS_NewFloat64(ctx, returnVal); + return ret; +} + +static JSValue js_getMouseWheelMoveV(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2 returnVal = GetMouseWheelMoveV(); + Vector2* ret_ptr = (Vector2*)js_malloc(ctx, sizeof(Vector2)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Vector2_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_setMouseCursor(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int cursor; + JS_ToInt32(ctx, &cursor, argv[0]); + SetMouseCursor(cursor); + return JS_UNDEFINED; +} + +static JSValue js_getTouchX(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int returnVal = GetTouchX(); + JSValue ret = JS_NewInt32(ctx, returnVal); + return ret; +} + +static JSValue js_getTouchY(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int returnVal = GetTouchY(); + JSValue ret = JS_NewInt32(ctx, returnVal); + return ret; +} + +static JSValue js_getTouchPosition(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int index; + JS_ToInt32(ctx, &index, argv[0]); + Vector2 returnVal = GetTouchPosition(index); + Vector2* ret_ptr = (Vector2*)js_malloc(ctx, sizeof(Vector2)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Vector2_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_getTouchPointId(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int index; + JS_ToInt32(ctx, &index, argv[0]); + int returnVal = GetTouchPointId(index); + JSValue ret = JS_NewInt32(ctx, returnVal); + return ret; +} + +static JSValue js_getTouchPointCount(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int returnVal = GetTouchPointCount(); + JSValue ret = JS_NewInt32(ctx, returnVal); + return ret; +} + +static JSValue js_setGesturesEnabled(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + unsigned int flags; + JS_ToUint32(ctx, &flags, argv[0]); + SetGesturesEnabled(flags); + return JS_UNDEFINED; +} + +static JSValue js_isGestureDetected(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int gesture; + JS_ToInt32(ctx, &gesture, argv[0]); + bool returnVal = IsGestureDetected(gesture); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_getGestureDetected(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int returnVal = GetGestureDetected(); + JSValue ret = JS_NewInt32(ctx, returnVal); + return ret; +} + +static JSValue js_getGestureHoldDuration(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + float returnVal = GetGestureHoldDuration(); + JSValue ret = JS_NewFloat64(ctx, returnVal); + return ret; +} + +static JSValue js_getGestureDragVector(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2 returnVal = GetGestureDragVector(); + Vector2* ret_ptr = (Vector2*)js_malloc(ctx, sizeof(Vector2)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Vector2_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_getGestureDragAngle(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + float returnVal = GetGestureDragAngle(); + JSValue ret = JS_NewFloat64(ctx, returnVal); + return ret; +} + +static JSValue js_getGesturePinchVector(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2 returnVal = GetGesturePinchVector(); + Vector2* ret_ptr = (Vector2*)js_malloc(ctx, sizeof(Vector2)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Vector2_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_getGesturePinchAngle(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + float returnVal = GetGesturePinchAngle(); + JSValue ret = JS_NewFloat64(ctx, returnVal); + return ret; +} + +static JSValue js_drawPixel(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int posX; - JS_ToInt32(ctx, (int *)&posX, argv[1]); + JS_ToInt32(ctx, &posX, argv[0]); int posY; - JS_ToInt32(ctx, (int *)&posY, argv[2]); - int fontSize; - JS_ToInt32(ctx, (int *)&fontSize, argv[3]); - Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + JS_ToInt32(ctx, &posY, argv[1]); + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[2], js_Color_class_id); if(color_ptr == NULL) return JS_EXCEPTION; Color color = *color_ptr; - DrawText(text, posX, posY, fontSize, color); - JS_FreeCString(ctx, text); + DrawPixel(posX, posY, color); + return JS_UNDEFINED; +} + +static JSValue js_drawPixelV(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* position_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector2 position = *position_ptr; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[1], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawPixelV(position, color); return JS_UNDEFINED; } static JSValue js_drawLine(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int startPosX; - JS_ToInt32(ctx, (int *)&startPosX, argv[0]); + JS_ToInt32(ctx, &startPosX, argv[0]); int startPosY; - JS_ToInt32(ctx, (int *)&startPosY, argv[1]); + JS_ToInt32(ctx, &startPosY, argv[1]); int endPosX; - JS_ToInt32(ctx, (int *)&endPosX, argv[2]); + JS_ToInt32(ctx, &endPosX, argv[2]); int endPosY; - JS_ToInt32(ctx, (int *)&endPosY, argv[3]); + JS_ToInt32(ctx, &endPosY, argv[3]); Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); if(color_ptr == NULL) return JS_EXCEPTION; Color color = *color_ptr; @@ -1510,6 +2452,174 @@ static JSValue js_drawLine(JSContext * ctx, JSValueConst this_val, int argc, JSV return JS_UNDEFINED; } +static JSValue js_drawLineV(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* startPos_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(startPos_ptr == NULL) return JS_EXCEPTION; + Vector2 startPos = *startPos_ptr; + Vector2* endPos_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[1], js_Vector2_class_id); + if(endPos_ptr == NULL) return JS_EXCEPTION; + Vector2 endPos = *endPos_ptr; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[2], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawLineV(startPos, endPos, color); + return JS_UNDEFINED; +} + +static JSValue js_drawLineEx(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* startPos_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(startPos_ptr == NULL) return JS_EXCEPTION; + Vector2 startPos = *startPos_ptr; + Vector2* endPos_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[1], js_Vector2_class_id); + if(endPos_ptr == NULL) return JS_EXCEPTION; + Vector2 endPos = *endPos_ptr; + double _double_thick; + JS_ToFloat64(ctx, &_double_thick, argv[2]); + float thick = (float)_double_thick; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[3], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawLineEx(startPos, endPos, thick, color); + return JS_UNDEFINED; +} + +static JSValue js_drawLineBezier(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* startPos_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(startPos_ptr == NULL) return JS_EXCEPTION; + Vector2 startPos = *startPos_ptr; + Vector2* endPos_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[1], js_Vector2_class_id); + if(endPos_ptr == NULL) return JS_EXCEPTION; + Vector2 endPos = *endPos_ptr; + double _double_thick; + JS_ToFloat64(ctx, &_double_thick, argv[2]); + float thick = (float)_double_thick; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[3], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawLineBezier(startPos, endPos, thick, color); + return JS_UNDEFINED; +} + +static JSValue js_drawLineBezierQuad(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* startPos_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(startPos_ptr == NULL) return JS_EXCEPTION; + Vector2 startPos = *startPos_ptr; + Vector2* endPos_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[1], js_Vector2_class_id); + if(endPos_ptr == NULL) return JS_EXCEPTION; + Vector2 endPos = *endPos_ptr; + Vector2* controlPos_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[2], js_Vector2_class_id); + if(controlPos_ptr == NULL) return JS_EXCEPTION; + Vector2 controlPos = *controlPos_ptr; + double _double_thick; + JS_ToFloat64(ctx, &_double_thick, argv[3]); + float thick = (float)_double_thick; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawLineBezierQuad(startPos, endPos, controlPos, thick, color); + return JS_UNDEFINED; +} + +static JSValue js_drawLineBezierCubic(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* startPos_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(startPos_ptr == NULL) return JS_EXCEPTION; + Vector2 startPos = *startPos_ptr; + Vector2* endPos_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[1], js_Vector2_class_id); + if(endPos_ptr == NULL) return JS_EXCEPTION; + Vector2 endPos = *endPos_ptr; + Vector2* startControlPos_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[2], js_Vector2_class_id); + if(startControlPos_ptr == NULL) return JS_EXCEPTION; + Vector2 startControlPos = *startControlPos_ptr; + Vector2* endControlPos_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[3], js_Vector2_class_id); + if(endControlPos_ptr == NULL) return JS_EXCEPTION; + Vector2 endControlPos = *endControlPos_ptr; + double _double_thick; + JS_ToFloat64(ctx, &_double_thick, argv[4]); + float thick = (float)_double_thick; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[5], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawLineBezierCubic(startPos, endPos, startControlPos, endControlPos, thick, color); + return JS_UNDEFINED; +} + +static JSValue js_drawCircle(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int centerX; + JS_ToInt32(ctx, ¢erX, argv[0]); + int centerY; + JS_ToInt32(ctx, ¢erY, argv[1]); + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[2]); + float radius = (float)_double_radius; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[3], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawCircle(centerX, centerY, radius, color); + return JS_UNDEFINED; +} + +static JSValue js_drawCircleSector(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* center_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(center_ptr == NULL) return JS_EXCEPTION; + Vector2 center = *center_ptr; + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[1]); + float radius = (float)_double_radius; + double _double_startAngle; + JS_ToFloat64(ctx, &_double_startAngle, argv[2]); + float startAngle = (float)_double_startAngle; + double _double_endAngle; + JS_ToFloat64(ctx, &_double_endAngle, argv[3]); + float endAngle = (float)_double_endAngle; + int segments; + JS_ToInt32(ctx, &segments, argv[4]); + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[5], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawCircleSector(center, radius, startAngle, endAngle, segments, color); + return JS_UNDEFINED; +} + +static JSValue js_drawCircleSectorLines(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* center_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(center_ptr == NULL) return JS_EXCEPTION; + Vector2 center = *center_ptr; + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[1]); + float radius = (float)_double_radius; + double _double_startAngle; + JS_ToFloat64(ctx, &_double_startAngle, argv[2]); + float startAngle = (float)_double_startAngle; + double _double_endAngle; + JS_ToFloat64(ctx, &_double_endAngle, argv[3]); + float endAngle = (float)_double_endAngle; + int segments; + JS_ToInt32(ctx, &segments, argv[4]); + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[5], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawCircleSectorLines(center, radius, startAngle, endAngle, segments, color); + return JS_UNDEFINED; +} + +static JSValue js_drawCircleGradient(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int centerX; + JS_ToInt32(ctx, ¢erX, argv[0]); + int centerY; + JS_ToInt32(ctx, ¢erY, argv[1]); + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[2]); + float radius = (float)_double_radius; + Color* color1_ptr = (Color*)JS_GetOpaque2(ctx, argv[3], js_Color_class_id); + if(color1_ptr == NULL) return JS_EXCEPTION; + Color color1 = *color1_ptr; + Color* color2_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(color2_ptr == NULL) return JS_EXCEPTION; + Color color2 = *color2_ptr; + DrawCircleGradient(centerX, centerY, radius, color1, color2); + return JS_UNDEFINED; +} + static JSValue js_drawCircleV(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { Vector2* center_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); if(center_ptr == NULL) return JS_EXCEPTION; @@ -1524,38 +2634,116 @@ static JSValue js_drawCircleV(JSContext * ctx, JSValueConst this_val, int argc, return JS_UNDEFINED; } -static JSValue js_getMousePosition(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { - Vector2 returnVal = GetMousePosition(); - Vector2* ret_ptr = (Vector2*)js_malloc(ctx, sizeof(Vector2)); - *ret_ptr = returnVal; - JSValue ret = JS_NewObjectClass(ctx, js_Vector2_class_id); - JS_SetOpaque(ret, ret_ptr); - return ret; +static JSValue js_drawCircleLines(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int centerX; + JS_ToInt32(ctx, ¢erX, argv[0]); + int centerY; + JS_ToInt32(ctx, ¢erY, argv[1]); + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[2]); + float radius = (float)_double_radius; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[3], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawCircleLines(centerX, centerY, radius, color); + return JS_UNDEFINED; } -static JSValue js_isMouseButtonPressed(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { - int button; - JS_ToInt32(ctx, (int *)&button, argv[0]); - bool returnVal = IsMouseButtonPressed(button); - JSValue ret = JS_NewBool(ctx, returnVal); - return ret; +static JSValue js_drawEllipse(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int centerX; + JS_ToInt32(ctx, ¢erX, argv[0]); + int centerY; + JS_ToInt32(ctx, ¢erY, argv[1]); + double _double_radiusH; + JS_ToFloat64(ctx, &_double_radiusH, argv[2]); + float radiusH = (float)_double_radiusH; + double _double_radiusV; + JS_ToFloat64(ctx, &_double_radiusV, argv[3]); + float radiusV = (float)_double_radiusV; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawEllipse(centerX, centerY, radiusH, radiusV, color); + return JS_UNDEFINED; } -static JSValue js_getMouseWheelMove(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { - float returnVal = GetMouseWheelMove(); - JSValue ret = JS_NewFloat64(ctx, returnVal); - return ret; +static JSValue js_drawEllipseLines(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int centerX; + JS_ToInt32(ctx, ¢erX, argv[0]); + int centerY; + JS_ToInt32(ctx, ¢erY, argv[1]); + double _double_radiusH; + JS_ToFloat64(ctx, &_double_radiusH, argv[2]); + float radiusH = (float)_double_radiusH; + double _double_radiusV; + JS_ToFloat64(ctx, &_double_radiusV, argv[3]); + float radiusV = (float)_double_radiusV; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawEllipseLines(centerX, centerY, radiusH, radiusV, color); + return JS_UNDEFINED; +} + +static JSValue js_drawRing(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* center_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(center_ptr == NULL) return JS_EXCEPTION; + Vector2 center = *center_ptr; + double _double_innerRadius; + JS_ToFloat64(ctx, &_double_innerRadius, argv[1]); + float innerRadius = (float)_double_innerRadius; + double _double_outerRadius; + JS_ToFloat64(ctx, &_double_outerRadius, argv[2]); + float outerRadius = (float)_double_outerRadius; + double _double_startAngle; + JS_ToFloat64(ctx, &_double_startAngle, argv[3]); + float startAngle = (float)_double_startAngle; + double _double_endAngle; + JS_ToFloat64(ctx, &_double_endAngle, argv[4]); + float endAngle = (float)_double_endAngle; + int segments; + JS_ToInt32(ctx, &segments, argv[5]); + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[6], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawRing(center, innerRadius, outerRadius, startAngle, endAngle, segments, color); + return JS_UNDEFINED; +} + +static JSValue js_drawRingLines(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* center_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(center_ptr == NULL) return JS_EXCEPTION; + Vector2 center = *center_ptr; + double _double_innerRadius; + JS_ToFloat64(ctx, &_double_innerRadius, argv[1]); + float innerRadius = (float)_double_innerRadius; + double _double_outerRadius; + JS_ToFloat64(ctx, &_double_outerRadius, argv[2]); + float outerRadius = (float)_double_outerRadius; + double _double_startAngle; + JS_ToFloat64(ctx, &_double_startAngle, argv[3]); + float startAngle = (float)_double_startAngle; + double _double_endAngle; + JS_ToFloat64(ctx, &_double_endAngle, argv[4]); + float endAngle = (float)_double_endAngle; + int segments; + JS_ToInt32(ctx, &segments, argv[5]); + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[6], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawRingLines(center, innerRadius, outerRadius, startAngle, endAngle, segments, color); + return JS_UNDEFINED; } static JSValue js_drawRectangle(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int posX; - JS_ToInt32(ctx, (int *)&posX, argv[0]); + JS_ToInt32(ctx, &posX, argv[0]); int posY; - JS_ToInt32(ctx, (int *)&posY, argv[1]); + JS_ToInt32(ctx, &posY, argv[1]); int width; - JS_ToInt32(ctx, (int *)&width, argv[2]); + JS_ToInt32(ctx, &width, argv[2]); int height; - JS_ToInt32(ctx, (int *)&height, argv[3]); + JS_ToInt32(ctx, &height, argv[3]); Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); if(color_ptr == NULL) return JS_EXCEPTION; Color color = *color_ptr; @@ -1563,6 +2751,20 @@ static JSValue js_drawRectangle(JSContext * ctx, JSValueConst this_val, int argc return JS_UNDEFINED; } +static JSValue js_drawRectangleV(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* position_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector2 position = *position_ptr; + Vector2* size_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[1], js_Vector2_class_id); + if(size_ptr == NULL) return JS_EXCEPTION; + Vector2 size = *size_ptr; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[2], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawRectangleV(position, size, color); + return JS_UNDEFINED; +} + static JSValue js_drawRectangleRec(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { Rectangle* rec_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[0], js_Rectangle_class_id); if(rec_ptr == NULL) return JS_EXCEPTION; @@ -1574,15 +2776,90 @@ static JSValue js_drawRectangleRec(JSContext * ctx, JSValueConst this_val, int a return JS_UNDEFINED; } +static JSValue js_drawRectanglePro(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Rectangle* rec_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[0], js_Rectangle_class_id); + if(rec_ptr == NULL) return JS_EXCEPTION; + Rectangle rec = *rec_ptr; + Vector2* origin_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[1], js_Vector2_class_id); + if(origin_ptr == NULL) return JS_EXCEPTION; + Vector2 origin = *origin_ptr; + double _double_rotation; + JS_ToFloat64(ctx, &_double_rotation, argv[2]); + float rotation = (float)_double_rotation; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[3], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawRectanglePro(rec, origin, rotation, color); + return JS_UNDEFINED; +} + +static JSValue js_drawRectangleGradientV(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int posX; + JS_ToInt32(ctx, &posX, argv[0]); + int posY; + JS_ToInt32(ctx, &posY, argv[1]); + int width; + JS_ToInt32(ctx, &width, argv[2]); + int height; + JS_ToInt32(ctx, &height, argv[3]); + Color* color1_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(color1_ptr == NULL) return JS_EXCEPTION; + Color color1 = *color1_ptr; + Color* color2_ptr = (Color*)JS_GetOpaque2(ctx, argv[5], js_Color_class_id); + if(color2_ptr == NULL) return JS_EXCEPTION; + Color color2 = *color2_ptr; + DrawRectangleGradientV(posX, posY, width, height, color1, color2); + return JS_UNDEFINED; +} + +static JSValue js_drawRectangleGradientH(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int posX; + JS_ToInt32(ctx, &posX, argv[0]); + int posY; + JS_ToInt32(ctx, &posY, argv[1]); + int width; + JS_ToInt32(ctx, &width, argv[2]); + int height; + JS_ToInt32(ctx, &height, argv[3]); + Color* color1_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(color1_ptr == NULL) return JS_EXCEPTION; + Color color1 = *color1_ptr; + Color* color2_ptr = (Color*)JS_GetOpaque2(ctx, argv[5], js_Color_class_id); + if(color2_ptr == NULL) return JS_EXCEPTION; + Color color2 = *color2_ptr; + DrawRectangleGradientH(posX, posY, width, height, color1, color2); + return JS_UNDEFINED; +} + +static JSValue js_drawRectangleGradientEx(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Rectangle* rec_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[0], js_Rectangle_class_id); + if(rec_ptr == NULL) return JS_EXCEPTION; + Rectangle rec = *rec_ptr; + Color* col1_ptr = (Color*)JS_GetOpaque2(ctx, argv[1], js_Color_class_id); + if(col1_ptr == NULL) return JS_EXCEPTION; + Color col1 = *col1_ptr; + Color* col2_ptr = (Color*)JS_GetOpaque2(ctx, argv[2], js_Color_class_id); + if(col2_ptr == NULL) return JS_EXCEPTION; + Color col2 = *col2_ptr; + Color* col3_ptr = (Color*)JS_GetOpaque2(ctx, argv[3], js_Color_class_id); + if(col3_ptr == NULL) return JS_EXCEPTION; + Color col3 = *col3_ptr; + Color* col4_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(col4_ptr == NULL) return JS_EXCEPTION; + Color col4 = *col4_ptr; + DrawRectangleGradientEx(rec, col1, col2, col3, col4); + return JS_UNDEFINED; +} + static JSValue js_drawRectangleLines(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { int posX; - JS_ToInt32(ctx, (int *)&posX, argv[0]); + JS_ToInt32(ctx, &posX, argv[0]); int posY; - JS_ToInt32(ctx, (int *)&posY, argv[1]); + JS_ToInt32(ctx, &posY, argv[1]); int width; - JS_ToInt32(ctx, (int *)&width, argv[2]); + JS_ToInt32(ctx, &width, argv[2]); int height; - JS_ToInt32(ctx, (int *)&height, argv[3]); + JS_ToInt32(ctx, &height, argv[3]); Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); if(color_ptr == NULL) return JS_EXCEPTION; Color color = *color_ptr; @@ -1590,6 +2867,742 @@ static JSValue js_drawRectangleLines(JSContext * ctx, JSValueConst this_val, int return JS_UNDEFINED; } +static JSValue js_drawRectangleLinesEx(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Rectangle* rec_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[0], js_Rectangle_class_id); + if(rec_ptr == NULL) return JS_EXCEPTION; + Rectangle rec = *rec_ptr; + double _double_lineThick; + JS_ToFloat64(ctx, &_double_lineThick, argv[1]); + float lineThick = (float)_double_lineThick; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[2], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawRectangleLinesEx(rec, lineThick, color); + return JS_UNDEFINED; +} + +static JSValue js_drawRectangleRounded(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Rectangle* rec_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[0], js_Rectangle_class_id); + if(rec_ptr == NULL) return JS_EXCEPTION; + Rectangle rec = *rec_ptr; + double _double_roundness; + JS_ToFloat64(ctx, &_double_roundness, argv[1]); + float roundness = (float)_double_roundness; + int segments; + JS_ToInt32(ctx, &segments, argv[2]); + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[3], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawRectangleRounded(rec, roundness, segments, color); + return JS_UNDEFINED; +} + +static JSValue js_drawRectangleRoundedLines(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Rectangle* rec_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[0], js_Rectangle_class_id); + if(rec_ptr == NULL) return JS_EXCEPTION; + Rectangle rec = *rec_ptr; + double _double_roundness; + JS_ToFloat64(ctx, &_double_roundness, argv[1]); + float roundness = (float)_double_roundness; + int segments; + JS_ToInt32(ctx, &segments, argv[2]); + double _double_lineThick; + JS_ToFloat64(ctx, &_double_lineThick, argv[3]); + float lineThick = (float)_double_lineThick; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawRectangleRoundedLines(rec, roundness, segments, lineThick, color); + return JS_UNDEFINED; +} + +static JSValue js_drawTriangle(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* v1_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(v1_ptr == NULL) return JS_EXCEPTION; + Vector2 v1 = *v1_ptr; + Vector2* v2_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[1], js_Vector2_class_id); + if(v2_ptr == NULL) return JS_EXCEPTION; + Vector2 v2 = *v2_ptr; + Vector2* v3_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[2], js_Vector2_class_id); + if(v3_ptr == NULL) return JS_EXCEPTION; + Vector2 v3 = *v3_ptr; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[3], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawTriangle(v1, v2, v3, color); + return JS_UNDEFINED; +} + +static JSValue js_drawTriangleLines(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* v1_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(v1_ptr == NULL) return JS_EXCEPTION; + Vector2 v1 = *v1_ptr; + Vector2* v2_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[1], js_Vector2_class_id); + if(v2_ptr == NULL) return JS_EXCEPTION; + Vector2 v2 = *v2_ptr; + Vector2* v3_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[2], js_Vector2_class_id); + if(v3_ptr == NULL) return JS_EXCEPTION; + Vector2 v3 = *v3_ptr; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[3], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawTriangleLines(v1, v2, v3, color); + return JS_UNDEFINED; +} + +static JSValue js_drawPoly(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* center_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(center_ptr == NULL) return JS_EXCEPTION; + Vector2 center = *center_ptr; + int sides; + JS_ToInt32(ctx, &sides, argv[1]); + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[2]); + float radius = (float)_double_radius; + double _double_rotation; + JS_ToFloat64(ctx, &_double_rotation, argv[3]); + float rotation = (float)_double_rotation; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawPoly(center, sides, radius, rotation, color); + return JS_UNDEFINED; +} + +static JSValue js_drawPolyLines(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* center_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(center_ptr == NULL) return JS_EXCEPTION; + Vector2 center = *center_ptr; + int sides; + JS_ToInt32(ctx, &sides, argv[1]); + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[2]); + float radius = (float)_double_radius; + double _double_rotation; + JS_ToFloat64(ctx, &_double_rotation, argv[3]); + float rotation = (float)_double_rotation; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawPolyLines(center, sides, radius, rotation, color); + return JS_UNDEFINED; +} + +static JSValue js_drawPolyLinesEx(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* center_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(center_ptr == NULL) return JS_EXCEPTION; + Vector2 center = *center_ptr; + int sides; + JS_ToInt32(ctx, &sides, argv[1]); + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[2]); + float radius = (float)_double_radius; + double _double_rotation; + JS_ToFloat64(ctx, &_double_rotation, argv[3]); + float rotation = (float)_double_rotation; + double _double_lineThick; + JS_ToFloat64(ctx, &_double_lineThick, argv[4]); + float lineThick = (float)_double_lineThick; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[5], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawPolyLinesEx(center, sides, radius, rotation, lineThick, color); + return JS_UNDEFINED; +} + +static JSValue js_checkCollisionRecs(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Rectangle* rec1_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[0], js_Rectangle_class_id); + if(rec1_ptr == NULL) return JS_EXCEPTION; + Rectangle rec1 = *rec1_ptr; + Rectangle* rec2_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[1], js_Rectangle_class_id); + if(rec2_ptr == NULL) return JS_EXCEPTION; + Rectangle rec2 = *rec2_ptr; + bool returnVal = CheckCollisionRecs(rec1, rec2); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_checkCollisionCircles(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* center1_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(center1_ptr == NULL) return JS_EXCEPTION; + Vector2 center1 = *center1_ptr; + double _double_radius1; + JS_ToFloat64(ctx, &_double_radius1, argv[1]); + float radius1 = (float)_double_radius1; + Vector2* center2_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[2], js_Vector2_class_id); + if(center2_ptr == NULL) return JS_EXCEPTION; + Vector2 center2 = *center2_ptr; + double _double_radius2; + JS_ToFloat64(ctx, &_double_radius2, argv[3]); + float radius2 = (float)_double_radius2; + bool returnVal = CheckCollisionCircles(center1, radius1, center2, radius2); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_checkCollisionCircleRec(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* center_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(center_ptr == NULL) return JS_EXCEPTION; + Vector2 center = *center_ptr; + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[1]); + float radius = (float)_double_radius; + Rectangle* rec_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[2], js_Rectangle_class_id); + if(rec_ptr == NULL) return JS_EXCEPTION; + Rectangle rec = *rec_ptr; + bool returnVal = CheckCollisionCircleRec(center, radius, rec); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_checkCollisionPointRec(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* point_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(point_ptr == NULL) return JS_EXCEPTION; + Vector2 point = *point_ptr; + Rectangle* rec_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[1], js_Rectangle_class_id); + if(rec_ptr == NULL) return JS_EXCEPTION; + Rectangle rec = *rec_ptr; + bool returnVal = CheckCollisionPointRec(point, rec); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_checkCollisionPointCircle(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* point_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(point_ptr == NULL) return JS_EXCEPTION; + Vector2 point = *point_ptr; + Vector2* center_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[1], js_Vector2_class_id); + if(center_ptr == NULL) return JS_EXCEPTION; + Vector2 center = *center_ptr; + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[2]); + float radius = (float)_double_radius; + bool returnVal = CheckCollisionPointCircle(point, center, radius); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_checkCollisionPointTriangle(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* point_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(point_ptr == NULL) return JS_EXCEPTION; + Vector2 point = *point_ptr; + Vector2* p1_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[1], js_Vector2_class_id); + if(p1_ptr == NULL) return JS_EXCEPTION; + Vector2 p1 = *p1_ptr; + Vector2* p2_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[2], js_Vector2_class_id); + if(p2_ptr == NULL) return JS_EXCEPTION; + Vector2 p2 = *p2_ptr; + Vector2* p3_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[3], js_Vector2_class_id); + if(p3_ptr == NULL) return JS_EXCEPTION; + Vector2 p3 = *p3_ptr; + bool returnVal = CheckCollisionPointTriangle(point, p1, p2, p3); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_checkCollisionPointLine(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector2* point_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[0], js_Vector2_class_id); + if(point_ptr == NULL) return JS_EXCEPTION; + Vector2 point = *point_ptr; + Vector2* p1_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[1], js_Vector2_class_id); + if(p1_ptr == NULL) return JS_EXCEPTION; + Vector2 p1 = *p1_ptr; + Vector2* p2_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[2], js_Vector2_class_id); + if(p2_ptr == NULL) return JS_EXCEPTION; + Vector2 p2 = *p2_ptr; + int threshold; + JS_ToInt32(ctx, &threshold, argv[3]); + bool returnVal = CheckCollisionPointLine(point, p1, p2, threshold); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_getCollisionRec(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Rectangle* rec1_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[0], js_Rectangle_class_id); + if(rec1_ptr == NULL) return JS_EXCEPTION; + Rectangle rec1 = *rec1_ptr; + Rectangle* rec2_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[1], js_Rectangle_class_id); + if(rec2_ptr == NULL) return JS_EXCEPTION; + Rectangle rec2 = *rec2_ptr; + Rectangle returnVal = GetCollisionRec(rec1, rec2); + Rectangle* ret_ptr = (Rectangle*)js_malloc(ctx, sizeof(Rectangle)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Rectangle_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_loadImage(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); + if(fileName == NULL) return JS_EXCEPTION; + Image returnVal = LoadImage(fileName); + JS_FreeCString(ctx, fileName); + Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Image_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_loadImageRaw(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); + if(fileName == NULL) return JS_EXCEPTION; + int width; + JS_ToInt32(ctx, &width, argv[1]); + int height; + JS_ToInt32(ctx, &height, argv[2]); + int format; + JS_ToInt32(ctx, &format, argv[3]); + int headerSize; + JS_ToInt32(ctx, &headerSize, argv[4]); + Image returnVal = LoadImageRaw(fileName, width, height, format, headerSize); + JS_FreeCString(ctx, fileName); + Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Image_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_loadImageFromTexture(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Texture2D* texture_ptr = (Texture2D*)JS_GetOpaque2(ctx, argv[0], js_Texture_class_id); + if(texture_ptr == NULL) return JS_EXCEPTION; + Texture2D texture = *texture_ptr; + Image returnVal = LoadImageFromTexture(texture); + Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Image_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_loadImageFromScreen(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Image returnVal = LoadImageFromScreen(); + Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Image_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_isImageReady(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Image* image_ptr = (Image*)JS_GetOpaque2(ctx, argv[0], js_Image_class_id); + if(image_ptr == NULL) return JS_EXCEPTION; + Image image = *image_ptr; + bool returnVal = IsImageReady(image); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_exportImage(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Image* image_ptr = (Image*)JS_GetOpaque2(ctx, argv[0], js_Image_class_id); + if(image_ptr == NULL) return JS_EXCEPTION; + Image image = *image_ptr; + const char * fileName = (const char *)JS_ToCString(ctx, argv[1]); + if(fileName == NULL) return JS_EXCEPTION; + bool returnVal = ExportImage(image, fileName); + JS_FreeCString(ctx, fileName); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_genImageColor(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int width; + JS_ToInt32(ctx, &width, argv[0]); + int height; + JS_ToInt32(ctx, &height, argv[1]); + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[2], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + Image returnVal = GenImageColor(width, height, color); + Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Image_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genImageGradientV(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int width; + JS_ToInt32(ctx, &width, argv[0]); + int height; + JS_ToInt32(ctx, &height, argv[1]); + Color* top_ptr = (Color*)JS_GetOpaque2(ctx, argv[2], js_Color_class_id); + if(top_ptr == NULL) return JS_EXCEPTION; + Color top = *top_ptr; + Color* bottom_ptr = (Color*)JS_GetOpaque2(ctx, argv[3], js_Color_class_id); + if(bottom_ptr == NULL) return JS_EXCEPTION; + Color bottom = *bottom_ptr; + Image returnVal = GenImageGradientV(width, height, top, bottom); + Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Image_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genImageGradientH(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int width; + JS_ToInt32(ctx, &width, argv[0]); + int height; + JS_ToInt32(ctx, &height, argv[1]); + Color* left_ptr = (Color*)JS_GetOpaque2(ctx, argv[2], js_Color_class_id); + if(left_ptr == NULL) return JS_EXCEPTION; + Color left = *left_ptr; + Color* right_ptr = (Color*)JS_GetOpaque2(ctx, argv[3], js_Color_class_id); + if(right_ptr == NULL) return JS_EXCEPTION; + Color right = *right_ptr; + Image returnVal = GenImageGradientH(width, height, left, right); + Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Image_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genImageGradientRadial(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int width; + JS_ToInt32(ctx, &width, argv[0]); + int height; + JS_ToInt32(ctx, &height, argv[1]); + double _double_density; + JS_ToFloat64(ctx, &_double_density, argv[2]); + float density = (float)_double_density; + Color* inner_ptr = (Color*)JS_GetOpaque2(ctx, argv[3], js_Color_class_id); + if(inner_ptr == NULL) return JS_EXCEPTION; + Color inner = *inner_ptr; + Color* outer_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(outer_ptr == NULL) return JS_EXCEPTION; + Color outer = *outer_ptr; + Image returnVal = GenImageGradientRadial(width, height, density, inner, outer); + Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Image_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genImageChecked(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int width; + JS_ToInt32(ctx, &width, argv[0]); + int height; + JS_ToInt32(ctx, &height, argv[1]); + int checksX; + JS_ToInt32(ctx, &checksX, argv[2]); + int checksY; + JS_ToInt32(ctx, &checksY, argv[3]); + Color* col1_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(col1_ptr == NULL) return JS_EXCEPTION; + Color col1 = *col1_ptr; + Color* col2_ptr = (Color*)JS_GetOpaque2(ctx, argv[5], js_Color_class_id); + if(col2_ptr == NULL) return JS_EXCEPTION; + Color col2 = *col2_ptr; + Image returnVal = GenImageChecked(width, height, checksX, checksY, col1, col2); + Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Image_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genImageWhiteNoise(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int width; + JS_ToInt32(ctx, &width, argv[0]); + int height; + JS_ToInt32(ctx, &height, argv[1]); + double _double_factor; + JS_ToFloat64(ctx, &_double_factor, argv[2]); + float factor = (float)_double_factor; + Image returnVal = GenImageWhiteNoise(width, height, factor); + Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Image_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genImagePerlinNoise(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int width; + JS_ToInt32(ctx, &width, argv[0]); + int height; + JS_ToInt32(ctx, &height, argv[1]); + int offsetX; + JS_ToInt32(ctx, &offsetX, argv[2]); + int offsetY; + JS_ToInt32(ctx, &offsetY, argv[3]); + double _double_scale; + JS_ToFloat64(ctx, &_double_scale, argv[4]); + float scale = (float)_double_scale; + Image returnVal = GenImagePerlinNoise(width, height, offsetX, offsetY, scale); + Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Image_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genImageCellular(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int width; + JS_ToInt32(ctx, &width, argv[0]); + int height; + JS_ToInt32(ctx, &height, argv[1]); + int tileSize; + JS_ToInt32(ctx, &tileSize, argv[2]); + Image returnVal = GenImageCellular(width, height, tileSize); + Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Image_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genImageText(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int width; + JS_ToInt32(ctx, &width, argv[0]); + int height; + JS_ToInt32(ctx, &height, argv[1]); + const char * text = (const char *)JS_ToCString(ctx, argv[2]); + if(text == NULL) return JS_EXCEPTION; + Image returnVal = GenImageText(width, height, text); + JS_FreeCString(ctx, text); + Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Image_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_imageCopy(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Image* image_ptr = (Image*)JS_GetOpaque2(ctx, argv[0], js_Image_class_id); + if(image_ptr == NULL) return JS_EXCEPTION; + Image image = *image_ptr; + Image returnVal = ImageCopy(image); + Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Image_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_imageFromImage(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Image* image_ptr = (Image*)JS_GetOpaque2(ctx, argv[0], js_Image_class_id); + if(image_ptr == NULL) return JS_EXCEPTION; + Image image = *image_ptr; + Rectangle* rec_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[1], js_Rectangle_class_id); + if(rec_ptr == NULL) return JS_EXCEPTION; + Rectangle rec = *rec_ptr; + Image returnVal = ImageFromImage(image, rec); + Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Image_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_imageText(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + const char * text = (const char *)JS_ToCString(ctx, argv[0]); + if(text == NULL) return JS_EXCEPTION; + int fontSize; + JS_ToInt32(ctx, &fontSize, argv[1]); + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[2], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + Image returnVal = ImageText(text, fontSize, color); + JS_FreeCString(ctx, text); + Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Image_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_getImageAlphaBorder(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Image* image_ptr = (Image*)JS_GetOpaque2(ctx, argv[0], js_Image_class_id); + if(image_ptr == NULL) return JS_EXCEPTION; + Image image = *image_ptr; + double _double_threshold; + JS_ToFloat64(ctx, &_double_threshold, argv[1]); + float threshold = (float)_double_threshold; + Rectangle returnVal = GetImageAlphaBorder(image, threshold); + Rectangle* ret_ptr = (Rectangle*)js_malloc(ctx, sizeof(Rectangle)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Rectangle_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_getImageColor(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Image* image_ptr = (Image*)JS_GetOpaque2(ctx, argv[0], js_Image_class_id); + if(image_ptr == NULL) return JS_EXCEPTION; + Image image = *image_ptr; + int x; + JS_ToInt32(ctx, &x, argv[1]); + int y; + JS_ToInt32(ctx, &y, argv[2]); + Color returnVal = GetImageColor(image, x, y); + Color* ret_ptr = (Color*)js_malloc(ctx, sizeof(Color)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Color_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_loadTexture(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); + if(fileName == NULL) return JS_EXCEPTION; + Texture2D returnVal = LoadTexture(fileName); + JS_FreeCString(ctx, fileName); + Texture2D* ret_ptr = (Texture2D*)js_malloc(ctx, sizeof(Texture2D)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Texture_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_loadTextureFromImage(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Image* image_ptr = (Image*)JS_GetOpaque2(ctx, argv[0], js_Image_class_id); + if(image_ptr == NULL) return JS_EXCEPTION; + Image image = *image_ptr; + Texture2D returnVal = LoadTextureFromImage(image); + Texture2D* ret_ptr = (Texture2D*)js_malloc(ctx, sizeof(Texture2D)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Texture_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_loadTextureCubemap(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Image* image_ptr = (Image*)JS_GetOpaque2(ctx, argv[0], js_Image_class_id); + if(image_ptr == NULL) return JS_EXCEPTION; + Image image = *image_ptr; + int layout; + JS_ToInt32(ctx, &layout, argv[1]); + TextureCubemap returnVal = LoadTextureCubemap(image, layout); + TextureCubemap* ret_ptr = (TextureCubemap*)js_malloc(ctx, sizeof(TextureCubemap)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Texture_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_isTextureReady(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Texture2D* texture_ptr = (Texture2D*)JS_GetOpaque2(ctx, argv[0], js_Texture_class_id); + if(texture_ptr == NULL) return JS_EXCEPTION; + Texture2D texture = *texture_ptr; + bool returnVal = IsTextureReady(texture); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_setTextureFilter(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Texture2D* texture_ptr = (Texture2D*)JS_GetOpaque2(ctx, argv[0], js_Texture_class_id); + if(texture_ptr == NULL) return JS_EXCEPTION; + Texture2D texture = *texture_ptr; + int filter; + JS_ToInt32(ctx, &filter, argv[1]); + SetTextureFilter(texture, filter); + return JS_UNDEFINED; +} + +static JSValue js_setTextureWrap(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Texture2D* texture_ptr = (Texture2D*)JS_GetOpaque2(ctx, argv[0], js_Texture_class_id); + if(texture_ptr == NULL) return JS_EXCEPTION; + Texture2D texture = *texture_ptr; + int wrap; + JS_ToInt32(ctx, &wrap, argv[1]); + SetTextureWrap(texture, wrap); + return JS_UNDEFINED; +} + +static JSValue js_drawTexture(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Texture2D* texture_ptr = (Texture2D*)JS_GetOpaque2(ctx, argv[0], js_Texture_class_id); + if(texture_ptr == NULL) return JS_EXCEPTION; + Texture2D texture = *texture_ptr; + int posX; + JS_ToInt32(ctx, &posX, argv[1]); + int posY; + JS_ToInt32(ctx, &posY, argv[2]); + Color* tint_ptr = (Color*)JS_GetOpaque2(ctx, argv[3], js_Color_class_id); + if(tint_ptr == NULL) return JS_EXCEPTION; + Color tint = *tint_ptr; + DrawTexture(texture, posX, posY, tint); + return JS_UNDEFINED; +} + +static JSValue js_drawTextureV(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Texture2D* texture_ptr = (Texture2D*)JS_GetOpaque2(ctx, argv[0], js_Texture_class_id); + if(texture_ptr == NULL) return JS_EXCEPTION; + Texture2D texture = *texture_ptr; + Vector2* position_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[1], js_Vector2_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector2 position = *position_ptr; + Color* tint_ptr = (Color*)JS_GetOpaque2(ctx, argv[2], js_Color_class_id); + if(tint_ptr == NULL) return JS_EXCEPTION; + Color tint = *tint_ptr; + DrawTextureV(texture, position, tint); + return JS_UNDEFINED; +} + +static JSValue js_drawTextureEx(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Texture2D* texture_ptr = (Texture2D*)JS_GetOpaque2(ctx, argv[0], js_Texture_class_id); + if(texture_ptr == NULL) return JS_EXCEPTION; + Texture2D texture = *texture_ptr; + Vector2* position_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[1], js_Vector2_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector2 position = *position_ptr; + double _double_rotation; + JS_ToFloat64(ctx, &_double_rotation, argv[2]); + float rotation = (float)_double_rotation; + double _double_scale; + JS_ToFloat64(ctx, &_double_scale, argv[3]); + float scale = (float)_double_scale; + Color* tint_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(tint_ptr == NULL) return JS_EXCEPTION; + Color tint = *tint_ptr; + DrawTextureEx(texture, position, rotation, scale, tint); + return JS_UNDEFINED; +} + +static JSValue js_drawTextureRec(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Texture2D* texture_ptr = (Texture2D*)JS_GetOpaque2(ctx, argv[0], js_Texture_class_id); + if(texture_ptr == NULL) return JS_EXCEPTION; + Texture2D texture = *texture_ptr; + Rectangle* source_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[1], js_Rectangle_class_id); + if(source_ptr == NULL) return JS_EXCEPTION; + Rectangle source = *source_ptr; + Vector2* position_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[2], js_Vector2_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector2 position = *position_ptr; + Color* tint_ptr = (Color*)JS_GetOpaque2(ctx, argv[3], js_Color_class_id); + if(tint_ptr == NULL) return JS_EXCEPTION; + Color tint = *tint_ptr; + DrawTextureRec(texture, source, position, tint); + return JS_UNDEFINED; +} + +static JSValue js_drawTexturePro(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Texture2D* texture_ptr = (Texture2D*)JS_GetOpaque2(ctx, argv[0], js_Texture_class_id); + if(texture_ptr == NULL) return JS_EXCEPTION; + Texture2D texture = *texture_ptr; + Rectangle* source_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[1], js_Rectangle_class_id); + if(source_ptr == NULL) return JS_EXCEPTION; + Rectangle source = *source_ptr; + Rectangle* dest_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[2], js_Rectangle_class_id); + if(dest_ptr == NULL) return JS_EXCEPTION; + Rectangle dest = *dest_ptr; + Vector2* origin_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[3], js_Vector2_class_id); + if(origin_ptr == NULL) return JS_EXCEPTION; + Vector2 origin = *origin_ptr; + double _double_rotation; + JS_ToFloat64(ctx, &_double_rotation, argv[4]); + float rotation = (float)_double_rotation; + Color* tint_ptr = (Color*)JS_GetOpaque2(ctx, argv[5], js_Color_class_id); + if(tint_ptr == NULL) return JS_EXCEPTION; + Color tint = *tint_ptr; + DrawTexturePro(texture, source, dest, origin, rotation, tint); + return JS_UNDEFINED; +} + static JSValue js_fade(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[0], js_Color_class_id); if(color_ptr == NULL) return JS_EXCEPTION; @@ -1605,6 +3618,1585 @@ static JSValue js_fade(JSContext * ctx, JSValueConst this_val, int argc, JSValue return ret; } +static JSValue js_colorToInt(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[0], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + int returnVal = ColorToInt(color); + JSValue ret = JS_NewInt32(ctx, returnVal); + return ret; +} + +static JSValue js_colorNormalize(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[0], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + Vector4 returnVal = ColorNormalize(color); + Vector4* ret_ptr = (Vector4*)js_malloc(ctx, sizeof(Vector4)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Vector4_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_colorFromNormalized(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector4* normalized_ptr = (Vector4*)JS_GetOpaque2(ctx, argv[0], js_Vector4_class_id); + if(normalized_ptr == NULL) return JS_EXCEPTION; + Vector4 normalized = *normalized_ptr; + Color returnVal = ColorFromNormalized(normalized); + Color* ret_ptr = (Color*)js_malloc(ctx, sizeof(Color)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Color_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_colorToHSV(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[0], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + Vector3 returnVal = ColorToHSV(color); + Vector3* ret_ptr = (Vector3*)js_malloc(ctx, sizeof(Vector3)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Vector3_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_colorFromHSV(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + double _double_hue; + JS_ToFloat64(ctx, &_double_hue, argv[0]); + float hue = (float)_double_hue; + double _double_saturation; + JS_ToFloat64(ctx, &_double_saturation, argv[1]); + float saturation = (float)_double_saturation; + double _double_value; + JS_ToFloat64(ctx, &_double_value, argv[2]); + float value = (float)_double_value; + Color returnVal = ColorFromHSV(hue, saturation, value); + Color* ret_ptr = (Color*)js_malloc(ctx, sizeof(Color)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Color_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_colorTint(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[0], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + Color* tint_ptr = (Color*)JS_GetOpaque2(ctx, argv[1], js_Color_class_id); + if(tint_ptr == NULL) return JS_EXCEPTION; + Color tint = *tint_ptr; + Color returnVal = ColorTint(color, tint); + Color* ret_ptr = (Color*)js_malloc(ctx, sizeof(Color)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Color_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_colorBrightness(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[0], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + double _double_factor; + JS_ToFloat64(ctx, &_double_factor, argv[1]); + float factor = (float)_double_factor; + Color returnVal = ColorBrightness(color, factor); + Color* ret_ptr = (Color*)js_malloc(ctx, sizeof(Color)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Color_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_colorContrast(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[0], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + double _double_contrast; + JS_ToFloat64(ctx, &_double_contrast, argv[1]); + float contrast = (float)_double_contrast; + Color returnVal = ColorContrast(color, contrast); + Color* ret_ptr = (Color*)js_malloc(ctx, sizeof(Color)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Color_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_colorAlpha(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[0], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + double _double_alpha; + JS_ToFloat64(ctx, &_double_alpha, argv[1]); + float alpha = (float)_double_alpha; + Color returnVal = ColorAlpha(color, alpha); + Color* ret_ptr = (Color*)js_malloc(ctx, sizeof(Color)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Color_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_colorAlphaBlend(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Color* dst_ptr = (Color*)JS_GetOpaque2(ctx, argv[0], js_Color_class_id); + if(dst_ptr == NULL) return JS_EXCEPTION; + Color dst = *dst_ptr; + Color* src_ptr = (Color*)JS_GetOpaque2(ctx, argv[1], js_Color_class_id); + if(src_ptr == NULL) return JS_EXCEPTION; + Color src = *src_ptr; + Color* tint_ptr = (Color*)JS_GetOpaque2(ctx, argv[2], js_Color_class_id); + if(tint_ptr == NULL) return JS_EXCEPTION; + Color tint = *tint_ptr; + Color returnVal = ColorAlphaBlend(dst, src, tint); + Color* ret_ptr = (Color*)js_malloc(ctx, sizeof(Color)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Color_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_getColor(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + unsigned int hexValue; + JS_ToUint32(ctx, &hexValue, argv[0]); + Color returnVal = GetColor(hexValue); + Color* ret_ptr = (Color*)js_malloc(ctx, sizeof(Color)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Color_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_getPixelDataSize(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int width; + JS_ToInt32(ctx, &width, argv[0]); + int height; + JS_ToInt32(ctx, &height, argv[1]); + int format; + JS_ToInt32(ctx, &format, argv[2]); + int returnVal = GetPixelDataSize(width, height, format); + JSValue ret = JS_NewInt32(ctx, returnVal); + return ret; +} + +static JSValue js_getFontDefault(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Font returnVal = GetFontDefault(); + Font* ret_ptr = (Font*)js_malloc(ctx, sizeof(Font)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Font_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_loadFont(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); + if(fileName == NULL) return JS_EXCEPTION; + Font returnVal = LoadFont(fileName); + JS_FreeCString(ctx, fileName); + Font* ret_ptr = (Font*)js_malloc(ctx, sizeof(Font)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Font_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_loadFontFromImage(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Image* image_ptr = (Image*)JS_GetOpaque2(ctx, argv[0], js_Image_class_id); + if(image_ptr == NULL) return JS_EXCEPTION; + Image image = *image_ptr; + Color* key_ptr = (Color*)JS_GetOpaque2(ctx, argv[1], js_Color_class_id); + if(key_ptr == NULL) return JS_EXCEPTION; + Color key = *key_ptr; + int firstChar; + JS_ToInt32(ctx, &firstChar, argv[2]); + Font returnVal = LoadFontFromImage(image, key, firstChar); + Font* ret_ptr = (Font*)js_malloc(ctx, sizeof(Font)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Font_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_isFontReady(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Font* font_ptr = (Font*)JS_GetOpaque2(ctx, argv[0], js_Font_class_id); + if(font_ptr == NULL) return JS_EXCEPTION; + Font font = *font_ptr; + bool returnVal = IsFontReady(font); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_drawFPS(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int posX; + JS_ToInt32(ctx, &posX, argv[0]); + int posY; + JS_ToInt32(ctx, &posY, argv[1]); + DrawFPS(posX, posY); + return JS_UNDEFINED; +} + +static JSValue js_drawText(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + const char * text = (const char *)JS_ToCString(ctx, argv[0]); + if(text == NULL) return JS_EXCEPTION; + int posX; + JS_ToInt32(ctx, &posX, argv[1]); + int posY; + JS_ToInt32(ctx, &posY, argv[2]); + int fontSize; + JS_ToInt32(ctx, &fontSize, argv[3]); + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawText(text, posX, posY, fontSize, color); + JS_FreeCString(ctx, text); + return JS_UNDEFINED; +} + +static JSValue js_drawTextEx(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Font* font_ptr = (Font*)JS_GetOpaque2(ctx, argv[0], js_Font_class_id); + if(font_ptr == NULL) return JS_EXCEPTION; + Font font = *font_ptr; + const char * text = (const char *)JS_ToCString(ctx, argv[1]); + if(text == NULL) return JS_EXCEPTION; + Vector2* position_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[2], js_Vector2_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector2 position = *position_ptr; + double _double_fontSize; + JS_ToFloat64(ctx, &_double_fontSize, argv[3]); + float fontSize = (float)_double_fontSize; + double _double_spacing; + JS_ToFloat64(ctx, &_double_spacing, argv[4]); + float spacing = (float)_double_spacing; + Color* tint_ptr = (Color*)JS_GetOpaque2(ctx, argv[5], js_Color_class_id); + if(tint_ptr == NULL) return JS_EXCEPTION; + Color tint = *tint_ptr; + DrawTextEx(font, text, position, fontSize, spacing, tint); + JS_FreeCString(ctx, text); + return JS_UNDEFINED; +} + +static JSValue js_drawTextPro(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Font* font_ptr = (Font*)JS_GetOpaque2(ctx, argv[0], js_Font_class_id); + if(font_ptr == NULL) return JS_EXCEPTION; + Font font = *font_ptr; + const char * text = (const char *)JS_ToCString(ctx, argv[1]); + if(text == NULL) return JS_EXCEPTION; + Vector2* position_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[2], js_Vector2_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector2 position = *position_ptr; + Vector2* origin_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[3], js_Vector2_class_id); + if(origin_ptr == NULL) return JS_EXCEPTION; + Vector2 origin = *origin_ptr; + double _double_rotation; + JS_ToFloat64(ctx, &_double_rotation, argv[4]); + float rotation = (float)_double_rotation; + double _double_fontSize; + JS_ToFloat64(ctx, &_double_fontSize, argv[5]); + float fontSize = (float)_double_fontSize; + double _double_spacing; + JS_ToFloat64(ctx, &_double_spacing, argv[6]); + float spacing = (float)_double_spacing; + Color* tint_ptr = (Color*)JS_GetOpaque2(ctx, argv[7], js_Color_class_id); + if(tint_ptr == NULL) return JS_EXCEPTION; + Color tint = *tint_ptr; + DrawTextPro(font, text, position, origin, rotation, fontSize, spacing, tint); + JS_FreeCString(ctx, text); + return JS_UNDEFINED; +} + +static JSValue js_drawTextCodepoint(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Font* font_ptr = (Font*)JS_GetOpaque2(ctx, argv[0], js_Font_class_id); + if(font_ptr == NULL) return JS_EXCEPTION; + Font font = *font_ptr; + int codepoint; + JS_ToInt32(ctx, &codepoint, argv[1]); + Vector2* position_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[2], js_Vector2_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector2 position = *position_ptr; + double _double_fontSize; + JS_ToFloat64(ctx, &_double_fontSize, argv[3]); + float fontSize = (float)_double_fontSize; + Color* tint_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(tint_ptr == NULL) return JS_EXCEPTION; + Color tint = *tint_ptr; + DrawTextCodepoint(font, codepoint, position, fontSize, tint); + return JS_UNDEFINED; +} + +static JSValue js_measureText(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + const char * text = (const char *)JS_ToCString(ctx, argv[0]); + if(text == NULL) return JS_EXCEPTION; + int fontSize; + JS_ToInt32(ctx, &fontSize, argv[1]); + int returnVal = MeasureText(text, fontSize); + JS_FreeCString(ctx, text); + JSValue ret = JS_NewInt32(ctx, returnVal); + return ret; +} + +static JSValue js_measureTextEx(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Font* font_ptr = (Font*)JS_GetOpaque2(ctx, argv[0], js_Font_class_id); + if(font_ptr == NULL) return JS_EXCEPTION; + Font font = *font_ptr; + const char * text = (const char *)JS_ToCString(ctx, argv[1]); + if(text == NULL) return JS_EXCEPTION; + double _double_fontSize; + JS_ToFloat64(ctx, &_double_fontSize, argv[2]); + float fontSize = (float)_double_fontSize; + double _double_spacing; + JS_ToFloat64(ctx, &_double_spacing, argv[3]); + float spacing = (float)_double_spacing; + Vector2 returnVal = MeasureTextEx(font, text, fontSize, spacing); + JS_FreeCString(ctx, text); + Vector2* ret_ptr = (Vector2*)js_malloc(ctx, sizeof(Vector2)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Vector2_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_getGlyphIndex(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Font* font_ptr = (Font*)JS_GetOpaque2(ctx, argv[0], js_Font_class_id); + if(font_ptr == NULL) return JS_EXCEPTION; + Font font = *font_ptr; + int codepoint; + JS_ToInt32(ctx, &codepoint, argv[1]); + int returnVal = GetGlyphIndex(font, codepoint); + JSValue ret = JS_NewInt32(ctx, returnVal); + return ret; +} + +static JSValue js_getGlyphAtlasRec(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Font* font_ptr = (Font*)JS_GetOpaque2(ctx, argv[0], js_Font_class_id); + if(font_ptr == NULL) return JS_EXCEPTION; + Font font = *font_ptr; + int codepoint; + JS_ToInt32(ctx, &codepoint, argv[1]); + Rectangle returnVal = GetGlyphAtlasRec(font, codepoint); + Rectangle* ret_ptr = (Rectangle*)js_malloc(ctx, sizeof(Rectangle)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Rectangle_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_drawLine3D(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* startPos_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(startPos_ptr == NULL) return JS_EXCEPTION; + Vector3 startPos = *startPos_ptr; + Vector3* endPos_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(endPos_ptr == NULL) return JS_EXCEPTION; + Vector3 endPos = *endPos_ptr; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[2], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawLine3D(startPos, endPos, color); + return JS_UNDEFINED; +} + +static JSValue js_drawPoint3D(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* position_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector3 position = *position_ptr; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[1], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawPoint3D(position, color); + return JS_UNDEFINED; +} + +static JSValue js_drawCircle3D(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* center_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(center_ptr == NULL) return JS_EXCEPTION; + Vector3 center = *center_ptr; + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[1]); + float radius = (float)_double_radius; + Vector3* rotationAxis_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[2], js_Vector3_class_id); + if(rotationAxis_ptr == NULL) return JS_EXCEPTION; + Vector3 rotationAxis = *rotationAxis_ptr; + double _double_rotationAngle; + JS_ToFloat64(ctx, &_double_rotationAngle, argv[3]); + float rotationAngle = (float)_double_rotationAngle; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawCircle3D(center, radius, rotationAxis, rotationAngle, color); + return JS_UNDEFINED; +} + +static JSValue js_drawTriangle3D(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* v1_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(v1_ptr == NULL) return JS_EXCEPTION; + Vector3 v1 = *v1_ptr; + Vector3* v2_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(v2_ptr == NULL) return JS_EXCEPTION; + Vector3 v2 = *v2_ptr; + Vector3* v3_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[2], js_Vector3_class_id); + if(v3_ptr == NULL) return JS_EXCEPTION; + Vector3 v3 = *v3_ptr; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[3], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawTriangle3D(v1, v2, v3, color); + return JS_UNDEFINED; +} + +static JSValue js_drawCube(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* position_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector3 position = *position_ptr; + double _double_width; + JS_ToFloat64(ctx, &_double_width, argv[1]); + float width = (float)_double_width; + double _double_height; + JS_ToFloat64(ctx, &_double_height, argv[2]); + float height = (float)_double_height; + double _double_length; + JS_ToFloat64(ctx, &_double_length, argv[3]); + float length = (float)_double_length; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawCube(position, width, height, length, color); + return JS_UNDEFINED; +} + +static JSValue js_drawCubeV(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* position_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector3 position = *position_ptr; + Vector3* size_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(size_ptr == NULL) return JS_EXCEPTION; + Vector3 size = *size_ptr; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[2], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawCubeV(position, size, color); + return JS_UNDEFINED; +} + +static JSValue js_drawCubeWires(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* position_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector3 position = *position_ptr; + double _double_width; + JS_ToFloat64(ctx, &_double_width, argv[1]); + float width = (float)_double_width; + double _double_height; + JS_ToFloat64(ctx, &_double_height, argv[2]); + float height = (float)_double_height; + double _double_length; + JS_ToFloat64(ctx, &_double_length, argv[3]); + float length = (float)_double_length; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawCubeWires(position, width, height, length, color); + return JS_UNDEFINED; +} + +static JSValue js_drawCubeWiresV(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* position_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector3 position = *position_ptr; + Vector3* size_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(size_ptr == NULL) return JS_EXCEPTION; + Vector3 size = *size_ptr; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[2], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawCubeWiresV(position, size, color); + return JS_UNDEFINED; +} + +static JSValue js_drawSphere(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* centerPos_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(centerPos_ptr == NULL) return JS_EXCEPTION; + Vector3 centerPos = *centerPos_ptr; + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[1]); + float radius = (float)_double_radius; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[2], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawSphere(centerPos, radius, color); + return JS_UNDEFINED; +} + +static JSValue js_drawSphereEx(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* centerPos_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(centerPos_ptr == NULL) return JS_EXCEPTION; + Vector3 centerPos = *centerPos_ptr; + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[1]); + float radius = (float)_double_radius; + int rings; + JS_ToInt32(ctx, &rings, argv[2]); + int slices; + JS_ToInt32(ctx, &slices, argv[3]); + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawSphereEx(centerPos, radius, rings, slices, color); + return JS_UNDEFINED; +} + +static JSValue js_drawSphereWires(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* centerPos_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(centerPos_ptr == NULL) return JS_EXCEPTION; + Vector3 centerPos = *centerPos_ptr; + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[1]); + float radius = (float)_double_radius; + int rings; + JS_ToInt32(ctx, &rings, argv[2]); + int slices; + JS_ToInt32(ctx, &slices, argv[3]); + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawSphereWires(centerPos, radius, rings, slices, color); + return JS_UNDEFINED; +} + +static JSValue js_drawCylinder(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* position_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector3 position = *position_ptr; + double _double_radiusTop; + JS_ToFloat64(ctx, &_double_radiusTop, argv[1]); + float radiusTop = (float)_double_radiusTop; + double _double_radiusBottom; + JS_ToFloat64(ctx, &_double_radiusBottom, argv[2]); + float radiusBottom = (float)_double_radiusBottom; + double _double_height; + JS_ToFloat64(ctx, &_double_height, argv[3]); + float height = (float)_double_height; + int slices; + JS_ToInt32(ctx, &slices, argv[4]); + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[5], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawCylinder(position, radiusTop, radiusBottom, height, slices, color); + return JS_UNDEFINED; +} + +static JSValue js_drawCylinderEx(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* startPos_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(startPos_ptr == NULL) return JS_EXCEPTION; + Vector3 startPos = *startPos_ptr; + Vector3* endPos_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(endPos_ptr == NULL) return JS_EXCEPTION; + Vector3 endPos = *endPos_ptr; + double _double_startRadius; + JS_ToFloat64(ctx, &_double_startRadius, argv[2]); + float startRadius = (float)_double_startRadius; + double _double_endRadius; + JS_ToFloat64(ctx, &_double_endRadius, argv[3]); + float endRadius = (float)_double_endRadius; + int sides; + JS_ToInt32(ctx, &sides, argv[4]); + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[5], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawCylinderEx(startPos, endPos, startRadius, endRadius, sides, color); + return JS_UNDEFINED; +} + +static JSValue js_drawCylinderWires(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* position_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector3 position = *position_ptr; + double _double_radiusTop; + JS_ToFloat64(ctx, &_double_radiusTop, argv[1]); + float radiusTop = (float)_double_radiusTop; + double _double_radiusBottom; + JS_ToFloat64(ctx, &_double_radiusBottom, argv[2]); + float radiusBottom = (float)_double_radiusBottom; + double _double_height; + JS_ToFloat64(ctx, &_double_height, argv[3]); + float height = (float)_double_height; + int slices; + JS_ToInt32(ctx, &slices, argv[4]); + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[5], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawCylinderWires(position, radiusTop, radiusBottom, height, slices, color); + return JS_UNDEFINED; +} + +static JSValue js_drawCylinderWiresEx(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* startPos_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(startPos_ptr == NULL) return JS_EXCEPTION; + Vector3 startPos = *startPos_ptr; + Vector3* endPos_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(endPos_ptr == NULL) return JS_EXCEPTION; + Vector3 endPos = *endPos_ptr; + double _double_startRadius; + JS_ToFloat64(ctx, &_double_startRadius, argv[2]); + float startRadius = (float)_double_startRadius; + double _double_endRadius; + JS_ToFloat64(ctx, &_double_endRadius, argv[3]); + float endRadius = (float)_double_endRadius; + int sides; + JS_ToInt32(ctx, &sides, argv[4]); + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[5], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawCylinderWiresEx(startPos, endPos, startRadius, endRadius, sides, color); + return JS_UNDEFINED; +} + +static JSValue js_drawCapsule(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* startPos_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(startPos_ptr == NULL) return JS_EXCEPTION; + Vector3 startPos = *startPos_ptr; + Vector3* endPos_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(endPos_ptr == NULL) return JS_EXCEPTION; + Vector3 endPos = *endPos_ptr; + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[2]); + float radius = (float)_double_radius; + int slices; + JS_ToInt32(ctx, &slices, argv[3]); + int rings; + JS_ToInt32(ctx, &rings, argv[4]); + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[5], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawCapsule(startPos, endPos, radius, slices, rings, color); + return JS_UNDEFINED; +} + +static JSValue js_drawCapsuleWires(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* startPos_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(startPos_ptr == NULL) return JS_EXCEPTION; + Vector3 startPos = *startPos_ptr; + Vector3* endPos_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(endPos_ptr == NULL) return JS_EXCEPTION; + Vector3 endPos = *endPos_ptr; + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[2]); + float radius = (float)_double_radius; + int slices; + JS_ToInt32(ctx, &slices, argv[3]); + int rings; + JS_ToInt32(ctx, &rings, argv[4]); + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[5], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawCapsuleWires(startPos, endPos, radius, slices, rings, color); + return JS_UNDEFINED; +} + +static JSValue js_drawPlane(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* centerPos_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(centerPos_ptr == NULL) return JS_EXCEPTION; + Vector3 centerPos = *centerPos_ptr; + Vector2* size_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[1], js_Vector2_class_id); + if(size_ptr == NULL) return JS_EXCEPTION; + Vector2 size = *size_ptr; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[2], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawPlane(centerPos, size, color); + return JS_UNDEFINED; +} + +static JSValue js_drawRay(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Ray* ray_ptr = (Ray*)JS_GetOpaque2(ctx, argv[0], js_Ray_class_id); + if(ray_ptr == NULL) return JS_EXCEPTION; + Ray ray = *ray_ptr; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[1], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawRay(ray, color); + return JS_UNDEFINED; +} + +static JSValue js_drawGrid(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int slices; + JS_ToInt32(ctx, &slices, argv[0]); + double _double_spacing; + JS_ToFloat64(ctx, &_double_spacing, argv[1]); + float spacing = (float)_double_spacing; + DrawGrid(slices, spacing); + return JS_UNDEFINED; +} + +static JSValue js_loadModel(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); + if(fileName == NULL) return JS_EXCEPTION; + Model returnVal = LoadModel(fileName); + JS_FreeCString(ctx, fileName); + Model* ret_ptr = (Model*)js_malloc(ctx, sizeof(Model)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Model_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_loadModelFromMesh(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Mesh* mesh_ptr = (Mesh*)JS_GetOpaque2(ctx, argv[0], js_Mesh_class_id); + if(mesh_ptr == NULL) return JS_EXCEPTION; + Mesh mesh = *mesh_ptr; + Model returnVal = LoadModelFromMesh(mesh); + Model* ret_ptr = (Model*)js_malloc(ctx, sizeof(Model)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Model_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_isModelReady(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Model* model_ptr = (Model*)JS_GetOpaque2(ctx, argv[0], js_Model_class_id); + if(model_ptr == NULL) return JS_EXCEPTION; + Model model = *model_ptr; + bool returnVal = IsModelReady(model); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_getModelBoundingBox(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Model* model_ptr = (Model*)JS_GetOpaque2(ctx, argv[0], js_Model_class_id); + if(model_ptr == NULL) return JS_EXCEPTION; + Model model = *model_ptr; + BoundingBox returnVal = GetModelBoundingBox(model); + BoundingBox* ret_ptr = (BoundingBox*)js_malloc(ctx, sizeof(BoundingBox)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_BoundingBox_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_drawModel(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Model* model_ptr = (Model*)JS_GetOpaque2(ctx, argv[0], js_Model_class_id); + if(model_ptr == NULL) return JS_EXCEPTION; + Model model = *model_ptr; + Vector3* position_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector3 position = *position_ptr; + double _double_scale; + JS_ToFloat64(ctx, &_double_scale, argv[2]); + float scale = (float)_double_scale; + Color* tint_ptr = (Color*)JS_GetOpaque2(ctx, argv[3], js_Color_class_id); + if(tint_ptr == NULL) return JS_EXCEPTION; + Color tint = *tint_ptr; + DrawModel(model, position, scale, tint); + return JS_UNDEFINED; +} + +static JSValue js_drawModelEx(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Model* model_ptr = (Model*)JS_GetOpaque2(ctx, argv[0], js_Model_class_id); + if(model_ptr == NULL) return JS_EXCEPTION; + Model model = *model_ptr; + Vector3* position_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector3 position = *position_ptr; + Vector3* rotationAxis_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[2], js_Vector3_class_id); + if(rotationAxis_ptr == NULL) return JS_EXCEPTION; + Vector3 rotationAxis = *rotationAxis_ptr; + double _double_rotationAngle; + JS_ToFloat64(ctx, &_double_rotationAngle, argv[3]); + float rotationAngle = (float)_double_rotationAngle; + Vector3* scale_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[4], js_Vector3_class_id); + if(scale_ptr == NULL) return JS_EXCEPTION; + Vector3 scale = *scale_ptr; + Color* tint_ptr = (Color*)JS_GetOpaque2(ctx, argv[5], js_Color_class_id); + if(tint_ptr == NULL) return JS_EXCEPTION; + Color tint = *tint_ptr; + DrawModelEx(model, position, rotationAxis, rotationAngle, scale, tint); + return JS_UNDEFINED; +} + +static JSValue js_drawModelWires(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Model* model_ptr = (Model*)JS_GetOpaque2(ctx, argv[0], js_Model_class_id); + if(model_ptr == NULL) return JS_EXCEPTION; + Model model = *model_ptr; + Vector3* position_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector3 position = *position_ptr; + double _double_scale; + JS_ToFloat64(ctx, &_double_scale, argv[2]); + float scale = (float)_double_scale; + Color* tint_ptr = (Color*)JS_GetOpaque2(ctx, argv[3], js_Color_class_id); + if(tint_ptr == NULL) return JS_EXCEPTION; + Color tint = *tint_ptr; + DrawModelWires(model, position, scale, tint); + return JS_UNDEFINED; +} + +static JSValue js_drawModelWiresEx(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Model* model_ptr = (Model*)JS_GetOpaque2(ctx, argv[0], js_Model_class_id); + if(model_ptr == NULL) return JS_EXCEPTION; + Model model = *model_ptr; + Vector3* position_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector3 position = *position_ptr; + Vector3* rotationAxis_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[2], js_Vector3_class_id); + if(rotationAxis_ptr == NULL) return JS_EXCEPTION; + Vector3 rotationAxis = *rotationAxis_ptr; + double _double_rotationAngle; + JS_ToFloat64(ctx, &_double_rotationAngle, argv[3]); + float rotationAngle = (float)_double_rotationAngle; + Vector3* scale_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[4], js_Vector3_class_id); + if(scale_ptr == NULL) return JS_EXCEPTION; + Vector3 scale = *scale_ptr; + Color* tint_ptr = (Color*)JS_GetOpaque2(ctx, argv[5], js_Color_class_id); + if(tint_ptr == NULL) return JS_EXCEPTION; + Color tint = *tint_ptr; + DrawModelWiresEx(model, position, rotationAxis, rotationAngle, scale, tint); + return JS_UNDEFINED; +} + +static JSValue js_drawBoundingBox(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + BoundingBox* box_ptr = (BoundingBox*)JS_GetOpaque2(ctx, argv[0], js_BoundingBox_class_id); + if(box_ptr == NULL) return JS_EXCEPTION; + BoundingBox box = *box_ptr; + Color* color_ptr = (Color*)JS_GetOpaque2(ctx, argv[1], js_Color_class_id); + if(color_ptr == NULL) return JS_EXCEPTION; + Color color = *color_ptr; + DrawBoundingBox(box, color); + return JS_UNDEFINED; +} + +static JSValue js_drawBillboard(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Camera* camera_ptr = (Camera*)JS_GetOpaque2(ctx, argv[0], js_Camera3D_class_id); + if(camera_ptr == NULL) return JS_EXCEPTION; + Camera camera = *camera_ptr; + Texture2D* texture_ptr = (Texture2D*)JS_GetOpaque2(ctx, argv[1], js_Texture_class_id); + if(texture_ptr == NULL) return JS_EXCEPTION; + Texture2D texture = *texture_ptr; + Vector3* position_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[2], js_Vector3_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector3 position = *position_ptr; + double _double_size; + JS_ToFloat64(ctx, &_double_size, argv[3]); + float size = (float)_double_size; + Color* tint_ptr = (Color*)JS_GetOpaque2(ctx, argv[4], js_Color_class_id); + if(tint_ptr == NULL) return JS_EXCEPTION; + Color tint = *tint_ptr; + DrawBillboard(camera, texture, position, size, tint); + return JS_UNDEFINED; +} + +static JSValue js_drawBillboardRec(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Camera* camera_ptr = (Camera*)JS_GetOpaque2(ctx, argv[0], js_Camera3D_class_id); + if(camera_ptr == NULL) return JS_EXCEPTION; + Camera camera = *camera_ptr; + Texture2D* texture_ptr = (Texture2D*)JS_GetOpaque2(ctx, argv[1], js_Texture_class_id); + if(texture_ptr == NULL) return JS_EXCEPTION; + Texture2D texture = *texture_ptr; + Rectangle* source_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[2], js_Rectangle_class_id); + if(source_ptr == NULL) return JS_EXCEPTION; + Rectangle source = *source_ptr; + Vector3* position_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[3], js_Vector3_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector3 position = *position_ptr; + Vector2* size_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[4], js_Vector2_class_id); + if(size_ptr == NULL) return JS_EXCEPTION; + Vector2 size = *size_ptr; + Color* tint_ptr = (Color*)JS_GetOpaque2(ctx, argv[5], js_Color_class_id); + if(tint_ptr == NULL) return JS_EXCEPTION; + Color tint = *tint_ptr; + DrawBillboardRec(camera, texture, source, position, size, tint); + return JS_UNDEFINED; +} + +static JSValue js_drawBillboardPro(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Camera* camera_ptr = (Camera*)JS_GetOpaque2(ctx, argv[0], js_Camera3D_class_id); + if(camera_ptr == NULL) return JS_EXCEPTION; + Camera camera = *camera_ptr; + Texture2D* texture_ptr = (Texture2D*)JS_GetOpaque2(ctx, argv[1], js_Texture_class_id); + if(texture_ptr == NULL) return JS_EXCEPTION; + Texture2D texture = *texture_ptr; + Rectangle* source_ptr = (Rectangle*)JS_GetOpaque2(ctx, argv[2], js_Rectangle_class_id); + if(source_ptr == NULL) return JS_EXCEPTION; + Rectangle source = *source_ptr; + Vector3* position_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[3], js_Vector3_class_id); + if(position_ptr == NULL) return JS_EXCEPTION; + Vector3 position = *position_ptr; + Vector3* up_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[4], js_Vector3_class_id); + if(up_ptr == NULL) return JS_EXCEPTION; + Vector3 up = *up_ptr; + Vector2* size_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[5], js_Vector2_class_id); + if(size_ptr == NULL) return JS_EXCEPTION; + Vector2 size = *size_ptr; + Vector2* origin_ptr = (Vector2*)JS_GetOpaque2(ctx, argv[6], js_Vector2_class_id); + if(origin_ptr == NULL) return JS_EXCEPTION; + Vector2 origin = *origin_ptr; + double _double_rotation; + JS_ToFloat64(ctx, &_double_rotation, argv[7]); + float rotation = (float)_double_rotation; + Color* tint_ptr = (Color*)JS_GetOpaque2(ctx, argv[8], js_Color_class_id); + if(tint_ptr == NULL) return JS_EXCEPTION; + Color tint = *tint_ptr; + DrawBillboardPro(camera, texture, source, position, up, size, origin, rotation, tint); + return JS_UNDEFINED; +} + +static JSValue js_exportMesh(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Mesh* mesh_ptr = (Mesh*)JS_GetOpaque2(ctx, argv[0], js_Mesh_class_id); + if(mesh_ptr == NULL) return JS_EXCEPTION; + Mesh mesh = *mesh_ptr; + const char * fileName = (const char *)JS_ToCString(ctx, argv[1]); + if(fileName == NULL) return JS_EXCEPTION; + bool returnVal = ExportMesh(mesh, fileName); + JS_FreeCString(ctx, fileName); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_getMeshBoundingBox(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Mesh* mesh_ptr = (Mesh*)JS_GetOpaque2(ctx, argv[0], js_Mesh_class_id); + if(mesh_ptr == NULL) return JS_EXCEPTION; + Mesh mesh = *mesh_ptr; + BoundingBox returnVal = GetMeshBoundingBox(mesh); + BoundingBox* ret_ptr = (BoundingBox*)js_malloc(ctx, sizeof(BoundingBox)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_BoundingBox_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genMeshPoly(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + int sides; + JS_ToInt32(ctx, &sides, argv[0]); + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[1]); + float radius = (float)_double_radius; + Mesh returnVal = GenMeshPoly(sides, radius); + Mesh* ret_ptr = (Mesh*)js_malloc(ctx, sizeof(Mesh)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Mesh_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genMeshPlane(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + double _double_width; + JS_ToFloat64(ctx, &_double_width, argv[0]); + float width = (float)_double_width; + double _double_length; + JS_ToFloat64(ctx, &_double_length, argv[1]); + float length = (float)_double_length; + int resX; + JS_ToInt32(ctx, &resX, argv[2]); + int resZ; + JS_ToInt32(ctx, &resZ, argv[3]); + Mesh returnVal = GenMeshPlane(width, length, resX, resZ); + Mesh* ret_ptr = (Mesh*)js_malloc(ctx, sizeof(Mesh)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Mesh_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genMeshCube(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + double _double_width; + JS_ToFloat64(ctx, &_double_width, argv[0]); + float width = (float)_double_width; + double _double_height; + JS_ToFloat64(ctx, &_double_height, argv[1]); + float height = (float)_double_height; + double _double_length; + JS_ToFloat64(ctx, &_double_length, argv[2]); + float length = (float)_double_length; + Mesh returnVal = GenMeshCube(width, height, length); + Mesh* ret_ptr = (Mesh*)js_malloc(ctx, sizeof(Mesh)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Mesh_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genMeshSphere(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[0]); + float radius = (float)_double_radius; + int rings; + JS_ToInt32(ctx, &rings, argv[1]); + int slices; + JS_ToInt32(ctx, &slices, argv[2]); + Mesh returnVal = GenMeshSphere(radius, rings, slices); + Mesh* ret_ptr = (Mesh*)js_malloc(ctx, sizeof(Mesh)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Mesh_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genMeshHemiSphere(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[0]); + float radius = (float)_double_radius; + int rings; + JS_ToInt32(ctx, &rings, argv[1]); + int slices; + JS_ToInt32(ctx, &slices, argv[2]); + Mesh returnVal = GenMeshHemiSphere(radius, rings, slices); + Mesh* ret_ptr = (Mesh*)js_malloc(ctx, sizeof(Mesh)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Mesh_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genMeshCylinder(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[0]); + float radius = (float)_double_radius; + double _double_height; + JS_ToFloat64(ctx, &_double_height, argv[1]); + float height = (float)_double_height; + int slices; + JS_ToInt32(ctx, &slices, argv[2]); + Mesh returnVal = GenMeshCylinder(radius, height, slices); + Mesh* ret_ptr = (Mesh*)js_malloc(ctx, sizeof(Mesh)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Mesh_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genMeshCone(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[0]); + float radius = (float)_double_radius; + double _double_height; + JS_ToFloat64(ctx, &_double_height, argv[1]); + float height = (float)_double_height; + int slices; + JS_ToInt32(ctx, &slices, argv[2]); + Mesh returnVal = GenMeshCone(radius, height, slices); + Mesh* ret_ptr = (Mesh*)js_malloc(ctx, sizeof(Mesh)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Mesh_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genMeshTorus(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[0]); + float radius = (float)_double_radius; + double _double_size; + JS_ToFloat64(ctx, &_double_size, argv[1]); + float size = (float)_double_size; + int radSeg; + JS_ToInt32(ctx, &radSeg, argv[2]); + int sides; + JS_ToInt32(ctx, &sides, argv[3]); + Mesh returnVal = GenMeshTorus(radius, size, radSeg, sides); + Mesh* ret_ptr = (Mesh*)js_malloc(ctx, sizeof(Mesh)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Mesh_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genMeshKnot(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[0]); + float radius = (float)_double_radius; + double _double_size; + JS_ToFloat64(ctx, &_double_size, argv[1]); + float size = (float)_double_size; + int radSeg; + JS_ToInt32(ctx, &radSeg, argv[2]); + int sides; + JS_ToInt32(ctx, &sides, argv[3]); + Mesh returnVal = GenMeshKnot(radius, size, radSeg, sides); + Mesh* ret_ptr = (Mesh*)js_malloc(ctx, sizeof(Mesh)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Mesh_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genMeshHeightmap(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Image* heightmap_ptr = (Image*)JS_GetOpaque2(ctx, argv[0], js_Image_class_id); + if(heightmap_ptr == NULL) return JS_EXCEPTION; + Image heightmap = *heightmap_ptr; + Vector3* size_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(size_ptr == NULL) return JS_EXCEPTION; + Vector3 size = *size_ptr; + Mesh returnVal = GenMeshHeightmap(heightmap, size); + Mesh* ret_ptr = (Mesh*)js_malloc(ctx, sizeof(Mesh)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Mesh_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_genMeshCubicmap(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Image* cubicmap_ptr = (Image*)JS_GetOpaque2(ctx, argv[0], js_Image_class_id); + if(cubicmap_ptr == NULL) return JS_EXCEPTION; + Image cubicmap = *cubicmap_ptr; + Vector3* cubeSize_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(cubeSize_ptr == NULL) return JS_EXCEPTION; + Vector3 cubeSize = *cubeSize_ptr; + Mesh returnVal = GenMeshCubicmap(cubicmap, cubeSize); + Mesh* ret_ptr = (Mesh*)js_malloc(ctx, sizeof(Mesh)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Mesh_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_checkCollisionSpheres(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Vector3* center1_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[0], js_Vector3_class_id); + if(center1_ptr == NULL) return JS_EXCEPTION; + Vector3 center1 = *center1_ptr; + double _double_radius1; + JS_ToFloat64(ctx, &_double_radius1, argv[1]); + float radius1 = (float)_double_radius1; + Vector3* center2_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[2], js_Vector3_class_id); + if(center2_ptr == NULL) return JS_EXCEPTION; + Vector3 center2 = *center2_ptr; + double _double_radius2; + JS_ToFloat64(ctx, &_double_radius2, argv[3]); + float radius2 = (float)_double_radius2; + bool returnVal = CheckCollisionSpheres(center1, radius1, center2, radius2); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_checkCollisionBoxes(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + BoundingBox* box1_ptr = (BoundingBox*)JS_GetOpaque2(ctx, argv[0], js_BoundingBox_class_id); + if(box1_ptr == NULL) return JS_EXCEPTION; + BoundingBox box1 = *box1_ptr; + BoundingBox* box2_ptr = (BoundingBox*)JS_GetOpaque2(ctx, argv[1], js_BoundingBox_class_id); + if(box2_ptr == NULL) return JS_EXCEPTION; + BoundingBox box2 = *box2_ptr; + bool returnVal = CheckCollisionBoxes(box1, box2); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_checkCollisionBoxSphere(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + BoundingBox* box_ptr = (BoundingBox*)JS_GetOpaque2(ctx, argv[0], js_BoundingBox_class_id); + if(box_ptr == NULL) return JS_EXCEPTION; + BoundingBox box = *box_ptr; + Vector3* center_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(center_ptr == NULL) return JS_EXCEPTION; + Vector3 center = *center_ptr; + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[2]); + float radius = (float)_double_radius; + bool returnVal = CheckCollisionBoxSphere(box, center, radius); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_getRayCollisionSphere(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Ray* ray_ptr = (Ray*)JS_GetOpaque2(ctx, argv[0], js_Ray_class_id); + if(ray_ptr == NULL) return JS_EXCEPTION; + Ray ray = *ray_ptr; + Vector3* center_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(center_ptr == NULL) return JS_EXCEPTION; + Vector3 center = *center_ptr; + double _double_radius; + JS_ToFloat64(ctx, &_double_radius, argv[2]); + float radius = (float)_double_radius; + RayCollision returnVal = GetRayCollisionSphere(ray, center, radius); + RayCollision* ret_ptr = (RayCollision*)js_malloc(ctx, sizeof(RayCollision)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_RayCollision_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_getRayCollisionBox(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Ray* ray_ptr = (Ray*)JS_GetOpaque2(ctx, argv[0], js_Ray_class_id); + if(ray_ptr == NULL) return JS_EXCEPTION; + Ray ray = *ray_ptr; + BoundingBox* box_ptr = (BoundingBox*)JS_GetOpaque2(ctx, argv[1], js_BoundingBox_class_id); + if(box_ptr == NULL) return JS_EXCEPTION; + BoundingBox box = *box_ptr; + RayCollision returnVal = GetRayCollisionBox(ray, box); + RayCollision* ret_ptr = (RayCollision*)js_malloc(ctx, sizeof(RayCollision)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_RayCollision_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_getRayCollisionMesh(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Ray* ray_ptr = (Ray*)JS_GetOpaque2(ctx, argv[0], js_Ray_class_id); + if(ray_ptr == NULL) return JS_EXCEPTION; + Ray ray = *ray_ptr; + Mesh* mesh_ptr = (Mesh*)JS_GetOpaque2(ctx, argv[1], js_Mesh_class_id); + if(mesh_ptr == NULL) return JS_EXCEPTION; + Mesh mesh = *mesh_ptr; + Matrix* transform_ptr = (Matrix*)JS_GetOpaque2(ctx, argv[2], js_Matrix_class_id); + if(transform_ptr == NULL) return JS_EXCEPTION; + Matrix transform = *transform_ptr; + RayCollision returnVal = GetRayCollisionMesh(ray, mesh, transform); + RayCollision* ret_ptr = (RayCollision*)js_malloc(ctx, sizeof(RayCollision)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_RayCollision_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_getRayCollisionTriangle(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Ray* ray_ptr = (Ray*)JS_GetOpaque2(ctx, argv[0], js_Ray_class_id); + if(ray_ptr == NULL) return JS_EXCEPTION; + Ray ray = *ray_ptr; + Vector3* p1_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(p1_ptr == NULL) return JS_EXCEPTION; + Vector3 p1 = *p1_ptr; + Vector3* p2_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[2], js_Vector3_class_id); + if(p2_ptr == NULL) return JS_EXCEPTION; + Vector3 p2 = *p2_ptr; + Vector3* p3_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[3], js_Vector3_class_id); + if(p3_ptr == NULL) return JS_EXCEPTION; + Vector3 p3 = *p3_ptr; + RayCollision returnVal = GetRayCollisionTriangle(ray, p1, p2, p3); + RayCollision* ret_ptr = (RayCollision*)js_malloc(ctx, sizeof(RayCollision)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_RayCollision_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_getRayCollisionQuad(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Ray* ray_ptr = (Ray*)JS_GetOpaque2(ctx, argv[0], js_Ray_class_id); + if(ray_ptr == NULL) return JS_EXCEPTION; + Ray ray = *ray_ptr; + Vector3* p1_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[1], js_Vector3_class_id); + if(p1_ptr == NULL) return JS_EXCEPTION; + Vector3 p1 = *p1_ptr; + Vector3* p2_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[2], js_Vector3_class_id); + if(p2_ptr == NULL) return JS_EXCEPTION; + Vector3 p2 = *p2_ptr; + Vector3* p3_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[3], js_Vector3_class_id); + if(p3_ptr == NULL) return JS_EXCEPTION; + Vector3 p3 = *p3_ptr; + Vector3* p4_ptr = (Vector3*)JS_GetOpaque2(ctx, argv[4], js_Vector3_class_id); + if(p4_ptr == NULL) return JS_EXCEPTION; + Vector3 p4 = *p4_ptr; + RayCollision returnVal = GetRayCollisionQuad(ray, p1, p2, p3, p4); + RayCollision* ret_ptr = (RayCollision*)js_malloc(ctx, sizeof(RayCollision)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_RayCollision_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_initAudioDevice(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + InitAudioDevice(); + return JS_UNDEFINED; +} + +static JSValue js_closeAudioDevice(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + CloseAudioDevice(); + return JS_UNDEFINED; +} + +static JSValue js_isAudioDeviceReady(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + bool returnVal = IsAudioDeviceReady(); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_setMasterVolume(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + double _double_volume; + JS_ToFloat64(ctx, &_double_volume, argv[0]); + float volume = (float)_double_volume; + SetMasterVolume(volume); + return JS_UNDEFINED; +} + +static JSValue js_loadWave(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); + if(fileName == NULL) return JS_EXCEPTION; + Wave returnVal = LoadWave(fileName); + JS_FreeCString(ctx, fileName); + Wave* ret_ptr = (Wave*)js_malloc(ctx, sizeof(Wave)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Wave_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_isWaveReady(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Wave* wave_ptr = (Wave*)JS_GetOpaque2(ctx, argv[0], js_Wave_class_id); + if(wave_ptr == NULL) return JS_EXCEPTION; + Wave wave = *wave_ptr; + bool returnVal = IsWaveReady(wave); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_loadSound(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); + if(fileName == NULL) return JS_EXCEPTION; + Sound returnVal = LoadSound(fileName); + JS_FreeCString(ctx, fileName); + Sound* ret_ptr = (Sound*)js_malloc(ctx, sizeof(Sound)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Sound_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_loadSoundFromWave(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Wave* wave_ptr = (Wave*)JS_GetOpaque2(ctx, argv[0], js_Wave_class_id); + if(wave_ptr == NULL) return JS_EXCEPTION; + Wave wave = *wave_ptr; + Sound returnVal = LoadSoundFromWave(wave); + Sound* ret_ptr = (Sound*)js_malloc(ctx, sizeof(Sound)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Sound_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_isSoundReady(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Sound* sound_ptr = (Sound*)JS_GetOpaque2(ctx, argv[0], js_Sound_class_id); + if(sound_ptr == NULL) return JS_EXCEPTION; + Sound sound = *sound_ptr; + bool returnVal = IsSoundReady(sound); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_exportWave(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Wave* wave_ptr = (Wave*)JS_GetOpaque2(ctx, argv[0], js_Wave_class_id); + if(wave_ptr == NULL) return JS_EXCEPTION; + Wave wave = *wave_ptr; + const char * fileName = (const char *)JS_ToCString(ctx, argv[1]); + if(fileName == NULL) return JS_EXCEPTION; + bool returnVal = ExportWave(wave, fileName); + JS_FreeCString(ctx, fileName); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_playSound(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Sound* sound_ptr = (Sound*)JS_GetOpaque2(ctx, argv[0], js_Sound_class_id); + if(sound_ptr == NULL) return JS_EXCEPTION; + Sound sound = *sound_ptr; + PlaySound(sound); + return JS_UNDEFINED; +} + +static JSValue js_stopSound(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Sound* sound_ptr = (Sound*)JS_GetOpaque2(ctx, argv[0], js_Sound_class_id); + if(sound_ptr == NULL) return JS_EXCEPTION; + Sound sound = *sound_ptr; + StopSound(sound); + return JS_UNDEFINED; +} + +static JSValue js_pauseSound(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Sound* sound_ptr = (Sound*)JS_GetOpaque2(ctx, argv[0], js_Sound_class_id); + if(sound_ptr == NULL) return JS_EXCEPTION; + Sound sound = *sound_ptr; + PauseSound(sound); + return JS_UNDEFINED; +} + +static JSValue js_resumeSound(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Sound* sound_ptr = (Sound*)JS_GetOpaque2(ctx, argv[0], js_Sound_class_id); + if(sound_ptr == NULL) return JS_EXCEPTION; + Sound sound = *sound_ptr; + ResumeSound(sound); + return JS_UNDEFINED; +} + +static JSValue js_isSoundPlaying(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Sound* sound_ptr = (Sound*)JS_GetOpaque2(ctx, argv[0], js_Sound_class_id); + if(sound_ptr == NULL) return JS_EXCEPTION; + Sound sound = *sound_ptr; + bool returnVal = IsSoundPlaying(sound); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_setSoundVolume(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Sound* sound_ptr = (Sound*)JS_GetOpaque2(ctx, argv[0], js_Sound_class_id); + if(sound_ptr == NULL) return JS_EXCEPTION; + Sound sound = *sound_ptr; + double _double_volume; + JS_ToFloat64(ctx, &_double_volume, argv[1]); + float volume = (float)_double_volume; + SetSoundVolume(sound, volume); + return JS_UNDEFINED; +} + +static JSValue js_setSoundPitch(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Sound* sound_ptr = (Sound*)JS_GetOpaque2(ctx, argv[0], js_Sound_class_id); + if(sound_ptr == NULL) return JS_EXCEPTION; + Sound sound = *sound_ptr; + double _double_pitch; + JS_ToFloat64(ctx, &_double_pitch, argv[1]); + float pitch = (float)_double_pitch; + SetSoundPitch(sound, pitch); + return JS_UNDEFINED; +} + +static JSValue js_setSoundPan(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Sound* sound_ptr = (Sound*)JS_GetOpaque2(ctx, argv[0], js_Sound_class_id); + if(sound_ptr == NULL) return JS_EXCEPTION; + Sound sound = *sound_ptr; + double _double_pan; + JS_ToFloat64(ctx, &_double_pan, argv[1]); + float pan = (float)_double_pan; + SetSoundPan(sound, pan); + return JS_UNDEFINED; +} + +static JSValue js_waveCopy(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Wave* wave_ptr = (Wave*)JS_GetOpaque2(ctx, argv[0], js_Wave_class_id); + if(wave_ptr == NULL) return JS_EXCEPTION; + Wave wave = *wave_ptr; + Wave returnVal = WaveCopy(wave); + Wave* ret_ptr = (Wave*)js_malloc(ctx, sizeof(Wave)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Wave_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_loadMusicStream(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); + if(fileName == NULL) return JS_EXCEPTION; + Music returnVal = LoadMusicStream(fileName); + JS_FreeCString(ctx, fileName); + Music* ret_ptr = (Music*)js_malloc(ctx, sizeof(Music)); + *ret_ptr = returnVal; + JSValue ret = JS_NewObjectClass(ctx, js_Music_class_id); + JS_SetOpaque(ret, ret_ptr); + return ret; +} + +static JSValue js_isMusicReady(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Music* music_ptr = (Music*)JS_GetOpaque2(ctx, argv[0], js_Music_class_id); + if(music_ptr == NULL) return JS_EXCEPTION; + Music music = *music_ptr; + bool returnVal = IsMusicReady(music); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_playMusicStream(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Music* music_ptr = (Music*)JS_GetOpaque2(ctx, argv[0], js_Music_class_id); + if(music_ptr == NULL) return JS_EXCEPTION; + Music music = *music_ptr; + PlayMusicStream(music); + return JS_UNDEFINED; +} + +static JSValue js_isMusicStreamPlaying(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Music* music_ptr = (Music*)JS_GetOpaque2(ctx, argv[0], js_Music_class_id); + if(music_ptr == NULL) return JS_EXCEPTION; + Music music = *music_ptr; + bool returnVal = IsMusicStreamPlaying(music); + JSValue ret = JS_NewBool(ctx, returnVal); + return ret; +} + +static JSValue js_updateMusicStream(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Music* music_ptr = (Music*)JS_GetOpaque2(ctx, argv[0], js_Music_class_id); + if(music_ptr == NULL) return JS_EXCEPTION; + Music music = *music_ptr; + UpdateMusicStream(music); + return JS_UNDEFINED; +} + +static JSValue js_stopMusicStream(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Music* music_ptr = (Music*)JS_GetOpaque2(ctx, argv[0], js_Music_class_id); + if(music_ptr == NULL) return JS_EXCEPTION; + Music music = *music_ptr; + StopMusicStream(music); + return JS_UNDEFINED; +} + +static JSValue js_pauseMusicStream(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Music* music_ptr = (Music*)JS_GetOpaque2(ctx, argv[0], js_Music_class_id); + if(music_ptr == NULL) return JS_EXCEPTION; + Music music = *music_ptr; + PauseMusicStream(music); + return JS_UNDEFINED; +} + +static JSValue js_resumeMusicStream(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Music* music_ptr = (Music*)JS_GetOpaque2(ctx, argv[0], js_Music_class_id); + if(music_ptr == NULL) return JS_EXCEPTION; + Music music = *music_ptr; + ResumeMusicStream(music); + return JS_UNDEFINED; +} + +static JSValue js_seekMusicStream(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Music* music_ptr = (Music*)JS_GetOpaque2(ctx, argv[0], js_Music_class_id); + if(music_ptr == NULL) return JS_EXCEPTION; + Music music = *music_ptr; + double _double_position; + JS_ToFloat64(ctx, &_double_position, argv[1]); + float position = (float)_double_position; + SeekMusicStream(music, position); + return JS_UNDEFINED; +} + +static JSValue js_setMusicVolume(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Music* music_ptr = (Music*)JS_GetOpaque2(ctx, argv[0], js_Music_class_id); + if(music_ptr == NULL) return JS_EXCEPTION; + Music music = *music_ptr; + double _double_volume; + JS_ToFloat64(ctx, &_double_volume, argv[1]); + float volume = (float)_double_volume; + SetMusicVolume(music, volume); + return JS_UNDEFINED; +} + +static JSValue js_setMusicPitch(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Music* music_ptr = (Music*)JS_GetOpaque2(ctx, argv[0], js_Music_class_id); + if(music_ptr == NULL) return JS_EXCEPTION; + Music music = *music_ptr; + double _double_pitch; + JS_ToFloat64(ctx, &_double_pitch, argv[1]); + float pitch = (float)_double_pitch; + SetMusicPitch(music, pitch); + return JS_UNDEFINED; +} + +static JSValue js_setMusicPan(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Music* music_ptr = (Music*)JS_GetOpaque2(ctx, argv[0], js_Music_class_id); + if(music_ptr == NULL) return JS_EXCEPTION; + Music music = *music_ptr; + double _double_pan; + JS_ToFloat64(ctx, &_double_pan, argv[1]); + float pan = (float)_double_pan; + SetMusicPan(music, pan); + return JS_UNDEFINED; +} + +static JSValue js_getMusicTimeLength(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Music* music_ptr = (Music*)JS_GetOpaque2(ctx, argv[0], js_Music_class_id); + if(music_ptr == NULL) return JS_EXCEPTION; + Music music = *music_ptr; + float returnVal = GetMusicTimeLength(music); + JSValue ret = JS_NewFloat64(ctx, returnVal); + return ret; +} + +static JSValue js_getMusicTimePlayed(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { + Music* music_ptr = (Music*)JS_GetOpaque2(ctx, argv[0], js_Music_class_id); + if(music_ptr == NULL) return JS_EXCEPTION; + Music music = *music_ptr; + float returnVal = GetMusicTimePlayed(music); + JSValue ret = JS_NewFloat64(ctx, returnVal); + return ret; +} + static const JSCFunctionListEntry js_raylib_core_funcs[] = { JS_CFUNC_DEF("initWindow",3,js_initWindow), JS_CFUNC_DEF("windowShouldClose",0,js_windowShouldClose), @@ -1659,6 +5251,8 @@ static const JSCFunctionListEntry js_raylib_core_funcs[] = { JS_CFUNC_DEF("endDrawing",0,js_endDrawing), JS_CFUNC_DEF("beginMode2D",1,js_beginMode2D), JS_CFUNC_DEF("endMode2D",0,js_endMode2D), + JS_CFUNC_DEF("beginMode3D",1,js_beginMode3D), + JS_CFUNC_DEF("endMode3D",0,js_endMode3D), JS_CFUNC_DEF("beginBlendMode",1,js_beginBlendMode), JS_CFUNC_DEF("endBlendMode",0,js_endBlendMode), JS_CFUNC_DEF("beginScissorMode",4,js_beginScissorMode), @@ -1711,16 +5305,218 @@ static const JSCFunctionListEntry js_raylib_core_funcs[] = { JS_CFUNC_DEF("getGamepadAxisCount",1,js_getGamepadAxisCount), JS_CFUNC_DEF("getGamepadAxisMovement",2,js_getGamepadAxisMovement), JS_CFUNC_DEF("setGamepadMappings",1,js_setGamepadMappings), - JS_CFUNC_DEF("drawText",5,js_drawText), - JS_CFUNC_DEF("drawLine",5,js_drawLine), - JS_CFUNC_DEF("drawCircleV",3,js_drawCircleV), - JS_CFUNC_DEF("getMousePosition",0,js_getMousePosition), JS_CFUNC_DEF("isMouseButtonPressed",1,js_isMouseButtonPressed), + JS_CFUNC_DEF("isMouseButtonDown",1,js_isMouseButtonDown), + JS_CFUNC_DEF("isMouseButtonReleased",1,js_isMouseButtonReleased), + JS_CFUNC_DEF("isMouseButtonUp",1,js_isMouseButtonUp), + JS_CFUNC_DEF("getMouseX",0,js_getMouseX), + JS_CFUNC_DEF("getMouseY",0,js_getMouseY), + JS_CFUNC_DEF("getMousePosition",0,js_getMousePosition), + JS_CFUNC_DEF("getMouseDelta",0,js_getMouseDelta), + JS_CFUNC_DEF("setMousePosition",2,js_setMousePosition), + JS_CFUNC_DEF("setMouseOffset",2,js_setMouseOffset), + JS_CFUNC_DEF("setMouseScale",2,js_setMouseScale), JS_CFUNC_DEF("getMouseWheelMove",0,js_getMouseWheelMove), + JS_CFUNC_DEF("getMouseWheelMoveV",0,js_getMouseWheelMoveV), + JS_CFUNC_DEF("setMouseCursor",1,js_setMouseCursor), + JS_CFUNC_DEF("getTouchX",0,js_getTouchX), + JS_CFUNC_DEF("getTouchY",0,js_getTouchY), + JS_CFUNC_DEF("getTouchPosition",1,js_getTouchPosition), + JS_CFUNC_DEF("getTouchPointId",1,js_getTouchPointId), + JS_CFUNC_DEF("getTouchPointCount",0,js_getTouchPointCount), + JS_CFUNC_DEF("setGesturesEnabled",1,js_setGesturesEnabled), + JS_CFUNC_DEF("isGestureDetected",1,js_isGestureDetected), + JS_CFUNC_DEF("getGestureDetected",0,js_getGestureDetected), + JS_CFUNC_DEF("getGestureHoldDuration",0,js_getGestureHoldDuration), + JS_CFUNC_DEF("getGestureDragVector",0,js_getGestureDragVector), + JS_CFUNC_DEF("getGestureDragAngle",0,js_getGestureDragAngle), + JS_CFUNC_DEF("getGesturePinchVector",0,js_getGesturePinchVector), + JS_CFUNC_DEF("getGesturePinchAngle",0,js_getGesturePinchAngle), + JS_CFUNC_DEF("drawPixel",3,js_drawPixel), + JS_CFUNC_DEF("drawPixelV",2,js_drawPixelV), + JS_CFUNC_DEF("drawLine",5,js_drawLine), + JS_CFUNC_DEF("drawLineV",3,js_drawLineV), + JS_CFUNC_DEF("drawLineEx",4,js_drawLineEx), + JS_CFUNC_DEF("drawLineBezier",4,js_drawLineBezier), + JS_CFUNC_DEF("drawLineBezierQuad",5,js_drawLineBezierQuad), + JS_CFUNC_DEF("drawLineBezierCubic",6,js_drawLineBezierCubic), + JS_CFUNC_DEF("drawCircle",4,js_drawCircle), + JS_CFUNC_DEF("drawCircleSector",6,js_drawCircleSector), + JS_CFUNC_DEF("drawCircleSectorLines",6,js_drawCircleSectorLines), + JS_CFUNC_DEF("drawCircleGradient",5,js_drawCircleGradient), + JS_CFUNC_DEF("drawCircleV",3,js_drawCircleV), + JS_CFUNC_DEF("drawCircleLines",4,js_drawCircleLines), + JS_CFUNC_DEF("drawEllipse",5,js_drawEllipse), + JS_CFUNC_DEF("drawEllipseLines",5,js_drawEllipseLines), + JS_CFUNC_DEF("drawRing",7,js_drawRing), + JS_CFUNC_DEF("drawRingLines",7,js_drawRingLines), JS_CFUNC_DEF("drawRectangle",5,js_drawRectangle), + JS_CFUNC_DEF("drawRectangleV",3,js_drawRectangleV), JS_CFUNC_DEF("drawRectangleRec",2,js_drawRectangleRec), + JS_CFUNC_DEF("drawRectanglePro",4,js_drawRectanglePro), + JS_CFUNC_DEF("drawRectangleGradientV",6,js_drawRectangleGradientV), + JS_CFUNC_DEF("drawRectangleGradientH",6,js_drawRectangleGradientH), + JS_CFUNC_DEF("drawRectangleGradientEx",5,js_drawRectangleGradientEx), JS_CFUNC_DEF("drawRectangleLines",5,js_drawRectangleLines), + JS_CFUNC_DEF("drawRectangleLinesEx",3,js_drawRectangleLinesEx), + JS_CFUNC_DEF("drawRectangleRounded",4,js_drawRectangleRounded), + JS_CFUNC_DEF("drawRectangleRoundedLines",5,js_drawRectangleRoundedLines), + JS_CFUNC_DEF("drawTriangle",4,js_drawTriangle), + JS_CFUNC_DEF("drawTriangleLines",4,js_drawTriangleLines), + JS_CFUNC_DEF("drawPoly",5,js_drawPoly), + JS_CFUNC_DEF("drawPolyLines",5,js_drawPolyLines), + JS_CFUNC_DEF("drawPolyLinesEx",6,js_drawPolyLinesEx), + JS_CFUNC_DEF("checkCollisionRecs",2,js_checkCollisionRecs), + JS_CFUNC_DEF("checkCollisionCircles",4,js_checkCollisionCircles), + JS_CFUNC_DEF("checkCollisionCircleRec",3,js_checkCollisionCircleRec), + JS_CFUNC_DEF("checkCollisionPointRec",2,js_checkCollisionPointRec), + JS_CFUNC_DEF("checkCollisionPointCircle",3,js_checkCollisionPointCircle), + JS_CFUNC_DEF("checkCollisionPointTriangle",4,js_checkCollisionPointTriangle), + JS_CFUNC_DEF("checkCollisionPointLine",4,js_checkCollisionPointLine), + JS_CFUNC_DEF("getCollisionRec",2,js_getCollisionRec), + JS_CFUNC_DEF("loadImage",1,js_loadImage), + JS_CFUNC_DEF("loadImageRaw",5,js_loadImageRaw), + JS_CFUNC_DEF("loadImageFromTexture",1,js_loadImageFromTexture), + JS_CFUNC_DEF("loadImageFromScreen",0,js_loadImageFromScreen), + JS_CFUNC_DEF("isImageReady",1,js_isImageReady), + JS_CFUNC_DEF("exportImage",2,js_exportImage), + JS_CFUNC_DEF("genImageColor",3,js_genImageColor), + JS_CFUNC_DEF("genImageGradientV",4,js_genImageGradientV), + JS_CFUNC_DEF("genImageGradientH",4,js_genImageGradientH), + JS_CFUNC_DEF("genImageGradientRadial",5,js_genImageGradientRadial), + JS_CFUNC_DEF("genImageChecked",6,js_genImageChecked), + JS_CFUNC_DEF("genImageWhiteNoise",3,js_genImageWhiteNoise), + JS_CFUNC_DEF("genImagePerlinNoise",5,js_genImagePerlinNoise), + JS_CFUNC_DEF("genImageCellular",3,js_genImageCellular), + JS_CFUNC_DEF("genImageText",3,js_genImageText), + JS_CFUNC_DEF("imageCopy",1,js_imageCopy), + JS_CFUNC_DEF("imageFromImage",2,js_imageFromImage), + JS_CFUNC_DEF("imageText",3,js_imageText), + JS_CFUNC_DEF("getImageAlphaBorder",2,js_getImageAlphaBorder), + JS_CFUNC_DEF("getImageColor",3,js_getImageColor), + JS_CFUNC_DEF("loadTexture",1,js_loadTexture), + JS_CFUNC_DEF("loadTextureFromImage",1,js_loadTextureFromImage), + JS_CFUNC_DEF("loadTextureCubemap",2,js_loadTextureCubemap), + JS_CFUNC_DEF("isTextureReady",1,js_isTextureReady), + JS_CFUNC_DEF("setTextureFilter",2,js_setTextureFilter), + JS_CFUNC_DEF("setTextureWrap",2,js_setTextureWrap), + JS_CFUNC_DEF("drawTexture",4,js_drawTexture), + JS_CFUNC_DEF("drawTextureV",3,js_drawTextureV), + JS_CFUNC_DEF("drawTextureEx",5,js_drawTextureEx), + JS_CFUNC_DEF("drawTextureRec",4,js_drawTextureRec), + JS_CFUNC_DEF("drawTexturePro",6,js_drawTexturePro), JS_CFUNC_DEF("fade",2,js_fade), + JS_CFUNC_DEF("colorToInt",1,js_colorToInt), + JS_CFUNC_DEF("colorNormalize",1,js_colorNormalize), + JS_CFUNC_DEF("colorFromNormalized",1,js_colorFromNormalized), + JS_CFUNC_DEF("colorToHSV",1,js_colorToHSV), + JS_CFUNC_DEF("colorFromHSV",3,js_colorFromHSV), + JS_CFUNC_DEF("colorTint",2,js_colorTint), + JS_CFUNC_DEF("colorBrightness",2,js_colorBrightness), + JS_CFUNC_DEF("colorContrast",2,js_colorContrast), + JS_CFUNC_DEF("colorAlpha",2,js_colorAlpha), + JS_CFUNC_DEF("colorAlphaBlend",3,js_colorAlphaBlend), + JS_CFUNC_DEF("getColor",1,js_getColor), + JS_CFUNC_DEF("getPixelDataSize",3,js_getPixelDataSize), + JS_CFUNC_DEF("getFontDefault",0,js_getFontDefault), + JS_CFUNC_DEF("loadFont",1,js_loadFont), + JS_CFUNC_DEF("loadFontFromImage",3,js_loadFontFromImage), + JS_CFUNC_DEF("isFontReady",1,js_isFontReady), + JS_CFUNC_DEF("drawFPS",2,js_drawFPS), + JS_CFUNC_DEF("drawText",5,js_drawText), + JS_CFUNC_DEF("drawTextEx",6,js_drawTextEx), + JS_CFUNC_DEF("drawTextPro",8,js_drawTextPro), + JS_CFUNC_DEF("drawTextCodepoint",5,js_drawTextCodepoint), + JS_CFUNC_DEF("measureText",2,js_measureText), + JS_CFUNC_DEF("measureTextEx",4,js_measureTextEx), + JS_CFUNC_DEF("getGlyphIndex",2,js_getGlyphIndex), + JS_CFUNC_DEF("getGlyphAtlasRec",2,js_getGlyphAtlasRec), + JS_CFUNC_DEF("drawLine3D",3,js_drawLine3D), + JS_CFUNC_DEF("drawPoint3D",2,js_drawPoint3D), + JS_CFUNC_DEF("drawCircle3D",5,js_drawCircle3D), + JS_CFUNC_DEF("drawTriangle3D",4,js_drawTriangle3D), + JS_CFUNC_DEF("drawCube",5,js_drawCube), + JS_CFUNC_DEF("drawCubeV",3,js_drawCubeV), + JS_CFUNC_DEF("drawCubeWires",5,js_drawCubeWires), + JS_CFUNC_DEF("drawCubeWiresV",3,js_drawCubeWiresV), + JS_CFUNC_DEF("drawSphere",3,js_drawSphere), + JS_CFUNC_DEF("drawSphereEx",5,js_drawSphereEx), + JS_CFUNC_DEF("drawSphereWires",5,js_drawSphereWires), + JS_CFUNC_DEF("drawCylinder",6,js_drawCylinder), + JS_CFUNC_DEF("drawCylinderEx",6,js_drawCylinderEx), + JS_CFUNC_DEF("drawCylinderWires",6,js_drawCylinderWires), + JS_CFUNC_DEF("drawCylinderWiresEx",6,js_drawCylinderWiresEx), + JS_CFUNC_DEF("drawCapsule",6,js_drawCapsule), + JS_CFUNC_DEF("drawCapsuleWires",6,js_drawCapsuleWires), + JS_CFUNC_DEF("drawPlane",3,js_drawPlane), + JS_CFUNC_DEF("drawRay",2,js_drawRay), + JS_CFUNC_DEF("drawGrid",2,js_drawGrid), + JS_CFUNC_DEF("loadModel",1,js_loadModel), + JS_CFUNC_DEF("loadModelFromMesh",1,js_loadModelFromMesh), + JS_CFUNC_DEF("isModelReady",1,js_isModelReady), + JS_CFUNC_DEF("getModelBoundingBox",1,js_getModelBoundingBox), + JS_CFUNC_DEF("drawModel",4,js_drawModel), + JS_CFUNC_DEF("drawModelEx",6,js_drawModelEx), + JS_CFUNC_DEF("drawModelWires",4,js_drawModelWires), + JS_CFUNC_DEF("drawModelWiresEx",6,js_drawModelWiresEx), + JS_CFUNC_DEF("drawBoundingBox",2,js_drawBoundingBox), + JS_CFUNC_DEF("drawBillboard",5,js_drawBillboard), + JS_CFUNC_DEF("drawBillboardRec",6,js_drawBillboardRec), + JS_CFUNC_DEF("drawBillboardPro",9,js_drawBillboardPro), + JS_CFUNC_DEF("exportMesh",2,js_exportMesh), + JS_CFUNC_DEF("getMeshBoundingBox",1,js_getMeshBoundingBox), + JS_CFUNC_DEF("genMeshPoly",2,js_genMeshPoly), + JS_CFUNC_DEF("genMeshPlane",4,js_genMeshPlane), + JS_CFUNC_DEF("genMeshCube",3,js_genMeshCube), + JS_CFUNC_DEF("genMeshSphere",3,js_genMeshSphere), + JS_CFUNC_DEF("genMeshHemiSphere",3,js_genMeshHemiSphere), + JS_CFUNC_DEF("genMeshCylinder",3,js_genMeshCylinder), + JS_CFUNC_DEF("genMeshCone",3,js_genMeshCone), + JS_CFUNC_DEF("genMeshTorus",4,js_genMeshTorus), + JS_CFUNC_DEF("genMeshKnot",4,js_genMeshKnot), + JS_CFUNC_DEF("genMeshHeightmap",2,js_genMeshHeightmap), + JS_CFUNC_DEF("genMeshCubicmap",2,js_genMeshCubicmap), + JS_CFUNC_DEF("checkCollisionSpheres",4,js_checkCollisionSpheres), + JS_CFUNC_DEF("checkCollisionBoxes",2,js_checkCollisionBoxes), + JS_CFUNC_DEF("checkCollisionBoxSphere",3,js_checkCollisionBoxSphere), + JS_CFUNC_DEF("getRayCollisionSphere",3,js_getRayCollisionSphere), + JS_CFUNC_DEF("getRayCollisionBox",2,js_getRayCollisionBox), + JS_CFUNC_DEF("getRayCollisionMesh",3,js_getRayCollisionMesh), + JS_CFUNC_DEF("getRayCollisionTriangle",4,js_getRayCollisionTriangle), + JS_CFUNC_DEF("getRayCollisionQuad",5,js_getRayCollisionQuad), + JS_CFUNC_DEF("initAudioDevice",0,js_initAudioDevice), + JS_CFUNC_DEF("closeAudioDevice",0,js_closeAudioDevice), + JS_CFUNC_DEF("isAudioDeviceReady",0,js_isAudioDeviceReady), + JS_CFUNC_DEF("setMasterVolume",1,js_setMasterVolume), + JS_CFUNC_DEF("loadWave",1,js_loadWave), + JS_CFUNC_DEF("isWaveReady",1,js_isWaveReady), + JS_CFUNC_DEF("loadSound",1,js_loadSound), + JS_CFUNC_DEF("loadSoundFromWave",1,js_loadSoundFromWave), + JS_CFUNC_DEF("isSoundReady",1,js_isSoundReady), + JS_CFUNC_DEF("exportWave",2,js_exportWave), + JS_CFUNC_DEF("playSound",1,js_playSound), + JS_CFUNC_DEF("stopSound",1,js_stopSound), + JS_CFUNC_DEF("pauseSound",1,js_pauseSound), + JS_CFUNC_DEF("resumeSound",1,js_resumeSound), + JS_CFUNC_DEF("isSoundPlaying",1,js_isSoundPlaying), + JS_CFUNC_DEF("setSoundVolume",2,js_setSoundVolume), + JS_CFUNC_DEF("setSoundPitch",2,js_setSoundPitch), + JS_CFUNC_DEF("setSoundPan",2,js_setSoundPan), + JS_CFUNC_DEF("waveCopy",1,js_waveCopy), + JS_CFUNC_DEF("loadMusicStream",1,js_loadMusicStream), + JS_CFUNC_DEF("isMusicReady",1,js_isMusicReady), + JS_CFUNC_DEF("playMusicStream",1,js_playMusicStream), + JS_CFUNC_DEF("isMusicStreamPlaying",1,js_isMusicStreamPlaying), + JS_CFUNC_DEF("updateMusicStream",1,js_updateMusicStream), + JS_CFUNC_DEF("stopMusicStream",1,js_stopMusicStream), + JS_CFUNC_DEF("pauseMusicStream",1,js_pauseMusicStream), + JS_CFUNC_DEF("resumeMusicStream",1,js_resumeMusicStream), + JS_CFUNC_DEF("seekMusicStream",2,js_seekMusicStream), + JS_CFUNC_DEF("setMusicVolume",2,js_setMusicVolume), + JS_CFUNC_DEF("setMusicPitch",2,js_setMusicPitch), + JS_CFUNC_DEF("setMusicPan",2,js_setMusicPan), + JS_CFUNC_DEF("getMusicTimeLength",1,js_getMusicTimeLength), + JS_CFUNC_DEF("getMusicTimePlayed",1,js_getMusicTimePlayed), }; static int js_raylib_core_init(JSContext * ctx, JSModuleDef * m) { @@ -1737,13 +5533,32 @@ static int js_raylib_core_init(JSContext * ctx, JSModuleDef * m) { js_declare_Vector3(ctx, m); JSValue Vector3_constr = JS_NewCFunction2(ctx, js_Vector3_constructor,"Vector3)", 3, JS_CFUNC_constructor_or_func, 0); JS_SetModuleExport(ctx, m, "Vector3", Vector3_constr); + js_declare_Vector4(ctx, m); + JSValue Vector4_constr = JS_NewCFunction2(ctx, js_Vector4_constructor,"Vector4)", 4, JS_CFUNC_constructor_or_func, 0); + JS_SetModuleExport(ctx, m, "Vector4", Vector4_constr); js_declare_Ray(ctx, m); JSValue Ray_constr = JS_NewCFunction2(ctx, js_Ray_constructor,"Ray)", 2, JS_CFUNC_constructor_or_func, 0); JS_SetModuleExport(ctx, m, "Ray", Ray_constr); + js_declare_RayCollision(ctx, m); js_declare_Camera2D(ctx, m); JSValue Camera2D_constr = JS_NewCFunction2(ctx, js_Camera2D_constructor,"Camera2D)", 4, JS_CFUNC_constructor_or_func, 0); JS_SetModuleExport(ctx, m, "Camera2D", Camera2D_constr); + js_declare_Camera3D(ctx, m); + JSValue Camera3D_constr = JS_NewCFunction2(ctx, js_Camera3D_constructor,"Camera3D)", 5, JS_CFUNC_constructor_or_func, 0); + JS_SetModuleExport(ctx, m, "Camera3D", Camera3D_constr); + js_declare_BoundingBox(ctx, m); + JSValue BoundingBox_constr = JS_NewCFunction2(ctx, js_BoundingBox_constructor,"BoundingBox)", 2, JS_CFUNC_constructor_or_func, 0); + JS_SetModuleExport(ctx, m, "BoundingBox", BoundingBox_constr); js_declare_Matrix(ctx, m); + js_declare_Image(ctx, m); + js_declare_Wave(ctx, m); + js_declare_Sound(ctx, m); + js_declare_Music(ctx, m); + js_declare_Model(ctx, m); + js_declare_Mesh(ctx, m); + js_declare_Shader(ctx, m); + js_declare_Texture(ctx, m); + js_declare_Font(ctx, m); Color LIGHTGRAY_struct = { 200, 200, 200, 255 }; Color* LIGHTGRAY_js_ptr = (Color*)js_malloc(ctx, sizeof(Color)); *LIGHTGRAY_js_ptr = LIGHTGRAY_struct; @@ -2048,6 +5863,40 @@ static int js_raylib_core_init(JSContext * ctx, JSModuleDef * m) { JS_SetModuleExport(ctx, m, "LOG_ERROR", JS_NewInt32(ctx, LOG_ERROR)); JS_SetModuleExport(ctx, m, "LOG_FATAL", JS_NewInt32(ctx, LOG_FATAL)); JS_SetModuleExport(ctx, m, "LOG_NONE", JS_NewInt32(ctx, LOG_NONE)); + JS_SetModuleExport(ctx, m, "MOUSE_CURSOR_DEFAULT", JS_NewInt32(ctx, MOUSE_CURSOR_DEFAULT)); + JS_SetModuleExport(ctx, m, "MOUSE_CURSOR_ARROW", JS_NewInt32(ctx, MOUSE_CURSOR_ARROW)); + JS_SetModuleExport(ctx, m, "MOUSE_CURSOR_IBEAM", JS_NewInt32(ctx, MOUSE_CURSOR_IBEAM)); + JS_SetModuleExport(ctx, m, "MOUSE_CURSOR_CROSSHAIR", JS_NewInt32(ctx, MOUSE_CURSOR_CROSSHAIR)); + JS_SetModuleExport(ctx, m, "MOUSE_CURSOR_POINTING_HAND", JS_NewInt32(ctx, MOUSE_CURSOR_POINTING_HAND)); + JS_SetModuleExport(ctx, m, "MOUSE_CURSOR_RESIZE_EW", JS_NewInt32(ctx, MOUSE_CURSOR_RESIZE_EW)); + JS_SetModuleExport(ctx, m, "MOUSE_CURSOR_RESIZE_NS", JS_NewInt32(ctx, MOUSE_CURSOR_RESIZE_NS)); + JS_SetModuleExport(ctx, m, "MOUSE_CURSOR_RESIZE_NWSE", JS_NewInt32(ctx, MOUSE_CURSOR_RESIZE_NWSE)); + JS_SetModuleExport(ctx, m, "MOUSE_CURSOR_RESIZE_NESW", JS_NewInt32(ctx, MOUSE_CURSOR_RESIZE_NESW)); + JS_SetModuleExport(ctx, m, "MOUSE_CURSOR_RESIZE_ALL", JS_NewInt32(ctx, MOUSE_CURSOR_RESIZE_ALL)); + JS_SetModuleExport(ctx, m, "MOUSE_CURSOR_NOT_ALLOWED", JS_NewInt32(ctx, MOUSE_CURSOR_NOT_ALLOWED)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_GRAYSCALE", JS_NewInt32(ctx, PIXELFORMAT_UNCOMPRESSED_GRAYSCALE)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA", JS_NewInt32(ctx, PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_R5G6B5", JS_NewInt32(ctx, PIXELFORMAT_UNCOMPRESSED_R5G6B5)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_R8G8B8", JS_NewInt32(ctx, PIXELFORMAT_UNCOMPRESSED_R8G8B8)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_R5G5B5A1", JS_NewInt32(ctx, PIXELFORMAT_UNCOMPRESSED_R5G5B5A1)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_R4G4B4A4", JS_NewInt32(ctx, PIXELFORMAT_UNCOMPRESSED_R4G4B4A4)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_R8G8B8A8", JS_NewInt32(ctx, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_R32", JS_NewInt32(ctx, PIXELFORMAT_UNCOMPRESSED_R32)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_R32G32B32", JS_NewInt32(ctx, PIXELFORMAT_UNCOMPRESSED_R32G32B32)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_R32G32B32A32", JS_NewInt32(ctx, PIXELFORMAT_UNCOMPRESSED_R32G32B32A32)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_DXT1_RGB", JS_NewInt32(ctx, PIXELFORMAT_COMPRESSED_DXT1_RGB)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_DXT1_RGBA", JS_NewInt32(ctx, PIXELFORMAT_COMPRESSED_DXT1_RGBA)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_DXT3_RGBA", JS_NewInt32(ctx, PIXELFORMAT_COMPRESSED_DXT3_RGBA)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_DXT5_RGBA", JS_NewInt32(ctx, PIXELFORMAT_COMPRESSED_DXT5_RGBA)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_ETC1_RGB", JS_NewInt32(ctx, PIXELFORMAT_COMPRESSED_ETC1_RGB)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_ETC2_RGB", JS_NewInt32(ctx, PIXELFORMAT_COMPRESSED_ETC2_RGB)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA", JS_NewInt32(ctx, PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_PVRT_RGB", JS_NewInt32(ctx, PIXELFORMAT_COMPRESSED_PVRT_RGB)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_PVRT_RGBA", JS_NewInt32(ctx, PIXELFORMAT_COMPRESSED_PVRT_RGBA)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA", JS_NewInt32(ctx, PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA)); + JS_SetModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA", JS_NewInt32(ctx, PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA)); + JS_SetModuleExport(ctx, m, "CAMERA_PERSPECTIVE", JS_NewInt32(ctx, CAMERA_PERSPECTIVE)); + JS_SetModuleExport(ctx, m, "CAMERA_ORTHOGRAPHIC", JS_NewInt32(ctx, CAMERA_ORTHOGRAPHIC)); return 0; } @@ -2060,8 +5909,11 @@ JSModuleDef * js_init_module_raylib_core(JSContext * ctx, const char * module_na JS_AddModuleExport(ctx, m, "Rectangle"); JS_AddModuleExport(ctx, m, "Vector2"); JS_AddModuleExport(ctx, m, "Vector3"); + JS_AddModuleExport(ctx, m, "Vector4"); JS_AddModuleExport(ctx, m, "Ray"); JS_AddModuleExport(ctx, m, "Camera2D"); + JS_AddModuleExport(ctx, m, "Camera3D"); + JS_AddModuleExport(ctx, m, "BoundingBox"); JS_AddModuleExport(ctx, m, "LIGHTGRAY"); JS_AddModuleExport(ctx, m, "GRAY"); JS_AddModuleExport(ctx, m, "DARKGRAY"); @@ -2236,6 +6088,40 @@ JSModuleDef * js_init_module_raylib_core(JSContext * ctx, const char * module_na JS_AddModuleExport(ctx, m, "LOG_ERROR"); JS_AddModuleExport(ctx, m, "LOG_FATAL"); JS_AddModuleExport(ctx, m, "LOG_NONE"); + JS_AddModuleExport(ctx, m, "MOUSE_CURSOR_DEFAULT"); + JS_AddModuleExport(ctx, m, "MOUSE_CURSOR_ARROW"); + JS_AddModuleExport(ctx, m, "MOUSE_CURSOR_IBEAM"); + JS_AddModuleExport(ctx, m, "MOUSE_CURSOR_CROSSHAIR"); + JS_AddModuleExport(ctx, m, "MOUSE_CURSOR_POINTING_HAND"); + JS_AddModuleExport(ctx, m, "MOUSE_CURSOR_RESIZE_EW"); + JS_AddModuleExport(ctx, m, "MOUSE_CURSOR_RESIZE_NS"); + JS_AddModuleExport(ctx, m, "MOUSE_CURSOR_RESIZE_NWSE"); + JS_AddModuleExport(ctx, m, "MOUSE_CURSOR_RESIZE_NESW"); + JS_AddModuleExport(ctx, m, "MOUSE_CURSOR_RESIZE_ALL"); + JS_AddModuleExport(ctx, m, "MOUSE_CURSOR_NOT_ALLOWED"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_GRAYSCALE"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_R5G6B5"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_R8G8B8"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_R5G5B5A1"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_R4G4B4A4"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_R8G8B8A8"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_R32"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_R32G32B32"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_UNCOMPRESSED_R32G32B32A32"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_DXT1_RGB"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_DXT1_RGBA"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_DXT3_RGBA"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_DXT5_RGBA"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_ETC1_RGB"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_ETC2_RGB"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_PVRT_RGB"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_PVRT_RGBA"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA"); + JS_AddModuleExport(ctx, m, "PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA"); + JS_AddModuleExport(ctx, m, "CAMERA_PERSPECTIVE"); + JS_AddModuleExport(ctx, m, "CAMERA_ORTHOGRAPHIC"); return m; } diff --git a/src/bindings/js_raylib_texture.h b/src/bindings/js_raylib_texture.h deleted file mode 100644 index 54fb249..0000000 --- a/src/bindings/js_raylib_texture.h +++ /dev/null @@ -1,91 +0,0 @@ -#ifndef JS_raylib_texture_GUARD -#define JS_raylib_texture_GUARD - -#include -#include -#include - -#include -#include - -#ifndef countof -#define countof(x) (sizeof(x) / sizeof((x)[0])) -#endif - -static JSClassID js_Image_class_id; - -static void js_Image_finalizer(JSRuntime * rt, JSValue val) { - Image* ptr = JS_GetOpaque(val, js_Image_class_id); - if(ptr) { - UnloadImage(*ptr); - js_free_rt(rt, ptr); - } -} - -static JSValue js_Image_get_width(JSContext* ctx, JSValueConst this_val) { - Image* ptr = JS_GetOpaque2(ctx, this_val, js_Image_class_id); - if(!ptr) { - return JS_EXCEPTION; - } - int width = ptr->width; - JSValue ret = JS_NewInt32(ctx, width); - return ret; -} - -static JSValue js_Image_get_height(JSContext* ctx, JSValueConst this_val) { - Image* ptr = JS_GetOpaque2(ctx, this_val, js_Image_class_id); - if(!ptr) { - return JS_EXCEPTION; - } - int height = ptr->height; - JSValue ret = JS_NewInt32(ctx, height); - return ret; -} - -static const JSCFunctionListEntry js_Image_proto_funcs[] = { - JS_CGETSET_DEF("width",js_Image_get_width,NULL), - JS_CGETSET_DEF("height",js_Image_get_height,NULL), - JS_PROP_STRING_DEF("[Symbol.toStringTag]","Image", JS_PROP_CONFIGURABLE), -}; - -static int js_declare_Image(JSContext * ctx, JSModuleDef * m) { - JS_NewClassID(&js_Image_class_id); - JSClassDef js_Image_def = { .class_name = "Image", .finalizer = js_Image_finalizer }; - JS_NewClass(JS_GetRuntime(ctx), js_Image_class_id, &js_Image_def); - JSValue proto = JS_NewObject(ctx); - JS_SetPropertyFunctionList(ctx, proto, js_Image_proto_funcs, countof(js_Image_proto_funcs)); - JS_SetClassProto(ctx, js_Image_class_id, proto); - return 0; -} - -static JSValue js_loadImage(JSContext * ctx, JSValueConst this_val, int argc, JSValueConst * argv) { - const char * fileName = (const char *)JS_ToCString(ctx, argv[0]); - if(fileName == NULL) return JS_EXCEPTION; - Image returnVal = LoadImage(fileName); - JS_FreeCString(ctx, fileName); - Image* ret_ptr = (Image*)js_malloc(ctx, sizeof(Image)); - *ret_ptr = returnVal; - JSValue ret = JS_NewObjectClass(ctx, js_Image_class_id); - JS_SetOpaque(ret, ret_ptr); - return ret; -} - -static const JSCFunctionListEntry js_raylib_texture_funcs[] = { - JS_CFUNC_DEF("loadImage",1,js_loadImage), -}; - -static int js_raylib_texture_init(JSContext * ctx, JSModuleDef * m) { - JS_SetModuleExportList(ctx, m,js_raylib_texture_funcs,countof(js_raylib_texture_funcs)); - js_declare_Image(ctx, m); - return 0; -} - -JSModuleDef * js_init_module_raylib_texture(JSContext * ctx, const char * module_name) { - JSModuleDef *m; - m = JS_NewCModule(ctx, module_name, js_raylib_texture_init); - if(!m) return NULL; - JS_AddModuleExportList(ctx, m, js_raylib_texture_funcs, countof(js_raylib_texture_funcs)); - return m; -} - -#endif // JS_raylib_texture_GUARD diff --git a/src/quickjs.c b/src/quickjs.c index dda8586..9545dd4 100644 --- a/src/quickjs.c +++ b/src/quickjs.c @@ -30,7 +30,6 @@ int app_update_quickjs(){ } #include "bindings/js_raylib_core.h" -#include "bindings/js_raylib_texture.h" int app_init_quickjs(int argc, char** argv){ rt = JS_NewRuntime(); @@ -51,11 +50,14 @@ int app_init_quickjs(int argc, char** argv){ js_std_add_helpers(ctx, argc, argv); + const char *str = "import * as rl from 'raylib'\n" + "for (const key in rl) { globalThis[key] = rl[key] }\n"; + // const char *str = "import * as std from 'std';\n" // "import * as os from 'os';\n" // "globalThis.std = std;\n" // "globalThis.os = os;\n"; - // eval_buf(ctx, str, strlen(str), "", JS_EVAL_TYPE_MODULE); + eval_buf(ctx, str, strlen(str), "", JS_EVAL_TYPE_MODULE); const char* filename = argc > 1 ? argv[1] : "main.js"; const char* buf = LoadFileText(filename); @@ -92,8 +94,7 @@ static JSContext *JS_NewCustomContext(JSRuntime *rt) /* system modules */ js_init_module_std(ctx, "std"); //js_init_module_os(ctx, "os"); - js_init_module_raylib_core(ctx, "raylib.core"); - js_init_module_raylib_texture(ctx, "raylib.texture"); + js_init_module_raylib_core(ctx, "raylib"); return ctx; }