More cleanup

This commit is contained in:
2026-04-30 22:40:32 -05:00
parent 2e43aa2c44
commit abd63cc6cf
5 changed files with 231 additions and 119 deletions
@@ -21,42 +21,6 @@ void entityCameraInit(const entityid_t ent, const componentid_t comp) {
cam->perspective.fov = glm_rad(45.0f); cam->perspective.fov = glm_rad(45.0f);
} }
float_t entityCameraGetZNear(const entityid_t ent, const componentid_t comp) {
entitycamera_t *cam = (entitycamera_t *)componentGetData(
ent, comp, COMPONENT_TYPE_CAMERA
);
return cam->nearClip;
}
void entityCameraSetZNear(
const entityid_t ent,
const componentid_t comp,
const float_t zNear
) {
entitycamera_t *cam = (entitycamera_t *)componentGetData(
ent, comp, COMPONENT_TYPE_CAMERA
);
cam->nearClip = zNear;
}
float_t entityCameraGetZFar(const entityid_t ent, const componentid_t comp) {
entitycamera_t *cam = (entitycamera_t *)componentGetData(
ent, comp, COMPONENT_TYPE_CAMERA
);
return cam->farClip;
}
void entityCameraSetZFar(
const entityid_t ent,
const componentid_t comp,
const float_t zFar
) {
entitycamera_t *cam = (entitycamera_t *)componentGetData(
ent, comp, COMPONENT_TYPE_CAMERA
);
cam->farClip = zFar;
}
void entityCameraGetProjection( void entityCameraGetProjection(
const entityid_t ent, const entityid_t ent,
const componentid_t comp, const componentid_t comp,
@@ -54,50 +54,6 @@ void entityCameraGetProjection(
mat4 out mat4 out
); );
/**
* Gets the near clip distance of a camera.
*
* @param ent The entity ID.
* @param comp The component ID.
* @return The near clip distance.
*/
float_t entityCameraGetZNear(const entityid_t ent, const componentid_t comp);
/**
* Sets the near clip distance of a camera.
*
* @param ent The entity ID.
* @param comp The component ID.
* @param zNear The near clip distance.
*/
void entityCameraSetZNear(
const entityid_t ent,
const componentid_t comp,
const float_t zNear
);
/**
* Gets the far clip distance of a camera.
*
* @param ent The entity ID.
* @param comp The component ID.
* @return The far clip distance.
*/
float_t entityCameraGetZFar(const entityid_t ent, const componentid_t comp);
/**
* Sets the far clip distance of a camera.
*
* @param ent The entity ID.
* @param comp The component ID.
* @param zFar The far clip distance.
*/
void entityCameraSetZFar(
const entityid_t ent,
const componentid_t comp,
const float_t zFar
);
/** /**
* Returns the entity ID of the first active camera, or ENTITY_COUNT_MAX if none. * Returns the entity ID of the first active camera, or ENTITY_COUNT_MAX if none.
*/ */
+12 -16
View File
@@ -52,40 +52,36 @@ moduleBaseFunction(moduleColorSetR) {
color_t *color = (color_t*)scriptProtoGetValue( color_t *color = (color_t*)scriptProtoGetValue(
&MODULE_COLOR_PROTO, callInfo->this_value &MODULE_COLOR_PROTO, callInfo->this_value
); );
if(color && argc > 0) { if(!color || argc < 1) return moduleBaseThrow("Expected a number argument");
color->r = (colorchannel8_t)jerry_value_as_number(args[0]); color->r = (colorchannel8_t)jerry_value_as_number(args[0]);
} return args[0];
return jerry_undefined();
} }
moduleBaseFunction(moduleColorSetG) { moduleBaseFunction(moduleColorSetG) {
color_t *color = (color_t*)scriptProtoGetValue( color_t *color = (color_t*)scriptProtoGetValue(
&MODULE_COLOR_PROTO, callInfo->this_value &MODULE_COLOR_PROTO, callInfo->this_value
); );
if(color && argc > 0) { if(!color || argc < 1) return moduleBaseThrow("Expected a number argument");
color->g = (colorchannel8_t)jerry_value_as_number(args[0]); color->g = (colorchannel8_t)jerry_value_as_number(args[0]);
} return args[0];
return jerry_undefined();
} }
moduleBaseFunction(moduleColorSetB) { moduleBaseFunction(moduleColorSetB) {
color_t *color = (color_t*)scriptProtoGetValue( color_t *color = (color_t*)scriptProtoGetValue(
&MODULE_COLOR_PROTO, callInfo->this_value &MODULE_COLOR_PROTO, callInfo->this_value
); );
if(color && argc > 0) { if(!color || argc < 1) return moduleBaseThrow("Expected a number argument");
color->b = (colorchannel8_t)jerry_value_as_number(args[0]); color->b = (colorchannel8_t)jerry_value_as_number(args[0]);
} return args[0];
return jerry_undefined();
} }
moduleBaseFunction(moduleColorSetA) { moduleBaseFunction(moduleColorSetA) {
color_t *color = (color_t*)scriptProtoGetValue( color_t *color = (color_t*)scriptProtoGetValue(
&MODULE_COLOR_PROTO, callInfo->this_value &MODULE_COLOR_PROTO, callInfo->this_value
); );
if(color && argc > 0) { if(!color || argc < 1) return moduleBaseThrow("Expected a number argument");
color->a = (colorchannel8_t)jerry_value_as_number(args[0]); color->a = (colorchannel8_t)jerry_value_as_number(args[0]);
} return args[0];
return jerry_undefined();
} }
moduleBaseFunction(moduleColorToString) { moduleBaseFunction(moduleColorToString) {
@@ -14,44 +14,194 @@
static scriptproto_t MODULE_ENTITY_CAMERA_PROTO; static scriptproto_t MODULE_ENTITY_CAMERA_PROTO;
// Getters /**
moduleBaseFunction(moduleEntityCameraGetZNear) { * 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
) {
componenthandle_t *h = scriptProtoGetValue( componenthandle_t *h = scriptProtoGetValue(
&MODULE_ENTITY_CAMERA_PROTO, callInfo->this_value &MODULE_ENTITY_CAMERA_PROTO, callInfo->this_value
); );
if(!h) return jerry_undefined(); if(!h) return NULL;
return jerry_number((double)entityCameraGetZNear(h->eid, h->cid));
entitycamera_t *cam = (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();
return jerry_number(cam->nearClip);
} }
moduleBaseFunction(moduleEntityCameraGetZFar) { moduleBaseFunction(moduleEntityCameraGetZFar) {
componenthandle_t *h = scriptProtoGetValue( entitycamera_t *cam = moduleEntityCameraGet(callInfo);
&MODULE_ENTITY_CAMERA_PROTO, callInfo->this_value if(!cam) return jerry_undefined();
); return jerry_number(cam->farClip);
if(!h) return jerry_undefined();
return jerry_number((double)entityCameraGetZFar(h->eid, h->cid));
} }
moduleBaseFunction(moduleEntityCameraGetOrthoTop) {
entitycamera_t *cam = moduleEntityCameraGet(callInfo);
if(!cam || cam->projType != ENTITY_CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC) {
return jerry_undefined();
}
return jerry_number(cam->orthographic.top);
}
moduleBaseFunction(moduleEntityCameraGetOrthoBottom) {
entitycamera_t *cam = moduleEntityCameraGet(callInfo);
if(!cam || cam->projType != ENTITY_CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC) {
return jerry_undefined();
}
return jerry_number(cam->orthographic.bottom);
}
moduleBaseFunction(moduleEntityCameraGetOrthoLeft) {
entitycamera_t *cam = moduleEntityCameraGet(callInfo);
if(!cam || cam->projType != ENTITY_CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC) {
return jerry_undefined();
}
return jerry_number(cam->orthographic.left);
}
moduleBaseFunction(moduleEntityCameraGetOrthoRight) {
entitycamera_t *cam = moduleEntityCameraGet(callInfo);
if(!cam || cam->projType != ENTITY_CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC) {
return jerry_undefined();
}
return jerry_number(cam->orthographic.right);
}
moduleBaseFunction(moduleEntityCameraGetFov) {
entitycamera_t *cam = moduleEntityCameraGet(callInfo);
if(!cam || (
cam->projType != ENTITY_CAMERA_PROJECTION_TYPE_PERSPECTIVE &&
cam->projType != ENTITY_CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED
)) {
return jerry_undefined();
}
return jerry_number(cam->perspective.fov);
}
moduleBaseFunction(moduleEntityCameraGetProjectionType) {
entitycamera_t *cam = moduleEntityCameraGet(callInfo);
if(!cam) return jerry_undefined();
return jerry_number(cam->projType);
}
// Setters // Setters
moduleBaseFunction(moduleEntityCameraSetZNear) { moduleBaseFunction(moduleEntityCameraSetZNear) {
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0); if(argc < 1 || !jerry_value_is_number(args[0])) {
componenthandle_t *h = scriptProtoGetValue( return moduleBaseThrow("Expected a number");
&MODULE_ENTITY_CAMERA_PROTO, callInfo->this_value }
); entitycamera_t *cam = moduleEntityCameraGet(callInfo);
if(!h) return jerry_undefined(); if(!cam) return jerry_undefined();
entityCameraSetZNear(h->eid, h->cid, (float_t)jerry_value_as_number(args[0])); cam->nearClip = (float_t)jerry_value_as_number(args[0]);
return jerry_undefined(); return args[0];
} }
moduleBaseFunction(moduleEntityCameraSetZFar) { moduleBaseFunction(moduleEntityCameraSetZFar) {
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0); if(argc < 1 || !jerry_value_is_number(args[0])) {
componenthandle_t *h = scriptProtoGetValue( return moduleBaseThrow("Expected a number");
&MODULE_ENTITY_CAMERA_PROTO, callInfo->this_value }
); entitycamera_t *cam = moduleEntityCameraGet(callInfo);
if(!h) return jerry_undefined(); if(!cam) return jerry_undefined();
entityCameraSetZFar(h->eid, h->cid, (float_t)jerry_value_as_number(args[0])); cam->farClip = (float_t)jerry_value_as_number(args[0]);
return jerry_undefined(); return args[0];
} }
moduleBaseFunction(moduleEntityCameraSetOrthoTop) {
if(argc < 1 || !jerry_value_is_number(args[0])) {
return moduleBaseThrow("Expected a number");
}
entitycamera_t *cam = moduleEntityCameraGet(callInfo);
if(!cam || cam->projType != ENTITY_CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC) {
return jerry_undefined();
}
cam->orthographic.top = (float_t)jerry_value_as_number(args[0]);
return args[0];
}
moduleBaseFunction(moduleEntityCameraSetOrthoBottom) {
if(argc < 1 || !jerry_value_is_number(args[0])) {
return moduleBaseThrow("Expected a number");
}
entitycamera_t *cam = moduleEntityCameraGet(callInfo);
if(!cam || cam->projType != ENTITY_CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC) {
return jerry_undefined();
}
cam->orthographic.bottom = (float_t)jerry_value_as_number(args[0]);
return args[0];
}
moduleBaseFunction(moduleEntityCameraSetOrthoLeft) {
if(argc < 1 || !jerry_value_is_number(args[0])) {
return moduleBaseThrow("Expected a number");
}
entitycamera_t *cam = moduleEntityCameraGet(callInfo);
if(!cam || cam->projType != ENTITY_CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC) {
return jerry_undefined();
}
cam->orthographic.left = (float_t)jerry_value_as_number(args[0]);
return args[0];
}
moduleBaseFunction(moduleEntityCameraSetOrthoRight) {
if(argc < 1 || !jerry_value_is_number(args[0])) {
return moduleBaseThrow("Expected a number");
}
entitycamera_t *cam = moduleEntityCameraGet(callInfo);
if(!cam || cam->projType != ENTITY_CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC) {
return jerry_undefined();
}
cam->orthographic.right = (float_t)jerry_value_as_number(args[0]);
return args[0];
}
moduleBaseFunction(moduleEntityCameraSetFov) {
if(argc < 1 || !jerry_value_is_number(args[0])) {
return moduleBaseThrow("Expected a number");
}
entitycamera_t *cam = moduleEntityCameraGet(callInfo);
if(!cam || (
cam->projType != ENTITY_CAMERA_PROJECTION_TYPE_PERSPECTIVE &&
cam->projType != ENTITY_CAMERA_PROJECTION_TYPE_PERSPECTIVE_FLIPPED
)) {
return jerry_undefined();
}
cam->perspective.fov = (float_t)jerry_value_as_number(args[0]);
return args[0];
}
moduleBaseFunction(moduleEntityCameraSetProjectionType) {
if(argc < 1 || !jerry_value_is_number(args[0])) {
return moduleBaseThrow("Expected a number");
}
entitycamera_t *cam = moduleEntityCameraGet(callInfo);
if(!cam) return jerry_undefined();
int32_t projType = (int32_t)jerry_value_as_number(args[0]);
if(
projType < ENTITY_CAMERA_PROJECTION_TYPE_PERSPECTIVE ||
projType > ENTITY_CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC
) {
return moduleBaseThrow("Invalid projection type");
}
cam->projType = (entitycameraprojectiontype_t)projType;
return args[0];
}
// Adder for this component. // Adder for this component.
moduleBaseFunction(moduleEntityCameraAdd) { moduleBaseFunction(moduleEntityCameraAdd) {
moduleBaseRequireArgs(1); moduleBaseRequireNumber(0); moduleBaseRequireArgs(1); moduleBaseRequireNumber(0);
@@ -61,6 +211,7 @@ 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
@@ -74,4 +225,37 @@ static void moduleEntityCAMERA(void) {
&MODULE_ENTITY_CAMERA_PROTO, "zFar", &MODULE_ENTITY_CAMERA_PROTO, "zFar",
moduleEntityCameraGetZFar, moduleEntityCameraSetZFar moduleEntityCameraGetZFar, moduleEntityCameraSetZFar
); );
scriptProtoDefineProp(
&MODULE_ENTITY_CAMERA_PROTO, "orthoTop",
moduleEntityCameraGetOrthoTop, moduleEntityCameraSetOrthoTop
);
scriptProtoDefineProp(
&MODULE_ENTITY_CAMERA_PROTO, "orthoBottom",
moduleEntityCameraGetOrthoBottom, moduleEntityCameraSetOrthoBottom
);
scriptProtoDefineProp(
&MODULE_ENTITY_CAMERA_PROTO, "orthoLeft",
moduleEntityCameraGetOrthoLeft, moduleEntityCameraSetOrthoLeft
);
scriptProtoDefineProp(
&MODULE_ENTITY_CAMERA_PROTO, "orthoRight",
moduleEntityCameraGetOrthoRight, moduleEntityCameraSetOrthoRight
);
scriptProtoDefineProp(
&MODULE_ENTITY_CAMERA_PROTO, "fov",
moduleEntityCameraGetFov, moduleEntityCameraSetFov
);
scriptProtoDefineProp(
&MODULE_ENTITY_CAMERA_PROTO, "projectionType",
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
);
moduleBaseEval(buffer);
} }
@@ -24,6 +24,13 @@ typedef struct {
static scriptproto_t MODULE_ENTITY_PROTO; static scriptproto_t MODULE_ENTITY_PROTO;
// Getters // Getters
moduleBaseFunction(moduleEntityGetId) {
entityscript_t *inst = (entityscript_t*)scriptProtoGetValue(
&MODULE_ENTITY_PROTO, callInfo->this_value
);
if(!inst) return jerry_undefined();
return jerry_number(inst->id);
}
// Getter defined for each component type // Getter defined for each component type
static jerry_value_t moduleEntityGetComponent( static jerry_value_t moduleEntityGetComponent(
@@ -127,6 +134,11 @@ static void moduleEntity(void) {
&MODULE_ENTITY_PROTO, "dispose", moduleEntityDisposeMethod &MODULE_ENTITY_PROTO, "dispose", moduleEntityDisposeMethod
); );
// Entity props
scriptProtoDefineProp(
&MODULE_ENTITY_PROTO, "id", moduleEntityGetId, NULL
);
// Init component type modules. // Init component type modules.
char_t buffer[64]; char_t buffer[64];