Cleanup, prepping for example game stuff
This commit is contained in:
@@ -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;
|
||||||
@@ -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;
|
||||||
@@ -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;
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
var Cube = include('entities/cube.js');
|
var CubeEntity = include('entities/CubeEntity.js');
|
||||||
|
|
||||||
function CubeScene() {
|
function CubeScene() {
|
||||||
this.cam = new Entity();
|
this.cam = new Entity();
|
||||||
@@ -8,7 +8,7 @@ function CubeScene() {
|
|||||||
this.cam.position.position = new Vec3(3, 3, 3);
|
this.cam.position.position = new Vec3(3, 3, 3);
|
||||||
this.cam.position.lookAt(new Vec3(0, 0, 0));
|
this.cam.position.lookAt(new Vec3(0, 0, 0));
|
||||||
|
|
||||||
this.cube = new Cube();
|
this.cube = new CubeEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
CubeScene.prototype = Object.create(Scene.prototype);
|
CubeScene.prototype = Object.create(Scene.prototype);
|
||||||
|
|||||||
@@ -11,138 +11,103 @@
|
|||||||
#include "time/time.h"
|
#include "time/time.h"
|
||||||
#include "script/scriptproto.h"
|
#include "script/scriptproto.h"
|
||||||
|
|
||||||
// Define the prototype.
|
|
||||||
static scriptproto_t MODULE_COLOR_PROTO;
|
static scriptproto_t MODULE_COLOR_PROTO;
|
||||||
|
|
||||||
// Getters
|
static inline color_t * moduleColorGet(
|
||||||
moduleBaseFunction(moduleColorGetR) {
|
const jerry_call_info_t *callInfo
|
||||||
color_t *color = (color_t*)scriptProtoGetValue(
|
) {
|
||||||
|
return (color_t*)scriptProtoGetValue(
|
||||||
&MODULE_COLOR_PROTO, callInfo->this_value
|
&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) {
|
moduleBaseFunction(moduleColorGetG) {
|
||||||
color_t *color = (color_t*)scriptProtoGetValue(
|
color_t *c = moduleColorGet(callInfo);
|
||||||
&MODULE_COLOR_PROTO, callInfo->this_value
|
return c ? jerry_number(c->g) : jerry_undefined();
|
||||||
);
|
|
||||||
if(!color) return jerry_undefined();
|
|
||||||
return jerry_number(color->g);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
moduleBaseFunction(moduleColorGetB) {
|
moduleBaseFunction(moduleColorGetB) {
|
||||||
color_t *color = (color_t*)scriptProtoGetValue(
|
color_t *c = moduleColorGet(callInfo);
|
||||||
&MODULE_COLOR_PROTO, callInfo->this_value
|
return c ? jerry_number(c->b) : jerry_undefined();
|
||||||
);
|
|
||||||
if(!color) return jerry_undefined();
|
|
||||||
return jerry_number(color->b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
moduleBaseFunction(moduleColorGetA) {
|
moduleBaseFunction(moduleColorGetA) {
|
||||||
color_t *color = (color_t*)scriptProtoGetValue(
|
color_t *c = moduleColorGet(callInfo);
|
||||||
&MODULE_COLOR_PROTO, callInfo->this_value
|
return c ? jerry_number(c->a) : jerry_undefined();
|
||||||
);
|
|
||||||
if(!color) return jerry_undefined();
|
|
||||||
return jerry_number(color->a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setters
|
|
||||||
moduleBaseFunction(moduleColorSetR) {
|
moduleBaseFunction(moduleColorSetR) {
|
||||||
color_t *color = (color_t*)scriptProtoGetValue(
|
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||||
&MODULE_COLOR_PROTO, callInfo->this_value
|
color_t *c = moduleColorGet(callInfo);
|
||||||
);
|
if(!c) return jerry_undefined();
|
||||||
if(!color || argc < 1) return moduleBaseThrow("Expected a number argument");
|
c->r = (colorchannel8_t)jerry_value_as_number(args[0]);
|
||||||
color->r = (colorchannel8_t)jerry_value_as_number(args[0]);
|
|
||||||
return args[0];
|
return args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
moduleBaseFunction(moduleColorSetG) {
|
moduleBaseFunction(moduleColorSetG) {
|
||||||
color_t *color = (color_t*)scriptProtoGetValue(
|
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||||
&MODULE_COLOR_PROTO, callInfo->this_value
|
color_t *c = moduleColorGet(callInfo);
|
||||||
);
|
if(!c) return jerry_undefined();
|
||||||
if(!color || argc < 1) return moduleBaseThrow("Expected a number argument");
|
c->g = (colorchannel8_t)jerry_value_as_number(args[0]);
|
||||||
color->g = (colorchannel8_t)jerry_value_as_number(args[0]);
|
|
||||||
return args[0];
|
return args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
moduleBaseFunction(moduleColorSetB) {
|
moduleBaseFunction(moduleColorSetB) {
|
||||||
color_t *color = (color_t*)scriptProtoGetValue(
|
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||||
&MODULE_COLOR_PROTO, callInfo->this_value
|
color_t *c = moduleColorGet(callInfo);
|
||||||
);
|
if(!c) return jerry_undefined();
|
||||||
if(!color || argc < 1) return moduleBaseThrow("Expected a number argument");
|
c->b = (colorchannel8_t)jerry_value_as_number(args[0]);
|
||||||
color->b = (colorchannel8_t)jerry_value_as_number(args[0]);
|
|
||||||
return args[0];
|
return args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
moduleBaseFunction(moduleColorSetA) {
|
moduleBaseFunction(moduleColorSetA) {
|
||||||
color_t *color = (color_t*)scriptProtoGetValue(
|
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||||
&MODULE_COLOR_PROTO, callInfo->this_value
|
color_t *c = moduleColorGet(callInfo);
|
||||||
);
|
if(!c) return jerry_undefined();
|
||||||
if(!color || argc < 1) return moduleBaseThrow("Expected a number argument");
|
c->a = (colorchannel8_t)jerry_value_as_number(args[0]);
|
||||||
color->a = (colorchannel8_t)jerry_value_as_number(args[0]);
|
|
||||||
return args[0];
|
return args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
moduleBaseFunction(moduleColorToString) {
|
moduleBaseFunction(moduleColorToString) {
|
||||||
color_t *color = (color_t*)scriptProtoGetValue(
|
color_t *c = moduleColorGet(callInfo);
|
||||||
&MODULE_COLOR_PROTO, callInfo->this_value
|
if(!c) return jerry_undefined();
|
||||||
);
|
|
||||||
if(!color) return jerry_undefined();
|
|
||||||
char_t buf[64];
|
char_t buf[64];
|
||||||
stringFormat(
|
stringFormat(
|
||||||
buf, sizeof(buf),
|
buf, sizeof(buf),
|
||||||
"{ \"r\": %d, \"g\": %d, \"b\": %d, \"a\": %d }",
|
"{ \"r\": %d, \"g\": %d, \"b\": %d, \"a\": %d }",
|
||||||
(int32_t)color->r, (int32_t)color->g,
|
(int32_t)c->r, (int32_t)c->g,
|
||||||
(int32_t)color->b, (int32_t)color->a
|
(int32_t)c->b, (int32_t)c->a
|
||||||
);
|
);
|
||||||
return jerry_string_sz(buf);
|
return jerry_string_sz(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
|
||||||
static jerry_value_t moduleColorMakeObject(color_t color) {
|
static jerry_value_t moduleColorMakeObject(color_t color) {
|
||||||
return scriptProtoCreateValue(&MODULE_COLOR_PROTO, &color);
|
return scriptProtoCreateValue(&MODULE_COLOR_PROTO, &color);
|
||||||
}
|
}
|
||||||
|
|
||||||
moduleBaseFunction(moduleColorConstructor) {
|
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;
|
color_t c;
|
||||||
|
c.r = argc > 0 ? (colorchannel8_t)jerry_value_as_number(args[0]) : 255;
|
||||||
if(argc > 0) {
|
c.g = argc > 1 ? (colorchannel8_t)jerry_value_as_number(args[1]) : 255;
|
||||||
if(!jerry_value_is_number(args[0])) {
|
c.b = argc > 2 ? (colorchannel8_t)jerry_value_as_number(args[2]) : 255;
|
||||||
return moduleBaseThrow("Expected number argument for r");
|
c.a = argc > 3 ? (colorchannel8_t)jerry_value_as_number(args[3]) : 255;
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return moduleColorMakeObject(c);
|
return moduleColorMakeObject(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,31 +125,34 @@ moduleBaseFunction(moduleColorRainbow) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
color_t c;
|
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.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.b = (colorchannel8_t)((sinf(t + 4.0f) + 1.0f) * 0.5f * 255.0f);
|
||||||
c.a = 255;
|
c.a = 255;
|
||||||
return moduleColorMakeObject(c);
|
return moduleColorMakeObject(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Root Module
|
|
||||||
static void moduleColor(void) {
|
static void moduleColor(void) {
|
||||||
scriptProtoInit(
|
scriptProtoInit(
|
||||||
&MODULE_COLOR_PROTO,
|
&MODULE_COLOR_PROTO, "Color", sizeof(color_t), moduleColorConstructor
|
||||||
"Color",
|
|
||||||
sizeof(color_t),
|
|
||||||
moduleColorConstructor
|
|
||||||
);
|
);
|
||||||
|
|
||||||
#define X(x, g, s) \
|
scriptProtoDefineProp(
|
||||||
scriptProtoDefineProp(&MODULE_COLOR_PROTO, #x, g, s);
|
&MODULE_COLOR_PROTO, "r", moduleColorGetR, moduleColorSetR
|
||||||
X(r, moduleColorGetR, moduleColorSetR);
|
);
|
||||||
X(g, moduleColorGetG, moduleColorSetG);
|
scriptProtoDefineProp(
|
||||||
X(b, moduleColorGetB, moduleColorSetB);
|
&MODULE_COLOR_PROTO, "g", moduleColorGetG, moduleColorSetG
|
||||||
X(a, moduleColorGetA, moduleColorSetA);
|
);
|
||||||
#undef X
|
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);
|
scriptProtoDefineToString(&MODULE_COLOR_PROTO, moduleColorToString);
|
||||||
moduleBaseEval(COLOR_SCRIPT);
|
moduleBaseEval(COLOR_SCRIPT);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,8 @@
|
|||||||
#include "script/module/display/modulecolor.h"
|
#include "script/module/display/modulecolor.h"
|
||||||
#include "display/screen/screen.h"
|
#include "display/screen/screen.h"
|
||||||
|
|
||||||
scriptproto_t MODULE_SCREEN_PROTO;
|
static scriptproto_t MODULE_SCREEN_PROTO;
|
||||||
|
|
||||||
// Getters
|
|
||||||
moduleBaseFunction(moduleScreenGetWidth) {
|
moduleBaseFunction(moduleScreenGetWidth) {
|
||||||
return jerry_number(SCREEN.width);
|
return jerry_number(SCREEN.width);
|
||||||
}
|
}
|
||||||
@@ -28,23 +27,20 @@ moduleBaseFunction(moduleScreenGetBackground) {
|
|||||||
return moduleColorMakeObject(SCREEN.background);
|
return moduleColorMakeObject(SCREEN.background);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setters
|
|
||||||
moduleBaseFunction(moduleScreenSetBackground) {
|
moduleBaseFunction(moduleScreenSetBackground) {
|
||||||
if(argc < 1 || !jerry_value_is_object(args[0])) {
|
if(argc < 1 || !jerry_value_is_object(args[0])) {
|
||||||
return moduleBaseThrow("Screen background color must be a color object");
|
return moduleBaseThrow("Screen background color must be a color object");
|
||||||
}
|
}
|
||||||
|
color_t *color = (color_t*)scriptProtoGetValue(
|
||||||
// Get color pointer from the object.
|
&MODULE_COLOR_PROTO, args[0]
|
||||||
color_t *color = (color_t*)scriptProtoGetValue(&MODULE_COLOR_PROTO, args[0]);
|
);
|
||||||
if(!color) {
|
if(!color) {
|
||||||
return moduleBaseThrow("Background must be a valid color object");
|
return moduleBaseThrow("Background must be a valid color object");
|
||||||
}
|
}
|
||||||
|
|
||||||
memoryCopy(&SCREEN.background, color, sizeof(color_t));
|
memoryCopy(&SCREEN.background, color, sizeof(color_t));
|
||||||
return jerry_undefined();
|
return jerry_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Functions
|
|
||||||
moduleBaseFunction(moduleScreenToString) {
|
moduleBaseFunction(moduleScreenToString) {
|
||||||
char_t buf[128];
|
char_t buf[128];
|
||||||
stringFormat(
|
stringFormat(
|
||||||
@@ -56,15 +52,23 @@ moduleBaseFunction(moduleScreenToString) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void moduleScreen(void) {
|
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(
|
||||||
scriptProtoDefineProp(&MODULE_SCREEN_PROTO, #x, g, s);
|
&MODULE_SCREEN_PROTO, "width", moduleScreenGetWidth, NULL
|
||||||
X(width, moduleScreenGetWidth, NULL)
|
);
|
||||||
X(height, moduleScreenGetHeight, NULL)
|
scriptProtoDefineProp(
|
||||||
X(aspect, moduleScreenGetAspect, NULL)
|
&MODULE_SCREEN_PROTO, "height", moduleScreenGetHeight, NULL
|
||||||
X(background, moduleScreenGetBackground, moduleScreenSetBackground)
|
);
|
||||||
#undef X
|
scriptProtoDefineProp(
|
||||||
|
&MODULE_SCREEN_PROTO, "aspect", moduleScreenGetAspect, NULL
|
||||||
|
);
|
||||||
|
scriptProtoDefineProp(
|
||||||
|
&MODULE_SCREEN_PROTO, "background",
|
||||||
|
moduleScreenGetBackground, moduleScreenSetBackground
|
||||||
|
);
|
||||||
|
|
||||||
scriptProtoDefineToString(&MODULE_SCREEN_PROTO, moduleScreenToString);
|
scriptProtoDefineToString(&MODULE_SCREEN_PROTO, moduleScreenToString);
|
||||||
}
|
}
|
||||||
@@ -14,12 +14,6 @@
|
|||||||
|
|
||||||
static scriptproto_t MODULE_ENTITY_CAMERA_PROTO;
|
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(
|
static entitycamera_t * moduleEntityCameraGet(
|
||||||
const jerry_call_info_t *callInfo
|
const jerry_call_info_t *callInfo
|
||||||
) {
|
) {
|
||||||
@@ -27,17 +21,11 @@ static entitycamera_t * moduleEntityCameraGet(
|
|||||||
&MODULE_ENTITY_CAMERA_PROTO, callInfo->this_value
|
&MODULE_ENTITY_CAMERA_PROTO, callInfo->this_value
|
||||||
);
|
);
|
||||||
if(!h) return NULL;
|
if(!h) return NULL;
|
||||||
|
return (entitycamera_t*)componentGetData(
|
||||||
entitycamera_t *cam = (entitycamera_t*)componentGetData(
|
|
||||||
h->eid, h->cid, COMPONENT_TYPE_CAMERA
|
h->eid, h->cid, COMPONENT_TYPE_CAMERA
|
||||||
);
|
);
|
||||||
if(!cam) return NULL;
|
|
||||||
|
|
||||||
return cam;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Getters
|
|
||||||
moduleBaseFunction(moduleEntityCameraGetZNear) {
|
moduleBaseFunction(moduleEntityCameraGetZNear) {
|
||||||
entitycamera_t *cam = moduleEntityCameraGet(callInfo);
|
entitycamera_t *cam = moduleEntityCameraGet(callInfo);
|
||||||
if(!cam) return jerry_undefined();
|
if(!cam) return jerry_undefined();
|
||||||
@@ -99,8 +87,6 @@ moduleBaseFunction(moduleEntityCameraGetProjectionType) {
|
|||||||
return jerry_number(cam->projType);
|
return jerry_number(cam->projType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Setters
|
|
||||||
moduleBaseFunction(moduleEntityCameraSetZNear) {
|
moduleBaseFunction(moduleEntityCameraSetZNear) {
|
||||||
if(argc < 1 || !jerry_value_is_number(args[0])) {
|
if(argc < 1 || !jerry_value_is_number(args[0])) {
|
||||||
return moduleBaseThrow("Expected a number");
|
return moduleBaseThrow("Expected a number");
|
||||||
@@ -201,8 +187,6 @@ moduleBaseFunction(moduleEntityCameraSetProjectionType) {
|
|||||||
return args[0];
|
return args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Adder for this component.
|
|
||||||
moduleBaseFunction(moduleEntityCameraAdd) {
|
moduleBaseFunction(moduleEntityCameraAdd) {
|
||||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||||
entityid_t id = (entityid_t)jerry_value_as_number(args[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);
|
return scriptProtoCreateValue(&MODULE_ENTITY_CAMERA_PROTO, &h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void moduleEntityCAMERA(void) {
|
static void moduleEntityCAMERA(void) {
|
||||||
scriptProtoInit(
|
scriptProtoInit(
|
||||||
&MODULE_ENTITY_CAMERA_PROTO, NULL, sizeof(componenthandle_t), NULL
|
&MODULE_ENTITY_CAMERA_PROTO, NULL, sizeof(componenthandle_t), NULL
|
||||||
@@ -223,7 +206,7 @@ static void moduleEntityCAMERA(void) {
|
|||||||
);
|
);
|
||||||
scriptProtoDefineProp(
|
scriptProtoDefineProp(
|
||||||
&MODULE_ENTITY_CAMERA_PROTO, "zFar",
|
&MODULE_ENTITY_CAMERA_PROTO, "zFar",
|
||||||
moduleEntityCameraGetZFar, moduleEntityCameraSetZFar
|
moduleEntityCameraGetZFar, moduleEntityCameraSetZFar
|
||||||
);
|
);
|
||||||
scriptProtoDefineProp(
|
scriptProtoDefineProp(
|
||||||
&MODULE_ENTITY_CAMERA_PROTO, "orthoTop",
|
&MODULE_ENTITY_CAMERA_PROTO, "orthoTop",
|
||||||
@@ -250,12 +233,12 @@ static void moduleEntityCAMERA(void) {
|
|||||||
moduleEntityCameraGetProjectionType, moduleEntityCameraSetProjectionType
|
moduleEntityCameraGetProjectionType, moduleEntityCameraSetProjectionType
|
||||||
);
|
);
|
||||||
|
|
||||||
char_t buffer[64];
|
moduleBaseSetInt(
|
||||||
snprintf(
|
"CAMERA_TYPE_ORTHOGRAPHIC",
|
||||||
buffer, sizeof(buffer),
|
ENTITY_CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC
|
||||||
"%s = %d;\n%s = %d;\n",
|
);
|
||||||
"CAMERA_TYPE_ORTHOGRAPHIC", ENTITY_CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC,
|
moduleBaseSetInt(
|
||||||
"CAMERA_TYPE_PERSPECTIVE", ENTITY_CAMERA_PROJECTION_TYPE_PERSPECTIVE
|
"CAMERA_TYPE_PERSPECTIVE",
|
||||||
|
ENTITY_CAMERA_PROJECTION_TYPE_PERSPECTIVE
|
||||||
);
|
);
|
||||||
moduleBaseEval(buffer);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ static entitymaterial_t * moduleEntityMaterialGet(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Setters
|
|
||||||
moduleBaseFunction(moduleEntityMaterialSetColor) {
|
moduleBaseFunction(moduleEntityMaterialSetColor) {
|
||||||
moduleBaseRequireArgs(1);
|
moduleBaseRequireArgs(1);
|
||||||
if(!jerry_value_is_object(args[0])) {
|
if(!jerry_value_is_object(args[0])) {
|
||||||
@@ -69,7 +67,6 @@ moduleBaseFunction(moduleEntityMaterialSetColor) {
|
|||||||
return jerry_undefined();
|
return jerry_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Component add method
|
|
||||||
moduleBaseFunction(moduleEntityMaterialAdd) {
|
moduleBaseFunction(moduleEntityMaterialAdd) {
|
||||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||||
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ static entitymesh_t * moduleEntityMeshGet(
|
|||||||
return (entitymesh_t*)componentGetData(h->eid, h->cid, COMPONENT_TYPE_MESH);
|
return (entitymesh_t*)componentGetData(h->eid, h->cid, COMPONENT_TYPE_MESH);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Component add
|
|
||||||
moduleBaseFunction(moduleEntityMeshAdd) {
|
moduleBaseFunction(moduleEntityMeshAdd) {
|
||||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||||
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
||||||
|
|||||||
@@ -25,8 +25,6 @@ static entityphysics_t * moduleEntityPhysicsGet(
|
|||||||
return entityPhysicsGet(h->eid, h->cid);
|
return entityPhysicsGet(h->eid, h->cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- velocity --
|
|
||||||
|
|
||||||
moduleBaseFunction(moduleEntityPhysicsGetVelocity) {
|
moduleBaseFunction(moduleEntityPhysicsGetVelocity) {
|
||||||
entityphysics_t *phys = moduleEntityPhysicsGet(callInfo);
|
entityphysics_t *phys = moduleEntityPhysicsGet(callInfo);
|
||||||
if(!phys) return jerry_undefined();
|
if(!phys) return jerry_undefined();
|
||||||
@@ -45,16 +43,12 @@ moduleBaseFunction(moduleEntityPhysicsSetVelocity) {
|
|||||||
return jerry_undefined();
|
return jerry_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- onGround (read-only) --
|
|
||||||
|
|
||||||
moduleBaseFunction(moduleEntityPhysicsGetOnGround) {
|
moduleBaseFunction(moduleEntityPhysicsGetOnGround) {
|
||||||
entityphysics_t *phys = moduleEntityPhysicsGet(callInfo);
|
entityphysics_t *phys = moduleEntityPhysicsGet(callInfo);
|
||||||
if(!phys) return jerry_undefined();
|
if(!phys) return jerry_undefined();
|
||||||
return jerry_boolean(phys->onGround);
|
return jerry_boolean(phys->onGround);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- bodyType --
|
|
||||||
|
|
||||||
moduleBaseFunction(moduleEntityPhysicsGetBodyType) {
|
moduleBaseFunction(moduleEntityPhysicsGetBodyType) {
|
||||||
entityphysics_t *phys = moduleEntityPhysicsGet(callInfo);
|
entityphysics_t *phys = moduleEntityPhysicsGet(callInfo);
|
||||||
if(!phys) return jerry_undefined();
|
if(!phys) return jerry_undefined();
|
||||||
@@ -69,8 +63,6 @@ moduleBaseFunction(moduleEntityPhysicsSetBodyType) {
|
|||||||
return jerry_undefined();
|
return jerry_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- methods --
|
|
||||||
|
|
||||||
moduleBaseFunction(moduleEntityPhysicsApplyImpulse) {
|
moduleBaseFunction(moduleEntityPhysicsApplyImpulse) {
|
||||||
moduleBaseRequireArgs(1);
|
moduleBaseRequireArgs(1);
|
||||||
entityphysics_t *phys = moduleEntityPhysicsGet(callInfo);
|
entityphysics_t *phys = moduleEntityPhysicsGet(callInfo);
|
||||||
@@ -132,8 +124,6 @@ moduleBaseFunction(moduleEntityPhysicsSetShapePlane) {
|
|||||||
return jerry_undefined();
|
return jerry_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- add function --
|
|
||||||
|
|
||||||
moduleBaseFunction(moduleEntityPhysicsAdd) {
|
moduleBaseFunction(moduleEntityPhysicsAdd) {
|
||||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||||
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
||||||
|
|||||||
@@ -33,8 +33,6 @@ static entityposition_t * moduleEntityPositionGet(
|
|||||||
return entityPositionGet(h->eid, h->cid);
|
return entityPositionGet(h->eid, h->cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- position --
|
|
||||||
|
|
||||||
moduleBaseFunction(moduleEntityPositionGetPosition) {
|
moduleBaseFunction(moduleEntityPositionGetPosition) {
|
||||||
entityposition_t *pos = moduleEntityPositionGet(callInfo);
|
entityposition_t *pos = moduleEntityPositionGet(callInfo);
|
||||||
if(!pos) return jerry_undefined();
|
if(!pos) return jerry_undefined();
|
||||||
@@ -56,8 +54,6 @@ moduleBaseFunction(moduleEntityPositionSetPosition) {
|
|||||||
return jerry_undefined();
|
return jerry_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- rotation --
|
|
||||||
|
|
||||||
moduleBaseFunction(moduleEntityPositionGetRotation) {
|
moduleBaseFunction(moduleEntityPositionGetRotation) {
|
||||||
entityposition_t *pos = moduleEntityPositionGet(callInfo);
|
entityposition_t *pos = moduleEntityPositionGet(callInfo);
|
||||||
if(!pos) return jerry_undefined();
|
if(!pos) return jerry_undefined();
|
||||||
@@ -79,8 +75,6 @@ moduleBaseFunction(moduleEntityPositionSetRotation) {
|
|||||||
return jerry_undefined();
|
return jerry_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- scale --
|
|
||||||
|
|
||||||
moduleBaseFunction(moduleEntityPositionGetScale) {
|
moduleBaseFunction(moduleEntityPositionGetScale) {
|
||||||
entityposition_t *pos = moduleEntityPositionGet(callInfo);
|
entityposition_t *pos = moduleEntityPositionGet(callInfo);
|
||||||
if(!pos) return jerry_undefined();
|
if(!pos) return jerry_undefined();
|
||||||
@@ -102,8 +96,6 @@ moduleBaseFunction(moduleEntityPositionSetScale) {
|
|||||||
return jerry_undefined();
|
return jerry_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- lookAt --
|
|
||||||
|
|
||||||
moduleBaseFunction(moduleEntityPositionLookAt) {
|
moduleBaseFunction(moduleEntityPositionLookAt) {
|
||||||
moduleBaseRequireArgs(1);
|
moduleBaseRequireArgs(1);
|
||||||
entityposition_t *pos = moduleEntityPositionGet(callInfo);
|
entityposition_t *pos = moduleEntityPositionGet(callInfo);
|
||||||
@@ -121,8 +113,6 @@ moduleBaseFunction(moduleEntityPositionLookAt) {
|
|||||||
return jerry_undefined();
|
return jerry_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- add function --
|
|
||||||
|
|
||||||
moduleBaseFunction(moduleEntityPositionAdd) {
|
moduleBaseFunction(moduleEntityPositionAdd) {
|
||||||
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
|
||||||
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
entityid_t id = (entityid_t)jerry_value_as_number(args[0]);
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ moduleBaseFunction(moduleInputAxis2D) {
|
|||||||
}
|
}
|
||||||
vec2 result;
|
vec2 result;
|
||||||
inputAxis2D(negX, posX, negY, posY, result);
|
inputAxis2D(negX, posX, negY, posY, result);
|
||||||
return scriptProtoCreateValue(&MODULE_VEC2_PROTO, result);
|
return moduleVec2Push(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
moduleBaseFunction(moduleInputGetEventAction) {
|
moduleBaseFunction(moduleInputGetEventAction) {
|
||||||
@@ -144,19 +144,32 @@ static void moduleInput(void) {
|
|||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
|
|
||||||
scriptProtoInit(&MODULE_INPUT_PROTO, "Input", sizeof(uint8_t), NULL);
|
scriptProtoInit(
|
||||||
|
&MODULE_INPUT_PROTO, "Input", sizeof(uint8_t), NULL
|
||||||
|
);
|
||||||
|
|
||||||
#define X(name, method) \
|
scriptProtoDefineStaticFunc(
|
||||||
scriptProtoDefineStaticFunc( \
|
&MODULE_INPUT_PROTO, "bind", moduleInputBind
|
||||||
&MODULE_INPUT_PROTO, #name, moduleInput##method \
|
);
|
||||||
);
|
scriptProtoDefineStaticFunc(
|
||||||
X(bind, Bind);
|
&MODULE_INPUT_PROTO, "isDown", moduleInputIsDown
|
||||||
X(isDown, IsDown);
|
);
|
||||||
X(pressed, Pressed);
|
scriptProtoDefineStaticFunc(
|
||||||
X(released, Released);
|
&MODULE_INPUT_PROTO, "pressed", moduleInputPressed
|
||||||
X(getValue, GetValue);
|
);
|
||||||
X(axis, Axis);
|
scriptProtoDefineStaticFunc(
|
||||||
X(axis2D, Axis2D);
|
&MODULE_INPUT_PROTO, "released", moduleInputReleased
|
||||||
X(getEventAction, GetEventAction);
|
);
|
||||||
#undef X
|
scriptProtoDefineStaticFunc(
|
||||||
|
&MODULE_INPUT_PROTO, "getValue", moduleInputGetValue
|
||||||
|
);
|
||||||
|
scriptProtoDefineStaticFunc(
|
||||||
|
&MODULE_INPUT_PROTO, "axis", moduleInputAxis
|
||||||
|
);
|
||||||
|
scriptProtoDefineStaticFunc(
|
||||||
|
&MODULE_INPUT_PROTO, "axis2D", moduleInputAxis2D
|
||||||
|
);
|
||||||
|
scriptProtoDefineStaticFunc(
|
||||||
|
&MODULE_INPUT_PROTO, "getEventAction", moduleInputGetEventAction
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ moduleBaseFunction(moduleSceneConstructor) {
|
|||||||
return jerry_undefined();
|
return jerry_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Static: Scene.set(name)
|
|
||||||
moduleBaseFunction(moduleSceneSet) {
|
moduleBaseFunction(moduleSceneSet) {
|
||||||
moduleBaseRequireArgs(1);
|
moduleBaseRequireArgs(1);
|
||||||
moduleBaseRequireString(0);
|
moduleBaseRequireString(0);
|
||||||
@@ -40,7 +39,6 @@ moduleBaseFunction(moduleSceneSet) {
|
|||||||
return jerry_undefined();
|
return jerry_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Static: Scene.current (getter)
|
|
||||||
moduleBaseFunction(moduleSceneGetCurrent) {
|
moduleBaseFunction(moduleSceneGetCurrent) {
|
||||||
if(SCENE.sceneCurrent[0] == '\0') return jerry_undefined();
|
if(SCENE.sceneCurrent[0] == '\0') return jerry_undefined();
|
||||||
return jerry_string_sz(SCENE.sceneCurrent);
|
return jerry_string_sz(SCENE.sceneCurrent);
|
||||||
@@ -101,8 +99,12 @@ static void moduleScene(void) {
|
|||||||
moduleSceneConstructor
|
moduleSceneConstructor
|
||||||
);
|
);
|
||||||
|
|
||||||
scriptProtoDefineFunc(&MODULE_SCENE_PROTO, "update", moduleSceneDefaultUpdate);
|
scriptProtoDefineFunc(
|
||||||
scriptProtoDefineFunc(&MODULE_SCENE_PROTO, "dispose", moduleSceneDefaultDispose);
|
&MODULE_SCENE_PROTO, "update", moduleSceneDefaultUpdate
|
||||||
|
);
|
||||||
|
scriptProtoDefineFunc(
|
||||||
|
&MODULE_SCENE_PROTO, "dispose", moduleSceneDefaultDispose
|
||||||
|
);
|
||||||
|
|
||||||
scriptProtoDefineStaticFunc(&MODULE_SCENE_PROTO, "set", moduleSceneSet);
|
scriptProtoDefineStaticFunc(&MODULE_SCENE_PROTO, "set", moduleSceneSet);
|
||||||
scriptProtoDefineStaticProp(
|
scriptProtoDefineStaticProp(
|
||||||
|
|||||||
Reference in New Issue
Block a user