diff --git a/assets/entities/CubeEntity.js b/assets/entities/CubeEntity.js new file mode 100644 index 00000000..8bc0f3d7 --- /dev/null +++ b/assets/entities/CubeEntity.js @@ -0,0 +1,22 @@ +var OverworldEntity = include('entities/OverworldEntity.js'); + +function CubeEntity() { + OverworldEntity.call(this); + + this.add(MESH); + this.add(MATERIAL); +} + +CubeEntity.prototype = Object.create(OverworldEntity.prototype); +CubeEntity.prototype.constructor = CubeEntity; + +CubeEntity.prototype.update = function() { + OverworldEntity.prototype.update.call(this); + var speed = 3.0; + var move = Input.axis2D(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT, INPUT_ACTION_UP, INPUT_ACTION_DOWN); + this.position.position.x += move.x * speed * TIME.delta; + this.position.position.z += move.y * speed * TIME.delta; + this.material.setColor(Color.rainbow()); +}; + +module = CubeEntity; diff --git a/assets/entities/OverworldEntity.js b/assets/entities/OverworldEntity.js new file mode 100644 index 00000000..57fb2a17 --- /dev/null +++ b/assets/entities/OverworldEntity.js @@ -0,0 +1,21 @@ +function OverworldEntity() { + Entity.call(this); + + this.add(POSITION); +} + +OverworldEntity.prototype = Object.create(Entity.prototype); +OverworldEntity.prototype.constructor = OverworldEntity; + +OverworldEntity.prototype.update = function() { + // var speed = 3.0; + // var move = Input.axis2D(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT, INPUT_ACTION_UP, INPUT_ACTION_DOWN); + // this.position.position.x += move.x * speed * TIME.delta; + // this.position.position.z += move.y * speed * TIME.delta; +} + +OverworldEntity.prototype.dispose = function() { + // Nothing to dispose +} + +module = OverworldEntity; \ No newline at end of file diff --git a/assets/entities/cube.js b/assets/entities/cube.js deleted file mode 100644 index cff9748d..00000000 --- a/assets/entities/cube.js +++ /dev/null @@ -1,21 +0,0 @@ -function CubeEntity() { - Entity.call(this); - this.add(POSITION); - this.add(MESH); - this.add(MATERIAL); -} - -CubeEntity.prototype = Object.create(Entity.prototype); -CubeEntity.prototype.constructor = CubeEntity; - -CubeEntity.prototype.update = function() { - // var speed = 3.0; - // var move = Input.axis2D(INPUT_ACTION_LEFT, INPUT_ACTION_RIGHT, INPUT_ACTION_UP, INPUT_ACTION_DOWN); - // this.position.position.x += move.x * speed * TIME.delta; - // this.position.position.z += move.y * speed * TIME.delta; - // this.position.rotation.x += 3 * TIME.delta; - // this.position.rotation.z += 2 * TIME.delta; - this.material.setColor(Color.rainbow()); -}; - -module = CubeEntity; diff --git a/assets/scenes/cube.js b/assets/scenes/cube.js index 8a227416..433f2d28 100644 --- a/assets/scenes/cube.js +++ b/assets/scenes/cube.js @@ -1,4 +1,4 @@ -var Cube = include('entities/cube.js'); +var CubeEntity = include('entities/CubeEntity.js'); function CubeScene() { this.cam = new Entity(); @@ -8,7 +8,7 @@ function CubeScene() { this.cam.position.position = new Vec3(3, 3, 3); this.cam.position.lookAt(new Vec3(0, 0, 0)); - this.cube = new Cube(); + this.cube = new CubeEntity(); } CubeScene.prototype = Object.create(Scene.prototype); diff --git a/src/dusk/script/module/display/modulecolor.h b/src/dusk/script/module/display/modulecolor.h index 8c9eeafd..9cdefb77 100644 --- a/src/dusk/script/module/display/modulecolor.h +++ b/src/dusk/script/module/display/modulecolor.h @@ -11,138 +11,103 @@ #include "time/time.h" #include "script/scriptproto.h" -// Define the prototype. static scriptproto_t MODULE_COLOR_PROTO; -// Getters -moduleBaseFunction(moduleColorGetR) { - color_t *color = (color_t*)scriptProtoGetValue( +static inline color_t * moduleColorGet( + const jerry_call_info_t *callInfo +) { + return (color_t*)scriptProtoGetValue( &MODULE_COLOR_PROTO, callInfo->this_value ); - if(!color) return jerry_undefined(); - return jerry_number(color->r); +} + +moduleBaseFunction(moduleColorGetR) { + color_t *c = moduleColorGet(callInfo); + return c ? jerry_number(c->r) : jerry_undefined(); } moduleBaseFunction(moduleColorGetG) { - color_t *color = (color_t*)scriptProtoGetValue( - &MODULE_COLOR_PROTO, callInfo->this_value - ); - if(!color) return jerry_undefined(); - return jerry_number(color->g); + color_t *c = moduleColorGet(callInfo); + return c ? jerry_number(c->g) : jerry_undefined(); } moduleBaseFunction(moduleColorGetB) { - color_t *color = (color_t*)scriptProtoGetValue( - &MODULE_COLOR_PROTO, callInfo->this_value - ); - if(!color) return jerry_undefined(); - return jerry_number(color->b); + color_t *c = moduleColorGet(callInfo); + return c ? jerry_number(c->b) : jerry_undefined(); } moduleBaseFunction(moduleColorGetA) { - color_t *color = (color_t*)scriptProtoGetValue( - &MODULE_COLOR_PROTO, callInfo->this_value - ); - if(!color) return jerry_undefined(); - return jerry_number(color->a); + color_t *c = moduleColorGet(callInfo); + return c ? jerry_number(c->a) : jerry_undefined(); } -// Setters moduleBaseFunction(moduleColorSetR) { - color_t *color = (color_t*)scriptProtoGetValue( - &MODULE_COLOR_PROTO, callInfo->this_value - ); - if(!color || argc < 1) return moduleBaseThrow("Expected a number argument"); - color->r = (colorchannel8_t)jerry_value_as_number(args[0]); + moduleBaseRequireArgs(1); moduleBaseRequireNumber(0); + color_t *c = moduleColorGet(callInfo); + if(!c) return jerry_undefined(); + c->r = (colorchannel8_t)jerry_value_as_number(args[0]); return args[0]; } moduleBaseFunction(moduleColorSetG) { - color_t *color = (color_t*)scriptProtoGetValue( - &MODULE_COLOR_PROTO, callInfo->this_value - ); - if(!color || argc < 1) return moduleBaseThrow("Expected a number argument"); - color->g = (colorchannel8_t)jerry_value_as_number(args[0]); + moduleBaseRequireArgs(1); moduleBaseRequireNumber(0); + color_t *c = moduleColorGet(callInfo); + if(!c) return jerry_undefined(); + c->g = (colorchannel8_t)jerry_value_as_number(args[0]); return args[0]; } moduleBaseFunction(moduleColorSetB) { - color_t *color = (color_t*)scriptProtoGetValue( - &MODULE_COLOR_PROTO, callInfo->this_value - ); - if(!color || argc < 1) return moduleBaseThrow("Expected a number argument"); - color->b = (colorchannel8_t)jerry_value_as_number(args[0]); + moduleBaseRequireArgs(1); moduleBaseRequireNumber(0); + color_t *c = moduleColorGet(callInfo); + if(!c) return jerry_undefined(); + c->b = (colorchannel8_t)jerry_value_as_number(args[0]); return args[0]; } moduleBaseFunction(moduleColorSetA) { - color_t *color = (color_t*)scriptProtoGetValue( - &MODULE_COLOR_PROTO, callInfo->this_value - ); - if(!color || argc < 1) return moduleBaseThrow("Expected a number argument"); - color->a = (colorchannel8_t)jerry_value_as_number(args[0]); + moduleBaseRequireArgs(1); moduleBaseRequireNumber(0); + color_t *c = moduleColorGet(callInfo); + if(!c) return jerry_undefined(); + c->a = (colorchannel8_t)jerry_value_as_number(args[0]); return args[0]; } moduleBaseFunction(moduleColorToString) { - color_t *color = (color_t*)scriptProtoGetValue( - &MODULE_COLOR_PROTO, callInfo->this_value - ); - if(!color) return jerry_undefined(); + color_t *c = moduleColorGet(callInfo); + if(!c) return jerry_undefined(); char_t buf[64]; stringFormat( buf, sizeof(buf), "{ \"r\": %d, \"g\": %d, \"b\": %d, \"a\": %d }", - (int32_t)color->r, (int32_t)color->g, - (int32_t)color->b, (int32_t)color->a + (int32_t)c->r, (int32_t)c->g, + (int32_t)c->b, (int32_t)c->a ); return jerry_string_sz(buf); } -// Constructor static jerry_value_t moduleColorMakeObject(color_t color) { return scriptProtoCreateValue(&MODULE_COLOR_PROTO, &color); } moduleBaseFunction(moduleColorConstructor) { + if(argc > 0 && !jerry_value_is_number(args[0])) { + return moduleBaseThrow("Color: r must be a number"); + } + if(argc > 1 && !jerry_value_is_number(args[1])) { + return moduleBaseThrow("Color: g must be a number"); + } + if(argc > 2 && !jerry_value_is_number(args[2])) { + return moduleBaseThrow("Color: b must be a number"); + } + if(argc > 3 && !jerry_value_is_number(args[3])) { + return moduleBaseThrow("Color: a must be a number"); + } color_t c; - - if(argc > 0) { - if(!jerry_value_is_number(args[0])) { - return moduleBaseThrow("Expected number argument for r"); - } - c.r = (colorchannel8_t)jerry_value_as_number(args[0]); - } else { - c.r = 255; - } - - if(argc > 1) { - if(!jerry_value_is_number(args[1])) { - return moduleBaseThrow("Expected number argument for g"); - } - c.g = (colorchannel8_t)jerry_value_as_number(args[1]); - } else { - c.g = 255; - } - - if(argc > 2) { - if(!jerry_value_is_number(args[2])) { - return moduleBaseThrow("Expected number argument for b"); - } - c.b = (colorchannel8_t)jerry_value_as_number(args[2]); - } else { - c.b = 255; - } - - if(argc > 3) { - if(!jerry_value_is_number(args[3])) { - return moduleBaseThrow("Expected number argument for a"); - } - c.a = (colorchannel8_t)jerry_value_as_number(args[3]); - } else { - c.a = 255; - } - + c.r = argc > 0 ? (colorchannel8_t)jerry_value_as_number(args[0]) : 255; + c.g = argc > 1 ? (colorchannel8_t)jerry_value_as_number(args[1]) : 255; + c.b = argc > 2 ? (colorchannel8_t)jerry_value_as_number(args[2]) : 255; + c.a = argc > 3 ? (colorchannel8_t)jerry_value_as_number(args[3]) : 255; return moduleColorMakeObject(c); } @@ -160,31 +125,34 @@ moduleBaseFunction(moduleColorRainbow) { } color_t c; - c.r = (colorchannel8_t)((sinf(t) + 1.0f) * 0.5f * 255.0f); + c.r = (colorchannel8_t)((sinf(t) + 1.0f) * 0.5f * 255.0f); c.g = (colorchannel8_t)((sinf(t + 2.0f) + 1.0f) * 0.5f * 255.0f); c.b = (colorchannel8_t)((sinf(t + 4.0f) + 1.0f) * 0.5f * 255.0f); c.a = 255; return moduleColorMakeObject(c); } -// Root Module static void moduleColor(void) { scriptProtoInit( - &MODULE_COLOR_PROTO, - "Color", - sizeof(color_t), - moduleColorConstructor + &MODULE_COLOR_PROTO, "Color", sizeof(color_t), moduleColorConstructor ); - #define X(x, g, s) \ - scriptProtoDefineProp(&MODULE_COLOR_PROTO, #x, g, s); - X(r, moduleColorGetR, moduleColorSetR); - X(g, moduleColorGetG, moduleColorSetG); - X(b, moduleColorGetB, moduleColorSetB); - X(a, moduleColorGetA, moduleColorSetA); - #undef X + scriptProtoDefineProp( + &MODULE_COLOR_PROTO, "r", moduleColorGetR, moduleColorSetR + ); + scriptProtoDefineProp( + &MODULE_COLOR_PROTO, "g", moduleColorGetG, moduleColorSetG + ); + scriptProtoDefineProp( + &MODULE_COLOR_PROTO, "b", moduleColorGetB, moduleColorSetB + ); + scriptProtoDefineProp( + &MODULE_COLOR_PROTO, "a", moduleColorGetA, moduleColorSetA + ); - scriptProtoDefineStaticFunc(&MODULE_COLOR_PROTO, "rainbow", moduleColorRainbow); + scriptProtoDefineStaticFunc( + &MODULE_COLOR_PROTO, "rainbow", moduleColorRainbow + ); scriptProtoDefineToString(&MODULE_COLOR_PROTO, moduleColorToString); moduleBaseEval(COLOR_SCRIPT); } diff --git a/src/dusk/script/module/display/modulescreen.h b/src/dusk/script/module/display/modulescreen.h index 0b77e318..e2ef22dc 100644 --- a/src/dusk/script/module/display/modulescreen.h +++ b/src/dusk/script/module/display/modulescreen.h @@ -9,9 +9,8 @@ #include "script/module/display/modulecolor.h" #include "display/screen/screen.h" -scriptproto_t MODULE_SCREEN_PROTO; +static scriptproto_t MODULE_SCREEN_PROTO; -// Getters moduleBaseFunction(moduleScreenGetWidth) { return jerry_number(SCREEN.width); } @@ -28,23 +27,20 @@ moduleBaseFunction(moduleScreenGetBackground) { return moduleColorMakeObject(SCREEN.background); } -// Setters moduleBaseFunction(moduleScreenSetBackground) { if(argc < 1 || !jerry_value_is_object(args[0])) { return moduleBaseThrow("Screen background color must be a color object"); } - - // Get color pointer from the object. - color_t *color = (color_t*)scriptProtoGetValue(&MODULE_COLOR_PROTO, args[0]); + 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(); } -// Functions moduleBaseFunction(moduleScreenToString) { char_t buf[128]; stringFormat( @@ -56,15 +52,23 @@ moduleBaseFunction(moduleScreenToString) { } static void moduleScreen(void) { - scriptProtoInit(&MODULE_SCREEN_PROTO, "Screen", sizeof(screen_t), NULL); + scriptProtoInit( + &MODULE_SCREEN_PROTO, "Screen", sizeof(screen_t), NULL + ); - #define X(x, g, s) \ - scriptProtoDefineProp(&MODULE_SCREEN_PROTO, #x, g, s); - X(width, moduleScreenGetWidth, NULL) - X(height, moduleScreenGetHeight, NULL) - X(aspect, moduleScreenGetAspect, NULL) - X(background, moduleScreenGetBackground, moduleScreenSetBackground) - #undef X + scriptProtoDefineProp( + &MODULE_SCREEN_PROTO, "width", moduleScreenGetWidth, NULL + ); + scriptProtoDefineProp( + &MODULE_SCREEN_PROTO, "height", moduleScreenGetHeight, NULL + ); + scriptProtoDefineProp( + &MODULE_SCREEN_PROTO, "aspect", moduleScreenGetAspect, NULL + ); + scriptProtoDefineProp( + &MODULE_SCREEN_PROTO, "background", + moduleScreenGetBackground, moduleScreenSetBackground + ); scriptProtoDefineToString(&MODULE_SCREEN_PROTO, moduleScreenToString); -} \ No newline at end of file +} diff --git a/src/dusk/script/module/entity/component/moduleentitycamera.h b/src/dusk/script/module/entity/component/moduleentitycamera.h index d591cf12..12361743 100644 --- a/src/dusk/script/module/entity/component/moduleentitycamera.h +++ b/src/dusk/script/module/entity/component/moduleentitycamera.h @@ -14,12 +14,6 @@ static scriptproto_t MODULE_ENTITY_CAMERA_PROTO; -/** - * Shorthand function to get the camera component data from "this". - * - * @param callInfo The call info of the current function call. - * @return The camera component data, or undefined if invalid. - */ static entitycamera_t * moduleEntityCameraGet( const jerry_call_info_t *callInfo ) { @@ -27,17 +21,11 @@ static entitycamera_t * moduleEntityCameraGet( &MODULE_ENTITY_CAMERA_PROTO, callInfo->this_value ); if(!h) return NULL; - - entitycamera_t *cam = (entitycamera_t*)componentGetData( + return (entitycamera_t*)componentGetData( h->eid, h->cid, COMPONENT_TYPE_CAMERA ); - if(!cam) return NULL; - - return cam; } - -// Getters moduleBaseFunction(moduleEntityCameraGetZNear) { entitycamera_t *cam = moduleEntityCameraGet(callInfo); if(!cam) return jerry_undefined(); @@ -99,8 +87,6 @@ moduleBaseFunction(moduleEntityCameraGetProjectionType) { return jerry_number(cam->projType); } - -// Setters moduleBaseFunction(moduleEntityCameraSetZNear) { if(argc < 1 || !jerry_value_is_number(args[0])) { return moduleBaseThrow("Expected a number"); @@ -201,8 +187,6 @@ moduleBaseFunction(moduleEntityCameraSetProjectionType) { return args[0]; } - -// Adder for this component. moduleBaseFunction(moduleEntityCameraAdd) { moduleBaseRequireArgs(1); moduleBaseRequireNumber(0); entityid_t id = (entityid_t)jerry_value_as_number(args[0]); @@ -211,7 +195,6 @@ moduleBaseFunction(moduleEntityCameraAdd) { return scriptProtoCreateValue(&MODULE_ENTITY_CAMERA_PROTO, &h); } - static void moduleEntityCAMERA(void) { scriptProtoInit( &MODULE_ENTITY_CAMERA_PROTO, NULL, sizeof(componenthandle_t), NULL @@ -223,7 +206,7 @@ static void moduleEntityCAMERA(void) { ); scriptProtoDefineProp( &MODULE_ENTITY_CAMERA_PROTO, "zFar", - moduleEntityCameraGetZFar, moduleEntityCameraSetZFar + moduleEntityCameraGetZFar, moduleEntityCameraSetZFar ); scriptProtoDefineProp( &MODULE_ENTITY_CAMERA_PROTO, "orthoTop", @@ -250,12 +233,12 @@ static void moduleEntityCAMERA(void) { moduleEntityCameraGetProjectionType, moduleEntityCameraSetProjectionType ); - char_t buffer[64]; - snprintf( - buffer, sizeof(buffer), - "%s = %d;\n%s = %d;\n", - "CAMERA_TYPE_ORTHOGRAPHIC", ENTITY_CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC, - "CAMERA_TYPE_PERSPECTIVE", ENTITY_CAMERA_PROJECTION_TYPE_PERSPECTIVE + moduleBaseSetInt( + "CAMERA_TYPE_ORTHOGRAPHIC", + ENTITY_CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC + ); + moduleBaseSetInt( + "CAMERA_TYPE_PERSPECTIVE", + ENTITY_CAMERA_PROJECTION_TYPE_PERSPECTIVE ); - moduleBaseEval(buffer); } diff --git a/src/dusk/script/module/entity/component/moduleentitymaterial.h b/src/dusk/script/module/entity/component/moduleentitymaterial.h index 5caf50aa..bfd45fc9 100644 --- a/src/dusk/script/module/entity/component/moduleentitymaterial.h +++ b/src/dusk/script/module/entity/component/moduleentitymaterial.h @@ -27,8 +27,6 @@ static entitymaterial_t * moduleEntityMaterialGet( ); } - -// Setters moduleBaseFunction(moduleEntityMaterialSetColor) { moduleBaseRequireArgs(1); if(!jerry_value_is_object(args[0])) { @@ -69,7 +67,6 @@ moduleBaseFunction(moduleEntityMaterialSetColor) { return jerry_undefined(); } -// Component add method moduleBaseFunction(moduleEntityMaterialAdd) { moduleBaseRequireArgs(1); moduleBaseRequireNumber(0); entityid_t id = (entityid_t)jerry_value_as_number(args[0]); diff --git a/src/dusk/script/module/entity/component/moduleentitymesh.h b/src/dusk/script/module/entity/component/moduleentitymesh.h index f7ed892e..e800b6bd 100644 --- a/src/dusk/script/module/entity/component/moduleentitymesh.h +++ b/src/dusk/script/module/entity/component/moduleentitymesh.h @@ -24,7 +24,6 @@ static entitymesh_t * moduleEntityMeshGet( return (entitymesh_t*)componentGetData(h->eid, h->cid, COMPONENT_TYPE_MESH); } -// Component add moduleBaseFunction(moduleEntityMeshAdd) { moduleBaseRequireArgs(1); moduleBaseRequireNumber(0); entityid_t id = (entityid_t)jerry_value_as_number(args[0]); diff --git a/src/dusk/script/module/entity/component/moduleentityphysics.h b/src/dusk/script/module/entity/component/moduleentityphysics.h index 9f235352..dc1df368 100644 --- a/src/dusk/script/module/entity/component/moduleentityphysics.h +++ b/src/dusk/script/module/entity/component/moduleentityphysics.h @@ -25,8 +25,6 @@ static entityphysics_t * moduleEntityPhysicsGet( return entityPhysicsGet(h->eid, h->cid); } -// -- velocity -- - moduleBaseFunction(moduleEntityPhysicsGetVelocity) { entityphysics_t *phys = moduleEntityPhysicsGet(callInfo); if(!phys) return jerry_undefined(); @@ -45,16 +43,12 @@ moduleBaseFunction(moduleEntityPhysicsSetVelocity) { return jerry_undefined(); } -// -- onGround (read-only) -- - moduleBaseFunction(moduleEntityPhysicsGetOnGround) { entityphysics_t *phys = moduleEntityPhysicsGet(callInfo); if(!phys) return jerry_undefined(); return jerry_boolean(phys->onGround); } -// -- bodyType -- - moduleBaseFunction(moduleEntityPhysicsGetBodyType) { entityphysics_t *phys = moduleEntityPhysicsGet(callInfo); if(!phys) return jerry_undefined(); @@ -69,8 +63,6 @@ moduleBaseFunction(moduleEntityPhysicsSetBodyType) { return jerry_undefined(); } -// -- methods -- - moduleBaseFunction(moduleEntityPhysicsApplyImpulse) { moduleBaseRequireArgs(1); entityphysics_t *phys = moduleEntityPhysicsGet(callInfo); @@ -132,8 +124,6 @@ moduleBaseFunction(moduleEntityPhysicsSetShapePlane) { return jerry_undefined(); } -// -- add function -- - moduleBaseFunction(moduleEntityPhysicsAdd) { moduleBaseRequireArgs(1); moduleBaseRequireNumber(0); entityid_t id = (entityid_t)jerry_value_as_number(args[0]); diff --git a/src/dusk/script/module/entity/component/moduleentityposition.h b/src/dusk/script/module/entity/component/moduleentityposition.h index c3789b38..149375cd 100644 --- a/src/dusk/script/module/entity/component/moduleentityposition.h +++ b/src/dusk/script/module/entity/component/moduleentityposition.h @@ -33,8 +33,6 @@ static entityposition_t * moduleEntityPositionGet( return entityPositionGet(h->eid, h->cid); } -// -- position -- - moduleBaseFunction(moduleEntityPositionGetPosition) { entityposition_t *pos = moduleEntityPositionGet(callInfo); if(!pos) return jerry_undefined(); @@ -56,8 +54,6 @@ moduleBaseFunction(moduleEntityPositionSetPosition) { return jerry_undefined(); } -// -- rotation -- - moduleBaseFunction(moduleEntityPositionGetRotation) { entityposition_t *pos = moduleEntityPositionGet(callInfo); if(!pos) return jerry_undefined(); @@ -79,8 +75,6 @@ moduleBaseFunction(moduleEntityPositionSetRotation) { return jerry_undefined(); } -// -- scale -- - moduleBaseFunction(moduleEntityPositionGetScale) { entityposition_t *pos = moduleEntityPositionGet(callInfo); if(!pos) return jerry_undefined(); @@ -102,8 +96,6 @@ moduleBaseFunction(moduleEntityPositionSetScale) { return jerry_undefined(); } -// -- lookAt -- - moduleBaseFunction(moduleEntityPositionLookAt) { moduleBaseRequireArgs(1); entityposition_t *pos = moduleEntityPositionGet(callInfo); @@ -121,8 +113,6 @@ moduleBaseFunction(moduleEntityPositionLookAt) { return jerry_undefined(); } -// -- add function -- - moduleBaseFunction(moduleEntityPositionAdd) { moduleBaseRequireArgs(1); moduleBaseRequireNumber(0); entityid_t id = (entityid_t)jerry_value_as_number(args[0]); diff --git a/src/dusk/script/module/input/moduleinput.h b/src/dusk/script/module/input/moduleinput.h index e225d774..5d3ea443 100644 --- a/src/dusk/script/module/input/moduleinput.h +++ b/src/dusk/script/module/input/moduleinput.h @@ -111,7 +111,7 @@ moduleBaseFunction(moduleInputAxis2D) { } vec2 result; inputAxis2D(negX, posX, negY, posY, result); - return scriptProtoCreateValue(&MODULE_VEC2_PROTO, result); + return moduleVec2Push(result); } moduleBaseFunction(moduleInputGetEventAction) { @@ -144,19 +144,32 @@ static void moduleInput(void) { #endif ); - scriptProtoInit(&MODULE_INPUT_PROTO, "Input", sizeof(uint8_t), NULL); + scriptProtoInit( + &MODULE_INPUT_PROTO, "Input", sizeof(uint8_t), NULL + ); - #define X(name, method) \ - scriptProtoDefineStaticFunc( \ - &MODULE_INPUT_PROTO, #name, moduleInput##method \ - ); - X(bind, Bind); - X(isDown, IsDown); - X(pressed, Pressed); - X(released, Released); - X(getValue, GetValue); - X(axis, Axis); - X(axis2D, Axis2D); - X(getEventAction, GetEventAction); - #undef X + scriptProtoDefineStaticFunc( + &MODULE_INPUT_PROTO, "bind", moduleInputBind + ); + scriptProtoDefineStaticFunc( + &MODULE_INPUT_PROTO, "isDown", moduleInputIsDown + ); + scriptProtoDefineStaticFunc( + &MODULE_INPUT_PROTO, "pressed", moduleInputPressed + ); + scriptProtoDefineStaticFunc( + &MODULE_INPUT_PROTO, "released", moduleInputReleased + ); + scriptProtoDefineStaticFunc( + &MODULE_INPUT_PROTO, "getValue", moduleInputGetValue + ); + scriptProtoDefineStaticFunc( + &MODULE_INPUT_PROTO, "axis", moduleInputAxis + ); + scriptProtoDefineStaticFunc( + &MODULE_INPUT_PROTO, "axis2D", moduleInputAxis2D + ); + scriptProtoDefineStaticFunc( + &MODULE_INPUT_PROTO, "getEventAction", moduleInputGetEventAction + ); } diff --git a/src/dusk/script/module/scene/modulescene.h b/src/dusk/script/module/scene/modulescene.h index a6923cd9..89999a4e 100644 --- a/src/dusk/script/module/scene/modulescene.h +++ b/src/dusk/script/module/scene/modulescene.h @@ -27,7 +27,6 @@ moduleBaseFunction(moduleSceneConstructor) { return jerry_undefined(); } -// Static: Scene.set(name) moduleBaseFunction(moduleSceneSet) { moduleBaseRequireArgs(1); moduleBaseRequireString(0); @@ -40,7 +39,6 @@ moduleBaseFunction(moduleSceneSet) { return jerry_undefined(); } -// Static: Scene.current (getter) moduleBaseFunction(moduleSceneGetCurrent) { if(SCENE.sceneCurrent[0] == '\0') return jerry_undefined(); return jerry_string_sz(SCENE.sceneCurrent); @@ -101,8 +99,12 @@ static void moduleScene(void) { moduleSceneConstructor ); - scriptProtoDefineFunc(&MODULE_SCENE_PROTO, "update", moduleSceneDefaultUpdate); - scriptProtoDefineFunc(&MODULE_SCENE_PROTO, "dispose", moduleSceneDefaultDispose); + scriptProtoDefineFunc( + &MODULE_SCENE_PROTO, "update", moduleSceneDefaultUpdate + ); + scriptProtoDefineFunc( + &MODULE_SCENE_PROTO, "dispose", moduleSceneDefaultDispose + ); scriptProtoDefineStaticFunc(&MODULE_SCENE_PROTO, "set", moduleSceneSet); scriptProtoDefineStaticProp(