mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
[ruamoko] Wrap the transform fuctions
Except for get/set name as I'm still pondering strings.
This commit is contained in:
parent
ba3879c6e0
commit
54f0af854b
3 changed files with 288 additions and 0 deletions
|
@ -49,6 +49,7 @@ scene_t *Scene_NewScene (void);
|
|||
void Scene_DeleteScene (scene_t *scene);
|
||||
struct entity_s *Scene_CreateEntity (scene_t *scene);
|
||||
struct entity_s *Scene_GetEntity (scene_t *scene, int id) __attribute__((pure));
|
||||
struct transform_s *Scene_GetTransform (scene_t *scene, int id) __attribute__((pure));
|
||||
void Scene_DestroyEntity (scene_t *scene, struct entity_s *entity);
|
||||
void Scene_FreeAllEntities (scene_t *scene);
|
||||
|
||||
|
|
|
@ -100,6 +100,19 @@ rua__entity_get (progs_t *pr, rua_scene_t *scene, int id, const char *name)
|
|||
}
|
||||
#define rua_entity_get(pr, scene, id) rua__entity_get(pr, scene, id, __FUNCTION__)
|
||||
|
||||
static transform_t * __attribute__((pure))
|
||||
rua__transform_get (progs_t *pr, rua_scene_t *scene, int id, const char *name)
|
||||
{
|
||||
transform_t *transform = Scene_GetTransform (scene->scene, id);
|
||||
|
||||
if (!transform) {
|
||||
PR_RunError (pr, "invalid transform passed to %s", name + 3);
|
||||
}
|
||||
return transform;
|
||||
}
|
||||
#define rua_transform_get(pr, scene, id) \
|
||||
rua__transform_get(pr, scene, id, __FUNCTION__)
|
||||
|
||||
static int __attribute__((pure))
|
||||
rua_scene_index (scene_resources_t *res, rua_scene_t *scene)
|
||||
{
|
||||
|
@ -169,6 +182,241 @@ bi_Entity_GetTransform (progs_t *pr, void *_res)
|
|||
R_INT (pr) = ent->transform->id;
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_ChildCount (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
|
||||
R_UINT (pr) = Transform_ChildCount (transform);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_GetChild (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
transform_t *child = Transform_GetChild (transform, P_UINT (pr, 2));
|
||||
|
||||
R_UINT (pr) = child ? child->id : 0;
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_SetParent (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
transform_t *parent = rua_transform_get (pr, scene, P_INT (pr, 2));
|
||||
|
||||
Transform_SetParent (transform, parent);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_GetParent (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
transform_t *parent = Transform_GetParent (transform);
|
||||
|
||||
R_INT (pr) = parent ? parent->id : 0;
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_SetTag (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
pr_uint_t tag = P_UINT (pr, 2);
|
||||
Transform_SetTag (transform, tag);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_GetTag (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
|
||||
R_UINT (pr) = Transform_GetTag (transform);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_GetLocalMatrix (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
Transform_GetLocalMatrix (transform, &R_PACKED (pr, pr_vec4_t));
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_GetLocalInverse (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
Transform_GetLocalInverse (transform, &R_PACKED (pr, pr_vec4_t));
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_GetWorldMatrix (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
Transform_GetWorldMatrix (transform, &R_PACKED (pr, pr_vec4_t));
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_GetWorldInverse (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
Transform_GetWorldInverse (transform, &R_PACKED (pr, pr_vec4_t));
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_SetLocalPosition (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
Transform_SetLocalPosition (transform, P_PACKED (pr, pr_vec4_t, 2));
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_GetLocalPosition (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
R_PACKED (pr, pr_vec4_t) = Transform_GetLocalPosition (transform);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_SetLocalRotation (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
Transform_SetLocalRotation (transform, P_PACKED (pr, pr_vec4_t, 2));
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_GetLocalRotation (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
R_PACKED (pr, pr_vec4_t) = Transform_GetLocalRotation (transform);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_SetLocalScale (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
Transform_SetLocalScale (transform, P_PACKED (pr, pr_vec4_t, 2));
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_GetLocalScale (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
R_PACKED (pr, pr_vec4_t) = Transform_GetLocalScale (transform);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_SetWorldPosition (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
Transform_SetWorldPosition (transform, P_PACKED (pr, pr_vec4_t, 2));
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_GetWorldPosition (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
R_PACKED (pr, pr_vec4_t) = Transform_GetWorldPosition (transform);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_SetWorldRotation (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
Transform_SetWorldRotation (transform, P_PACKED (pr, pr_vec4_t, 2));
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_GetWorldRotation (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
R_PACKED (pr, pr_vec4_t) = Transform_GetWorldRotation (transform);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_GetWorldScale (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
R_PACKED (pr, pr_vec4_t) = Transform_GetWorldScale (transform);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_SetLocalTransform (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
Transform_SetLocalTransform (transform, P_PACKED (pr, pr_vec4_t, 2),
|
||||
P_PACKED (pr, pr_vec4_t, 3), P_PACKED (pr, pr_vec4_t, 4));
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_Forward (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
R_PACKED (pr, pr_vec4_t) = Transform_Forward (transform);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_Right (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
R_PACKED (pr, pr_vec4_t) = Transform_Right (transform);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Transform_Up (progs_t *pr, void *_res)
|
||||
{
|
||||
scene_resources_t *res = _res;
|
||||
rua_scene_t *scene = rua_scene_get (res, P_INT (pr, 0));
|
||||
transform_t *transform = rua_transform_get (pr, scene, P_INT (pr, 1));
|
||||
R_PACKED (pr, pr_vec4_t) = Transform_Up (transform);
|
||||
}
|
||||
|
||||
#define p(type) PR_PARAM(type)
|
||||
#define P(a, s) { .size = (s), .alignment = BITOP_LOG2 (a), }
|
||||
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}}
|
||||
|
@ -180,6 +428,38 @@ static builtin_t builtins[] = {
|
|||
|
||||
bi(Entity_GetTransform, 2, p(ptr), p(ptr)),
|
||||
|
||||
bi(Transform_ChildCount, 2, p(ptr), p(ptr)),
|
||||
bi(Transform_GetChild, 3, p(ptr), p(ptr), p(int)),
|
||||
bi(Transform_SetParent, 3, p(ptr), p(ptr), p(ptr)),
|
||||
bi(Transform_GetParent, 2, p(ptr), p(ptr)),
|
||||
|
||||
bi(Transform_SetTag, 3, p(ptr), p(ptr), p(uint)),
|
||||
bi(Transform_GetTag, 2, p(ptr), p(ptr)),
|
||||
|
||||
bi(Transform_GetLocalMatrix, 2, p(ptr), p(ptr)),
|
||||
bi(Transform_GetLocalInverse, 2, p(ptr), p(ptr)),
|
||||
bi(Transform_GetWorldMatrix, 2, p(ptr), p(ptr)),
|
||||
bi(Transform_GetWorldInverse, 2, p(ptr), p(ptr)),
|
||||
|
||||
bi(Transform_SetLocalPosition, 3, p(ptr), p(ptr), p(vec4)),
|
||||
bi(Transform_GetLocalPosition, 2, p(ptr), p(ptr)),
|
||||
bi(Transform_SetLocalRotation, 3, p(ptr), p(ptr), p(vec4)),
|
||||
bi(Transform_GetLocalRotation, 2, p(ptr), p(ptr)),
|
||||
bi(Transform_SetLocalScale, 3, p(ptr), p(ptr), p(vec4)),
|
||||
bi(Transform_GetLocalScale, 2, p(ptr), p(ptr)),
|
||||
|
||||
bi(Transform_SetWorldPosition, 3, p(ptr), p(ptr), p(vec4)),
|
||||
bi(Transform_GetWorldPosition, 2, p(ptr), p(ptr)),
|
||||
bi(Transform_SetWorldRotation, 3, p(ptr), p(ptr), p(vec4)),
|
||||
bi(Transform_GetWorldRotation, 2, p(ptr), p(ptr)),
|
||||
bi(Transform_GetWorldScale, 2, p(ptr), p(ptr)),
|
||||
|
||||
bi(Transform_SetLocalTransform, 5, p(ptr), p(ptr),
|
||||
p(vec4), p(vec4), p(vec4)),
|
||||
bi(Transform_Forward, 2, p(ptr), p(ptr)),
|
||||
bi(Transform_Right, 2, p(ptr), p(ptr)),
|
||||
bi(Transform_Up, 2, p(ptr), p(ptr)),
|
||||
|
||||
{0}
|
||||
};
|
||||
|
||||
|
|
|
@ -157,3 +157,10 @@ Scene_FreeAllEntities (scene_t *scene)
|
|||
scene_resources_t *res = scene->resources;
|
||||
PR_RESRESET (res->entities);
|
||||
}
|
||||
|
||||
transform_t *
|
||||
Scene_GetTransform (scene_t *scene, int id)
|
||||
{
|
||||
scene_resources_t *res = scene->resources;
|
||||
return PR_RESGET (res->transforms, id);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue