2022-02-14 07:43:10 +00:00
|
|
|
/*
|
|
|
|
bi_scene.c
|
|
|
|
|
|
|
|
Ruamoko scene builtins
|
|
|
|
|
|
|
|
Copyright (C) 2022 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "QF/cmem.h"
|
|
|
|
#include "QF/hash.h"
|
2022-05-04 08:38:38 +00:00
|
|
|
#include "QF/model.h"
|
2022-02-14 07:43:10 +00:00
|
|
|
#include "QF/progs.h"
|
2022-05-04 08:38:38 +00:00
|
|
|
#include "QF/render.h"
|
|
|
|
|
|
|
|
#include "QF/plugin/vid_render.h"
|
2022-02-14 07:43:10 +00:00
|
|
|
|
2022-03-29 05:40:48 +00:00
|
|
|
#include "QF/scene/entity.h"
|
2022-05-05 14:43:39 +00:00
|
|
|
#include "QF/scene/light.h"
|
2022-02-14 07:43:10 +00:00
|
|
|
#include "QF/scene/scene.h"
|
|
|
|
#include "QF/scene/transform.h"
|
|
|
|
|
|
|
|
#include "rua_internal.h"
|
|
|
|
|
|
|
|
typedef struct rua_scene_s {
|
|
|
|
struct rua_scene_s *next;
|
|
|
|
struct rua_scene_s **prev;
|
|
|
|
scene_t *scene;
|
|
|
|
} rua_scene_t;
|
|
|
|
|
2022-05-05 14:43:39 +00:00
|
|
|
typedef struct rua_lighting_s {
|
|
|
|
struct rua_lighting_s *next;
|
|
|
|
struct rua_lighting_s **prev;
|
|
|
|
lightingdata_t *ldata;
|
|
|
|
} rua_lighting_t;
|
|
|
|
|
2022-03-04 17:05:59 +00:00
|
|
|
typedef struct rua_scene_resources_s {
|
2022-02-14 07:43:10 +00:00
|
|
|
progs_t *pr;
|
|
|
|
PR_RESMAP (rua_scene_t) scene_map;
|
2022-05-05 14:43:39 +00:00
|
|
|
PR_RESMAP (rua_lighting_t) lighting_map;
|
2022-02-14 07:43:10 +00:00
|
|
|
rua_scene_t *scenes;
|
2022-05-05 14:43:39 +00:00
|
|
|
rua_lighting_t *ldatas;
|
2022-03-04 17:05:59 +00:00
|
|
|
} rua_scene_resources_t;
|
2022-02-14 07:43:10 +00:00
|
|
|
|
|
|
|
static rua_scene_t *
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_new (rua_scene_resources_t *res)
|
2022-02-14 07:43:10 +00:00
|
|
|
{
|
|
|
|
return PR_RESNEW (res->scene_map);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_free (rua_scene_resources_t *res, rua_scene_t *scene)
|
2022-02-14 07:43:10 +00:00
|
|
|
{
|
|
|
|
if (scene->next) {
|
|
|
|
scene->next->prev = scene->prev;
|
|
|
|
}
|
|
|
|
*scene->prev = scene->next;
|
|
|
|
scene->prev = 0;
|
|
|
|
PR_RESFREE (res->scene_map, scene);
|
|
|
|
}
|
|
|
|
|
2022-02-14 10:56:56 +00:00
|
|
|
static rua_scene_t * __attribute__((pure))
|
2022-04-26 08:40:06 +00:00
|
|
|
rua__scene_get (rua_scene_resources_t *res, pr_ulong_t id, const char *name)
|
2022-02-14 07:43:10 +00:00
|
|
|
{
|
2022-04-26 08:40:06 +00:00
|
|
|
rua_scene_t *scene = 0;
|
|
|
|
|
|
|
|
if (id <= 0xffffffffu) {
|
|
|
|
scene = PR_RESGET (res->scene_map, (pr_int_t) id);
|
|
|
|
}
|
2022-02-14 07:43:10 +00:00
|
|
|
|
|
|
|
// scene->prev will be null if the handle is unallocated
|
|
|
|
if (!scene || !scene->prev) {
|
|
|
|
PR_RunError (res->pr, "invalid scene passed to %s", name + 3);
|
|
|
|
}
|
|
|
|
return scene;
|
|
|
|
}
|
|
|
|
#define rua_scene_get(res, id) rua__scene_get(res, id, __FUNCTION__)
|
|
|
|
|
2022-05-05 14:43:39 +00:00
|
|
|
static int __attribute__((pure))
|
|
|
|
rua_scene_index (rua_scene_resources_t *res, rua_scene_t *scene)
|
|
|
|
{
|
|
|
|
return PR_RESINDEX (res->scene_map, scene);
|
|
|
|
}
|
|
|
|
|
2022-02-14 10:56:56 +00:00
|
|
|
static entity_t * __attribute__((pure))
|
2022-04-26 08:40:06 +00:00
|
|
|
rua__entity_get (rua_scene_resources_t *res, pr_ulong_t id, const char *name)
|
2022-02-14 07:43:10 +00:00
|
|
|
{
|
2022-04-26 08:40:06 +00:00
|
|
|
pr_ulong_t scene_id = id & 0xffffffff;
|
|
|
|
entity_t *ent = 0;
|
|
|
|
|
|
|
|
rua_scene_t *scene = rua__scene_get (res, scene_id, name);
|
|
|
|
if (scene) {
|
|
|
|
pr_int_t entity_id = id >> 32;
|
|
|
|
ent = Scene_GetEntity (scene->scene, entity_id);
|
|
|
|
}
|
2022-02-14 07:43:10 +00:00
|
|
|
|
|
|
|
if (!ent) {
|
2022-04-26 08:40:06 +00:00
|
|
|
PR_RunError (res->pr, "invalid entity passed to %s", name + 3);
|
2022-02-14 07:43:10 +00:00
|
|
|
}
|
|
|
|
return ent;
|
|
|
|
}
|
2022-04-26 08:40:06 +00:00
|
|
|
#define rua_entity_get(res, id) rua__entity_get(res, id, __FUNCTION__)
|
2022-02-14 07:43:10 +00:00
|
|
|
|
2022-02-14 15:06:39 +00:00
|
|
|
static transform_t * __attribute__((pure))
|
2022-04-26 08:40:06 +00:00
|
|
|
rua__transform_get (rua_scene_resources_t *res, pr_ulong_t id, const char *name)
|
2022-02-14 15:06:39 +00:00
|
|
|
{
|
2022-04-26 08:40:06 +00:00
|
|
|
pr_ulong_t scene_id = id & 0xffffffff;
|
|
|
|
transform_t *transform = 0;
|
|
|
|
|
|
|
|
rua_scene_t *scene = rua_scene_get (res, scene_id);
|
|
|
|
if (scene) {
|
|
|
|
pr_int_t transform_id = id >> 32;
|
|
|
|
transform = Scene_GetTransform (scene->scene, transform_id);
|
|
|
|
}
|
2022-02-14 15:06:39 +00:00
|
|
|
|
|
|
|
if (!transform) {
|
2022-04-26 08:40:06 +00:00
|
|
|
PR_RunError (res->pr, "invalid transform passed to %s", name + 3);
|
2022-02-14 15:06:39 +00:00
|
|
|
}
|
|
|
|
return transform;
|
|
|
|
}
|
2022-04-26 08:40:06 +00:00
|
|
|
#define rua_transform_get(res, id) rua__transform_get(res, id, __FUNCTION__)
|
2022-02-14 15:06:39 +00:00
|
|
|
|
2022-05-05 14:43:39 +00:00
|
|
|
static rua_lighting_t *
|
|
|
|
rua_lighting_new (rua_scene_resources_t *res)
|
|
|
|
{
|
|
|
|
return PR_RESNEW (res->lighting_map);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rua_lighting_free (rua_scene_resources_t *res, rua_lighting_t *ldata)
|
|
|
|
{
|
|
|
|
if (ldata->next) {
|
|
|
|
ldata->next->prev = ldata->prev;
|
|
|
|
}
|
|
|
|
*ldata->prev = ldata->next;
|
|
|
|
ldata->prev = 0;
|
|
|
|
PR_RESFREE (res->lighting_map, ldata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static rua_lighting_t * __attribute__((pure))
|
|
|
|
rua__lighting_get (rua_scene_resources_t *res, pr_ulong_t id, const char *name)
|
|
|
|
{
|
|
|
|
rua_lighting_t *ldata = 0;
|
|
|
|
|
|
|
|
if (id <= 0xffffffffu) {
|
|
|
|
ldata = PR_RESGET (res->lighting_map, (pr_int_t) id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ldata->prev will be null if the handle is unallocated
|
|
|
|
if (!ldata || !ldata->prev) {
|
|
|
|
PR_RunError (res->pr, "invalid lighting passed to %s", name + 3);
|
|
|
|
}
|
|
|
|
return ldata;
|
|
|
|
}
|
|
|
|
#define rua_lighting_get(res, id) rua__lighting_get(res, id, __FUNCTION__)
|
|
|
|
|
2022-02-14 10:56:56 +00:00
|
|
|
static int __attribute__((pure))
|
2022-05-05 14:43:39 +00:00
|
|
|
rua_lighting_index (rua_scene_resources_t *res, rua_lighting_t *ldata)
|
2022-02-14 07:43:10 +00:00
|
|
|
{
|
2022-05-05 14:43:39 +00:00
|
|
|
return PR_RESINDEX (res->lighting_map, ldata);
|
2022-02-14 07:43:10 +00:00
|
|
|
}
|
|
|
|
|
2022-04-26 08:40:06 +00:00
|
|
|
#define MAKE_ID(id, sc_id) ((((pr_ulong_t) (id)) << 32) \
|
|
|
|
| ((sc_id) & 0xffffffff))
|
|
|
|
|
2022-02-14 07:43:10 +00:00
|
|
|
static void
|
|
|
|
bi_Scene_NewScene (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-02-14 07:43:10 +00:00
|
|
|
|
|
|
|
rua_scene_t *scene = rua_scene_new (res);
|
|
|
|
|
|
|
|
scene->scene = Scene_NewScene ();
|
|
|
|
|
|
|
|
scene->next = res->scenes;
|
|
|
|
if (res->scenes) {
|
|
|
|
res->scenes->prev = &scene->next;
|
|
|
|
}
|
|
|
|
scene->prev = &res->scenes;
|
|
|
|
res->scenes = scene;
|
|
|
|
|
2022-04-26 08:40:06 +00:00
|
|
|
// scene id in lower 32-bits for all handles
|
|
|
|
// zero upper 32-bits zero means scene, otherwise transform or entity
|
|
|
|
R_ULONG (pr) = MAKE_ID (0, rua_scene_index (res, scene));
|
2022-02-14 07:43:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_delete_scene (rua_scene_resources_t *res, rua_scene_t *scene)
|
2022-02-14 07:43:10 +00:00
|
|
|
{
|
|
|
|
Scene_DeleteScene (scene->scene);
|
|
|
|
rua_scene_free (res, scene);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Scene_DeleteScene (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
rua_scene_t *scene = rua_scene_get (res, P_ULONG (pr, 0));
|
2022-02-14 07:43:10 +00:00
|
|
|
|
|
|
|
rua_delete_scene (res, scene);
|
|
|
|
}
|
|
|
|
|
2022-05-05 12:26:18 +00:00
|
|
|
scene_t *
|
|
|
|
Scene_GetScene (progs_t *pr, pr_ulong_t handle)
|
|
|
|
{
|
|
|
|
if (!handle) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rua_scene_resources_t *res = PR_Resources_Find (pr, "Scene");
|
|
|
|
rua_scene_t *scene = rua_scene_get (res, P_ULONG (pr, 0));
|
|
|
|
return scene->scene;
|
|
|
|
}
|
|
|
|
|
2022-02-14 07:43:10 +00:00
|
|
|
static void
|
|
|
|
bi_Scene_CreateEntity (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
pr_ulong_t scene_id = P_ULONG (pr, 0);
|
|
|
|
rua_scene_t *scene = rua_scene_get (res, scene_id);
|
2022-02-14 07:43:10 +00:00
|
|
|
entity_t *ent = Scene_CreateEntity (scene->scene);
|
2022-04-26 08:40:06 +00:00
|
|
|
R_ULONG (pr) = MAKE_ID (ent->id, scene_id);
|
2022-02-14 07:43:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Scene_DestroyEntity (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
pr_ulong_t id = P_ULONG (pr, 0);
|
|
|
|
entity_t *ent = rua_entity_get (res, id);
|
|
|
|
pr_ulong_t scene_id = id & 0xffffffff;
|
2022-05-07 00:53:26 +00:00
|
|
|
|
|
|
|
R_RemoveEfrags (ent);
|
2022-04-26 08:40:06 +00:00
|
|
|
// bad scene caught above
|
|
|
|
rua_scene_t *scene = rua_scene_get (res, scene_id);
|
2022-02-14 07:43:10 +00:00
|
|
|
Scene_DestroyEntity (scene->scene, ent);
|
|
|
|
}
|
|
|
|
|
2022-05-05 14:43:39 +00:00
|
|
|
static void
|
|
|
|
bi_Scene_SetLighting (progs_t *pr, void *_res)
|
|
|
|
{
|
|
|
|
rua_scene_resources_t *res = _res;
|
|
|
|
pr_ulong_t scene_id = P_ULONG (pr, 0);
|
|
|
|
rua_scene_t *scene = rua_scene_get (res, scene_id);
|
|
|
|
pr_ulong_t ldata_id = P_ULONG (pr, 1);
|
|
|
|
rua_lighting_t *ldata = 0;
|
|
|
|
|
|
|
|
if (ldata_id) {
|
|
|
|
ldata = rua_lighting_get (res, ldata_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
scene->scene->lights = ldata->ldata;
|
|
|
|
}
|
|
|
|
|
2022-02-14 07:43:10 +00:00
|
|
|
static void
|
|
|
|
bi_Entity_GetTransform (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
pr_ulong_t ent_id = P_ULONG (pr, 0);
|
|
|
|
entity_t *ent = rua_entity_get (res, ent_id);
|
2022-02-14 07:43:10 +00:00
|
|
|
|
2022-04-26 08:40:06 +00:00
|
|
|
// ent_id contains scene id
|
|
|
|
R_ULONG (pr) = MAKE_ID (ent->transform->id, ent_id);
|
2022-02-14 07:43:10 +00:00
|
|
|
}
|
|
|
|
|
2022-05-04 08:38:38 +00:00
|
|
|
static void
|
|
|
|
bi_Entity_SetModel (progs_t *pr, void *_res)
|
|
|
|
{
|
|
|
|
rua_scene_resources_t *res = _res;
|
|
|
|
pr_ulong_t ent_id = P_ULONG (pr, 0);
|
|
|
|
pr_int_t model_id = P_INT (pr, 1);
|
|
|
|
entity_t *ent = rua_entity_get (res, ent_id);
|
|
|
|
model_t *model = Model_GetModel (pr, model_id);
|
2022-05-05 12:26:18 +00:00
|
|
|
pr_ulong_t scene_id = ent_id & 0xffffffff;
|
|
|
|
// bad scene caught above
|
|
|
|
rua_scene_t *scene = rua_scene_get (res, scene_id);
|
2022-05-04 08:38:38 +00:00
|
|
|
|
|
|
|
R_RemoveEfrags (ent);
|
|
|
|
ent->renderer.model = model;
|
2022-05-05 12:26:18 +00:00
|
|
|
R_AddEfrags (&scene->scene->worldmodel->brush, ent);
|
2022-05-04 08:38:38 +00:00
|
|
|
}
|
|
|
|
|
2022-02-14 15:06:39 +00:00
|
|
|
static void
|
|
|
|
bi_Transform_ChildCount (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
2022-02-14 15:06:39 +00:00
|
|
|
|
|
|
|
R_UINT (pr) = Transform_ChildCount (transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_GetChild (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
2022-02-14 15:06:39 +00:00
|
|
|
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)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
|
|
|
transform_t *parent = rua_transform_get (res, P_ULONG (pr, 1));
|
2022-02-14 15:06:39 +00:00
|
|
|
|
|
|
|
Transform_SetParent (transform, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_GetParent (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
pr_ulong_t transform_id = P_ULONG (pr, 0);
|
|
|
|
transform_t *transform = rua_transform_get (res, transform_id);
|
2022-02-14 15:06:39 +00:00
|
|
|
transform_t *parent = Transform_GetParent (transform);
|
|
|
|
|
2022-04-26 08:40:06 +00:00
|
|
|
// transform_id contains scene id
|
|
|
|
R_ULONG (pr) = parent ? MAKE_ID (parent->id, transform_id) : 0;
|
2022-02-14 15:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_SetTag (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
2022-02-14 15:06:39 +00:00
|
|
|
pr_uint_t tag = P_UINT (pr, 2);
|
|
|
|
Transform_SetTag (transform, tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_GetTag (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
2022-02-14 15:06:39 +00:00
|
|
|
|
|
|
|
R_UINT (pr) = Transform_GetTag (transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_GetLocalMatrix (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
2022-02-14 15:06:39 +00:00
|
|
|
Transform_GetLocalMatrix (transform, &R_PACKED (pr, pr_vec4_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_GetLocalInverse (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
2022-02-14 15:06:39 +00:00
|
|
|
Transform_GetLocalInverse (transform, &R_PACKED (pr, pr_vec4_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_GetWorldMatrix (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
2022-02-14 15:06:39 +00:00
|
|
|
Transform_GetWorldMatrix (transform, &R_PACKED (pr, pr_vec4_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_GetWorldInverse (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
2022-02-14 15:06:39 +00:00
|
|
|
Transform_GetWorldInverse (transform, &R_PACKED (pr, pr_vec4_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_SetLocalPosition (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
|
|
|
Transform_SetLocalPosition (transform, P_PACKED (pr, pr_vec4_t, 1));
|
2022-02-14 15:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_GetLocalPosition (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
2022-02-14 15:06:39 +00:00
|
|
|
R_PACKED (pr, pr_vec4_t) = Transform_GetLocalPosition (transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_SetLocalRotation (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
|
|
|
Transform_SetLocalRotation (transform, P_PACKED (pr, pr_vec4_t, 1));
|
2022-02-14 15:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_GetLocalRotation (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
2022-02-14 15:06:39 +00:00
|
|
|
R_PACKED (pr, pr_vec4_t) = Transform_GetLocalRotation (transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_SetLocalScale (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
|
|
|
Transform_SetLocalScale (transform, P_PACKED (pr, pr_vec4_t, 1));
|
2022-02-14 15:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_GetLocalScale (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
2022-02-14 15:06:39 +00:00
|
|
|
R_PACKED (pr, pr_vec4_t) = Transform_GetLocalScale (transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_SetWorldPosition (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
|
|
|
Transform_SetWorldPosition (transform, P_PACKED (pr, pr_vec4_t, 1));
|
2022-02-14 15:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_GetWorldPosition (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
2022-02-14 15:06:39 +00:00
|
|
|
R_PACKED (pr, pr_vec4_t) = Transform_GetWorldPosition (transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_SetWorldRotation (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
|
|
|
Transform_SetWorldRotation (transform, P_PACKED (pr, pr_vec4_t, 1));
|
2022-02-14 15:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_GetWorldRotation (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
2022-02-14 15:06:39 +00:00
|
|
|
R_PACKED (pr, pr_vec4_t) = Transform_GetWorldRotation (transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_GetWorldScale (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
2022-02-14 15:06:39 +00:00
|
|
|
R_PACKED (pr, pr_vec4_t) = Transform_GetWorldScale (transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_SetLocalTransform (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
|
|
|
Transform_SetLocalTransform (transform, P_PACKED (pr, pr_vec4_t, 1),
|
|
|
|
P_PACKED (pr, pr_vec4_t, 2), P_PACKED (pr, pr_vec4_t, 3));
|
2022-02-14 15:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_Forward (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
2022-02-14 15:06:39 +00:00
|
|
|
R_PACKED (pr, pr_vec4_t) = Transform_Forward (transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_Right (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
2022-02-14 15:06:39 +00:00
|
|
|
R_PACKED (pr, pr_vec4_t) = Transform_Right (transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Transform_Up (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-04-26 08:40:06 +00:00
|
|
|
transform_t *transform = rua_transform_get (res, P_ULONG (pr, 0));
|
2022-02-14 15:06:39 +00:00
|
|
|
R_PACKED (pr, pr_vec4_t) = Transform_Up (transform);
|
|
|
|
}
|
|
|
|
|
2022-05-05 14:43:39 +00:00
|
|
|
static void
|
|
|
|
bi_Light_CreateLightingData (progs_t *pr, void *_res)
|
|
|
|
{
|
|
|
|
rua_scene_resources_t *res = _res;
|
|
|
|
pr_ulong_t scene_id = P_ULONG (pr, 0);
|
|
|
|
rua_scene_t *scene = rua_scene_get (res, scene_id);
|
|
|
|
|
|
|
|
rua_lighting_t *ldata = rua_lighting_new (res);
|
|
|
|
|
|
|
|
ldata->ldata = Light_CreateLightingData (scene->scene);
|
|
|
|
|
|
|
|
ldata->next = res->ldatas;
|
|
|
|
if (res->ldatas) {
|
|
|
|
res->ldatas->prev = &ldata->next;
|
|
|
|
}
|
|
|
|
ldata->prev = &res->ldatas;
|
|
|
|
res->ldatas = ldata;
|
|
|
|
|
|
|
|
// ldata id in lower 32-bits for all handles
|
|
|
|
// upper 32-bits reserved
|
|
|
|
R_ULONG (pr) = MAKE_ID (0, rua_lighting_index (res, ldata));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rua_delete_lighting (rua_scene_resources_t *res, rua_lighting_t *ldata)
|
|
|
|
{
|
|
|
|
Light_DestroyLightingData (ldata->ldata);
|
|
|
|
rua_lighting_free (res, ldata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Light_DestroyLightingData (progs_t *pr, void *_res)
|
|
|
|
{
|
|
|
|
rua_scene_resources_t *res = _res;
|
|
|
|
rua_lighting_t *ldata = rua_lighting_get (res, P_ULONG (pr, 0));
|
|
|
|
|
|
|
|
rua_delete_lighting (res, ldata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Light_ClearLights (progs_t *pr, void *_res)
|
|
|
|
{
|
|
|
|
rua_scene_resources_t *res = _res;
|
|
|
|
rua_lighting_t *ldata = rua_lighting_get (res, P_ULONG (pr, 0));
|
|
|
|
|
|
|
|
Light_ClearLights (ldata->ldata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Light_AddLight (progs_t *pr, void *_res)
|
|
|
|
{
|
|
|
|
rua_scene_resources_t *res = _res;
|
|
|
|
rua_lighting_t *ldata = rua_lighting_get (res, P_ULONG (pr, 0));
|
|
|
|
light_t *light = &P_PACKED (pr, light_t, 1);
|
|
|
|
int style = P_INT (pr, 5);
|
|
|
|
|
|
|
|
Light_AddLight (ldata->ldata, light, style);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_Light_EnableSun (progs_t *pr, void *_res)
|
|
|
|
{
|
|
|
|
rua_scene_resources_t *res = _res;
|
|
|
|
rua_lighting_t *ldata = rua_lighting_get (res, P_ULONG (pr, 0));
|
|
|
|
|
|
|
|
Light_EnableSun (ldata->ldata);
|
|
|
|
}
|
|
|
|
|
2022-02-14 07:43:10 +00:00
|
|
|
#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}}
|
|
|
|
static builtin_t builtins[] = {
|
2022-04-26 08:40:06 +00:00
|
|
|
bi(Scene_NewScene, 0),
|
|
|
|
bi(Scene_DeleteScene, 1, p(ulong)),
|
|
|
|
bi(Scene_CreateEntity, 1, p(ulong)),
|
|
|
|
bi(Scene_DestroyEntity, 1, p(ulong)),
|
2022-05-05 14:43:39 +00:00
|
|
|
bi(Scene_SetLighting , 2, p(ulong), p(ulong)),
|
2022-04-26 08:40:06 +00:00
|
|
|
|
|
|
|
bi(Entity_GetTransform, 1, p(ulong)),
|
2022-05-04 08:38:38 +00:00
|
|
|
bi(Entity_SetModel, 2, p(ulong), p(int)),
|
2022-04-26 08:40:06 +00:00
|
|
|
|
|
|
|
bi(Transform_ChildCount, 1, p(ulong)),
|
|
|
|
bi(Transform_GetChild, 2, p(ulong), p(int)),
|
|
|
|
bi(Transform_SetParent, 2, p(ulong), p(ulong)),
|
|
|
|
bi(Transform_GetParent, 1, p(ulong)),
|
|
|
|
|
|
|
|
bi(Transform_SetTag, 2, p(ulong), p(uint)),
|
|
|
|
bi(Transform_GetTag, 1, p(ulong)),
|
|
|
|
|
|
|
|
bi(Transform_GetLocalMatrix, 1, p(ulong)),
|
|
|
|
bi(Transform_GetLocalInverse, 1, p(ulong)),
|
|
|
|
bi(Transform_GetWorldMatrix, 1, p(ulong)),
|
|
|
|
bi(Transform_GetWorldInverse, 1, p(ulong)),
|
|
|
|
|
|
|
|
bi(Transform_SetLocalPosition, 2, p(ulong), p(vec4)),
|
|
|
|
bi(Transform_GetLocalPosition, 1, p(ulong)),
|
|
|
|
bi(Transform_SetLocalRotation, 2, p(ulong), p(vec4)),
|
|
|
|
bi(Transform_GetLocalRotation, 1, p(ulong)),
|
|
|
|
bi(Transform_SetLocalScale, 2, p(ulong), p(vec4)),
|
|
|
|
bi(Transform_GetLocalScale, 1, p(ulong)),
|
|
|
|
|
|
|
|
bi(Transform_SetWorldPosition, 2, p(ulong), p(vec4)),
|
|
|
|
bi(Transform_GetWorldPosition, 1, p(ulong)),
|
|
|
|
bi(Transform_SetWorldRotation, 2, p(ulong), p(vec4)),
|
|
|
|
bi(Transform_GetWorldRotation, 1, p(ulong)),
|
|
|
|
bi(Transform_GetWorldScale, 1, p(ulong)),
|
|
|
|
|
|
|
|
bi(Transform_SetLocalTransform, 4, p(ulong), p(vec4), p(vec4), p(vec4)),
|
|
|
|
bi(Transform_Forward, 1, p(ulong)),
|
|
|
|
bi(Transform_Right, 1, p(ulong)),
|
|
|
|
bi(Transform_Up, 1, p(ulong)),
|
2022-02-14 15:06:39 +00:00
|
|
|
|
2022-05-05 14:43:39 +00:00
|
|
|
bi(Light_CreateLightingData, 1, p(ulong)),
|
|
|
|
bi(Light_DestroyLightingData, 1, p(ulong)),
|
|
|
|
bi(Light_ClearLights, 1, p(ulong)),
|
|
|
|
bi(Light_AddLight, 5, p(ulong),// really, 3
|
|
|
|
p(vec4), p(vec4), p(vec4), p(vec4), p(int)),
|
|
|
|
bi(Light_EnableSun, 1, p(ulong)),
|
|
|
|
|
2022-02-14 07:43:10 +00:00
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
bi_scene_clear (progs_t *pr, void *_res)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = _res;
|
2022-02-14 07:43:10 +00:00
|
|
|
|
2022-05-05 23:26:55 +00:00
|
|
|
while (res->ldatas) {
|
|
|
|
rua_delete_lighting (res, res->ldatas);
|
|
|
|
}
|
2022-02-14 07:43:10 +00:00
|
|
|
while (res->scenes) {
|
|
|
|
rua_delete_scene (res, res->scenes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RUA_Scene_Init (progs_t *pr, int secure)
|
|
|
|
{
|
2022-03-04 17:05:59 +00:00
|
|
|
rua_scene_resources_t *res = calloc (sizeof (rua_scene_resources_t), 1);
|
2022-02-14 07:43:10 +00:00
|
|
|
|
|
|
|
res->pr = pr;
|
|
|
|
|
2022-05-05 12:26:18 +00:00
|
|
|
PR_Resources_Register (pr, "Scene", res, bi_scene_clear);
|
2022-02-14 07:43:10 +00:00
|
|
|
PR_RegisterBuiltins (pr, builtins, res);
|
|
|
|
}
|