Refactor pass 1
This commit is contained in:
@@ -7,7 +7,10 @@ var Cube = {
|
||||
e.position.z = 0;
|
||||
e.add(COMPONENT_TYPE_MESH);
|
||||
e.add(COMPONENT_TYPE_MATERIAL);
|
||||
e.material.setColor(colorRed());
|
||||
// e.material.setColor(Color.black());
|
||||
|
||||
print(Color);
|
||||
print(Color.prototype);
|
||||
|
||||
return {
|
||||
_e: e,
|
||||
@@ -22,7 +25,6 @@ var Cube = {
|
||||
var dz = inputAxis(INPUT_ACTION_UP, INPUT_ACTION_DOWN);
|
||||
this._e.position.x += dx * speed * TIME.delta;
|
||||
this._e.position.z += dz * speed * TIME.delta;
|
||||
this._e.material.setColor(colorRainbow());
|
||||
},
|
||||
|
||||
dispose: function() {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
var Cube = include('entities/cube.js');
|
||||
|
||||
print('Screen.aspect in JavaScript: ' + Screen.aspect);
|
||||
|
||||
var cam;
|
||||
var cube;
|
||||
|
||||
@@ -14,7 +12,6 @@ var SceneCube = {
|
||||
cam.position.z = 3;
|
||||
cam.position.lookAt(0, 0, 0);
|
||||
cam.add(COMPONENT_TYPE_CAMERA);
|
||||
|
||||
cube = Cube.create();
|
||||
},
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
#include "display/shader/shaderunlit.h"
|
||||
#include "time/time.h"
|
||||
|
||||
#include "script/module/display/moduleshader.h"
|
||||
|
||||
display_t DISPLAY = { 0 };
|
||||
|
||||
errorret_t displayInit(void) {
|
||||
|
||||
@@ -8,6 +8,7 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
||||
PUBLIC
|
||||
scriptmanager.c
|
||||
scriptcontext.c
|
||||
scriptproto.c
|
||||
)
|
||||
|
||||
# Subdirectories
|
||||
@@ -9,38 +9,39 @@
|
||||
#include "script/module/modulebase.h"
|
||||
#include "display/color.h"
|
||||
#include "time/time.h"
|
||||
#include "script/scriptproto.h"
|
||||
|
||||
// Define the prototype.
|
||||
moduleBaseProtoDefine(MODULE_COLOR);
|
||||
scriptproto_t MODULE_COLOR_PROTO;
|
||||
|
||||
// Getters
|
||||
moduleBaseFunction(moduleColorGetR) {
|
||||
color_t *color = (color_t*)moduleBaseGetProto(
|
||||
callInfo->this_value, &MODULE_COLOR_INFO
|
||||
color_t *color = (color_t*)scriptProtoGetValue(
|
||||
&MODULE_COLOR_PROTO, callInfo->this_value
|
||||
);
|
||||
if(!color) return jerry_undefined();
|
||||
return jerry_number(color->r);
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleColorGetG) {
|
||||
color_t *color = (color_t*)moduleBaseGetProto(
|
||||
callInfo->this_value, &MODULE_COLOR_INFO
|
||||
color_t *color = (color_t*)scriptProtoGetValue(
|
||||
&MODULE_COLOR_PROTO, callInfo->this_value
|
||||
);
|
||||
if(!color) return jerry_undefined();
|
||||
return jerry_number(color->g);
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleColorGetB) {
|
||||
color_t *color = (color_t*)moduleBaseGetProto(
|
||||
callInfo->this_value, &MODULE_COLOR_INFO
|
||||
color_t *color = (color_t*)scriptProtoGetValue(
|
||||
&MODULE_COLOR_PROTO, callInfo->this_value
|
||||
);
|
||||
if(!color) return jerry_undefined();
|
||||
return jerry_number(color->b);
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleColorGetA) {
|
||||
color_t *color = (color_t*)moduleBaseGetProto(
|
||||
callInfo->this_value, &MODULE_COLOR_INFO
|
||||
color_t *color = (color_t*)scriptProtoGetValue(
|
||||
&MODULE_COLOR_PROTO, callInfo->this_value
|
||||
);
|
||||
if(!color) return jerry_undefined();
|
||||
return jerry_number(color->a);
|
||||
@@ -48,8 +49,8 @@ moduleBaseFunction(moduleColorGetA) {
|
||||
|
||||
// Setters
|
||||
moduleBaseFunction(moduleColorSetR) {
|
||||
color_t *color = (color_t*)moduleBaseGetProto(
|
||||
callInfo->this_value, &MODULE_COLOR_INFO
|
||||
color_t *color = (color_t*)scriptProtoGetValue(
|
||||
&MODULE_COLOR_PROTO, callInfo->this_value
|
||||
);
|
||||
if(color && argc > 0) {
|
||||
color->r = (colorchannel8_t)jerry_value_as_number(args[0]);
|
||||
@@ -58,8 +59,8 @@ moduleBaseFunction(moduleColorSetR) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleColorSetG) {
|
||||
color_t *color = (color_t*)moduleBaseGetProto(
|
||||
callInfo->this_value, &MODULE_COLOR_INFO
|
||||
color_t *color = (color_t*)scriptProtoGetValue(
|
||||
&MODULE_COLOR_PROTO, callInfo->this_value
|
||||
);
|
||||
if(color && argc > 0) {
|
||||
color->g = (colorchannel8_t)jerry_value_as_number(args[0]);
|
||||
@@ -68,8 +69,8 @@ moduleBaseFunction(moduleColorSetG) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleColorSetB) {
|
||||
color_t *color = (color_t*)moduleBaseGetProto(
|
||||
callInfo->this_value, &MODULE_COLOR_INFO
|
||||
color_t *color = (color_t*)scriptProtoGetValue(
|
||||
&MODULE_COLOR_PROTO, callInfo->this_value
|
||||
);
|
||||
if(color && argc > 0) {
|
||||
color->b = (colorchannel8_t)jerry_value_as_number(args[0]);
|
||||
@@ -78,8 +79,8 @@ moduleBaseFunction(moduleColorSetB) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleColorSetA) {
|
||||
color_t *color = (color_t*)moduleBaseGetProto(
|
||||
callInfo->this_value, &MODULE_COLOR_INFO
|
||||
color_t *color = (color_t*)scriptProtoGetValue(
|
||||
&MODULE_COLOR_PROTO, callInfo->this_value
|
||||
);
|
||||
if(color && argc > 0) {
|
||||
color->a = (colorchannel8_t)jerry_value_as_number(args[0]);
|
||||
@@ -89,14 +90,10 @@ moduleBaseFunction(moduleColorSetA) {
|
||||
|
||||
// Constructor
|
||||
static jerry_value_t moduleColorMakeObject(color_t color) {
|
||||
return moduleBaseCreateProto(
|
||||
&color,
|
||||
sizeof(color_t),
|
||||
&MODULE_COLOR_INFO, MODULE_COLOR_PROTOTYPE
|
||||
);
|
||||
return scriptProtoCreateValue(&MODULE_COLOR_PROTO, &color);
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleColorCreate) {
|
||||
moduleBaseFunction(moduleColorRGBA) {
|
||||
color_t c;
|
||||
|
||||
if(argc > 0) {
|
||||
@@ -161,18 +158,21 @@ moduleBaseFunction(moduleColorRainbow) {
|
||||
|
||||
// Root Module
|
||||
static void moduleColor(void) {
|
||||
MODULE_COLOR_PROTOTYPE = jerry_object();
|
||||
scriptProtoInit(&MODULE_COLOR_PROTO, sizeof(color_t));
|
||||
|
||||
#define X(x, g, s) \
|
||||
moduleBaseProtoDefineProp(MODULE_COLOR_PROTOTYPE, #x, g, s);
|
||||
scriptProtoDefineProperty(&MODULE_COLOR_PROTO, #x, g, s);
|
||||
X(r, moduleColorGetR, moduleColorSetR);
|
||||
X(g, moduleColorGetG, moduleColorSetG);
|
||||
X(b, moduleColorGetB, moduleColorSetB);
|
||||
X(a, moduleColorGetA, moduleColorSetA);
|
||||
#undef X
|
||||
|
||||
moduleBaseFunctionRegister("color", moduleColorCreate);
|
||||
moduleBaseFunctionRegister("colorRainbow", moduleColorRainbow);
|
||||
scriptProtoDefineMethod(&MODULE_COLOR_PROTO, "rgba", moduleColorRGBA);
|
||||
scriptProtoDefineMethod(
|
||||
&MODULE_COLOR_PROTO,"rainbow", moduleColorRainbow
|
||||
);
|
||||
|
||||
moduleBaseEval(COLOR_SCRIPT);
|
||||
scriptProtoCreateGlobal(&MODULE_COLOR_PROTO, "Color");
|
||||
moduleBaseEval("Color.prototype.black = function() { print('test'); };");
|
||||
}
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
#include "script/module/display/modulecolor.h"
|
||||
#include "display/screen/screen.h"
|
||||
|
||||
// Define the prototype.
|
||||
moduleBaseProtoDefine(MODULE_SCREEN);
|
||||
scriptproto_t MODULE_SCREEN_PROTO;
|
||||
|
||||
// Getters
|
||||
moduleBaseFunction(moduleScreenGetWidth) {
|
||||
@@ -22,7 +21,6 @@ moduleBaseFunction(moduleScreenGetHeight) {
|
||||
}
|
||||
|
||||
moduleBaseFunction(moduleScreenGetAspect) {
|
||||
printf("Screen.aspect in C: %f\n", SCREEN.aspect);
|
||||
return jerry_number(SCREEN.aspect);
|
||||
}
|
||||
|
||||
@@ -37,38 +35,31 @@ moduleBaseFunction(moduleScreenSetBackground) {
|
||||
}
|
||||
|
||||
// Get color pointer from the object.
|
||||
color_t *color = (color_t*)moduleBaseGetProto(args[0], &MODULE_COLOR_INFO);
|
||||
color_t *color = (color_t*)scriptProtoGetValue(&MODULE_COLOR_PROTO, args[0]);
|
||||
if(!color) {
|
||||
return moduleBaseThrow("Background must be a valid color object");
|
||||
}
|
||||
|
||||
memoryCopy(&SCREEN.background, color, sizeof(color_t));
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
static void moduleScreen(void) {
|
||||
jerry_value_t proto = jerry_object();
|
||||
MODULE_SCREEN_PROTOTYPE = proto;
|
||||
// Define the prototype
|
||||
scriptProtoInit(&MODULE_SCREEN_PROTO, sizeof(screen_t));
|
||||
|
||||
#define X(x, g, s) \
|
||||
moduleBaseProtoDefineProp(MODULE_SCREEN_PROTOTYPE, #x, g, s);
|
||||
scriptProtoDefineProperty(&MODULE_SCREEN_PROTO, #x, g, s);
|
||||
|
||||
// Setup the getters and setters
|
||||
X(width, moduleScreenGetWidth, NULL)
|
||||
X(height, moduleScreenGetHeight, NULL)
|
||||
X(aspect, moduleScreenGetAspect, NULL)
|
||||
X(background, moduleScreenGetBackground, moduleScreenSetBackground)
|
||||
|
||||
#undef X
|
||||
|
||||
jsDefineMethod(proto, "getWidth", moduleScreenGetWidth);
|
||||
jsDefineMethod(proto, "getHeight", moduleScreenGetHeight);
|
||||
jsDefineMethod(proto, "getAspect", moduleScreenGetAspect);
|
||||
jsDefineMethod(proto, "getBackground", moduleScreenGetBackground);
|
||||
jsDefineMethod(proto, "setBackground", moduleScreenSetBackground);
|
||||
|
||||
|
||||
// Create global Scene object
|
||||
jerry_value_t global = jerry_current_realm();
|
||||
jerry_value_t key = jerry_string_sz("Screen");
|
||||
jerry_object_set(global, key, proto);
|
||||
jerry_value_free(key);
|
||||
jerry_value_free(global);
|
||||
// Create global Screen object
|
||||
scriptProtoCreateGlobal(&MODULE_SCREEN_PROTO, "Screen");
|
||||
}
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "script/module/modulebase.h"
|
||||
#include "display/shader/shader.h"
|
||||
#include "display/shader/shaderunlit.h"
|
||||
#include "script/module/math/modulemat4.h"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Functions
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
JS_FUNC(moduleShaderBind) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
shader_t *shader = (shader_t *)jsUnwrapPointer(args_p[0]);
|
||||
if(!shader) return JS_THROW("shaderBind: expected a shader object");
|
||||
|
||||
errorret_t ret = shaderBind(shader);
|
||||
if(ret.code != ERROR_OK) {
|
||||
errorCatch(errorPrint(ret));
|
||||
return JS_THROW("shaderBind: failed to bind shader");
|
||||
}
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleShaderSetMatrix) {
|
||||
JS_REQUIRE_ARGS(3);
|
||||
shader_t *shader = (shader_t *)jsUnwrapPointer(args_p[0]);
|
||||
if(!shader) return JS_THROW("shaderSetMatrix: expected a shader object");
|
||||
|
||||
JS_REQUIRE_STRING(1);
|
||||
char_t uniformName[128];
|
||||
jsToString(args_p[1], uniformName, sizeof(uniformName));
|
||||
|
||||
mat4 mat;
|
||||
if(!moduleMat4Check(args_p[2], mat)) {
|
||||
return JS_THROW("shaderSetMatrix: third argument must be a mat4");
|
||||
}
|
||||
|
||||
errorret_t ret = shaderSetMatrix(shader, uniformName, mat);
|
||||
if(ret.code != ERROR_OK) {
|
||||
errorCatch(errorPrint(ret));
|
||||
return JS_THROW("shaderSetMatrix: failed to set shader matrix");
|
||||
}
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleShaderSetTexture) {
|
||||
JS_REQUIRE_ARGS(2);
|
||||
shader_t *shader = (shader_t *)jsUnwrapPointer(args_p[0]);
|
||||
if(!shader) return JS_THROW("shaderSetTexture: expected a shader object");
|
||||
|
||||
JS_REQUIRE_STRING(1);
|
||||
char_t uniformName[128];
|
||||
jsToString(args_p[1], uniformName, sizeof(uniformName));
|
||||
|
||||
texture_t *texture = NULL;
|
||||
if(
|
||||
args_count >= 3 &&
|
||||
!jerry_value_is_null(args_p[2]) &&
|
||||
!jerry_value_is_undefined(args_p[2])
|
||||
) {
|
||||
texture = (texture_t *)jsUnwrapPointer(args_p[2]);
|
||||
if(!texture) return JS_THROW("shaderSetTexture: third argument must be a texture object or null");
|
||||
}
|
||||
|
||||
errorret_t ret = shaderSetTexture(shader, uniformName, texture);
|
||||
if(ret.code != ERROR_OK) {
|
||||
errorCatch(errorPrint(ret));
|
||||
return JS_THROW("shaderSetTexture: failed to set shader texture");
|
||||
}
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Module init
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static void moduleShader(void) {
|
||||
jerry_value_t shaderUnlitVal = jsWrapPointer(&SHADER_UNLIT);
|
||||
jsSetValue("SHADER_UNLIT", shaderUnlitVal);
|
||||
jerry_value_free(shaderUnlitVal);
|
||||
|
||||
jsSetString("SHADER_UNLIT_PROJECTION", SHADER_UNLIT_PROJECTION);
|
||||
jsSetString("SHADER_UNLIT_VIEW", SHADER_UNLIT_VIEW);
|
||||
jsSetString("SHADER_UNLIT_MODEL", SHADER_UNLIT_MODEL);
|
||||
jsSetString("SHADER_UNLIT_TEXTURE", SHADER_UNLIT_TEXTURE);
|
||||
|
||||
jsRegister("shaderBind", moduleShaderBind);
|
||||
jsRegister("shaderSetMatrix", moduleShaderSetMatrix);
|
||||
jsRegister("shaderSetTexture", moduleShaderSetTexture);
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "script/module/modulebase.h"
|
||||
#include "display/spritebatch/spritebatch.h"
|
||||
#include "script/module/math/modulevec2.h"
|
||||
#include "script/module/math/modulevec4.h"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Functions
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
JS_FUNC(moduleSpriteBatchFlush) {
|
||||
spriteBatchFlush();
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleSpriteBatchClear) {
|
||||
spriteBatchClear();
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleSpriteBatchPush) {
|
||||
JS_REQUIRE_ARGS(2);
|
||||
|
||||
vec2 minPos, maxPos;
|
||||
if(!moduleVec2Check(args_p[0], minPos)) {
|
||||
return JS_THROW("spriteBatchPush: first argument must be a vec2");
|
||||
}
|
||||
if(!moduleVec2Check(args_p[1], maxPos)) {
|
||||
return JS_THROW("spriteBatchPush: second argument must be a vec2");
|
||||
}
|
||||
|
||||
#if MESH_ENABLE_COLOR
|
||||
color_t col = COLOR_WHITE;
|
||||
if(
|
||||
args_count >= 3 &&
|
||||
jerry_value_is_object(args_p[2]) &&
|
||||
!jerry_value_is_null(args_p[2]) &&
|
||||
!jerry_value_is_undefined(args_p[2])
|
||||
) {
|
||||
jerry_value_t kr = jerry_string_sz("r");
|
||||
jerry_value_t vr = jerry_object_get(args_p[2], kr);
|
||||
col.r = (colorchannel8_t)jerry_value_as_number(vr);
|
||||
jerry_value_free(vr);
|
||||
jerry_value_free(kr);
|
||||
|
||||
jerry_value_t kg = jerry_string_sz("g");
|
||||
jerry_value_t vg = jerry_object_get(args_p[2], kg);
|
||||
col.g = (colorchannel8_t)jerry_value_as_number(vg);
|
||||
jerry_value_free(vg);
|
||||
jerry_value_free(kg);
|
||||
|
||||
jerry_value_t kb = jerry_string_sz("b");
|
||||
jerry_value_t vb = jerry_object_get(args_p[2], kb);
|
||||
col.b = (colorchannel8_t)jerry_value_as_number(vb);
|
||||
jerry_value_free(vb);
|
||||
jerry_value_free(kb);
|
||||
|
||||
jerry_value_t ka = jerry_string_sz("a");
|
||||
jerry_value_t va = jerry_object_get(args_p[2], ka);
|
||||
col.a = (colorchannel8_t)jerry_value_as_number(va);
|
||||
jerry_value_free(va);
|
||||
jerry_value_free(ka);
|
||||
}
|
||||
#endif
|
||||
|
||||
float_t u0 = 0.0f, v0 = 0.0f, u1 = 1.0f, v1 = 1.0f;
|
||||
if(
|
||||
args_count >= 4 &&
|
||||
!jerry_value_is_null(args_p[3]) &&
|
||||
!jerry_value_is_undefined(args_p[3])
|
||||
) {
|
||||
vec4 uv;
|
||||
if(!moduleVec4Check(args_p[3], uv)) {
|
||||
return JS_THROW("spriteBatchPush: fourth argument must be a vec4 or null");
|
||||
}
|
||||
u0 = uv[0]; v0 = uv[1]; u1 = uv[2]; v1 = uv[3];
|
||||
}
|
||||
|
||||
errorret_t ret = spriteBatchPush(
|
||||
minPos[0], minPos[1], maxPos[0], maxPos[1],
|
||||
#if MESH_ENABLE_COLOR
|
||||
col,
|
||||
#endif
|
||||
u0, v0, u1, v1
|
||||
);
|
||||
if(ret.code != ERROR_OK) {
|
||||
errorCatch(errorPrint(ret));
|
||||
return JS_THROW("spriteBatchPush: failed to push sprite to batch");
|
||||
}
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Module init
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static void moduleSpriteBatch(void) {
|
||||
jsRegister("spriteBatchFlush", moduleSpriteBatchFlush);
|
||||
jsRegister("spriteBatchClear", moduleSpriteBatchClear);
|
||||
jsRegister("spriteBatchPush", moduleSpriteBatchPush);
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "script/module/modulebase.h"
|
||||
#include "display/text/text.h"
|
||||
#include "display/spritebatch/spritebatch.h"
|
||||
#include "script/module/math/modulevec2.h"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Functions
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
JS_FUNC(moduleTextDraw) {
|
||||
JS_REQUIRE_ARGS(2);
|
||||
|
||||
vec2 pos;
|
||||
if(!moduleVec2Check(args_p[0], pos)) {
|
||||
return JS_THROW("textDraw: first argument must be a vec2 position");
|
||||
}
|
||||
|
||||
JS_REQUIRE_STRING(1);
|
||||
char_t text[1024];
|
||||
jsToString(args_p[1], text, sizeof(text));
|
||||
|
||||
color_t color = COLOR_WHITE;
|
||||
if(
|
||||
args_count >= 3 &&
|
||||
jerry_value_is_object(args_p[2]) &&
|
||||
!jerry_value_is_null(args_p[2]) &&
|
||||
!jerry_value_is_undefined(args_p[2])
|
||||
) {
|
||||
jerry_value_t kr = jerry_string_sz("r");
|
||||
jerry_value_t vr = jerry_object_get(args_p[2], kr);
|
||||
color.r = (colorchannel8_t)jerry_value_as_number(vr);
|
||||
jerry_value_free(vr);
|
||||
jerry_value_free(kr);
|
||||
|
||||
jerry_value_t kg = jerry_string_sz("g");
|
||||
jerry_value_t vg = jerry_object_get(args_p[2], kg);
|
||||
color.g = (colorchannel8_t)jerry_value_as_number(vg);
|
||||
jerry_value_free(vg);
|
||||
jerry_value_free(kg);
|
||||
|
||||
jerry_value_t kb = jerry_string_sz("b");
|
||||
jerry_value_t vb = jerry_object_get(args_p[2], kb);
|
||||
color.b = (colorchannel8_t)jerry_value_as_number(vb);
|
||||
jerry_value_free(vb);
|
||||
jerry_value_free(kb);
|
||||
|
||||
jerry_value_t ka = jerry_string_sz("a");
|
||||
jerry_value_t va = jerry_object_get(args_p[2], ka);
|
||||
color.a = (colorchannel8_t)jerry_value_as_number(va);
|
||||
jerry_value_free(va);
|
||||
jerry_value_free(ka);
|
||||
}
|
||||
|
||||
errorret_t ret = textDraw(
|
||||
pos[0], pos[1], text, color,
|
||||
&DEFAULT_FONT_TILESET,
|
||||
&DEFAULT_FONT_TEXTURE
|
||||
);
|
||||
if(ret.code != ERROR_OK) {
|
||||
errorCatch(errorPrint(ret));
|
||||
return JS_THROW("textDraw: failed to draw text");
|
||||
}
|
||||
|
||||
ret = spriteBatchFlush();
|
||||
if(ret.code != ERROR_OK) {
|
||||
errorCatch(errorPrint(ret));
|
||||
return JS_THROW("textDraw: failed to flush sprite batch");
|
||||
}
|
||||
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleTextMeasure) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
JS_REQUIRE_STRING(0);
|
||||
|
||||
char_t text[1024];
|
||||
jsToString(args_p[0], text, sizeof(text));
|
||||
|
||||
int32_t w = 0, h = 0;
|
||||
textMeasure(text, &DEFAULT_FONT_TILESET, &w, &h);
|
||||
|
||||
vec2 size = { (float_t)w, (float_t)h };
|
||||
return moduleVec2Push(size);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Module init
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static void moduleText(void) {
|
||||
jsRegister("textDraw", moduleTextDraw);
|
||||
jsRegister("textMeasure", moduleTextMeasure);
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "script/module/modulebase.h"
|
||||
#include "display/texture/texture.h"
|
||||
#include "asset/loader/display/assettextureloader.h"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Native info / prototype
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static void freeTextureNative(void *ptr, jerry_object_native_info_t *info) {
|
||||
(void)info;
|
||||
textureDispose((texture_t *)ptr);
|
||||
free(ptr);
|
||||
}
|
||||
static const jerry_object_native_info_t TEXTURE_NATIVE_INFO = {
|
||||
.free_cb = freeTextureNative,
|
||||
.number_of_references = 0,
|
||||
.offset_of_references = 0
|
||||
};
|
||||
static jerry_value_t s_textureProto = 0;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helper
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns the native texture_t pointer stored in a JS value, or NULL.
|
||||
*
|
||||
* @param val JS value to inspect.
|
||||
* @return Pointer to the texture_t, or NULL if not a texture object.
|
||||
*/
|
||||
static inline texture_t *moduleTextureGetNative(jerry_value_t val) {
|
||||
return (texture_t *)jerry_object_get_native_ptr(val, &TEXTURE_NATIVE_INFO);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Property getters (read-only)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
JS_FUNC(moduleTextureGetWidth) {
|
||||
texture_t *tex = (texture_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &TEXTURE_NATIVE_INFO
|
||||
);
|
||||
return tex ? jerry_number(tex->width) : jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleTextureGetHeight) {
|
||||
texture_t *tex = (texture_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &TEXTURE_NATIVE_INFO
|
||||
);
|
||||
return tex ? jerry_number(tex->height) : jerry_undefined();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Constructor
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
JS_FUNC(moduleTextureLoad) {
|
||||
JS_REQUIRE_ARGS(2);
|
||||
JS_REQUIRE_STRING(0);
|
||||
JS_REQUIRE_NUMBER(1);
|
||||
|
||||
char_t filename[256];
|
||||
jsToString(args_p[0], filename, sizeof(filename));
|
||||
|
||||
textureformat_t format = (textureformat_t)(int32_t)jerry_value_as_number(args_p[1]);
|
||||
|
||||
texture_t *tex = (texture_t *)malloc(sizeof(texture_t));
|
||||
memoryZero(tex, sizeof(texture_t));
|
||||
|
||||
errorret_t ret = assetTextureLoad(filename, tex, format);
|
||||
if(ret.code != ERROR_OK) {
|
||||
errorCatch(errorPrint(ret));
|
||||
free(tex);
|
||||
return JS_THROW("textureLoad: failed to load texture");
|
||||
}
|
||||
|
||||
jerry_value_t obj = jerry_object();
|
||||
jerry_object_set_native_ptr(obj, &TEXTURE_NATIVE_INFO, tex);
|
||||
if(s_textureProto != 0) jerry_object_set_proto(obj, s_textureProto);
|
||||
return obj;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Module init
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static void moduleTexture(void) {
|
||||
s_textureProto = jerry_object();
|
||||
|
||||
jsDefineProperty(s_textureProto, "width", moduleTextureGetWidth, NULL);
|
||||
jsDefineProperty(s_textureProto, "height", moduleTextureGetHeight, NULL);
|
||||
|
||||
jsSetInt("TEXTURE_FORMAT_RGBA", (int32_t)TEXTURE_FORMAT_RGBA);
|
||||
|
||||
jsRegister("textureLoad", moduleTextureLoad);
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "script/module/modulebase.h"
|
||||
#include "display/texture/tileset.h"
|
||||
#include "asset/loader/display/assettilesetloader.h"
|
||||
#include "script/module/math/modulevec4.h"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Native info / prototype
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static void freeTilesetNative(void *ptr, jerry_object_native_info_t *info) {
|
||||
(void)info;
|
||||
free(ptr);
|
||||
}
|
||||
static const jerry_object_native_info_t TILESET_NATIVE_INFO = {
|
||||
.free_cb = freeTilesetNative,
|
||||
.number_of_references = 0,
|
||||
.offset_of_references = 0
|
||||
};
|
||||
static jerry_value_t s_tilesetProto = 0;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Property getters (read-only)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
JS_FUNC(moduleTilesetGetTileWidth) {
|
||||
tileset_t *ts = (tileset_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &TILESET_NATIVE_INFO
|
||||
);
|
||||
return ts ? jerry_number(ts->tileWidth) : jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleTilesetGetTileHeight) {
|
||||
tileset_t *ts = (tileset_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &TILESET_NATIVE_INFO
|
||||
);
|
||||
return ts ? jerry_number(ts->tileHeight) : jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleTilesetGetTileCount) {
|
||||
tileset_t *ts = (tileset_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &TILESET_NATIVE_INFO
|
||||
);
|
||||
return ts ? jerry_number(ts->tileCount) : jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleTilesetGetColumns) {
|
||||
tileset_t *ts = (tileset_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &TILESET_NATIVE_INFO
|
||||
);
|
||||
return ts ? jerry_number(ts->columns) : jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleTilesetGetRows) {
|
||||
tileset_t *ts = (tileset_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &TILESET_NATIVE_INFO
|
||||
);
|
||||
return ts ? jerry_number(ts->rows) : jerry_undefined();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Functions
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
JS_FUNC(modulesTilesetTileGetUV) {
|
||||
JS_REQUIRE_ARGS(2);
|
||||
tileset_t *ts = (tileset_t *)jerry_object_get_native_ptr(
|
||||
args_p[0], &TILESET_NATIVE_INFO
|
||||
);
|
||||
if(!ts) return JS_THROW("tilesetTileGetUV: expected a tileset object");
|
||||
|
||||
JS_REQUIRE_NUMBER(1);
|
||||
uint16_t tileIndex = (uint16_t)jerry_value_as_number(args_p[1]);
|
||||
|
||||
vec4 uv;
|
||||
tilesetTileGetUV(ts, tileIndex, uv);
|
||||
return moduleVec4Push(uv);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleTilesetPositionGetUV) {
|
||||
JS_REQUIRE_ARGS(3);
|
||||
tileset_t *ts = (tileset_t *)jerry_object_get_native_ptr(
|
||||
args_p[0], &TILESET_NATIVE_INFO
|
||||
);
|
||||
if(!ts) return JS_THROW("tilesetPositionGetUV: expected a tileset object");
|
||||
|
||||
JS_REQUIRE_NUMBER(1);
|
||||
JS_REQUIRE_NUMBER(2);
|
||||
uint16_t col = (uint16_t)jerry_value_as_number(args_p[1]);
|
||||
uint16_t row = (uint16_t)jerry_value_as_number(args_p[2]);
|
||||
|
||||
vec4 uv;
|
||||
tilesetPositionGetUV(ts, col, row, uv);
|
||||
return moduleVec4Push(uv);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleTilesetLoad) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
JS_REQUIRE_STRING(0);
|
||||
|
||||
char_t filename[256];
|
||||
jsToString(args_p[0], filename, sizeof(filename));
|
||||
|
||||
tileset_t *ts = (tileset_t *)malloc(sizeof(tileset_t));
|
||||
memoryZero(ts, sizeof(tileset_t));
|
||||
|
||||
errorret_t ret = assetTilesetLoad(filename, ts);
|
||||
if(ret.code != ERROR_OK) {
|
||||
errorCatch(errorPrint(ret));
|
||||
free(ts);
|
||||
return JS_THROW("tilesetLoad: failed to load tileset");
|
||||
}
|
||||
|
||||
jerry_value_t obj = jerry_object();
|
||||
jerry_object_set_native_ptr(obj, &TILESET_NATIVE_INFO, ts);
|
||||
if(s_tilesetProto != 0) jerry_object_set_proto(obj, s_tilesetProto);
|
||||
return obj;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Module init
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
static void moduleTileset(void) {
|
||||
s_tilesetProto = jerry_object();
|
||||
|
||||
jsDefineProperty(s_tilesetProto, "tileWidth", moduleTilesetGetTileWidth, NULL);
|
||||
jsDefineProperty(s_tilesetProto, "tileHeight", moduleTilesetGetTileHeight, NULL);
|
||||
jsDefineProperty(s_tilesetProto, "tileCount", moduleTilesetGetTileCount, NULL);
|
||||
jsDefineProperty(s_tilesetProto, "columns", moduleTilesetGetColumns, NULL);
|
||||
jsDefineProperty(s_tilesetProto, "rows", moduleTilesetGetRows, NULL);
|
||||
|
||||
jsRegister("tilesetLoad", moduleTilesetLoad);
|
||||
jsRegister("tilesetTileGetUV", modulesTilesetTileGetUV);
|
||||
jsRegister("tilesetPositionGetUV", moduleTilesetPositionGetUV);
|
||||
}
|
||||
@@ -17,33 +17,33 @@ static jerry_value_t s_camProto = 0;
|
||||
|
||||
// -- zNear getter/setter --
|
||||
|
||||
JS_FUNC(moduleEntityCameraGetZNear) {
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityCameraGetZNear) {
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
return jerry_number((double)entityCameraGetZNear(eid, cid));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityCameraSetZNear) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
entityCameraSetZNear(eid, cid, (float_t)jerry_value_as_number(args_p[0]));
|
||||
moduleBaseFunction(moduleEntityCameraSetZNear) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
entityCameraSetZNear(eid, cid, (float_t)jerry_value_as_number(args[0]));
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
// -- zFar getter/setter --
|
||||
|
||||
JS_FUNC(moduleEntityCameraGetZFar) {
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityCameraGetZFar) {
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
return jerry_number((double)entityCameraGetZFar(eid, cid));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityCameraSetZFar) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
entityCameraSetZFar(eid, cid, (float_t)jerry_value_as_number(args_p[0]));
|
||||
moduleBaseFunction(moduleEntityCameraSetZFar) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
entityCameraSetZFar(eid, cid, (float_t)jerry_value_as_number(args[0]));
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
@@ -53,9 +53,9 @@ JS_FUNC(moduleEntityCameraSetZFar) {
|
||||
* Adds a camera component to an entity and returns a handle object.
|
||||
* Arg 0: entity id (number).
|
||||
*/
|
||||
JS_FUNC(moduleEntityCameraAdd) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t id = (entityid_t)jerry_value_as_number(args_p[0]);
|
||||
moduleBaseFunction(moduleEntityCameraAdd) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
||||
componentid_t comp = entityAddComponent(id, COMPONENT_TYPE_CAMERA);
|
||||
jerry_value_t handle = makeEntityHandle(id, comp);
|
||||
if(s_camProto != 0) jerry_object_set_proto(handle, s_camProto);
|
||||
@@ -68,8 +68,8 @@ JS_FUNC(moduleEntityCameraAdd) {
|
||||
static void moduleEntityCamera(void) {
|
||||
s_camProto = jerry_object();
|
||||
|
||||
jsDefineProperty(s_camProto, "zNear", moduleEntityCameraGetZNear, moduleEntityCameraSetZNear);
|
||||
jsDefineProperty(s_camProto, "zFar", moduleEntityCameraGetZFar, moduleEntityCameraSetZFar);
|
||||
moduleBaseDefineProperty(s_camProto, "zNear", moduleEntityCameraGetZNear, moduleEntityCameraSetZNear);
|
||||
moduleBaseDefineProperty(s_camProto, "zFar", moduleEntityCameraGetZFar, moduleEntityCameraSetZFar);
|
||||
|
||||
jsRegister("entityCameraAdd", moduleEntityCameraAdd);
|
||||
moduleBaseFunctionRegister("entityCameraAdd", moduleEntityCameraAdd);
|
||||
}
|
||||
|
||||
@@ -23,38 +23,38 @@ static jerry_value_t s_matProto = 0;
|
||||
* properties (each a number 0-255).
|
||||
* Args: colorObj (object).
|
||||
*/
|
||||
JS_FUNC(moduleEntityMaterialSetColor) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
if(!jerry_value_is_object(args_p[0])) {
|
||||
return JS_THROW("expected color object");
|
||||
moduleBaseFunction(moduleEntityMaterialSetColor) {
|
||||
moduleBaseRequireArgs(1);
|
||||
if(!jerry_value_is_object(args[0])) {
|
||||
return moduleBaseThrow("expected color object");
|
||||
}
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
|
||||
jerry_value_t key;
|
||||
jerry_value_t v;
|
||||
color_t col;
|
||||
|
||||
key = jerry_string_sz("r");
|
||||
v = jerry_object_get(args_p[0], key);
|
||||
v = jerry_object_get(args[0], key);
|
||||
jerry_value_free(key);
|
||||
col.r = (colorchannel8_t)jerry_value_as_number(v);
|
||||
jerry_value_free(v);
|
||||
|
||||
key = jerry_string_sz("g");
|
||||
v = jerry_object_get(args_p[0], key);
|
||||
v = jerry_object_get(args[0], key);
|
||||
jerry_value_free(key);
|
||||
col.g = (colorchannel8_t)jerry_value_as_number(v);
|
||||
jerry_value_free(v);
|
||||
|
||||
key = jerry_string_sz("b");
|
||||
v = jerry_object_get(args_p[0], key);
|
||||
v = jerry_object_get(args[0], key);
|
||||
jerry_value_free(key);
|
||||
col.b = (colorchannel8_t)jerry_value_as_number(v);
|
||||
jerry_value_free(v);
|
||||
|
||||
key = jerry_string_sz("a");
|
||||
v = jerry_object_get(args_p[0], key);
|
||||
v = jerry_object_get(args[0], key);
|
||||
jerry_value_free(key);
|
||||
col.a = (colorchannel8_t)jerry_value_as_number(v);
|
||||
jerry_value_free(v);
|
||||
@@ -69,9 +69,9 @@ JS_FUNC(moduleEntityMaterialSetColor) {
|
||||
* Adds a material component to an entity and returns a handle object.
|
||||
* Arg 0: entity id (number).
|
||||
*/
|
||||
JS_FUNC(moduleEntityMaterialAdd) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t id = (entityid_t)jerry_value_as_number(args_p[0]);
|
||||
moduleBaseFunction(moduleEntityMaterialAdd) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
||||
componentid_t comp = entityAddComponent(id, COMPONENT_TYPE_MATERIAL);
|
||||
jerry_value_t handle = makeEntityHandle(id, comp);
|
||||
if(s_matProto != 0) jerry_object_set_proto(handle, s_matProto);
|
||||
@@ -84,7 +84,7 @@ JS_FUNC(moduleEntityMaterialAdd) {
|
||||
static void moduleEntityMaterial(void) {
|
||||
s_matProto = jerry_object();
|
||||
|
||||
jsDefineMethod(s_matProto, "setColor", moduleEntityMaterialSetColor);
|
||||
moduleBaseDefineMethod(s_matProto, "setColor", moduleEntityMaterialSetColor);
|
||||
|
||||
jsRegister("entityMaterialAdd", moduleEntityMaterialAdd);
|
||||
moduleBaseFunctionRegister("entityMaterialAdd", moduleEntityMaterialAdd);
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ static jerry_value_t s_meshProto = 0;
|
||||
* Generates an XZ-aligned plane mesh owned by this component.
|
||||
* Args: width (number), depth (number).
|
||||
*/
|
||||
JS_FUNC(moduleEntityMeshGeneratePlane) {
|
||||
JS_REQUIRE_ARGS(2);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
float_t w = (float_t)jerry_value_as_number(args_p[0]);
|
||||
float_t d = (float_t)jerry_value_as_number(args_p[1]);
|
||||
moduleBaseFunction(moduleEntityMeshGeneratePlane) {
|
||||
moduleBaseRequireArgs(2);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
float_t w = (float_t)jerry_value_as_number(args[0]);
|
||||
float_t d = (float_t)jerry_value_as_number(args[1]);
|
||||
entityMeshGeneratePlane(eid, cid, w, d);
|
||||
return jerry_undefined();
|
||||
}
|
||||
@@ -35,12 +35,12 @@ JS_FUNC(moduleEntityMeshGeneratePlane) {
|
||||
* Generates a Y-axis capsule mesh owned by this component.
|
||||
* Args: radius (number), halfHeight (number).
|
||||
*/
|
||||
JS_FUNC(moduleEntityMeshGenerateCapsule) {
|
||||
JS_REQUIRE_ARGS(2);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
float_t r = (float_t)jerry_value_as_number(args_p[0]);
|
||||
float_t hh = (float_t)jerry_value_as_number(args_p[1]);
|
||||
moduleBaseFunction(moduleEntityMeshGenerateCapsule) {
|
||||
moduleBaseRequireArgs(2);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
float_t r = (float_t)jerry_value_as_number(args[0]);
|
||||
float_t hh = (float_t)jerry_value_as_number(args[1]);
|
||||
entityMeshGenerateCapsule(eid, cid, r, hh);
|
||||
return jerry_undefined();
|
||||
}
|
||||
@@ -51,9 +51,9 @@ JS_FUNC(moduleEntityMeshGenerateCapsule) {
|
||||
* Adds a mesh component to an entity and returns a handle object.
|
||||
* Arg 0: entity id (number).
|
||||
*/
|
||||
JS_FUNC(moduleEntityMeshAdd) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t id = (entityid_t)jerry_value_as_number(args_p[0]);
|
||||
moduleBaseFunction(moduleEntityMeshAdd) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
||||
componentid_t comp = entityAddComponent(id, COMPONENT_TYPE_MESH);
|
||||
jerry_value_t handle = makeEntityHandle(id, comp);
|
||||
if(s_meshProto != 0) jerry_object_set_proto(handle, s_meshProto);
|
||||
@@ -66,8 +66,8 @@ JS_FUNC(moduleEntityMeshAdd) {
|
||||
static void moduleEntityMesh(void) {
|
||||
s_meshProto = jerry_object();
|
||||
|
||||
jsDefineMethod(s_meshProto, "generatePlane", moduleEntityMeshGeneratePlane);
|
||||
jsDefineMethod(s_meshProto, "generateCapsule", moduleEntityMeshGenerateCapsule);
|
||||
moduleBaseDefineMethod(s_meshProto, "generatePlane", moduleEntityMeshGeneratePlane);
|
||||
moduleBaseDefineMethod(s_meshProto, "generateCapsule", moduleEntityMeshGenerateCapsule);
|
||||
|
||||
jsRegister("entityMeshAdd", moduleEntityMeshAdd);
|
||||
moduleBaseFunctionRegister("entityMeshAdd", moduleEntityMeshAdd);
|
||||
}
|
||||
|
||||
@@ -17,86 +17,86 @@ static jerry_value_t s_physProto = 0;
|
||||
|
||||
// -- velocity getters/setters --
|
||||
|
||||
JS_FUNC(moduleEntityPhysicsGetVelX) {
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPhysicsGetVelX) {
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPhysicsGetVelocity(eid, cid, v);
|
||||
return jerry_number(v[0]);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPhysicsSetVelX) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPhysicsSetVelX) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPhysicsGetVelocity(eid, cid, v);
|
||||
v[0] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
v[0] = (float_t)jerry_value_as_number(args[0]);
|
||||
entityPhysicsSetVelocity(eid, cid, v);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPhysicsGetVelY) {
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPhysicsGetVelY) {
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPhysicsGetVelocity(eid, cid, v);
|
||||
return jerry_number(v[1]);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPhysicsSetVelY) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPhysicsSetVelY) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPhysicsGetVelocity(eid, cid, v);
|
||||
v[1] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
v[1] = (float_t)jerry_value_as_number(args[0]);
|
||||
entityPhysicsSetVelocity(eid, cid, v);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPhysicsGetVelZ) {
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPhysicsGetVelZ) {
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPhysicsGetVelocity(eid, cid, v);
|
||||
return jerry_number(v[2]);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPhysicsSetVelZ) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPhysicsSetVelZ) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPhysicsGetVelocity(eid, cid, v);
|
||||
v[2] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
v[2] = (float_t)jerry_value_as_number(args[0]);
|
||||
entityPhysicsSetVelocity(eid, cid, v);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
// -- onGround getter (read-only) --
|
||||
|
||||
JS_FUNC(moduleEntityPhysicsGetOnGround) {
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPhysicsGetOnGround) {
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
return jerry_boolean(entityPhysicsIsOnGround(eid, cid));
|
||||
}
|
||||
|
||||
// -- bodyType getter/setter --
|
||||
|
||||
JS_FUNC(moduleEntityPhysicsGetBodyType) {
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPhysicsGetBodyType) {
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
return jerry_number((double)entityPhysicsGetBodyType(eid, cid));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPhysicsSetBodyType) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPhysicsSetBodyType) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
entityPhysicsSetBodyType(
|
||||
eid, cid,
|
||||
(physicsbodytype_t)(int32_t)jerry_value_as_number(args_p[0])
|
||||
(physicsbodytype_t)(int32_t)jerry_value_as_number(args[0])
|
||||
);
|
||||
return jerry_undefined();
|
||||
}
|
||||
@@ -107,14 +107,14 @@ JS_FUNC(moduleEntityPhysicsSetBodyType) {
|
||||
* Applies an immediate velocity impulse to the physics body.
|
||||
* Args: x, y, z (numbers).
|
||||
*/
|
||||
JS_FUNC(moduleEntityPhysicsApplyImpulse) {
|
||||
JS_REQUIRE_ARGS(3);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPhysicsApplyImpulse) {
|
||||
moduleBaseRequireArgs(3);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 impulse = {
|
||||
(float_t)jerry_value_as_number(args_p[0]),
|
||||
(float_t)jerry_value_as_number(args_p[1]),
|
||||
(float_t)jerry_value_as_number(args_p[2])
|
||||
(float_t)jerry_value_as_number(args[0]),
|
||||
(float_t)jerry_value_as_number(args[1]),
|
||||
(float_t)jerry_value_as_number(args[2])
|
||||
};
|
||||
entityPhysicsApplyImpulse(eid, cid, impulse);
|
||||
return jerry_undefined();
|
||||
@@ -124,15 +124,15 @@ JS_FUNC(moduleEntityPhysicsApplyImpulse) {
|
||||
* Sets the physics shape to an axis-aligned box.
|
||||
* Args: halfX, halfY, halfZ (numbers).
|
||||
*/
|
||||
JS_FUNC(moduleEntityPhysicsSetShapeCube) {
|
||||
JS_REQUIRE_ARGS(3);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPhysicsSetShapeCube) {
|
||||
moduleBaseRequireArgs(3);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
physicsshape_t shape;
|
||||
shape.type = PHYSICS_SHAPE_CUBE;
|
||||
shape.data.cube.halfExtents[0] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
shape.data.cube.halfExtents[1] = (float_t)jerry_value_as_number(args_p[1]);
|
||||
shape.data.cube.halfExtents[2] = (float_t)jerry_value_as_number(args_p[2]);
|
||||
shape.data.cube.halfExtents[0] = (float_t)jerry_value_as_number(args[0]);
|
||||
shape.data.cube.halfExtents[1] = (float_t)jerry_value_as_number(args[1]);
|
||||
shape.data.cube.halfExtents[2] = (float_t)jerry_value_as_number(args[2]);
|
||||
entityPhysicsSetShape(eid, cid, shape);
|
||||
return jerry_undefined();
|
||||
}
|
||||
@@ -141,13 +141,13 @@ JS_FUNC(moduleEntityPhysicsSetShapeCube) {
|
||||
* Sets the physics shape to a sphere.
|
||||
* Args: radius (number).
|
||||
*/
|
||||
JS_FUNC(moduleEntityPhysicsSetShapeSphere) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPhysicsSetShapeSphere) {
|
||||
moduleBaseRequireArgs(1);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
physicsshape_t shape;
|
||||
shape.type = PHYSICS_SHAPE_SPHERE;
|
||||
shape.data.sphere.radius = (float_t)jerry_value_as_number(args_p[0]);
|
||||
shape.data.sphere.radius = (float_t)jerry_value_as_number(args[0]);
|
||||
entityPhysicsSetShape(eid, cid, shape);
|
||||
return jerry_undefined();
|
||||
}
|
||||
@@ -156,14 +156,14 @@ JS_FUNC(moduleEntityPhysicsSetShapeSphere) {
|
||||
* Sets the physics shape to a Y-axis capsule.
|
||||
* Args: radius (number), halfHeight (number).
|
||||
*/
|
||||
JS_FUNC(moduleEntityPhysicsSetShapeCapsule) {
|
||||
JS_REQUIRE_ARGS(2);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPhysicsSetShapeCapsule) {
|
||||
moduleBaseRequireArgs(2);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
physicsshape_t shape;
|
||||
shape.type = PHYSICS_SHAPE_CAPSULE;
|
||||
shape.data.capsule.radius = (float_t)jerry_value_as_number(args_p[0]);
|
||||
shape.data.capsule.halfHeight = (float_t)jerry_value_as_number(args_p[1]);
|
||||
shape.data.capsule.radius = (float_t)jerry_value_as_number(args[0]);
|
||||
shape.data.capsule.halfHeight = (float_t)jerry_value_as_number(args[1]);
|
||||
entityPhysicsSetShape(eid, cid, shape);
|
||||
return jerry_undefined();
|
||||
}
|
||||
@@ -172,16 +172,16 @@ JS_FUNC(moduleEntityPhysicsSetShapeCapsule) {
|
||||
* Sets the physics shape to an infinite plane.
|
||||
* Args: normalX, normalY, normalZ, distance (numbers).
|
||||
*/
|
||||
JS_FUNC(moduleEntityPhysicsSetShapePlane) {
|
||||
JS_REQUIRE_ARGS(4);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPhysicsSetShapePlane) {
|
||||
moduleBaseRequireArgs(4);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
physicsshape_t shape;
|
||||
shape.type = PHYSICS_SHAPE_PLANE;
|
||||
shape.data.plane.normal[0] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
shape.data.plane.normal[1] = (float_t)jerry_value_as_number(args_p[1]);
|
||||
shape.data.plane.normal[2] = (float_t)jerry_value_as_number(args_p[2]);
|
||||
shape.data.plane.distance = (float_t)jerry_value_as_number(args_p[3]);
|
||||
shape.data.plane.normal[0] = (float_t)jerry_value_as_number(args[0]);
|
||||
shape.data.plane.normal[1] = (float_t)jerry_value_as_number(args[1]);
|
||||
shape.data.plane.normal[2] = (float_t)jerry_value_as_number(args[2]);
|
||||
shape.data.plane.distance = (float_t)jerry_value_as_number(args[3]);
|
||||
entityPhysicsSetShape(eid, cid, shape);
|
||||
return jerry_undefined();
|
||||
}
|
||||
@@ -192,9 +192,9 @@ JS_FUNC(moduleEntityPhysicsSetShapePlane) {
|
||||
* Adds a physics component to an entity and returns a handle object.
|
||||
* Arg 0: entity id (number).
|
||||
*/
|
||||
JS_FUNC(moduleEntityPhysicsAdd) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t id = (entityid_t)jerry_value_as_number(args_p[0]);
|
||||
moduleBaseFunction(moduleEntityPhysicsAdd) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
||||
componentid_t comp = entityAddComponent(id, COMPONENT_TYPE_PHYSICS);
|
||||
jerry_value_t handle = makeEntityHandle(id, comp);
|
||||
if(s_physProto != 0) jerry_object_set_proto(handle, s_physProto);
|
||||
@@ -208,26 +208,26 @@ JS_FUNC(moduleEntityPhysicsAdd) {
|
||||
static void moduleEntityPhysics(void) {
|
||||
s_physProto = jerry_object();
|
||||
|
||||
jsDefineProperty(s_physProto, "velX", moduleEntityPhysicsGetVelX, moduleEntityPhysicsSetVelX);
|
||||
jsDefineProperty(s_physProto, "velY", moduleEntityPhysicsGetVelY, moduleEntityPhysicsSetVelY);
|
||||
jsDefineProperty(s_physProto, "velZ", moduleEntityPhysicsGetVelZ, moduleEntityPhysicsSetVelZ);
|
||||
jsDefineProperty(s_physProto, "onGround", moduleEntityPhysicsGetOnGround, NULL);
|
||||
jsDefineProperty(s_physProto, "bodyType", moduleEntityPhysicsGetBodyType, moduleEntityPhysicsSetBodyType);
|
||||
moduleBaseDefineProperty(s_physProto, "velX", moduleEntityPhysicsGetVelX, moduleEntityPhysicsSetVelX);
|
||||
moduleBaseDefineProperty(s_physProto, "velY", moduleEntityPhysicsGetVelY, moduleEntityPhysicsSetVelY);
|
||||
moduleBaseDefineProperty(s_physProto, "velZ", moduleEntityPhysicsGetVelZ, moduleEntityPhysicsSetVelZ);
|
||||
moduleBaseDefineProperty(s_physProto, "onGround", moduleEntityPhysicsGetOnGround, NULL);
|
||||
moduleBaseDefineProperty(s_physProto, "bodyType", moduleEntityPhysicsGetBodyType, moduleEntityPhysicsSetBodyType);
|
||||
|
||||
jsDefineMethod(s_physProto, "applyImpulse", moduleEntityPhysicsApplyImpulse);
|
||||
jsDefineMethod(s_physProto, "setShapeCube", moduleEntityPhysicsSetShapeCube);
|
||||
jsDefineMethod(s_physProto, "setShapeSphere", moduleEntityPhysicsSetShapeSphere);
|
||||
jsDefineMethod(s_physProto, "setShapeCapsule", moduleEntityPhysicsSetShapeCapsule);
|
||||
jsDefineMethod(s_physProto, "setShapePlane", moduleEntityPhysicsSetShapePlane);
|
||||
moduleBaseDefineMethod(s_physProto, "applyImpulse", moduleEntityPhysicsApplyImpulse);
|
||||
moduleBaseDefineMethod(s_physProto, "setShapeCube", moduleEntityPhysicsSetShapeCube);
|
||||
moduleBaseDefineMethod(s_physProto, "setShapeSphere", moduleEntityPhysicsSetShapeSphere);
|
||||
moduleBaseDefineMethod(s_physProto, "setShapeCapsule", moduleEntityPhysicsSetShapeCapsule);
|
||||
moduleBaseDefineMethod(s_physProto, "setShapePlane", moduleEntityPhysicsSetShapePlane);
|
||||
|
||||
jsRegister("entityPhysicsAdd", moduleEntityPhysicsAdd);
|
||||
moduleBaseFunctionRegister("entityPhysicsAdd", moduleEntityPhysicsAdd);
|
||||
|
||||
jsSetInt("PHYSICS_BODY_STATIC", PHYSICS_BODY_STATIC);
|
||||
jsSetInt("PHYSICS_BODY_DYNAMIC", PHYSICS_BODY_DYNAMIC);
|
||||
jsSetInt("PHYSICS_BODY_KINEMATIC", PHYSICS_BODY_KINEMATIC);
|
||||
moduleBaseSetInt("PHYSICS_BODY_STATIC", PHYSICS_BODY_STATIC);
|
||||
moduleBaseSetInt("PHYSICS_BODY_DYNAMIC", PHYSICS_BODY_DYNAMIC);
|
||||
moduleBaseSetInt("PHYSICS_BODY_KINEMATIC", PHYSICS_BODY_KINEMATIC);
|
||||
|
||||
jsSetInt("PHYSICS_SHAPE_CUBE", PHYSICS_SHAPE_CUBE);
|
||||
jsSetInt("PHYSICS_SHAPE_SPHERE", PHYSICS_SHAPE_SPHERE);
|
||||
jsSetInt("PHYSICS_SHAPE_CAPSULE", PHYSICS_SHAPE_CAPSULE);
|
||||
jsSetInt("PHYSICS_SHAPE_PLANE", PHYSICS_SHAPE_PLANE);
|
||||
moduleBaseSetInt("PHYSICS_SHAPE_CUBE", PHYSICS_SHAPE_CUBE);
|
||||
moduleBaseSetInt("PHYSICS_SHAPE_SPHERE", PHYSICS_SHAPE_SPHERE);
|
||||
moduleBaseSetInt("PHYSICS_SHAPE_CAPSULE", PHYSICS_SHAPE_CAPSULE);
|
||||
moduleBaseSetInt("PHYSICS_SHAPE_PLANE", PHYSICS_SHAPE_PLANE);
|
||||
}
|
||||
|
||||
@@ -74,177 +74,177 @@ static jerry_value_t s_posProto = 0;
|
||||
|
||||
// -- position getters/setters --
|
||||
|
||||
JS_FUNC(moduleEntityPositionGetX) {
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionGetX) {
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPositionGetPosition(eid, cid, v);
|
||||
return jerry_number(v[0]);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPositionSetX) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionSetX) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPositionGetPosition(eid, cid, v);
|
||||
v[0] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
v[0] = (float_t)jerry_value_as_number(args[0]);
|
||||
entityPositionSetPosition(eid, cid, v);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPositionGetY) {
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionGetY) {
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPositionGetPosition(eid, cid, v);
|
||||
return jerry_number(v[1]);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPositionSetY) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionSetY) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPositionGetPosition(eid, cid, v);
|
||||
v[1] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
v[1] = (float_t)jerry_value_as_number(args[0]);
|
||||
entityPositionSetPosition(eid, cid, v);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPositionGetZ) {
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionGetZ) {
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPositionGetPosition(eid, cid, v);
|
||||
return jerry_number(v[2]);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPositionSetZ) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionSetZ) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPositionGetPosition(eid, cid, v);
|
||||
v[2] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
v[2] = (float_t)jerry_value_as_number(args[0]);
|
||||
entityPositionSetPosition(eid, cid, v);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
// -- rotation getters/setters --
|
||||
|
||||
JS_FUNC(moduleEntityPositionGetRotX) {
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionGetRotX) {
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPositionGetRotation(eid, cid, v);
|
||||
return jerry_number(v[0]);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPositionSetRotX) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionSetRotX) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPositionGetRotation(eid, cid, v);
|
||||
v[0] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
v[0] = (float_t)jerry_value_as_number(args[0]);
|
||||
entityPositionSetRotation(eid, cid, v);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPositionGetRotY) {
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionGetRotY) {
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPositionGetRotation(eid, cid, v);
|
||||
return jerry_number(v[1]);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPositionSetRotY) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionSetRotY) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPositionGetRotation(eid, cid, v);
|
||||
v[1] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
v[1] = (float_t)jerry_value_as_number(args[0]);
|
||||
entityPositionSetRotation(eid, cid, v);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPositionGetRotZ) {
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionGetRotZ) {
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPositionGetRotation(eid, cid, v);
|
||||
return jerry_number(v[2]);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPositionSetRotZ) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionSetRotZ) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPositionGetRotation(eid, cid, v);
|
||||
v[2] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
v[2] = (float_t)jerry_value_as_number(args[0]);
|
||||
entityPositionSetRotation(eid, cid, v);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
// -- scale getters/setters --
|
||||
|
||||
JS_FUNC(moduleEntityPositionGetScaleX) {
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionGetScaleX) {
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPositionGetScale(eid, cid, v);
|
||||
return jerry_number(v[0]);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPositionSetScaleX) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionSetScaleX) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPositionGetScale(eid, cid, v);
|
||||
v[0] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
v[0] = (float_t)jerry_value_as_number(args[0]);
|
||||
entityPositionSetScale(eid, cid, v);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPositionGetScaleY) {
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionGetScaleY) {
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPositionGetScale(eid, cid, v);
|
||||
return jerry_number(v[1]);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPositionSetScaleY) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionSetScaleY) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPositionGetScale(eid, cid, v);
|
||||
v[1] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
v[1] = (float_t)jerry_value_as_number(args[0]);
|
||||
entityPositionSetScale(eid, cid, v);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPositionGetScaleZ) {
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionGetScaleZ) {
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPositionGetScale(eid, cid, v);
|
||||
return jerry_number(v[2]);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEntityPositionSetScaleZ) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionSetScaleZ) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 v;
|
||||
entityPositionGetScale(eid, cid, v);
|
||||
v[2] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
v[2] = (float_t)jerry_value_as_number(args[0]);
|
||||
entityPositionSetScale(eid, cid, v);
|
||||
return jerry_undefined();
|
||||
}
|
||||
@@ -255,20 +255,20 @@ JS_FUNC(moduleEntityPositionSetScaleZ) {
|
||||
* Rotates the entity to face a world-space target point.
|
||||
* Args: target x, y, z [, up x, y, z]. Up defaults to (0,1,0).
|
||||
*/
|
||||
JS_FUNC(moduleEntityPositionLookAt) {
|
||||
JS_REQUIRE_ARGS(3);
|
||||
entityid_t eid = getEntityId(call_info_p->this_value);
|
||||
componentid_t cid = getCompId(call_info_p->this_value);
|
||||
moduleBaseFunction(moduleEntityPositionLookAt) {
|
||||
moduleBaseRequireArgs(3);
|
||||
entityid_t eid = getEntityId(callInfo->this_value);
|
||||
componentid_t cid = getCompId(callInfo->this_value);
|
||||
vec3 target = {
|
||||
(float_t)jerry_value_as_number(args_p[0]),
|
||||
(float_t)jerry_value_as_number(args_p[1]),
|
||||
(float_t)jerry_value_as_number(args_p[2])
|
||||
(float_t)jerry_value_as_number(args[0]),
|
||||
(float_t)jerry_value_as_number(args[1]),
|
||||
(float_t)jerry_value_as_number(args[2])
|
||||
};
|
||||
vec3 up = { 0.0f, 1.0f, 0.0f };
|
||||
if(args_count >= 6) {
|
||||
up[0] = (float_t)jerry_value_as_number(args_p[3]);
|
||||
up[1] = (float_t)jerry_value_as_number(args_p[4]);
|
||||
up[2] = (float_t)jerry_value_as_number(args_p[5]);
|
||||
if(argc >= 6) {
|
||||
up[0] = (float_t)jerry_value_as_number(args[3]);
|
||||
up[1] = (float_t)jerry_value_as_number(args[4]);
|
||||
up[2] = (float_t)jerry_value_as_number(args[5]);
|
||||
}
|
||||
vec3 eye;
|
||||
entityPositionGetPosition(eid, cid, eye);
|
||||
@@ -282,9 +282,9 @@ JS_FUNC(moduleEntityPositionLookAt) {
|
||||
* Adds a position component to an entity and returns a handle object.
|
||||
* Arg 0: entity id (number).
|
||||
*/
|
||||
JS_FUNC(moduleEntityPositionAdd) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityid_t id = (entityid_t)jerry_value_as_number(args_p[0]);
|
||||
moduleBaseFunction(moduleEntityPositionAdd) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
||||
componentid_t comp = entityAddComponent(id, COMPONENT_TYPE_POSITION);
|
||||
jerry_value_t handle = makeEntityHandle(id, comp);
|
||||
if(s_posProto != 0) jerry_object_set_proto(handle, s_posProto);
|
||||
@@ -297,17 +297,17 @@ JS_FUNC(moduleEntityPositionAdd) {
|
||||
static void moduleEntityPosition(void) {
|
||||
s_posProto = jerry_object();
|
||||
|
||||
jsDefineProperty(s_posProto, "x", moduleEntityPositionGetX, moduleEntityPositionSetX);
|
||||
jsDefineProperty(s_posProto, "y", moduleEntityPositionGetY, moduleEntityPositionSetY);
|
||||
jsDefineProperty(s_posProto, "z", moduleEntityPositionGetZ, moduleEntityPositionSetZ);
|
||||
jsDefineProperty(s_posProto, "rotX", moduleEntityPositionGetRotX, moduleEntityPositionSetRotX);
|
||||
jsDefineProperty(s_posProto, "rotY", moduleEntityPositionGetRotY, moduleEntityPositionSetRotY);
|
||||
jsDefineProperty(s_posProto, "rotZ", moduleEntityPositionGetRotZ, moduleEntityPositionSetRotZ);
|
||||
jsDefineProperty(s_posProto, "scaleX", moduleEntityPositionGetScaleX, moduleEntityPositionSetScaleX);
|
||||
jsDefineProperty(s_posProto, "scaleY", moduleEntityPositionGetScaleY, moduleEntityPositionSetScaleY);
|
||||
jsDefineProperty(s_posProto, "scaleZ", moduleEntityPositionGetScaleZ, moduleEntityPositionSetScaleZ);
|
||||
moduleBaseDefineProperty(s_posProto, "x", moduleEntityPositionGetX, moduleEntityPositionSetX);
|
||||
moduleBaseDefineProperty(s_posProto, "y", moduleEntityPositionGetY, moduleEntityPositionSetY);
|
||||
moduleBaseDefineProperty(s_posProto, "z", moduleEntityPositionGetZ, moduleEntityPositionSetZ);
|
||||
moduleBaseDefineProperty(s_posProto, "rotX", moduleEntityPositionGetRotX, moduleEntityPositionSetRotX);
|
||||
moduleBaseDefineProperty(s_posProto, "rotY", moduleEntityPositionGetRotY, moduleEntityPositionSetRotY);
|
||||
moduleBaseDefineProperty(s_posProto, "rotZ", moduleEntityPositionGetRotZ, moduleEntityPositionSetRotZ);
|
||||
moduleBaseDefineProperty(s_posProto, "scaleX", moduleEntityPositionGetScaleX, moduleEntityPositionSetScaleX);
|
||||
moduleBaseDefineProperty(s_posProto, "scaleY", moduleEntityPositionGetScaleY, moduleEntityPositionSetScaleY);
|
||||
moduleBaseDefineProperty(s_posProto, "scaleZ", moduleEntityPositionGetScaleZ, moduleEntityPositionSetScaleZ);
|
||||
|
||||
jsDefineMethod(s_posProto, "lookAt", moduleEntityPositionLookAt);
|
||||
moduleBaseDefineMethod(s_posProto, "lookAt", moduleEntityPositionLookAt);
|
||||
|
||||
jsRegister("entityPositionAdd", moduleEntityPositionAdd);
|
||||
moduleBaseFunctionRegister("entityPositionAdd", moduleEntityPositionAdd);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ static const char_t *ENTITY_SCRIPT =
|
||||
/**
|
||||
* Allocates a new entity and returns its id as a JS number.
|
||||
*/
|
||||
JS_FUNC(moduleEntityAdd) {
|
||||
moduleBaseFunction(moduleEntityAdd) {
|
||||
return jerry_number((double)entityManagerAdd());
|
||||
}
|
||||
|
||||
@@ -72,9 +72,9 @@ JS_FUNC(moduleEntityAdd) {
|
||||
* Disposes the entity with the given id.
|
||||
* Arg 0: entity id (number).
|
||||
*/
|
||||
JS_FUNC(moduleEntityRemove) {
|
||||
JS_REQUIRE_ARGS(1); JS_REQUIRE_NUMBER(0);
|
||||
entityDispose((entityid_t)jerry_value_as_number(args_p[0]));
|
||||
moduleBaseFunction(moduleEntityRemove) {
|
||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||
entityDispose((entityid_t)jerry_value_as_number(args[0]));
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
@@ -89,9 +89,9 @@ static void moduleEntity(void) {
|
||||
moduleEntityMaterial();
|
||||
moduleEntityPhysics();
|
||||
|
||||
jsRegister("entityAdd", moduleEntityAdd);
|
||||
jsRegister("entityRemove", moduleEntityRemove);
|
||||
moduleBaseFunctionRegister("entityAdd", moduleEntityAdd);
|
||||
moduleBaseFunctionRegister("entityRemove", moduleEntityRemove);
|
||||
|
||||
jsEvalStr(COMPONENT_TYPE_SCRIPT);
|
||||
jsEvalStr(ENTITY_SCRIPT);
|
||||
moduleBaseEval(COMPONENT_TYPE_SCRIPT);
|
||||
moduleBaseEval(ENTITY_SCRIPT);
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "script/module/modulebase.h"
|
||||
#include "event/event.h"
|
||||
|
||||
JS_FUNC(moduleEventSubscribe) {
|
||||
JS_REQUIRE_ARGS(2);
|
||||
JS_REQUIRE_OBJECT(0);
|
||||
JS_REQUIRE_FUNCTION(1);
|
||||
|
||||
event_t *event = (event_t *)jsUnwrapPointer(args_p[0]);
|
||||
if(event == NULL) return JS_THROW("eventSubscribe: Expected event object");
|
||||
|
||||
jerry_value_t funcCopy = jerry_value_copy(args_p[1]);
|
||||
eventsub_t id = eventSubscribeScriptContext(event, scriptContextCurrent, funcCopy);
|
||||
|
||||
return jerry_number((double)id);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleEventUnsubscribe) {
|
||||
JS_REQUIRE_ARGS(2);
|
||||
JS_REQUIRE_OBJECT(0);
|
||||
JS_REQUIRE_NUMBER(1);
|
||||
|
||||
event_t *event = (event_t *)jsUnwrapPointer(args_p[0]);
|
||||
if(event == NULL) return JS_THROW("eventUnsubscribe: Expected event object");
|
||||
|
||||
eventsub_t id = (eventsub_t)jerry_value_as_number(args_p[1]);
|
||||
eventUnsubscribe(event, id);
|
||||
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
static void moduleEvent(void) {
|
||||
jsRegister("eventSubscribe", moduleEventSubscribe);
|
||||
jsRegister("eventUnsubscribe", moduleEventUnsubscribe);
|
||||
}
|
||||
@@ -9,108 +9,108 @@
|
||||
#include "script/module/modulebase.h"
|
||||
#include "input/input.h"
|
||||
|
||||
JS_FUNC(moduleInputBind) {
|
||||
JS_REQUIRE_ARGS(2);
|
||||
JS_REQUIRE_STRING(0);
|
||||
JS_REQUIRE_NUMBER(1);
|
||||
moduleBaseFunction(moduleInputBind) {
|
||||
moduleBaseRequireArgs(2);
|
||||
moduleBaseRequireString(0);
|
||||
moduleBaseRequireNumber(1);
|
||||
|
||||
char_t strBtn[128];
|
||||
jsToString(args_p[0], strBtn, sizeof(strBtn));
|
||||
if(strBtn[0] == '\0') return JS_THROW("inputBind: Button name cannot be empty");
|
||||
moduleBaseToString(args[0], strBtn, sizeof(strBtn));
|
||||
if(strBtn[0] == '\0') return moduleBaseThrow("inputBind: Button name cannot be empty");
|
||||
|
||||
const inputaction_t action = (inputaction_t)jerry_value_as_number(args_p[1]);
|
||||
const inputaction_t action = (inputaction_t)jerry_value_as_number(args[1]);
|
||||
if(action < INPUT_ACTION_NULL || action >= INPUT_ACTION_COUNT) {
|
||||
return JS_THROW("inputBind: Invalid action ID");
|
||||
return moduleBaseThrow("inputBind: Invalid action ID");
|
||||
}
|
||||
|
||||
inputbutton_t btn = inputButtonGetByName(strBtn);
|
||||
if(btn.type == INPUT_BUTTON_TYPE_NONE) {
|
||||
return JS_THROW("inputBind: Invalid button name");
|
||||
return moduleBaseThrow("inputBind: Invalid button name");
|
||||
}
|
||||
|
||||
inputBind(btn, action);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleInputIsDown) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
JS_REQUIRE_NUMBER(0);
|
||||
moduleBaseFunction(moduleInputIsDown) {
|
||||
moduleBaseRequireArgs(1);
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
const inputaction_t action = (inputaction_t)jerry_value_as_number(args_p[0]);
|
||||
const inputaction_t action = (inputaction_t)jerry_value_as_number(args[0]);
|
||||
if(action < INPUT_ACTION_NULL || action >= INPUT_ACTION_COUNT) {
|
||||
return JS_THROW("inputIsDown: Invalid action ID");
|
||||
return moduleBaseThrow("inputIsDown: Invalid action ID");
|
||||
}
|
||||
|
||||
return jerry_boolean(inputIsDown(action));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleInputPressed) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
JS_REQUIRE_NUMBER(0);
|
||||
moduleBaseFunction(moduleInputPressed) {
|
||||
moduleBaseRequireArgs(1);
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
const inputaction_t action = (inputaction_t)jerry_value_as_number(args_p[0]);
|
||||
const inputaction_t action = (inputaction_t)jerry_value_as_number(args[0]);
|
||||
if(action < INPUT_ACTION_NULL || action >= INPUT_ACTION_COUNT) {
|
||||
return JS_THROW("inputPressed: Invalid action ID");
|
||||
return moduleBaseThrow("inputPressed: Invalid action ID");
|
||||
}
|
||||
|
||||
return jerry_boolean(inputPressed(action));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleInputReleased) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
JS_REQUIRE_NUMBER(0);
|
||||
moduleBaseFunction(moduleInputReleased) {
|
||||
moduleBaseRequireArgs(1);
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
const inputaction_t action = (inputaction_t)jerry_value_as_number(args_p[0]);
|
||||
const inputaction_t action = (inputaction_t)jerry_value_as_number(args[0]);
|
||||
if(action < INPUT_ACTION_NULL || action >= INPUT_ACTION_COUNT) {
|
||||
return JS_THROW("inputReleased: Invalid action ID");
|
||||
return moduleBaseThrow("inputReleased: Invalid action ID");
|
||||
}
|
||||
|
||||
return jerry_boolean(inputReleased(action));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleInputGetValue) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
JS_REQUIRE_NUMBER(0);
|
||||
moduleBaseFunction(moduleInputGetValue) {
|
||||
moduleBaseRequireArgs(1);
|
||||
moduleBaseRequireNumber(0);
|
||||
|
||||
const inputaction_t action = (inputaction_t)jerry_value_as_number(args_p[0]);
|
||||
const inputaction_t action = (inputaction_t)jerry_value_as_number(args[0]);
|
||||
if(action < INPUT_ACTION_NULL || action >= INPUT_ACTION_COUNT) {
|
||||
return JS_THROW("inputGetValue: Invalid action ID");
|
||||
return moduleBaseThrow("inputGetValue: Invalid action ID");
|
||||
}
|
||||
|
||||
return jerry_number(inputGetCurrentValue(action));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleInputAxis) {
|
||||
JS_REQUIRE_ARGS(2);
|
||||
JS_REQUIRE_NUMBER(0);
|
||||
JS_REQUIRE_NUMBER(1);
|
||||
moduleBaseFunction(moduleInputAxis) {
|
||||
moduleBaseRequireArgs(2);
|
||||
moduleBaseRequireNumber(0);
|
||||
moduleBaseRequireNumber(1);
|
||||
|
||||
const inputaction_t neg = (inputaction_t)jerry_value_as_number(args_p[0]);
|
||||
const inputaction_t pos = (inputaction_t)jerry_value_as_number(args_p[1]);
|
||||
const inputaction_t neg = (inputaction_t)jerry_value_as_number(args[0]);
|
||||
const inputaction_t pos = (inputaction_t)jerry_value_as_number(args[1]);
|
||||
|
||||
if(neg < INPUT_ACTION_NULL || neg >= INPUT_ACTION_COUNT) {
|
||||
return JS_THROW("inputAxis: Invalid negative action ID");
|
||||
return moduleBaseThrow("inputAxis: Invalid negative action ID");
|
||||
}
|
||||
if(pos < INPUT_ACTION_NULL || pos >= INPUT_ACTION_COUNT) {
|
||||
return JS_THROW("inputAxis: Invalid positive action ID");
|
||||
return moduleBaseThrow("inputAxis: Invalid positive action ID");
|
||||
}
|
||||
|
||||
return jerry_number(inputAxis(neg, pos));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleInputGetEventAction) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
moduleBaseFunction(moduleInputGetEventAction) {
|
||||
moduleBaseRequireArgs(1);
|
||||
|
||||
const inputevent_t *event = (const inputevent_t *)jsUnwrapPointer(args_p[0]);
|
||||
if(event == NULL) return JS_THROW("inputGetEventAction: Expected input event object");
|
||||
const inputevent_t *event = (const inputevent_t *)moduleBaseUnwrapPointer(args[0]);
|
||||
if(event == NULL) return moduleBaseThrow("inputGetEventAction: Expected input event object");
|
||||
|
||||
return jerry_number(event->action);
|
||||
}
|
||||
|
||||
static void moduleInput(void) {
|
||||
jsEvalStr(INPUT_ACTION_SCRIPT);
|
||||
moduleBaseEval(INPUT_ACTION_SCRIPT);
|
||||
|
||||
jsEvalStr(
|
||||
moduleBaseEval(
|
||||
""
|
||||
#ifdef DUSK_INPUT_KEYBOARD
|
||||
"var INPUT_KEYBOARD = true;\n"
|
||||
@@ -126,19 +126,19 @@ static void moduleInput(void) {
|
||||
#endif
|
||||
);
|
||||
|
||||
jerry_value_t evPressed = jsWrapPointer(&INPUT.eventPressed);
|
||||
jsSetValue("INPUT_EVENT_PRESSED", evPressed);
|
||||
jerry_value_t evPressed = moduleBaseWrapPointer(&INPUT.eventPressed);
|
||||
moduleBaseSetValue("INPUT_EVENT_PRESSED", evPressed);
|
||||
jerry_value_free(evPressed);
|
||||
|
||||
jerry_value_t evReleased = jsWrapPointer(&INPUT.eventReleased);
|
||||
jsSetValue("INPUT_EVENT_RELEASED", evReleased);
|
||||
jerry_value_t evReleased = moduleBaseWrapPointer(&INPUT.eventReleased);
|
||||
moduleBaseSetValue("INPUT_EVENT_RELEASED", evReleased);
|
||||
jerry_value_free(evReleased);
|
||||
|
||||
jsRegister("inputBind", moduleInputBind);
|
||||
jsRegister("inputIsDown", moduleInputIsDown);
|
||||
jsRegister("inputPressed", moduleInputPressed);
|
||||
jsRegister("inputReleased", moduleInputReleased);
|
||||
jsRegister("inputGetValue", moduleInputGetValue);
|
||||
jsRegister("inputAxis", moduleInputAxis);
|
||||
jsRegister("inputGetEventAction", moduleInputGetEventAction);
|
||||
moduleBaseFunctionRegister("inputBind", moduleInputBind);
|
||||
moduleBaseFunctionRegister("inputIsDown", moduleInputIsDown);
|
||||
moduleBaseFunctionRegister("inputPressed", moduleInputPressed);
|
||||
moduleBaseFunctionRegister("inputReleased", moduleInputReleased);
|
||||
moduleBaseFunctionRegister("inputGetValue", moduleInputGetValue);
|
||||
moduleBaseFunctionRegister("inputAxis", moduleInputAxis);
|
||||
moduleBaseFunctionRegister("inputGetEventAction", moduleInputGetEventAction);
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "script/module/modulebase.h"
|
||||
#include "locale/localemanager.h"
|
||||
|
||||
#define MODULE_LOCALE_MAX_ARGS 16
|
||||
|
||||
JS_FUNC(moduleLocaleGetText) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
JS_REQUIRE_STRING(0);
|
||||
|
||||
char_t id[256];
|
||||
jsToString(args_p[0], id, sizeof(id));
|
||||
if(id[0] == '\0') return JS_THROW("localeGetText: Message ID cannot be empty");
|
||||
|
||||
int32_t plural = 0;
|
||||
jerry_length_t argStart = 1;
|
||||
|
||||
if(args_count >= 2 && !jerry_value_is_undefined(args_p[1])) {
|
||||
if(!jerry_value_is_number(args_p[1])) {
|
||||
return JS_THROW("localeGetText: Expected plural as second argument");
|
||||
}
|
||||
plural = (int32_t)jerry_value_as_number(args_p[1]);
|
||||
if(plural < 0) return JS_THROW("localeGetText: Plural cannot be negative");
|
||||
argStart = 2;
|
||||
}
|
||||
|
||||
size_t argCount = (args_count > argStart) ? (size_t)(args_count - argStart) : 0;
|
||||
|
||||
if(argCount > MODULE_LOCALE_MAX_ARGS) {
|
||||
return JS_THROW("localeGetText: Too many format arguments");
|
||||
}
|
||||
|
||||
assetlocalearg_t argsStack[MODULE_LOCALE_MAX_ARGS];
|
||||
char_t strBufs[MODULE_LOCALE_MAX_ARGS][128];
|
||||
|
||||
for(size_t i = 0; i < argCount; ++i) {
|
||||
jerry_value_t arg = args_p[argStart + i];
|
||||
|
||||
if(jerry_value_is_number(arg)) {
|
||||
double num = jerry_value_as_number(arg);
|
||||
if(num == (double)(int32_t)num) {
|
||||
argsStack[i].type = ASSET_LOCALE_ARG_INT;
|
||||
argsStack[i].intValue = (int32_t)num;
|
||||
} else {
|
||||
argsStack[i].type = ASSET_LOCALE_ARG_FLOAT;
|
||||
argsStack[i].floatValue = (float_t)num;
|
||||
}
|
||||
} else if(jerry_value_is_string(arg)) {
|
||||
jsToString(arg, strBufs[i], sizeof(strBufs[i]));
|
||||
argsStack[i].type = ASSET_LOCALE_ARG_STRING;
|
||||
argsStack[i].stringValue = strBufs[i];
|
||||
} else {
|
||||
return JS_THROW("localeGetText: Unsupported argument type");
|
||||
}
|
||||
}
|
||||
|
||||
char_t buffer[1024];
|
||||
errorret_t err = localeManagerGetTextArgs(
|
||||
id, buffer, sizeof(buffer), plural, argsStack, argCount
|
||||
);
|
||||
if(err.code != ERROR_OK) {
|
||||
errorCatch(errorPrint(err));
|
||||
return JS_THROW("localeGetText: Failed to get localized text");
|
||||
}
|
||||
|
||||
return jerry_string_sz(buffer);
|
||||
}
|
||||
|
||||
static void moduleLocale(void) {
|
||||
jsRegister("localeGetText", moduleLocaleGetText);
|
||||
}
|
||||
@@ -28,16 +28,16 @@ static jerry_value_t s_mat4Proto = 0;
|
||||
// Methods
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
JS_FUNC(moduleMatMul) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
moduleBaseFunction(moduleMatMul) {
|
||||
moduleBaseRequireArgs(1);
|
||||
float_t (*a)[4] = (float_t (*)[4])jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &MAT4_NATIVE_INFO
|
||||
callInfo->this_value, &MAT4_NATIVE_INFO
|
||||
);
|
||||
if(!a) return JS_THROW("mat4.mul: invalid this");
|
||||
if(!a) return moduleBaseThrow("mat4.mul: invalid this");
|
||||
float_t (*b)[4] = (float_t (*)[4])jerry_object_get_native_ptr(
|
||||
args_p[0], &MAT4_NATIVE_INFO
|
||||
args[0], &MAT4_NATIVE_INFO
|
||||
);
|
||||
if(!b) return JS_THROW("mat4.mul: argument must be a mat4");
|
||||
if(!b) return moduleBaseThrow("mat4.mul: argument must be a mat4");
|
||||
float_t (*r)[4] = (float_t (*)[4])malloc(sizeof(mat4));
|
||||
glm_mat4_mul(a, b, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -46,11 +46,11 @@ JS_FUNC(moduleMatMul) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleMatTranspose) {
|
||||
moduleBaseFunction(moduleMatTranspose) {
|
||||
float_t (*m)[4] = (float_t (*)[4])jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &MAT4_NATIVE_INFO
|
||||
callInfo->this_value, &MAT4_NATIVE_INFO
|
||||
);
|
||||
if(!m) return JS_THROW("mat4.transpose: invalid this");
|
||||
if(!m) return moduleBaseThrow("mat4.transpose: invalid this");
|
||||
float_t (*r)[4] = (float_t (*)[4])malloc(sizeof(mat4));
|
||||
glm_mat4_transpose_to(m, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -59,11 +59,11 @@ JS_FUNC(moduleMatTranspose) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleMatInverse) {
|
||||
moduleBaseFunction(moduleMatInverse) {
|
||||
float_t (*m)[4] = (float_t (*)[4])jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &MAT4_NATIVE_INFO
|
||||
callInfo->this_value, &MAT4_NATIVE_INFO
|
||||
);
|
||||
if(!m) return JS_THROW("mat4.inverse: invalid this");
|
||||
if(!m) return moduleBaseThrow("mat4.inverse: invalid this");
|
||||
float_t (*r)[4] = (float_t (*)[4])malloc(sizeof(mat4));
|
||||
glm_mat4_inv(m, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -72,56 +72,56 @@ JS_FUNC(moduleMatInverse) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleMatDeterminant) {
|
||||
moduleBaseFunction(moduleMatDeterminant) {
|
||||
float_t (*m)[4] = (float_t (*)[4])jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &MAT4_NATIVE_INFO
|
||||
callInfo->this_value, &MAT4_NATIVE_INFO
|
||||
);
|
||||
if(!m) return JS_THROW("mat4.determinant: invalid this");
|
||||
if(!m) return moduleBaseThrow("mat4.determinant: invalid this");
|
||||
return jerry_number(glm_mat4_det(m));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleMatMulVec3) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
moduleBaseFunction(moduleMatMulVec3) {
|
||||
moduleBaseRequireArgs(1);
|
||||
float_t (*m)[4] = (float_t (*)[4])jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &MAT4_NATIVE_INFO
|
||||
callInfo->this_value, &MAT4_NATIVE_INFO
|
||||
);
|
||||
if(!m) return JS_THROW("mat4.mulVec3: invalid this");
|
||||
if(!m) return moduleBaseThrow("mat4.mulVec3: invalid this");
|
||||
vec3 vin;
|
||||
if(!moduleVec3Check(args_p[0], vin)) {
|
||||
return JS_THROW("mat4.mulVec3: first argument must be a vec3");
|
||||
if(!moduleVec3Check(args[0], vin)) {
|
||||
return moduleBaseThrow("mat4.mulVec3: first argument must be a vec3");
|
||||
}
|
||||
float_t w = (args_count >= 2 && jerry_value_is_number(args_p[1]))
|
||||
? (float_t)jerry_value_as_number(args_p[1])
|
||||
float_t w = (argc >= 2 && jerry_value_is_number(args[1]))
|
||||
? (float_t)jerry_value_as_number(args[1])
|
||||
: 1.0f;
|
||||
vec3 vout;
|
||||
glm_mat4_mulv3(m, vin, w, vout);
|
||||
return moduleVec3Push(vout);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleMatMulVec4) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
moduleBaseFunction(moduleMatMulVec4) {
|
||||
moduleBaseRequireArgs(1);
|
||||
float_t (*m)[4] = (float_t (*)[4])jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &MAT4_NATIVE_INFO
|
||||
callInfo->this_value, &MAT4_NATIVE_INFO
|
||||
);
|
||||
if(!m) return JS_THROW("mat4.mulVec4: invalid this");
|
||||
if(!m) return moduleBaseThrow("mat4.mulVec4: invalid this");
|
||||
vec4 vin;
|
||||
if(!moduleVec4Check(args_p[0], vin)) {
|
||||
return JS_THROW("mat4.mulVec4: first argument must be a vec4");
|
||||
if(!moduleVec4Check(args[0], vin)) {
|
||||
return moduleBaseThrow("mat4.mulVec4: first argument must be a vec4");
|
||||
}
|
||||
vec4 vout;
|
||||
glm_mat4_mulv(m, vin, vout);
|
||||
return moduleVec4Push(vout);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleMatTranslate) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
moduleBaseFunction(moduleMatTranslate) {
|
||||
moduleBaseRequireArgs(1);
|
||||
float_t (*m)[4] = (float_t (*)[4])jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &MAT4_NATIVE_INFO
|
||||
callInfo->this_value, &MAT4_NATIVE_INFO
|
||||
);
|
||||
if(!m) return JS_THROW("mat4.translate: invalid this");
|
||||
if(!m) return moduleBaseThrow("mat4.translate: invalid this");
|
||||
vec3 tv;
|
||||
if(!moduleVec3Check(args_p[0], tv)) {
|
||||
return JS_THROW("mat4.translate: argument must be a vec3");
|
||||
if(!moduleVec3Check(args[0], tv)) {
|
||||
return moduleBaseThrow("mat4.translate: argument must be a vec3");
|
||||
}
|
||||
float_t (*r)[4] = (float_t (*)[4])malloc(sizeof(mat4));
|
||||
glm_mat4_copy(m, r);
|
||||
@@ -132,15 +132,15 @@ JS_FUNC(moduleMatTranslate) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleMatScale) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
moduleBaseFunction(moduleMatScale) {
|
||||
moduleBaseRequireArgs(1);
|
||||
float_t (*m)[4] = (float_t (*)[4])jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &MAT4_NATIVE_INFO
|
||||
callInfo->this_value, &MAT4_NATIVE_INFO
|
||||
);
|
||||
if(!m) return JS_THROW("mat4.scale: invalid this");
|
||||
if(!m) return moduleBaseThrow("mat4.scale: invalid this");
|
||||
vec3 sv;
|
||||
if(!moduleVec3Check(args_p[0], sv)) {
|
||||
return JS_THROW("mat4.scale: argument must be a vec3");
|
||||
if(!moduleVec3Check(args[0], sv)) {
|
||||
return moduleBaseThrow("mat4.scale: argument must be a vec3");
|
||||
}
|
||||
float_t (*r)[4] = (float_t (*)[4])malloc(sizeof(mat4));
|
||||
glm_mat4_copy(m, r);
|
||||
@@ -151,7 +151,7 @@ JS_FUNC(moduleMatScale) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleMatIdentityMethod) {
|
||||
moduleBaseFunction(moduleMatIdentityMethod) {
|
||||
float_t (*r)[4] = (float_t (*)[4])malloc(sizeof(mat4));
|
||||
glm_mat4_identity(r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -167,7 +167,7 @@ JS_FUNC(moduleMatIdentityMethod) {
|
||||
/**
|
||||
* mat4Identity() - returns a new identity matrix.
|
||||
*/
|
||||
JS_FUNC(moduleMatIdentity) {
|
||||
moduleBaseFunction(moduleMatIdentity) {
|
||||
float_t (*r)[4] = (float_t (*)[4])malloc(sizeof(mat4));
|
||||
glm_mat4_identity(r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -180,16 +180,16 @@ JS_FUNC(moduleMatIdentity) {
|
||||
* mat4Perspective(fov, aspect, near, far) - returns a perspective projection
|
||||
* matrix.
|
||||
*/
|
||||
JS_FUNC(moduleMatPerspective) {
|
||||
JS_REQUIRE_ARGS(4);
|
||||
JS_REQUIRE_NUMBER(0);
|
||||
JS_REQUIRE_NUMBER(1);
|
||||
JS_REQUIRE_NUMBER(2);
|
||||
JS_REQUIRE_NUMBER(3);
|
||||
float_t fov = (float_t)jerry_value_as_number(args_p[0]);
|
||||
float_t aspect = (float_t)jerry_value_as_number(args_p[1]);
|
||||
float_t znear = (float_t)jerry_value_as_number(args_p[2]);
|
||||
float_t zfar = (float_t)jerry_value_as_number(args_p[3]);
|
||||
moduleBaseFunction(moduleMatPerspective) {
|
||||
moduleBaseRequireArgs(4);
|
||||
moduleBaseRequireNumber(0);
|
||||
moduleBaseRequireNumber(1);
|
||||
moduleBaseRequireNumber(2);
|
||||
moduleBaseRequireNumber(3);
|
||||
float_t fov = (float_t)jerry_value_as_number(args[0]);
|
||||
float_t aspect = (float_t)jerry_value_as_number(args[1]);
|
||||
float_t znear = (float_t)jerry_value_as_number(args[2]);
|
||||
float_t zfar = (float_t)jerry_value_as_number(args[3]);
|
||||
float_t (*r)[4] = (float_t (*)[4])malloc(sizeof(mat4));
|
||||
glm_perspective(fov, aspect, znear, zfar, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -202,17 +202,17 @@ JS_FUNC(moduleMatPerspective) {
|
||||
* mat4LookAt(eye, center, up) - returns a view matrix.
|
||||
* eye, center, up are vec3 objects.
|
||||
*/
|
||||
JS_FUNC(moduleMatLookAt) {
|
||||
JS_REQUIRE_ARGS(3);
|
||||
moduleBaseFunction(moduleMatLookAt) {
|
||||
moduleBaseRequireArgs(3);
|
||||
vec3 eye, center, up;
|
||||
if(!moduleVec3Check(args_p[0], eye)) {
|
||||
return JS_THROW("mat4LookAt: first argument (eye) must be a vec3");
|
||||
if(!moduleVec3Check(args[0], eye)) {
|
||||
return moduleBaseThrow("mat4LookAt: first argument (eye) must be a vec3");
|
||||
}
|
||||
if(!moduleVec3Check(args_p[1], center)) {
|
||||
return JS_THROW("mat4LookAt: second argument (center) must be a vec3");
|
||||
if(!moduleVec3Check(args[1], center)) {
|
||||
return moduleBaseThrow("mat4LookAt: second argument (center) must be a vec3");
|
||||
}
|
||||
if(!moduleVec3Check(args_p[2], up)) {
|
||||
return JS_THROW("mat4LookAt: third argument (up) must be a vec3");
|
||||
if(!moduleVec3Check(args[2], up)) {
|
||||
return moduleBaseThrow("mat4LookAt: third argument (up) must be a vec3");
|
||||
}
|
||||
float_t (*r)[4] = (float_t (*)[4])malloc(sizeof(mat4));
|
||||
glm_lookat(eye, center, up, r);
|
||||
@@ -272,17 +272,17 @@ static inline bool_t moduleMat4Check(jerry_value_t val, float (*out)[4]) {
|
||||
static void moduleMat4(void) {
|
||||
s_mat4Proto = jerry_object();
|
||||
|
||||
jsDefineMethod(s_mat4Proto, "mul", moduleMatMul);
|
||||
jsDefineMethod(s_mat4Proto, "transpose", moduleMatTranspose);
|
||||
jsDefineMethod(s_mat4Proto, "inverse", moduleMatInverse);
|
||||
jsDefineMethod(s_mat4Proto, "determinant", moduleMatDeterminant);
|
||||
jsDefineMethod(s_mat4Proto, "mulVec3", moduleMatMulVec3);
|
||||
jsDefineMethod(s_mat4Proto, "mulVec4", moduleMatMulVec4);
|
||||
jsDefineMethod(s_mat4Proto, "translate", moduleMatTranslate);
|
||||
jsDefineMethod(s_mat4Proto, "scale", moduleMatScale);
|
||||
jsDefineMethod(s_mat4Proto, "identity", moduleMatIdentityMethod);
|
||||
moduleBaseDefineMethod(s_mat4Proto, "mul", moduleMatMul);
|
||||
moduleBaseDefineMethod(s_mat4Proto, "transpose", moduleMatTranspose);
|
||||
moduleBaseDefineMethod(s_mat4Proto, "inverse", moduleMatInverse);
|
||||
moduleBaseDefineMethod(s_mat4Proto, "determinant", moduleMatDeterminant);
|
||||
moduleBaseDefineMethod(s_mat4Proto, "mulVec3", moduleMatMulVec3);
|
||||
moduleBaseDefineMethod(s_mat4Proto, "mulVec4", moduleMatMulVec4);
|
||||
moduleBaseDefineMethod(s_mat4Proto, "translate", moduleMatTranslate);
|
||||
moduleBaseDefineMethod(s_mat4Proto, "scale", moduleMatScale);
|
||||
moduleBaseDefineMethod(s_mat4Proto, "identity", moduleMatIdentityMethod);
|
||||
|
||||
jsRegister("mat4Identity", moduleMatIdentity);
|
||||
jsRegister("mat4Perspective", moduleMatPerspective);
|
||||
jsRegister("mat4LookAt", moduleMatLookAt);
|
||||
moduleBaseFunctionRegister("mat4Identity", moduleMatIdentity);
|
||||
moduleBaseFunctionRegister("mat4Perspective", moduleMatPerspective);
|
||||
moduleBaseFunctionRegister("mat4LookAt", moduleMatLookAt);
|
||||
}
|
||||
|
||||
@@ -26,31 +26,31 @@ static jerry_value_t s_vec2Proto = 0;
|
||||
// Property getters / setters
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
JS_FUNC(moduleVec2GetX) {
|
||||
moduleBaseFunction(moduleVec2GetX) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC2_NATIVE_INFO
|
||||
callInfo->this_value, &VEC2_NATIVE_INFO
|
||||
);
|
||||
return v ? jerry_number(v[0]) : jerry_undefined();
|
||||
}
|
||||
JS_FUNC(moduleVec2SetX) {
|
||||
moduleBaseFunction(moduleVec2SetX) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC2_NATIVE_INFO
|
||||
callInfo->this_value, &VEC2_NATIVE_INFO
|
||||
);
|
||||
if(v && args_count > 0) v[0] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
if(v && argc > 0) v[0] = (float_t)jerry_value_as_number(args[0]);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec2GetY) {
|
||||
moduleBaseFunction(moduleVec2GetY) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC2_NATIVE_INFO
|
||||
callInfo->this_value, &VEC2_NATIVE_INFO
|
||||
);
|
||||
return v ? jerry_number(v[1]) : jerry_undefined();
|
||||
}
|
||||
JS_FUNC(moduleVec2SetY) {
|
||||
moduleBaseFunction(moduleVec2SetY) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC2_NATIVE_INFO
|
||||
callInfo->this_value, &VEC2_NATIVE_INFO
|
||||
);
|
||||
if(v && args_count > 0) v[1] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
if(v && argc > 0) v[1] = (float_t)jerry_value_as_number(args[0]);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
@@ -58,38 +58,38 @@ JS_FUNC(moduleVec2SetY) {
|
||||
// Methods
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
JS_FUNC(moduleVec2Dot) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
moduleBaseFunction(moduleVec2Dot) {
|
||||
moduleBaseRequireArgs(1);
|
||||
float_t *a = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC2_NATIVE_INFO
|
||||
callInfo->this_value, &VEC2_NATIVE_INFO
|
||||
);
|
||||
if(!a) return JS_THROW("vec2.dot: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args_p[0], &VEC2_NATIVE_INFO);
|
||||
if(!b) return JS_THROW("vec2.dot: argument must be a vec2");
|
||||
if(!a) return moduleBaseThrow("vec2.dot: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args[0], &VEC2_NATIVE_INFO);
|
||||
if(!b) return moduleBaseThrow("vec2.dot: argument must be a vec2");
|
||||
return jerry_number(glm_vec2_dot(a, b));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec2Length) {
|
||||
moduleBaseFunction(moduleVec2Length) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC2_NATIVE_INFO
|
||||
callInfo->this_value, &VEC2_NATIVE_INFO
|
||||
);
|
||||
if(!v) return JS_THROW("vec2.length: invalid this");
|
||||
if(!v) return moduleBaseThrow("vec2.length: invalid this");
|
||||
return jerry_number(glm_vec2_norm(v));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec2LengthSq) {
|
||||
moduleBaseFunction(moduleVec2LengthSq) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC2_NATIVE_INFO
|
||||
callInfo->this_value, &VEC2_NATIVE_INFO
|
||||
);
|
||||
if(!v) return JS_THROW("vec2.lengthSq: invalid this");
|
||||
if(!v) return moduleBaseThrow("vec2.lengthSq: invalid this");
|
||||
return jerry_number(glm_vec2_norm2(v));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec2Normalize) {
|
||||
moduleBaseFunction(moduleVec2Normalize) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC2_NATIVE_INFO
|
||||
callInfo->this_value, &VEC2_NATIVE_INFO
|
||||
);
|
||||
if(!v) return JS_THROW("vec2.normalize: invalid this");
|
||||
if(!v) return moduleBaseThrow("vec2.normalize: invalid this");
|
||||
float_t *r = (float_t *)malloc(sizeof(vec2));
|
||||
glm_vec2_normalize_to(v, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -98,11 +98,11 @@ JS_FUNC(moduleVec2Normalize) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec2Negate) {
|
||||
moduleBaseFunction(moduleVec2Negate) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC2_NATIVE_INFO
|
||||
callInfo->this_value, &VEC2_NATIVE_INFO
|
||||
);
|
||||
if(!v) return JS_THROW("vec2.negate: invalid this");
|
||||
if(!v) return moduleBaseThrow("vec2.negate: invalid this");
|
||||
float_t *r = (float_t *)malloc(sizeof(vec2));
|
||||
glm_vec2_negate_to(v, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -111,14 +111,14 @@ JS_FUNC(moduleVec2Negate) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec2Add) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
moduleBaseFunction(moduleVec2Add) {
|
||||
moduleBaseRequireArgs(1);
|
||||
float_t *a = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC2_NATIVE_INFO
|
||||
callInfo->this_value, &VEC2_NATIVE_INFO
|
||||
);
|
||||
if(!a) return JS_THROW("vec2.add: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args_p[0], &VEC2_NATIVE_INFO);
|
||||
if(!b) return JS_THROW("vec2.add: argument must be a vec2");
|
||||
if(!a) return moduleBaseThrow("vec2.add: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args[0], &VEC2_NATIVE_INFO);
|
||||
if(!b) return moduleBaseThrow("vec2.add: argument must be a vec2");
|
||||
float_t *r = (float_t *)malloc(sizeof(vec2));
|
||||
glm_vec2_add(a, b, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -127,14 +127,14 @@ JS_FUNC(moduleVec2Add) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec2Sub) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
moduleBaseFunction(moduleVec2Sub) {
|
||||
moduleBaseRequireArgs(1);
|
||||
float_t *a = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC2_NATIVE_INFO
|
||||
callInfo->this_value, &VEC2_NATIVE_INFO
|
||||
);
|
||||
if(!a) return JS_THROW("vec2.sub: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args_p[0], &VEC2_NATIVE_INFO);
|
||||
if(!b) return JS_THROW("vec2.sub: argument must be a vec2");
|
||||
if(!a) return moduleBaseThrow("vec2.sub: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args[0], &VEC2_NATIVE_INFO);
|
||||
if(!b) return moduleBaseThrow("vec2.sub: argument must be a vec2");
|
||||
float_t *r = (float_t *)malloc(sizeof(vec2));
|
||||
glm_vec2_sub(a, b, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -143,14 +143,14 @@ JS_FUNC(moduleVec2Sub) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec2Scale) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
JS_REQUIRE_NUMBER(0);
|
||||
moduleBaseFunction(moduleVec2Scale) {
|
||||
moduleBaseRequireArgs(1);
|
||||
moduleBaseRequireNumber(0);
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC2_NATIVE_INFO
|
||||
callInfo->this_value, &VEC2_NATIVE_INFO
|
||||
);
|
||||
if(!v) return JS_THROW("vec2.scale: invalid this");
|
||||
float_t s = (float_t)jerry_value_as_number(args_p[0]);
|
||||
if(!v) return moduleBaseThrow("vec2.scale: invalid this");
|
||||
float_t s = (float_t)jerry_value_as_number(args[0]);
|
||||
float_t *r = (float_t *)malloc(sizeof(vec2));
|
||||
glm_vec2_scale(v, s, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -159,16 +159,16 @@ JS_FUNC(moduleVec2Scale) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec2Lerp) {
|
||||
JS_REQUIRE_ARGS(2);
|
||||
JS_REQUIRE_NUMBER(1);
|
||||
moduleBaseFunction(moduleVec2Lerp) {
|
||||
moduleBaseRequireArgs(2);
|
||||
moduleBaseRequireNumber(1);
|
||||
float_t *a = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC2_NATIVE_INFO
|
||||
callInfo->this_value, &VEC2_NATIVE_INFO
|
||||
);
|
||||
if(!a) return JS_THROW("vec2.lerp: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args_p[0], &VEC2_NATIVE_INFO);
|
||||
if(!b) return JS_THROW("vec2.lerp: first argument must be a vec2");
|
||||
float_t t = (float_t)jerry_value_as_number(args_p[1]);
|
||||
if(!a) return moduleBaseThrow("vec2.lerp: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args[0], &VEC2_NATIVE_INFO);
|
||||
if(!b) return moduleBaseThrow("vec2.lerp: first argument must be a vec2");
|
||||
float_t t = (float_t)jerry_value_as_number(args[1]);
|
||||
float_t *r = (float_t *)malloc(sizeof(vec2));
|
||||
glm_vec2_lerp(a, b, t, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -177,14 +177,14 @@ JS_FUNC(moduleVec2Lerp) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec2Distance) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
moduleBaseFunction(moduleVec2Distance) {
|
||||
moduleBaseRequireArgs(1);
|
||||
float_t *a = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC2_NATIVE_INFO
|
||||
callInfo->this_value, &VEC2_NATIVE_INFO
|
||||
);
|
||||
if(!a) return JS_THROW("vec2.distance: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args_p[0], &VEC2_NATIVE_INFO);
|
||||
if(!b) return JS_THROW("vec2.distance: argument must be a vec2");
|
||||
if(!a) return moduleBaseThrow("vec2.distance: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args[0], &VEC2_NATIVE_INFO);
|
||||
if(!b) return moduleBaseThrow("vec2.distance: argument must be a vec2");
|
||||
return jerry_number(glm_vec2_distance(a, b));
|
||||
}
|
||||
|
||||
@@ -192,13 +192,13 @@ JS_FUNC(moduleVec2Distance) {
|
||||
// Constructor
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
JS_FUNC(moduleVec2Create) {
|
||||
JS_REQUIRE_ARGS(2);
|
||||
JS_REQUIRE_NUMBER(0);
|
||||
JS_REQUIRE_NUMBER(1);
|
||||
moduleBaseFunction(moduleVec2Create) {
|
||||
moduleBaseRequireArgs(2);
|
||||
moduleBaseRequireNumber(0);
|
||||
moduleBaseRequireNumber(1);
|
||||
float_t *v = (float_t *)malloc(sizeof(vec2));
|
||||
v[0] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
v[1] = (float_t)jerry_value_as_number(args_p[1]);
|
||||
v[0] = (float_t)jerry_value_as_number(args[0]);
|
||||
v[1] = (float_t)jerry_value_as_number(args[1]);
|
||||
jerry_value_t obj = jerry_object();
|
||||
jerry_object_set_native_ptr(obj, &VEC2_NATIVE_INFO, v);
|
||||
jerry_object_set_proto(obj, s_vec2Proto);
|
||||
@@ -255,19 +255,19 @@ static inline bool_t moduleVec2Check(jerry_value_t val, float_t *out) {
|
||||
static void moduleVec2(void) {
|
||||
s_vec2Proto = jerry_object();
|
||||
|
||||
jsDefineProperty(s_vec2Proto, "x", moduleVec2GetX, moduleVec2SetX);
|
||||
jsDefineProperty(s_vec2Proto, "y", moduleVec2GetY, moduleVec2SetY);
|
||||
moduleBaseDefineProperty(s_vec2Proto, "x", moduleVec2GetX, moduleVec2SetX);
|
||||
moduleBaseDefineProperty(s_vec2Proto, "y", moduleVec2GetY, moduleVec2SetY);
|
||||
|
||||
jsDefineMethod(s_vec2Proto, "dot", moduleVec2Dot);
|
||||
jsDefineMethod(s_vec2Proto, "length", moduleVec2Length);
|
||||
jsDefineMethod(s_vec2Proto, "lengthSq", moduleVec2LengthSq);
|
||||
jsDefineMethod(s_vec2Proto, "normalize", moduleVec2Normalize);
|
||||
jsDefineMethod(s_vec2Proto, "negate", moduleVec2Negate);
|
||||
jsDefineMethod(s_vec2Proto, "add", moduleVec2Add);
|
||||
jsDefineMethod(s_vec2Proto, "sub", moduleVec2Sub);
|
||||
jsDefineMethod(s_vec2Proto, "scale", moduleVec2Scale);
|
||||
jsDefineMethod(s_vec2Proto, "lerp", moduleVec2Lerp);
|
||||
jsDefineMethod(s_vec2Proto, "distance", moduleVec2Distance);
|
||||
moduleBaseDefineMethod(s_vec2Proto, "dot", moduleVec2Dot);
|
||||
moduleBaseDefineMethod(s_vec2Proto, "length", moduleVec2Length);
|
||||
moduleBaseDefineMethod(s_vec2Proto, "lengthSq", moduleVec2LengthSq);
|
||||
moduleBaseDefineMethod(s_vec2Proto, "normalize", moduleVec2Normalize);
|
||||
moduleBaseDefineMethod(s_vec2Proto, "negate", moduleVec2Negate);
|
||||
moduleBaseDefineMethod(s_vec2Proto, "add", moduleVec2Add);
|
||||
moduleBaseDefineMethod(s_vec2Proto, "sub", moduleVec2Sub);
|
||||
moduleBaseDefineMethod(s_vec2Proto, "scale", moduleVec2Scale);
|
||||
moduleBaseDefineMethod(s_vec2Proto, "lerp", moduleVec2Lerp);
|
||||
moduleBaseDefineMethod(s_vec2Proto, "distance", moduleVec2Distance);
|
||||
|
||||
jsRegister("vec2", moduleVec2Create);
|
||||
moduleBaseFunctionRegister("vec2", moduleVec2Create);
|
||||
}
|
||||
|
||||
@@ -26,45 +26,45 @@ static jerry_value_t s_vec3Proto = 0;
|
||||
// Property getters / setters
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
JS_FUNC(moduleVec3GetX) {
|
||||
moduleBaseFunction(moduleVec3GetX) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC3_NATIVE_INFO
|
||||
callInfo->this_value, &VEC3_NATIVE_INFO
|
||||
);
|
||||
return v ? jerry_number(v[0]) : jerry_undefined();
|
||||
}
|
||||
JS_FUNC(moduleVec3SetX) {
|
||||
moduleBaseFunction(moduleVec3SetX) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC3_NATIVE_INFO
|
||||
callInfo->this_value, &VEC3_NATIVE_INFO
|
||||
);
|
||||
if(v && args_count > 0) v[0] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
if(v && argc > 0) v[0] = (float_t)jerry_value_as_number(args[0]);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec3GetY) {
|
||||
moduleBaseFunction(moduleVec3GetY) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC3_NATIVE_INFO
|
||||
callInfo->this_value, &VEC3_NATIVE_INFO
|
||||
);
|
||||
return v ? jerry_number(v[1]) : jerry_undefined();
|
||||
}
|
||||
JS_FUNC(moduleVec3SetY) {
|
||||
moduleBaseFunction(moduleVec3SetY) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC3_NATIVE_INFO
|
||||
callInfo->this_value, &VEC3_NATIVE_INFO
|
||||
);
|
||||
if(v && args_count > 0) v[1] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
if(v && argc > 0) v[1] = (float_t)jerry_value_as_number(args[0]);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec3GetZ) {
|
||||
moduleBaseFunction(moduleVec3GetZ) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC3_NATIVE_INFO
|
||||
callInfo->this_value, &VEC3_NATIVE_INFO
|
||||
);
|
||||
return v ? jerry_number(v[2]) : jerry_undefined();
|
||||
}
|
||||
JS_FUNC(moduleVec3SetZ) {
|
||||
moduleBaseFunction(moduleVec3SetZ) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC3_NATIVE_INFO
|
||||
callInfo->this_value, &VEC3_NATIVE_INFO
|
||||
);
|
||||
if(v && args_count > 0) v[2] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
if(v && argc > 0) v[2] = (float_t)jerry_value_as_number(args[0]);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
@@ -72,25 +72,25 @@ JS_FUNC(moduleVec3SetZ) {
|
||||
// Methods
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
JS_FUNC(moduleVec3Dot) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
moduleBaseFunction(moduleVec3Dot) {
|
||||
moduleBaseRequireArgs(1);
|
||||
float_t *a = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC3_NATIVE_INFO
|
||||
callInfo->this_value, &VEC3_NATIVE_INFO
|
||||
);
|
||||
if(!a) return JS_THROW("vec3.dot: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args_p[0], &VEC3_NATIVE_INFO);
|
||||
if(!b) return JS_THROW("vec3.dot: argument must be a vec3");
|
||||
if(!a) return moduleBaseThrow("vec3.dot: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args[0], &VEC3_NATIVE_INFO);
|
||||
if(!b) return moduleBaseThrow("vec3.dot: argument must be a vec3");
|
||||
return jerry_number(glm_vec3_dot(a, b));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec3Cross) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
moduleBaseFunction(moduleVec3Cross) {
|
||||
moduleBaseRequireArgs(1);
|
||||
float_t *a = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC3_NATIVE_INFO
|
||||
callInfo->this_value, &VEC3_NATIVE_INFO
|
||||
);
|
||||
if(!a) return JS_THROW("vec3.cross: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args_p[0], &VEC3_NATIVE_INFO);
|
||||
if(!b) return JS_THROW("vec3.cross: argument must be a vec3");
|
||||
if(!a) return moduleBaseThrow("vec3.cross: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args[0], &VEC3_NATIVE_INFO);
|
||||
if(!b) return moduleBaseThrow("vec3.cross: argument must be a vec3");
|
||||
float_t *r = (float_t *)malloc(sizeof(vec3));
|
||||
glm_vec3_cross(a, b, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -99,27 +99,27 @@ JS_FUNC(moduleVec3Cross) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec3Length) {
|
||||
moduleBaseFunction(moduleVec3Length) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC3_NATIVE_INFO
|
||||
callInfo->this_value, &VEC3_NATIVE_INFO
|
||||
);
|
||||
if(!v) return JS_THROW("vec3.length: invalid this");
|
||||
if(!v) return moduleBaseThrow("vec3.length: invalid this");
|
||||
return jerry_number(glm_vec3_norm(v));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec3LengthSq) {
|
||||
moduleBaseFunction(moduleVec3LengthSq) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC3_NATIVE_INFO
|
||||
callInfo->this_value, &VEC3_NATIVE_INFO
|
||||
);
|
||||
if(!v) return JS_THROW("vec3.lengthSq: invalid this");
|
||||
if(!v) return moduleBaseThrow("vec3.lengthSq: invalid this");
|
||||
return jerry_number(glm_vec3_norm2(v));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec3Normalize) {
|
||||
moduleBaseFunction(moduleVec3Normalize) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC3_NATIVE_INFO
|
||||
callInfo->this_value, &VEC3_NATIVE_INFO
|
||||
);
|
||||
if(!v) return JS_THROW("vec3.normalize: invalid this");
|
||||
if(!v) return moduleBaseThrow("vec3.normalize: invalid this");
|
||||
float_t *r = (float_t *)malloc(sizeof(vec3));
|
||||
glm_vec3_normalize_to(v, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -128,11 +128,11 @@ JS_FUNC(moduleVec3Normalize) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec3Negate) {
|
||||
moduleBaseFunction(moduleVec3Negate) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC3_NATIVE_INFO
|
||||
callInfo->this_value, &VEC3_NATIVE_INFO
|
||||
);
|
||||
if(!v) return JS_THROW("vec3.negate: invalid this");
|
||||
if(!v) return moduleBaseThrow("vec3.negate: invalid this");
|
||||
float_t *r = (float_t *)malloc(sizeof(vec3));
|
||||
glm_vec3_negate_to(v, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -141,14 +141,14 @@ JS_FUNC(moduleVec3Negate) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec3Add) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
moduleBaseFunction(moduleVec3Add) {
|
||||
moduleBaseRequireArgs(1);
|
||||
float_t *a = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC3_NATIVE_INFO
|
||||
callInfo->this_value, &VEC3_NATIVE_INFO
|
||||
);
|
||||
if(!a) return JS_THROW("vec3.add: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args_p[0], &VEC3_NATIVE_INFO);
|
||||
if(!b) return JS_THROW("vec3.add: argument must be a vec3");
|
||||
if(!a) return moduleBaseThrow("vec3.add: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args[0], &VEC3_NATIVE_INFO);
|
||||
if(!b) return moduleBaseThrow("vec3.add: argument must be a vec3");
|
||||
float_t *r = (float_t *)malloc(sizeof(vec3));
|
||||
glm_vec3_add(a, b, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -157,14 +157,14 @@ JS_FUNC(moduleVec3Add) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec3Sub) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
moduleBaseFunction(moduleVec3Sub) {
|
||||
moduleBaseRequireArgs(1);
|
||||
float_t *a = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC3_NATIVE_INFO
|
||||
callInfo->this_value, &VEC3_NATIVE_INFO
|
||||
);
|
||||
if(!a) return JS_THROW("vec3.sub: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args_p[0], &VEC3_NATIVE_INFO);
|
||||
if(!b) return JS_THROW("vec3.sub: argument must be a vec3");
|
||||
if(!a) return moduleBaseThrow("vec3.sub: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args[0], &VEC3_NATIVE_INFO);
|
||||
if(!b) return moduleBaseThrow("vec3.sub: argument must be a vec3");
|
||||
float_t *r = (float_t *)malloc(sizeof(vec3));
|
||||
glm_vec3_sub(a, b, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -173,14 +173,14 @@ JS_FUNC(moduleVec3Sub) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec3Scale) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
JS_REQUIRE_NUMBER(0);
|
||||
moduleBaseFunction(moduleVec3Scale) {
|
||||
moduleBaseRequireArgs(1);
|
||||
moduleBaseRequireNumber(0);
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC3_NATIVE_INFO
|
||||
callInfo->this_value, &VEC3_NATIVE_INFO
|
||||
);
|
||||
if(!v) return JS_THROW("vec3.scale: invalid this");
|
||||
float_t s = (float_t)jerry_value_as_number(args_p[0]);
|
||||
if(!v) return moduleBaseThrow("vec3.scale: invalid this");
|
||||
float_t s = (float_t)jerry_value_as_number(args[0]);
|
||||
float_t *r = (float_t *)malloc(sizeof(vec3));
|
||||
glm_vec3_scale(v, s, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -189,16 +189,16 @@ JS_FUNC(moduleVec3Scale) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec3Lerp) {
|
||||
JS_REQUIRE_ARGS(2);
|
||||
JS_REQUIRE_NUMBER(1);
|
||||
moduleBaseFunction(moduleVec3Lerp) {
|
||||
moduleBaseRequireArgs(2);
|
||||
moduleBaseRequireNumber(1);
|
||||
float_t *a = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC3_NATIVE_INFO
|
||||
callInfo->this_value, &VEC3_NATIVE_INFO
|
||||
);
|
||||
if(!a) return JS_THROW("vec3.lerp: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args_p[0], &VEC3_NATIVE_INFO);
|
||||
if(!b) return JS_THROW("vec3.lerp: first argument must be a vec3");
|
||||
float_t t = (float_t)jerry_value_as_number(args_p[1]);
|
||||
if(!a) return moduleBaseThrow("vec3.lerp: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args[0], &VEC3_NATIVE_INFO);
|
||||
if(!b) return moduleBaseThrow("vec3.lerp: first argument must be a vec3");
|
||||
float_t t = (float_t)jerry_value_as_number(args[1]);
|
||||
float_t *r = (float_t *)malloc(sizeof(vec3));
|
||||
glm_vec3_lerp(a, b, t, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -207,14 +207,14 @@ JS_FUNC(moduleVec3Lerp) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec3Distance) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
moduleBaseFunction(moduleVec3Distance) {
|
||||
moduleBaseRequireArgs(1);
|
||||
float_t *a = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC3_NATIVE_INFO
|
||||
callInfo->this_value, &VEC3_NATIVE_INFO
|
||||
);
|
||||
if(!a) return JS_THROW("vec3.distance: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args_p[0], &VEC3_NATIVE_INFO);
|
||||
if(!b) return JS_THROW("vec3.distance: argument must be a vec3");
|
||||
if(!a) return moduleBaseThrow("vec3.distance: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args[0], &VEC3_NATIVE_INFO);
|
||||
if(!b) return moduleBaseThrow("vec3.distance: argument must be a vec3");
|
||||
return jerry_number(glm_vec3_distance(a, b));
|
||||
}
|
||||
|
||||
@@ -222,15 +222,15 @@ JS_FUNC(moduleVec3Distance) {
|
||||
// Constructor
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
JS_FUNC(moduleVec3Create) {
|
||||
JS_REQUIRE_ARGS(3);
|
||||
JS_REQUIRE_NUMBER(0);
|
||||
JS_REQUIRE_NUMBER(1);
|
||||
JS_REQUIRE_NUMBER(2);
|
||||
moduleBaseFunction(moduleVec3Create) {
|
||||
moduleBaseRequireArgs(3);
|
||||
moduleBaseRequireNumber(0);
|
||||
moduleBaseRequireNumber(1);
|
||||
moduleBaseRequireNumber(2);
|
||||
float_t *v = (float_t *)malloc(sizeof(vec3));
|
||||
v[0] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
v[1] = (float_t)jerry_value_as_number(args_p[1]);
|
||||
v[2] = (float_t)jerry_value_as_number(args_p[2]);
|
||||
v[0] = (float_t)jerry_value_as_number(args[0]);
|
||||
v[1] = (float_t)jerry_value_as_number(args[1]);
|
||||
v[2] = (float_t)jerry_value_as_number(args[2]);
|
||||
jerry_value_t obj = jerry_object();
|
||||
jerry_object_set_native_ptr(obj, &VEC3_NATIVE_INFO, v);
|
||||
jerry_object_set_proto(obj, s_vec3Proto);
|
||||
@@ -289,21 +289,21 @@ static inline bool_t moduleVec3Check(jerry_value_t val, float_t *out) {
|
||||
static void moduleVec3(void) {
|
||||
s_vec3Proto = jerry_object();
|
||||
|
||||
jsDefineProperty(s_vec3Proto, "x", moduleVec3GetX, moduleVec3SetX);
|
||||
jsDefineProperty(s_vec3Proto, "y", moduleVec3GetY, moduleVec3SetY);
|
||||
jsDefineProperty(s_vec3Proto, "z", moduleVec3GetZ, moduleVec3SetZ);
|
||||
moduleBaseDefineProperty(s_vec3Proto, "x", moduleVec3GetX, moduleVec3SetX);
|
||||
moduleBaseDefineProperty(s_vec3Proto, "y", moduleVec3GetY, moduleVec3SetY);
|
||||
moduleBaseDefineProperty(s_vec3Proto, "z", moduleVec3GetZ, moduleVec3SetZ);
|
||||
|
||||
jsDefineMethod(s_vec3Proto, "dot", moduleVec3Dot);
|
||||
jsDefineMethod(s_vec3Proto, "cross", moduleVec3Cross);
|
||||
jsDefineMethod(s_vec3Proto, "length", moduleVec3Length);
|
||||
jsDefineMethod(s_vec3Proto, "lengthSq", moduleVec3LengthSq);
|
||||
jsDefineMethod(s_vec3Proto, "normalize", moduleVec3Normalize);
|
||||
jsDefineMethod(s_vec3Proto, "negate", moduleVec3Negate);
|
||||
jsDefineMethod(s_vec3Proto, "add", moduleVec3Add);
|
||||
jsDefineMethod(s_vec3Proto, "sub", moduleVec3Sub);
|
||||
jsDefineMethod(s_vec3Proto, "scale", moduleVec3Scale);
|
||||
jsDefineMethod(s_vec3Proto, "lerp", moduleVec3Lerp);
|
||||
jsDefineMethod(s_vec3Proto, "distance", moduleVec3Distance);
|
||||
moduleBaseDefineMethod(s_vec3Proto, "dot", moduleVec3Dot);
|
||||
moduleBaseDefineMethod(s_vec3Proto, "cross", moduleVec3Cross);
|
||||
moduleBaseDefineMethod(s_vec3Proto, "length", moduleVec3Length);
|
||||
moduleBaseDefineMethod(s_vec3Proto, "lengthSq", moduleVec3LengthSq);
|
||||
moduleBaseDefineMethod(s_vec3Proto, "normalize", moduleVec3Normalize);
|
||||
moduleBaseDefineMethod(s_vec3Proto, "negate", moduleVec3Negate);
|
||||
moduleBaseDefineMethod(s_vec3Proto, "add", moduleVec3Add);
|
||||
moduleBaseDefineMethod(s_vec3Proto, "sub", moduleVec3Sub);
|
||||
moduleBaseDefineMethod(s_vec3Proto, "scale", moduleVec3Scale);
|
||||
moduleBaseDefineMethod(s_vec3Proto, "lerp", moduleVec3Lerp);
|
||||
moduleBaseDefineMethod(s_vec3Proto, "distance", moduleVec3Distance);
|
||||
|
||||
jsRegister("vec3", moduleVec3Create);
|
||||
moduleBaseFunctionRegister("vec3", moduleVec3Create);
|
||||
}
|
||||
|
||||
@@ -26,116 +26,116 @@ static jerry_value_t s_vec4Proto = 0;
|
||||
// Property getters / setters (x/u0, y/v0, z/u1, w/v1)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
JS_FUNC(moduleVec4GetX) {
|
||||
moduleBaseFunction(moduleVec4GetX) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
return v ? jerry_number(v[0]) : jerry_undefined();
|
||||
}
|
||||
JS_FUNC(moduleVec4SetX) {
|
||||
moduleBaseFunction(moduleVec4SetX) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
if(v && args_count > 0) v[0] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
if(v && argc > 0) v[0] = (float_t)jerry_value_as_number(args[0]);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec4GetY) {
|
||||
moduleBaseFunction(moduleVec4GetY) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
return v ? jerry_number(v[1]) : jerry_undefined();
|
||||
}
|
||||
JS_FUNC(moduleVec4SetY) {
|
||||
moduleBaseFunction(moduleVec4SetY) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
if(v && args_count > 0) v[1] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
if(v && argc > 0) v[1] = (float_t)jerry_value_as_number(args[0]);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec4GetZ) {
|
||||
moduleBaseFunction(moduleVec4GetZ) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
return v ? jerry_number(v[2]) : jerry_undefined();
|
||||
}
|
||||
JS_FUNC(moduleVec4SetZ) {
|
||||
moduleBaseFunction(moduleVec4SetZ) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
if(v && args_count > 0) v[2] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
if(v && argc > 0) v[2] = (float_t)jerry_value_as_number(args[0]);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec4GetW) {
|
||||
moduleBaseFunction(moduleVec4GetW) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
return v ? jerry_number(v[3]) : jerry_undefined();
|
||||
}
|
||||
JS_FUNC(moduleVec4SetW) {
|
||||
moduleBaseFunction(moduleVec4SetW) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
if(v && args_count > 0) v[3] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
if(v && argc > 0) v[3] = (float_t)jerry_value_as_number(args[0]);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
// u0/v0/u1/v1 aliases share the same backing floats
|
||||
JS_FUNC(moduleVec4GetU0) {
|
||||
moduleBaseFunction(moduleVec4GetU0) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
return v ? jerry_number(v[0]) : jerry_undefined();
|
||||
}
|
||||
JS_FUNC(moduleVec4SetU0) {
|
||||
moduleBaseFunction(moduleVec4SetU0) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
if(v && args_count > 0) v[0] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
if(v && argc > 0) v[0] = (float_t)jerry_value_as_number(args[0]);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec4GetV0) {
|
||||
moduleBaseFunction(moduleVec4GetV0) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
return v ? jerry_number(v[1]) : jerry_undefined();
|
||||
}
|
||||
JS_FUNC(moduleVec4SetV0) {
|
||||
moduleBaseFunction(moduleVec4SetV0) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
if(v && args_count > 0) v[1] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
if(v && argc > 0) v[1] = (float_t)jerry_value_as_number(args[0]);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec4GetU1) {
|
||||
moduleBaseFunction(moduleVec4GetU1) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
return v ? jerry_number(v[2]) : jerry_undefined();
|
||||
}
|
||||
JS_FUNC(moduleVec4SetU1) {
|
||||
moduleBaseFunction(moduleVec4SetU1) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
if(v && args_count > 0) v[2] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
if(v && argc > 0) v[2] = (float_t)jerry_value_as_number(args[0]);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec4GetV1) {
|
||||
moduleBaseFunction(moduleVec4GetV1) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
return v ? jerry_number(v[3]) : jerry_undefined();
|
||||
}
|
||||
JS_FUNC(moduleVec4SetV1) {
|
||||
moduleBaseFunction(moduleVec4SetV1) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
if(v && args_count > 0) v[3] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
if(v && argc > 0) v[3] = (float_t)jerry_value_as_number(args[0]);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
@@ -143,38 +143,38 @@ JS_FUNC(moduleVec4SetV1) {
|
||||
// Methods
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
JS_FUNC(moduleVec4Dot) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
moduleBaseFunction(moduleVec4Dot) {
|
||||
moduleBaseRequireArgs(1);
|
||||
float_t *a = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
if(!a) return JS_THROW("vec4.dot: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args_p[0], &VEC4_NATIVE_INFO);
|
||||
if(!b) return JS_THROW("vec4.dot: argument must be a vec4");
|
||||
if(!a) return moduleBaseThrow("vec4.dot: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args[0], &VEC4_NATIVE_INFO);
|
||||
if(!b) return moduleBaseThrow("vec4.dot: argument must be a vec4");
|
||||
return jerry_number(glm_vec4_dot(a, b));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec4Length) {
|
||||
moduleBaseFunction(moduleVec4Length) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
if(!v) return JS_THROW("vec4.length: invalid this");
|
||||
if(!v) return moduleBaseThrow("vec4.length: invalid this");
|
||||
return jerry_number(glm_vec4_norm(v));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec4LengthSq) {
|
||||
moduleBaseFunction(moduleVec4LengthSq) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
if(!v) return JS_THROW("vec4.lengthSq: invalid this");
|
||||
if(!v) return moduleBaseThrow("vec4.lengthSq: invalid this");
|
||||
return jerry_number(glm_vec4_norm2(v));
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec4Normalize) {
|
||||
moduleBaseFunction(moduleVec4Normalize) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
if(!v) return JS_THROW("vec4.normalize: invalid this");
|
||||
if(!v) return moduleBaseThrow("vec4.normalize: invalid this");
|
||||
float_t *r = (float_t *)malloc(sizeof(vec4));
|
||||
glm_vec4_normalize_to(v, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -183,11 +183,11 @@ JS_FUNC(moduleVec4Normalize) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec4Negate) {
|
||||
moduleBaseFunction(moduleVec4Negate) {
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
if(!v) return JS_THROW("vec4.negate: invalid this");
|
||||
if(!v) return moduleBaseThrow("vec4.negate: invalid this");
|
||||
float_t *r = (float_t *)malloc(sizeof(vec4));
|
||||
glm_vec4_negate_to(v, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -196,14 +196,14 @@ JS_FUNC(moduleVec4Negate) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec4Add) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
moduleBaseFunction(moduleVec4Add) {
|
||||
moduleBaseRequireArgs(1);
|
||||
float_t *a = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
if(!a) return JS_THROW("vec4.add: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args_p[0], &VEC4_NATIVE_INFO);
|
||||
if(!b) return JS_THROW("vec4.add: argument must be a vec4");
|
||||
if(!a) return moduleBaseThrow("vec4.add: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args[0], &VEC4_NATIVE_INFO);
|
||||
if(!b) return moduleBaseThrow("vec4.add: argument must be a vec4");
|
||||
float_t *r = (float_t *)malloc(sizeof(vec4));
|
||||
glm_vec4_add(a, b, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -212,14 +212,14 @@ JS_FUNC(moduleVec4Add) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec4Sub) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
moduleBaseFunction(moduleVec4Sub) {
|
||||
moduleBaseRequireArgs(1);
|
||||
float_t *a = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
if(!a) return JS_THROW("vec4.sub: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args_p[0], &VEC4_NATIVE_INFO);
|
||||
if(!b) return JS_THROW("vec4.sub: argument must be a vec4");
|
||||
if(!a) return moduleBaseThrow("vec4.sub: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args[0], &VEC4_NATIVE_INFO);
|
||||
if(!b) return moduleBaseThrow("vec4.sub: argument must be a vec4");
|
||||
float_t *r = (float_t *)malloc(sizeof(vec4));
|
||||
glm_vec4_sub(a, b, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -228,14 +228,14 @@ JS_FUNC(moduleVec4Sub) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec4Scale) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
JS_REQUIRE_NUMBER(0);
|
||||
moduleBaseFunction(moduleVec4Scale) {
|
||||
moduleBaseRequireArgs(1);
|
||||
moduleBaseRequireNumber(0);
|
||||
float_t *v = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
if(!v) return JS_THROW("vec4.scale: invalid this");
|
||||
float_t s = (float_t)jerry_value_as_number(args_p[0]);
|
||||
if(!v) return moduleBaseThrow("vec4.scale: invalid this");
|
||||
float_t s = (float_t)jerry_value_as_number(args[0]);
|
||||
float_t *r = (float_t *)malloc(sizeof(vec4));
|
||||
glm_vec4_scale(v, s, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -244,16 +244,16 @@ JS_FUNC(moduleVec4Scale) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
JS_FUNC(moduleVec4Lerp) {
|
||||
JS_REQUIRE_ARGS(2);
|
||||
JS_REQUIRE_NUMBER(1);
|
||||
moduleBaseFunction(moduleVec4Lerp) {
|
||||
moduleBaseRequireArgs(2);
|
||||
moduleBaseRequireNumber(1);
|
||||
float_t *a = (float_t *)jerry_object_get_native_ptr(
|
||||
call_info_p->this_value, &VEC4_NATIVE_INFO
|
||||
callInfo->this_value, &VEC4_NATIVE_INFO
|
||||
);
|
||||
if(!a) return JS_THROW("vec4.lerp: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args_p[0], &VEC4_NATIVE_INFO);
|
||||
if(!b) return JS_THROW("vec4.lerp: first argument must be a vec4");
|
||||
float_t t = (float_t)jerry_value_as_number(args_p[1]);
|
||||
if(!a) return moduleBaseThrow("vec4.lerp: invalid this");
|
||||
float_t *b = (float_t *)jerry_object_get_native_ptr(args[0], &VEC4_NATIVE_INFO);
|
||||
if(!b) return moduleBaseThrow("vec4.lerp: first argument must be a vec4");
|
||||
float_t t = (float_t)jerry_value_as_number(args[1]);
|
||||
float_t *r = (float_t *)malloc(sizeof(vec4));
|
||||
glm_vec4_lerp(a, b, t, r);
|
||||
jerry_value_t obj = jerry_object();
|
||||
@@ -266,17 +266,17 @@ JS_FUNC(moduleVec4Lerp) {
|
||||
// Constructor
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
JS_FUNC(moduleVec4Create) {
|
||||
JS_REQUIRE_ARGS(4);
|
||||
JS_REQUIRE_NUMBER(0);
|
||||
JS_REQUIRE_NUMBER(1);
|
||||
JS_REQUIRE_NUMBER(2);
|
||||
JS_REQUIRE_NUMBER(3);
|
||||
moduleBaseFunction(moduleVec4Create) {
|
||||
moduleBaseRequireArgs(4);
|
||||
moduleBaseRequireNumber(0);
|
||||
moduleBaseRequireNumber(1);
|
||||
moduleBaseRequireNumber(2);
|
||||
moduleBaseRequireNumber(3);
|
||||
float_t *v = (float_t *)malloc(sizeof(vec4));
|
||||
v[0] = (float_t)jerry_value_as_number(args_p[0]);
|
||||
v[1] = (float_t)jerry_value_as_number(args_p[1]);
|
||||
v[2] = (float_t)jerry_value_as_number(args_p[2]);
|
||||
v[3] = (float_t)jerry_value_as_number(args_p[3]);
|
||||
v[0] = (float_t)jerry_value_as_number(args[0]);
|
||||
v[1] = (float_t)jerry_value_as_number(args[1]);
|
||||
v[2] = (float_t)jerry_value_as_number(args[2]);
|
||||
v[3] = (float_t)jerry_value_as_number(args[3]);
|
||||
jerry_value_t obj = jerry_object();
|
||||
jerry_object_set_native_ptr(obj, &VEC4_NATIVE_INFO, v);
|
||||
jerry_object_set_proto(obj, s_vec4Proto);
|
||||
@@ -339,26 +339,26 @@ static void moduleVec4(void) {
|
||||
s_vec4Proto = jerry_object();
|
||||
|
||||
// Primary component names
|
||||
jsDefineProperty(s_vec4Proto, "x", moduleVec4GetX, moduleVec4SetX);
|
||||
jsDefineProperty(s_vec4Proto, "y", moduleVec4GetY, moduleVec4SetY);
|
||||
jsDefineProperty(s_vec4Proto, "z", moduleVec4GetZ, moduleVec4SetZ);
|
||||
jsDefineProperty(s_vec4Proto, "w", moduleVec4GetW, moduleVec4SetW);
|
||||
moduleBaseDefineProperty(s_vec4Proto, "x", moduleVec4GetX, moduleVec4SetX);
|
||||
moduleBaseDefineProperty(s_vec4Proto, "y", moduleVec4GetY, moduleVec4SetY);
|
||||
moduleBaseDefineProperty(s_vec4Proto, "z", moduleVec4GetZ, moduleVec4SetZ);
|
||||
moduleBaseDefineProperty(s_vec4Proto, "w", moduleVec4GetW, moduleVec4SetW);
|
||||
|
||||
// UV alias names (same backing components)
|
||||
jsDefineProperty(s_vec4Proto, "u0", moduleVec4GetU0, moduleVec4SetU0);
|
||||
jsDefineProperty(s_vec4Proto, "v0", moduleVec4GetV0, moduleVec4SetV0);
|
||||
jsDefineProperty(s_vec4Proto, "u1", moduleVec4GetU1, moduleVec4SetU1);
|
||||
jsDefineProperty(s_vec4Proto, "v1", moduleVec4GetV1, moduleVec4SetV1);
|
||||
moduleBaseDefineProperty(s_vec4Proto, "u0", moduleVec4GetU0, moduleVec4SetU0);
|
||||
moduleBaseDefineProperty(s_vec4Proto, "v0", moduleVec4GetV0, moduleVec4SetV0);
|
||||
moduleBaseDefineProperty(s_vec4Proto, "u1", moduleVec4GetU1, moduleVec4SetU1);
|
||||
moduleBaseDefineProperty(s_vec4Proto, "v1", moduleVec4GetV1, moduleVec4SetV1);
|
||||
|
||||
jsDefineMethod(s_vec4Proto, "dot", moduleVec4Dot);
|
||||
jsDefineMethod(s_vec4Proto, "length", moduleVec4Length);
|
||||
jsDefineMethod(s_vec4Proto, "lengthSq", moduleVec4LengthSq);
|
||||
jsDefineMethod(s_vec4Proto, "normalize", moduleVec4Normalize);
|
||||
jsDefineMethod(s_vec4Proto, "negate", moduleVec4Negate);
|
||||
jsDefineMethod(s_vec4Proto, "add", moduleVec4Add);
|
||||
jsDefineMethod(s_vec4Proto, "sub", moduleVec4Sub);
|
||||
jsDefineMethod(s_vec4Proto, "scale", moduleVec4Scale);
|
||||
jsDefineMethod(s_vec4Proto, "lerp", moduleVec4Lerp);
|
||||
moduleBaseDefineMethod(s_vec4Proto, "dot", moduleVec4Dot);
|
||||
moduleBaseDefineMethod(s_vec4Proto, "length", moduleVec4Length);
|
||||
moduleBaseDefineMethod(s_vec4Proto, "lengthSq", moduleVec4LengthSq);
|
||||
moduleBaseDefineMethod(s_vec4Proto, "normalize", moduleVec4Normalize);
|
||||
moduleBaseDefineMethod(s_vec4Proto, "negate", moduleVec4Negate);
|
||||
moduleBaseDefineMethod(s_vec4Proto, "add", moduleVec4Add);
|
||||
moduleBaseDefineMethod(s_vec4Proto, "sub", moduleVec4Sub);
|
||||
moduleBaseDefineMethod(s_vec4Proto, "scale", moduleVec4Scale);
|
||||
moduleBaseDefineMethod(s_vec4Proto, "lerp", moduleVec4Lerp);
|
||||
|
||||
jsRegister("vec4", moduleVec4Create);
|
||||
moduleBaseFunctionRegister("vec4", moduleVec4Create);
|
||||
}
|
||||
|
||||
@@ -10,18 +10,10 @@
|
||||
#include "script/module/entity/moduleentity.h"
|
||||
#include "script/module/input/moduleinput.h"
|
||||
#include "script/module/moduleplatform.h"
|
||||
#include "script/module/locale/modulelocale.h"
|
||||
#include "script/module/time/moduletime.h"
|
||||
#include "script/module/event/moduleevent.h"
|
||||
#include "script/module/display/modulecolor.h"
|
||||
#include "script/module/display/modulespritebatch.h"
|
||||
#include "script/module/math/modulemath.h"
|
||||
#include "script/module/display/moduleshader.h"
|
||||
#include "script/module/ui/moduleui.h"
|
||||
#include "script/module/display/moduletext.h"
|
||||
#include "script/module/display/modulescreen.h"
|
||||
#include "script/module/display/moduletexture.h"
|
||||
#include "script/module/display/moduletileset.h"
|
||||
#include "script/module/scene/modulescene.h"
|
||||
|
||||
static void moduleRegister(void) {
|
||||
@@ -29,17 +21,9 @@ static void moduleRegister(void) {
|
||||
moduleEntity();
|
||||
moduleInput();
|
||||
modulePlatform();
|
||||
moduleLocale();
|
||||
moduleTime();
|
||||
moduleEvent();
|
||||
moduleColor();
|
||||
moduleSpriteBatch();
|
||||
moduleMath();
|
||||
moduleShader();
|
||||
moduleUi();
|
||||
moduleText();
|
||||
moduleScreen();
|
||||
moduleTexture();
|
||||
moduleTileset();
|
||||
moduleScene();
|
||||
}
|
||||
|
||||
@@ -59,7 +59,6 @@ static void* moduleBaseGetProto(
|
||||
if(!jerry_value_is_object(object)) return NULL;
|
||||
|
||||
return (void*)jerry_object_get_native_ptr(object, info);
|
||||
// return (void*)jerry_object_get_native_ptr(callInfo->this_value, info);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,87 +184,86 @@ static jerry_value_t moduleBaseThrow(const char_t *message) {
|
||||
return jerry_throw_sz(JERRY_ERROR_TYPE, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a global string constant.
|
||||
*/
|
||||
static void moduleBaseSetString(const char_t *name, const char_t *value) {
|
||||
jerry_value_t global = jerry_current_realm();
|
||||
jerry_value_t key = jerry_string_sz(name);
|
||||
jerry_value_t val = jerry_string_sz(value);
|
||||
jerry_object_set(global, key, val);
|
||||
jerry_value_free(val);
|
||||
jerry_value_free(key);
|
||||
jerry_value_free(global);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a global object with the provided name and prototype.
|
||||
*
|
||||
* @param name The name of the global object to create.
|
||||
* @param prototype The prototype to set on the global object.
|
||||
*/
|
||||
static void moduleBaseCreateGlobalObject(
|
||||
const char_t *name, jerry_value_t prototype
|
||||
) {
|
||||
jerry_value_t global = jerry_current_realm();
|
||||
jerry_value_t key = jerry_string_sz(name);
|
||||
jerry_object_set(global, key, prototype);
|
||||
jerry_value_free(key);
|
||||
jerry_value_free(global);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define JS_FUNC(name) \
|
||||
static jerry_value_t name( \
|
||||
const jerry_call_info_t *call_info_p, \
|
||||
const jerry_value_t args_p[], \
|
||||
const jerry_length_t args_count)
|
||||
|
||||
#define JS_THROW(msg) moduleBaseThrow((msg))
|
||||
#define JS_REQUIRE_ARGS(n) \
|
||||
if((args_count) < (n)) { \
|
||||
return JS_THROW("Expected at least " #n " arguments"); \
|
||||
/**
|
||||
* Assert at least n arguments were passed; return type error if not.
|
||||
*/
|
||||
#define moduleBaseRequireArgs(n) \
|
||||
if((argc) < (n)) { \
|
||||
return moduleBaseThrow("Expected at least " #n " arguments"); \
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert an argument is a number; return type error if not.
|
||||
*/
|
||||
#define JS_REQUIRE_NUMBER(i) do { \
|
||||
if(!jerry_value_is_number(args_p[(i)])) { \
|
||||
return JS_THROW("Expected number argument"); \
|
||||
#define moduleBaseRequireNumber(i) do { \
|
||||
if(!jerry_value_is_number(args[(i)])) { \
|
||||
return moduleBaseThrow("Expected number argument"); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* Assert an argument is a string; return type error if not.
|
||||
*/
|
||||
#define JS_REQUIRE_STRING(i) do { \
|
||||
if(!jerry_value_is_string(args_p[(i)])) { \
|
||||
return JS_THROW("Expected string argument"); \
|
||||
#define moduleBaseRequireString(i) do { \
|
||||
if(!jerry_value_is_string(args[(i)])) { \
|
||||
return moduleBaseThrow("Expected string argument"); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* Assert an argument is a function; return type error if not.
|
||||
*/
|
||||
#define JS_REQUIRE_FUNCTION(i) do { \
|
||||
if(!jerry_value_is_function(args_p[(i)])) { \
|
||||
return JS_THROW("Expected function argument"); \
|
||||
#define moduleBaseRequireFunction(i) do { \
|
||||
if(!jerry_value_is_function(args[(i)])) { \
|
||||
return moduleBaseThrow("Expected function argument"); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* Assert an argument is an object; return type error if not.
|
||||
*/
|
||||
#define JS_REQUIRE_OBJECT(i) do { \
|
||||
if(!jerry_value_is_object(args_p[(i)])) { \
|
||||
return JS_THROW("Expected object argument"); \
|
||||
#define moduleBaseRequireObject(i) do { \
|
||||
if(!jerry_value_is_object(args[(i)])) { \
|
||||
return moduleBaseThrow("Expected object argument"); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/* JS_PTR_NATIVE_INFO is declared in scriptcontext.h and defined in
|
||||
scriptcontext.c so all TUs share a single address for native-ptr lookups. */
|
||||
|
||||
/**
|
||||
* Register a global JS function.
|
||||
*
|
||||
* @param name Function name as seen in scripts.
|
||||
* @param fn C handler function.
|
||||
*/
|
||||
static inline void jsRegister(
|
||||
const char_t *name,
|
||||
jerry_external_handler_t fn
|
||||
) {
|
||||
jerry_value_t global = jerry_current_realm();
|
||||
jerry_value_t key = jerry_string_sz(name);
|
||||
jerry_value_t func = jerry_function_external(fn);
|
||||
jerry_object_set(global, key, func);
|
||||
jerry_value_free(func);
|
||||
jerry_value_free(key);
|
||||
jerry_value_free(global);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a global numeric constant.
|
||||
*/
|
||||
static inline void jsSetNumber(const char_t *name, double value) {
|
||||
static inline void moduleBaseSetNumber(const char_t *name, double value) {
|
||||
jerry_value_t global = jerry_current_realm();
|
||||
jerry_value_t key = jerry_string_sz(name);
|
||||
jerry_value_t val = jerry_number(value);
|
||||
@@ -278,28 +276,15 @@ static inline void jsSetNumber(const char_t *name, double value) {
|
||||
/**
|
||||
* Set a global integer constant.
|
||||
*/
|
||||
static inline void jsSetInt(const char_t *name, int32_t value) {
|
||||
jsSetNumber(name, (double)value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a global string constant.
|
||||
*/
|
||||
static inline void jsSetString(const char_t *name, const char_t *value) {
|
||||
jerry_value_t global = jerry_current_realm();
|
||||
jerry_value_t key = jerry_string_sz(name);
|
||||
jerry_value_t val = jerry_string_sz(value);
|
||||
jerry_object_set(global, key, val);
|
||||
jerry_value_free(val);
|
||||
jerry_value_free(key);
|
||||
jerry_value_free(global);
|
||||
static inline void moduleBaseSetInt(const char_t *name, int32_t value) {
|
||||
moduleBaseSetNumber(name, (double)value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a global JS value. Caller retains ownership of the value and must free
|
||||
* it independently.
|
||||
*/
|
||||
static inline void jsSetValue(const char_t *name, jerry_value_t value) {
|
||||
static inline void moduleBaseSetValue(const char_t *name, jerry_value_t value) {
|
||||
jerry_value_t global = jerry_current_realm();
|
||||
jerry_value_t key = jerry_string_sz(name);
|
||||
jerry_object_set(global, key, value);
|
||||
@@ -311,33 +296,29 @@ static inline void jsSetValue(const char_t *name, jerry_value_t value) {
|
||||
* Wrap an engine-owned C pointer as a JS object (no GC free callback).
|
||||
* Used for global singletons like INPUT_EVENT_PRESSED, SHADER_UNLIT, etc.
|
||||
*/
|
||||
static inline jerry_value_t jsWrapPointer(void *ptr) {
|
||||
static inline jerry_value_t moduleBaseWrapPointer(void *ptr) {
|
||||
jerry_value_t obj = jerry_object();
|
||||
jerry_object_set_native_ptr(obj, &JS_PTR_NATIVE_INFO, ptr);
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unwrap a C pointer from a JS object created by jsWrapPointer.
|
||||
* Returns NULL if the object does not carry a matching native pointer.
|
||||
* Set a named global to a wrapped engine-owned C pointer.
|
||||
* Combines moduleBaseWrapPointer and moduleBaseSetValue in one call.
|
||||
*/
|
||||
static inline void *jsUnwrapPointer(jerry_value_t val) {
|
||||
if(!jerry_value_is_object(val)) return NULL;
|
||||
return jerry_object_get_native_ptr(val, &JS_PTR_NATIVE_INFO);
|
||||
static inline void moduleBaseSetWrappedPointer(const char_t *name, void *ptr) {
|
||||
jerry_value_t val = moduleBaseWrapPointer(ptr);
|
||||
moduleBaseSetValue(name, val);
|
||||
jerry_value_free(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate a JS source string in the global scope.
|
||||
* Errors are silently discarded; use scriptContextExec for error-propagating
|
||||
* execution.
|
||||
* Unwrap a C pointer from a JS object created by moduleBaseWrapPointer.
|
||||
* Returns NULL if the object does not carry a matching native pointer.
|
||||
*/
|
||||
static inline void jsEvalStr(const char_t *script) {
|
||||
jerry_value_t result = jerry_eval(
|
||||
(const jerry_char_t *)script,
|
||||
strlen(script),
|
||||
JERRY_PARSE_NO_OPTS
|
||||
);
|
||||
jerry_value_free(result);
|
||||
static inline void *moduleBaseUnwrapPointer(jerry_value_t val) {
|
||||
if(!jerry_value_is_object(val)) return NULL;
|
||||
return jerry_object_get_native_ptr(val, &JS_PTR_NATIVE_INFO);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -347,7 +328,7 @@ static inline void jsEvalStr(const char_t *script) {
|
||||
* @param buf Output buffer.
|
||||
* @param buflen Buffer capacity including the null terminator.
|
||||
*/
|
||||
static inline void jsToString(
|
||||
static inline void moduleBaseToString(
|
||||
jerry_value_t val,
|
||||
char_t *buf,
|
||||
jerry_size_t buflen
|
||||
@@ -360,14 +341,13 @@ static inline void jsToString(
|
||||
|
||||
/**
|
||||
* Define a named property on a JS object with getter and optional setter.
|
||||
* Both getter and setter are external C functions.
|
||||
*
|
||||
* @param obj Target object (e.g. a prototype).
|
||||
* @param name Property name.
|
||||
* @param getter C getter handler.
|
||||
* @param setter C setter handler, or NULL for read-only property.
|
||||
*/
|
||||
static inline void jsDefineProperty(
|
||||
static inline void moduleBaseDefineProperty(
|
||||
jerry_value_t obj,
|
||||
const char_t *name,
|
||||
jerry_external_handler_t getter,
|
||||
@@ -400,7 +380,7 @@ static inline void jsDefineProperty(
|
||||
* @param name Method name.
|
||||
* @param fn C handler function.
|
||||
*/
|
||||
static inline void jsDefineMethod(
|
||||
static inline void moduleBaseDefineMethod(
|
||||
jerry_value_t obj,
|
||||
const char_t *name,
|
||||
jerry_external_handler_t fn
|
||||
@@ -416,7 +396,7 @@ static inline void jsDefineMethod(
|
||||
* Format an error message from a JerryScript exception value.
|
||||
* Caller must ensure buf is large enough.
|
||||
*/
|
||||
static inline void jsExceptionMessage(
|
||||
static inline void moduleBaseExceptionMessage(
|
||||
jerry_value_t exception,
|
||||
char_t *buf,
|
||||
size_t buflen
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#define MODULE_PLATFORM_VALUE "var PLATFORM = '" DUSK_TARGET_SYSTEM "';\n"
|
||||
|
||||
static void modulePlatform(void) {
|
||||
jsEvalStr(MODULE_PLATFORM_VALUE);
|
||||
moduleBaseEval(MODULE_PLATFORM_VALUE);
|
||||
|
||||
#ifdef modulePlatformPlatform
|
||||
modulePlatformPlatform();
|
||||
|
||||
@@ -9,19 +9,19 @@
|
||||
#include "script/module/modulebase.h"
|
||||
#include "scene/scene.h"
|
||||
|
||||
JS_FUNC(moduleSceneSet) {
|
||||
JS_REQUIRE_ARGS(1);
|
||||
JS_REQUIRE_STRING(0);
|
||||
moduleBaseFunction(moduleSceneSet) {
|
||||
moduleBaseRequireArgs(1);
|
||||
moduleBaseRequireString(0);
|
||||
|
||||
char_t name[ASSET_FILE_PATH_MAX];
|
||||
jsToString(args_p[0], name, sizeof(name));
|
||||
if(name[0] == '\0') return JS_THROW("Scene.set: Scene name cannot be empty");
|
||||
moduleBaseToString(args[0], name, sizeof(name));
|
||||
if(name[0] == '\0') return moduleBaseThrow("Scene.set: Scene name cannot be empty");
|
||||
|
||||
sceneSet(name);
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleSceneGetCurrent) {
|
||||
moduleBaseFunction(moduleSceneGetCurrent) {
|
||||
if(SCENE.sceneCurrent[0] == '\0') return jerry_undefined();
|
||||
return jerry_string_sz(SCENE.sceneCurrent);
|
||||
}
|
||||
@@ -34,10 +34,10 @@ static void moduleSceneReset(void) {
|
||||
|
||||
jerry_value_t obj = jerry_object();
|
||||
|
||||
jsDefineMethod(obj, "set", moduleSceneSet);
|
||||
jsDefineProperty(obj, "current", moduleSceneGetCurrent, NULL);
|
||||
moduleBaseDefineMethod(obj, "set", moduleSceneSet);
|
||||
moduleBaseDefineProperty(obj, "current", moduleSceneGetCurrent, NULL);
|
||||
|
||||
jsSetValue("Scene", obj);
|
||||
moduleBaseSetValue("Scene", obj);
|
||||
jerry_value_free(obj);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ static errorret_t moduleSceneCall(const char_t *method) {
|
||||
|
||||
if(jerry_value_is_exception(result)) {
|
||||
char_t errMsg[512];
|
||||
jsExceptionMessage(result, errMsg, sizeof(errMsg));
|
||||
moduleBaseExceptionMessage(result, errMsg, sizeof(errMsg));
|
||||
jerry_value_free(result);
|
||||
errorThrow("Scene:%s failed: %s", method, errMsg);
|
||||
}
|
||||
|
||||
@@ -9,14 +9,14 @@
|
||||
#include "script/module/modulebase.h"
|
||||
#include "console/console.h"
|
||||
|
||||
JS_FUNC(moduleScriptPrint) {
|
||||
moduleBaseFunction(moduleScriptPrint) {
|
||||
char_t buf[512];
|
||||
char_t msg[4096];
|
||||
size_t msgLen = 0;
|
||||
|
||||
for(jerry_length_t i = 0; i < args_count; ++i) {
|
||||
jerry_value_t strVal = jerry_value_to_string(args_p[i]);
|
||||
jsToString(strVal, buf, sizeof(buf));
|
||||
for(jerry_length_t i = 0; i < argc; ++i) {
|
||||
jerry_value_t strVal = jerry_value_to_string(args[i]);
|
||||
moduleBaseToString(strVal, buf, sizeof(buf));
|
||||
jerry_value_free(strVal);
|
||||
|
||||
size_t partLen = strlen(buf);
|
||||
@@ -25,7 +25,7 @@ JS_FUNC(moduleScriptPrint) {
|
||||
msgLen += partLen;
|
||||
}
|
||||
|
||||
if(i + 1 < args_count && msgLen + 1 < sizeof(msg)) {
|
||||
if(i + 1 < argc && msgLen + 1 < sizeof(msg)) {
|
||||
msg[msgLen++] = '\t';
|
||||
msg[msgLen] = '\0';
|
||||
}
|
||||
@@ -35,16 +35,16 @@ JS_FUNC(moduleScriptPrint) {
|
||||
return jerry_undefined();
|
||||
}
|
||||
|
||||
JS_FUNC(moduleScriptInclude) {
|
||||
if(args_count < 1 || !jerry_value_is_string(args_p[0])) {
|
||||
return JS_THROW("Expected string filename");
|
||||
moduleBaseFunction(moduleScriptInclude) {
|
||||
if(argc < 1 || !jerry_value_is_string(args[0])) {
|
||||
return moduleBaseThrow("Expected string filename");
|
||||
}
|
||||
|
||||
char_t filename[1024];
|
||||
jsToString(args_p[0], filename, sizeof(filename));
|
||||
moduleBaseToString(args[0], filename, sizeof(filename));
|
||||
|
||||
if(filename[0] == '\0') {
|
||||
return JS_THROW("Filename cannot be empty");
|
||||
return moduleBaseThrow("Filename cannot be empty");
|
||||
}
|
||||
|
||||
char_t buffer[1024];
|
||||
@@ -53,7 +53,7 @@ JS_FUNC(moduleScriptInclude) {
|
||||
size_t len = strlen(buffer);
|
||||
if(len < 3 || stringCompare(&buffer[len - 3], ".js") != 0) {
|
||||
if(len + 3 >= sizeof(buffer)) {
|
||||
return JS_THROW("Filename too long to append .js");
|
||||
return moduleBaseThrow("Filename too long to append .js");
|
||||
}
|
||||
stringCopy(&buffer[len], ".js", 4);
|
||||
}
|
||||
@@ -63,7 +63,7 @@ JS_FUNC(moduleScriptInclude) {
|
||||
if(err.code != ERROR_OK) {
|
||||
if(result != 0) jerry_value_free(result);
|
||||
errorCatch(errorPrint(err));
|
||||
return JS_THROW("Failed to include script file");
|
||||
return moduleBaseThrow("Failed to include script file");
|
||||
}
|
||||
|
||||
if(result == 0) return jerry_undefined();
|
||||
@@ -71,6 +71,6 @@ JS_FUNC(moduleScriptInclude) {
|
||||
}
|
||||
|
||||
static void moduleScript(void) {
|
||||
jsRegister("print", moduleScriptPrint);
|
||||
jsRegister("include", moduleScriptInclude);
|
||||
moduleBaseFunctionRegister("print", moduleScriptPrint);
|
||||
moduleBaseFunctionRegister("include", moduleScriptInclude);
|
||||
}
|
||||
|
||||
@@ -9,18 +9,18 @@
|
||||
#include "script/module/modulebase.h"
|
||||
#include "time/time.h"
|
||||
|
||||
JS_FUNC(moduleTimeGetDelta) {
|
||||
moduleBaseFunction(moduleTimeGetDelta) {
|
||||
return jerry_number(TIME.delta);
|
||||
}
|
||||
|
||||
JS_FUNC(moduleTimeGetTime) {
|
||||
moduleBaseFunction(moduleTimeGetTime) {
|
||||
return jerry_number(TIME.time);
|
||||
}
|
||||
|
||||
static void moduleTime(void) {
|
||||
jerry_value_t obj = jerry_object();
|
||||
jsDefineProperty(obj, "delta", moduleTimeGetDelta, NULL);
|
||||
jsDefineProperty(obj, "time", moduleTimeGetTime, NULL);
|
||||
jsSetValue("TIME", obj);
|
||||
moduleBaseDefineProperty(obj, "delta", moduleTimeGetDelta, NULL);
|
||||
moduleBaseDefineProperty(obj, "time", moduleTimeGetTime, NULL);
|
||||
moduleBaseSetValue("TIME", obj);
|
||||
jerry_value_free(obj);
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "script/module/modulebase.h"
|
||||
|
||||
static void moduleUi(void) {
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "scriptproto.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/memory.h"
|
||||
#include "script/module/modulebase.h"
|
||||
|
||||
void scriptProtoInit(scriptproto_t *proto, const size_t size) {
|
||||
assertNotNull(proto, "Script prototype struct must not be null");
|
||||
memoryZero(proto, sizeof(scriptproto_t));
|
||||
|
||||
proto->info = (jerry_object_native_info_t){
|
||||
.free_cb = moduleBaseFreeProto,
|
||||
.number_of_references = 0,
|
||||
.offset_of_references = 0
|
||||
};
|
||||
|
||||
proto->prototype = jerry_object();
|
||||
|
||||
proto->size = size;
|
||||
}
|
||||
|
||||
void scriptProtoDefineProperty(
|
||||
scriptproto_t *proto,
|
||||
const char_t *name,
|
||||
jerry_external_handler_t getter,
|
||||
jerry_external_handler_t setter
|
||||
) {
|
||||
assertNotNull(proto, "Script prototype struct must not be null");
|
||||
assertStrLenMin(name, 1, "Property name must not be empty");
|
||||
assertNotNull(getter, "Getter must not be null");
|
||||
|
||||
jerry_property_descriptor_t desc;
|
||||
memoryZero(&desc, sizeof(desc));
|
||||
desc.flags = (uint16_t)(
|
||||
JERRY_PROP_IS_GET_DEFINED |
|
||||
JERRY_PROP_IS_ENUMERABLE_DEFINED | JERRY_PROP_IS_ENUMERABLE |
|
||||
JERRY_PROP_IS_CONFIGURABLE_DEFINED | JERRY_PROP_IS_CONFIGURABLE
|
||||
);
|
||||
|
||||
desc.getter = jerry_function_external(getter);
|
||||
|
||||
if(setter != NULL) {
|
||||
desc.flags |= JERRY_PROP_IS_SET_DEFINED;
|
||||
desc.setter = jerry_function_external(setter);
|
||||
}
|
||||
|
||||
jerry_value_t key = jerry_string_sz(name);
|
||||
jerry_value_t result = jerry_object_define_own_prop(
|
||||
proto->prototype, key, &desc
|
||||
);
|
||||
jerry_value_free(result);
|
||||
jerry_value_free(key);
|
||||
jerry_value_free(desc.getter);
|
||||
if(setter != NULL) jerry_value_free(desc.setter);
|
||||
}
|
||||
|
||||
void scriptProtoDefineMethod(
|
||||
scriptproto_t *proto,
|
||||
const char_t *name,
|
||||
jerry_external_handler_t fn
|
||||
) {
|
||||
assertNotNull(proto, "Script prototype struct must not be null");
|
||||
assertStrLenMin(name, 1, "Method name must not be empty");
|
||||
assertNotNull(fn, "Function handler must not be null");
|
||||
|
||||
jerry_value_t key = jerry_string_sz(name);
|
||||
jerry_value_t func = jerry_function_external(fn);
|
||||
jerry_object_set(proto->prototype, key, func);
|
||||
jerry_value_free(func);
|
||||
jerry_value_free(key);
|
||||
}
|
||||
|
||||
void scriptProtoCreateGlobal(
|
||||
scriptproto_t *proto,
|
||||
const char_t *name
|
||||
) {
|
||||
assertNotNull(proto, "Script prototype struct must not be null");
|
||||
assertStrLenMin(name, 1, "Global object name must not be empty");
|
||||
|
||||
jerry_value_t global = jerry_current_realm();
|
||||
jerry_value_t key = jerry_string_sz(name);
|
||||
jerry_object_set(global, key, proto->prototype);
|
||||
jerry_value_free(key);
|
||||
jerry_value_free(global);
|
||||
}
|
||||
|
||||
void * scriptProtoGetValue(const scriptproto_t *proto, const jerry_value_t obj){
|
||||
assertNotNull(proto, "Script prototype struct must not be null");
|
||||
if(!jerry_value_is_object(obj)) return NULL;
|
||||
return jerry_object_get_native_ptr(obj, &proto->info);
|
||||
}
|
||||
|
||||
jerry_value_t scriptProtoCreateValue(
|
||||
const scriptproto_t *proto,
|
||||
const void *value
|
||||
) {
|
||||
assertNotNull(proto, "Script prototype struct must not be null");
|
||||
assertNotNull(value, "Value pointer must not be null");
|
||||
|
||||
void *ptr = memoryAllocate(proto->size);
|
||||
memoryCopy(ptr, value, proto->size);
|
||||
jerry_value_t obj = jerry_object();
|
||||
jerry_object_set_native_ptr(obj, ptr, &proto->info);
|
||||
jerry_object_set_proto(obj, proto->prototype);
|
||||
return obj;
|
||||
}
|
||||
|
||||
void scriptProtoDispose(scriptproto_t *proto) {
|
||||
assertNotNull(proto, "Script prototype struct must not be null");
|
||||
jerry_value_free(proto->prototype);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
#include <jerryscript.h>
|
||||
|
||||
typedef struct {
|
||||
jerry_object_native_info_t info;
|
||||
jerry_value_t prototype;
|
||||
size_t size;
|
||||
} scriptproto_t;
|
||||
|
||||
/**
|
||||
* Initialize a script prototype struct.
|
||||
*
|
||||
* @param proto The script prototype struct to initialize.
|
||||
* @param size Size of the struct that this proto represents.
|
||||
*/
|
||||
void scriptProtoInit(scriptproto_t *proto, const size_t size);
|
||||
|
||||
/**
|
||||
* Define a property on a prototype with the provided getter and setter.
|
||||
*
|
||||
* @param proto The prototype to define the property on.
|
||||
* @param name The name of the property.
|
||||
* @param getter Function to call for getting.
|
||||
* @param setter Function to call for setting (or NULL for read-only).
|
||||
*/
|
||||
void scriptProtoDefineProperty(
|
||||
scriptproto_t *proto,
|
||||
const char_t *name,
|
||||
jerry_external_handler_t getter,
|
||||
jerry_external_handler_t setter
|
||||
);
|
||||
|
||||
/**
|
||||
* Define a method on a prototype.
|
||||
*
|
||||
* @param proto The prototype to define the method on.
|
||||
* @param name The name of the method.
|
||||
* @param fn The C function to call when the method is invoked in JS.
|
||||
*/
|
||||
void scriptProtoDefineMethod(
|
||||
scriptproto_t *proto,
|
||||
const char_t *name,
|
||||
jerry_external_handler_t fn
|
||||
);
|
||||
|
||||
/**
|
||||
* Defines a global object with the provided name and prototype.
|
||||
*
|
||||
* @param proto The prototype struct to use for the global object.
|
||||
* @param name The name of the global object to create.
|
||||
*/
|
||||
void scriptProtoCreateGlobal(
|
||||
scriptproto_t *proto,
|
||||
const char_t *name
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a JS object based on a C value using the provided prototype.
|
||||
*
|
||||
* @param proto The prototype.
|
||||
* @param value The pointer to the C value to create a JS object for.
|
||||
* @return A JS object wrapping the provided C value.
|
||||
*/
|
||||
jerry_value_t scriptProtoCreateValue(
|
||||
const scriptproto_t *proto,
|
||||
const void *value
|
||||
);
|
||||
|
||||
/**
|
||||
* Gets the native C struct pointer from a JS object using the prototype info.
|
||||
*
|
||||
* @param proto The prototype struct containing the native info.
|
||||
* @param obj The JS object to get the native value from.
|
||||
*/
|
||||
void * scriptProtoGetValue(const scriptproto_t *proto, const jerry_value_t obj);
|
||||
@@ -9,5 +9,5 @@
|
||||
#include "script/module/modulebase.h"
|
||||
|
||||
static void modulePlatformDolphin(void) {
|
||||
jsEvalStr("var DOLPHIN = true;\n");
|
||||
moduleBaseEval("var DOLPHIN = true;\n");
|
||||
}
|
||||
|
||||
@@ -9,5 +9,5 @@
|
||||
#include "script/module/modulebase.h"
|
||||
|
||||
static void modulePlatformLinux(void) {
|
||||
jsEvalStr("var LINUX = true;\n");
|
||||
moduleBaseEval("var LINUX = true;\n");
|
||||
}
|
||||
|
||||
@@ -9,5 +9,5 @@
|
||||
#include "script/module/modulebase.h"
|
||||
|
||||
static void modulePlatformPSP(void) {
|
||||
jsEvalStr("var PSP = true;\n");
|
||||
moduleBaseEval("var PSP = true;\n");
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ JS_FUNC(moduleInventorySort) {
|
||||
}
|
||||
|
||||
static void moduleItem(void) {
|
||||
jsEvalStr(ITEM_SCRIPT);
|
||||
moduleBaseEval(ITEM_SCRIPT);
|
||||
|
||||
jerry_value_t backpack = jsWrapPointer(&BACKPACK);
|
||||
jsSetValue("BACKPACK", backpack);
|
||||
|
||||
@@ -61,9 +61,9 @@ for name, (r, g, b, a) in colors.items():
|
||||
"",
|
||||
]
|
||||
js += [
|
||||
f"function color{camel}() {{",
|
||||
f" return color({r8}, {g8}, {b8}, {a8});",
|
||||
"}",
|
||||
f"Color.{name.lower()} = function() {{",
|
||||
f" return Color.rgba({r8}, {g8}, {b8}, {a8});",
|
||||
"};",
|
||||
"",
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user