mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-26 22:31:05 +00:00
[ruamoko] Add builtins for adding lights to scenes
Pretty much just raw wrappers around the C versions. I'm not sure about Light_EnableSun (even in C), but it does build the sky surf pvs.
This commit is contained in:
parent
95264b3a54
commit
d14b17567e
3 changed files with 166 additions and 3 deletions
|
@ -45,6 +45,7 @@
|
||||||
#include "QF/plugin/vid_render.h"
|
#include "QF/plugin/vid_render.h"
|
||||||
|
|
||||||
#include "QF/scene/entity.h"
|
#include "QF/scene/entity.h"
|
||||||
|
#include "QF/scene/light.h"
|
||||||
#include "QF/scene/scene.h"
|
#include "QF/scene/scene.h"
|
||||||
#include "QF/scene/transform.h"
|
#include "QF/scene/transform.h"
|
||||||
|
|
||||||
|
@ -56,10 +57,18 @@ typedef struct rua_scene_s {
|
||||||
scene_t *scene;
|
scene_t *scene;
|
||||||
} rua_scene_t;
|
} rua_scene_t;
|
||||||
|
|
||||||
|
typedef struct rua_lighting_s {
|
||||||
|
struct rua_lighting_s *next;
|
||||||
|
struct rua_lighting_s **prev;
|
||||||
|
lightingdata_t *ldata;
|
||||||
|
} rua_lighting_t;
|
||||||
|
|
||||||
typedef struct rua_scene_resources_s {
|
typedef struct rua_scene_resources_s {
|
||||||
progs_t *pr;
|
progs_t *pr;
|
||||||
PR_RESMAP (rua_scene_t) scene_map;
|
PR_RESMAP (rua_scene_t) scene_map;
|
||||||
|
PR_RESMAP (rua_lighting_t) lighting_map;
|
||||||
rua_scene_t *scenes;
|
rua_scene_t *scenes;
|
||||||
|
rua_lighting_t *ldatas;
|
||||||
} rua_scene_resources_t;
|
} rua_scene_resources_t;
|
||||||
|
|
||||||
static rua_scene_t *
|
static rua_scene_t *
|
||||||
|
@ -96,6 +105,12 @@ rua__scene_get (rua_scene_resources_t *res, pr_ulong_t id, const char *name)
|
||||||
}
|
}
|
||||||
#define rua_scene_get(res, id) rua__scene_get(res, id, __FUNCTION__)
|
#define rua_scene_get(res, id) rua__scene_get(res, id, __FUNCTION__)
|
||||||
|
|
||||||
|
static int __attribute__((pure))
|
||||||
|
rua_scene_index (rua_scene_resources_t *res, rua_scene_t *scene)
|
||||||
|
{
|
||||||
|
return PR_RESINDEX (res->scene_map, scene);
|
||||||
|
}
|
||||||
|
|
||||||
static entity_t * __attribute__((pure))
|
static entity_t * __attribute__((pure))
|
||||||
rua__entity_get (rua_scene_resources_t *res, pr_ulong_t id, const char *name)
|
rua__entity_get (rua_scene_resources_t *res, pr_ulong_t id, const char *name)
|
||||||
{
|
{
|
||||||
|
@ -134,10 +149,44 @@ rua__transform_get (rua_scene_resources_t *res, pr_ulong_t id, const char *name)
|
||||||
}
|
}
|
||||||
#define rua_transform_get(res, id) rua__transform_get(res, id, __FUNCTION__)
|
#define rua_transform_get(res, id) rua__transform_get(res, id, __FUNCTION__)
|
||||||
|
|
||||||
static int __attribute__((pure))
|
static rua_lighting_t *
|
||||||
rua_scene_index (rua_scene_resources_t *res, rua_scene_t *scene)
|
rua_lighting_new (rua_scene_resources_t *res)
|
||||||
{
|
{
|
||||||
return PR_RESINDEX (res->scene_map, scene);
|
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__)
|
||||||
|
|
||||||
|
static int __attribute__((pure))
|
||||||
|
rua_lighting_index (rua_scene_resources_t *res, rua_lighting_t *ldata)
|
||||||
|
{
|
||||||
|
return PR_RESINDEX (res->lighting_map, ldata);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAKE_ID(id, sc_id) ((((pr_ulong_t) (id)) << 32) \
|
#define MAKE_ID(id, sc_id) ((((pr_ulong_t) (id)) << 32) \
|
||||||
|
@ -213,6 +262,22 @@ bi_Scene_DestroyEntity (progs_t *pr, void *_res)
|
||||||
Scene_DestroyEntity (scene->scene, ent);
|
Scene_DestroyEntity (scene->scene, ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bi_Entity_GetTransform (progs_t *pr, void *_res)
|
bi_Entity_GetTransform (progs_t *pr, void *_res)
|
||||||
{
|
{
|
||||||
|
@ -453,6 +518,74 @@ bi_Transform_Up (progs_t *pr, void *_res)
|
||||||
R_PACKED (pr, pr_vec4_t) = Transform_Up (transform);
|
R_PACKED (pr, pr_vec4_t) = Transform_Up (transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
#define p(type) PR_PARAM(type)
|
#define p(type) PR_PARAM(type)
|
||||||
#define P(a, s) { .size = (s), .alignment = BITOP_LOG2 (a), }
|
#define P(a, s) { .size = (s), .alignment = BITOP_LOG2 (a), }
|
||||||
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}}
|
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}}
|
||||||
|
@ -461,6 +594,7 @@ static builtin_t builtins[] = {
|
||||||
bi(Scene_DeleteScene, 1, p(ulong)),
|
bi(Scene_DeleteScene, 1, p(ulong)),
|
||||||
bi(Scene_CreateEntity, 1, p(ulong)),
|
bi(Scene_CreateEntity, 1, p(ulong)),
|
||||||
bi(Scene_DestroyEntity, 1, p(ulong)),
|
bi(Scene_DestroyEntity, 1, p(ulong)),
|
||||||
|
bi(Scene_SetLighting , 2, p(ulong), p(ulong)),
|
||||||
|
|
||||||
bi(Entity_GetTransform, 1, p(ulong)),
|
bi(Entity_GetTransform, 1, p(ulong)),
|
||||||
bi(Entity_SetModel, 2, p(ulong), p(int)),
|
bi(Entity_SetModel, 2, p(ulong), p(int)),
|
||||||
|
@ -496,6 +630,13 @@ static builtin_t builtins[] = {
|
||||||
bi(Transform_Right, 1, p(ulong)),
|
bi(Transform_Right, 1, p(ulong)),
|
||||||
bi(Transform_Up, 1, p(ulong)),
|
bi(Transform_Up, 1, p(ulong)),
|
||||||
|
|
||||||
|
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)),
|
||||||
|
|
||||||
{0}
|
{0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,16 +6,25 @@ typedef struct {
|
||||||
vec4 col[4];
|
vec4 col[4];
|
||||||
} mat4x4;
|
} mat4x4;
|
||||||
|
|
||||||
|
typedef struct light_s {
|
||||||
|
vec4 color;
|
||||||
|
vec4 position;
|
||||||
|
vec4 direction;
|
||||||
|
vec4 attenuation;
|
||||||
|
} light_t;
|
||||||
|
|
||||||
//FIXME need a handle type
|
//FIXME need a handle type
|
||||||
typedef struct { long handle; } scene_t;
|
typedef struct { long handle; } scene_t;
|
||||||
typedef struct { long handle; } entity_t;
|
typedef struct { long handle; } entity_t;
|
||||||
typedef struct { long handle; } transform_t;
|
typedef struct { long handle; } transform_t;
|
||||||
|
typedef struct { long handle; } lightingdata_t;
|
||||||
typedef struct { int handle; } model_t;
|
typedef struct { int handle; } model_t;
|
||||||
|
|
||||||
scene_t Scene_NewScene (void);
|
scene_t Scene_NewScene (void);
|
||||||
void Scene_DeleteScene (scene_t scene);
|
void Scene_DeleteScene (scene_t scene);
|
||||||
entity_t Scene_CreateEntity (scene_t scene);
|
entity_t Scene_CreateEntity (scene_t scene);
|
||||||
void Scene_DestroyEntity (entity_t ent);
|
void Scene_DestroyEntity (entity_t ent);
|
||||||
|
void Scene_SetLighting (scene_t scene, lightingdata_t ldata);
|
||||||
|
|
||||||
transform_t Entity_GetTransform (entity_t ent);
|
transform_t Entity_GetTransform (entity_t ent);
|
||||||
void Entity_SetModel (entity_t ent, model_t model);
|
void Entity_SetModel (entity_t ent, model_t model);
|
||||||
|
@ -48,6 +57,12 @@ vec4 Transform_Forward (transform_t transform);
|
||||||
vec4 Transform_Right (transform_t transform);
|
vec4 Transform_Right (transform_t transform);
|
||||||
vec4 Transform_Up (transform_t transform);
|
vec4 Transform_Up (transform_t transform);
|
||||||
|
|
||||||
|
lightingdata_t Light_CreateLightingData (scene_t scene);
|
||||||
|
void Light_DestroyLightingData (lightingdata_t ldata);
|
||||||
|
void Light_ClearLights (lightingdata_t ldata);
|
||||||
|
void Light_AddLight (lightingdata_t ldata, light_t light);
|
||||||
|
void Light_EnableSun (lightingdata_t ldata);
|
||||||
|
|
||||||
model_t Model_Load (string path);
|
model_t Model_Load (string path);
|
||||||
void Model_Unload (model_t model);
|
void Model_Unload (model_t model);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ scene_t Scene_NewScene (void) = #0;
|
||||||
void Scene_DeleteScene (scene_t scene) = #0;
|
void Scene_DeleteScene (scene_t scene) = #0;
|
||||||
entity_t Scene_CreateEntity (scene_t scene) = #0;
|
entity_t Scene_CreateEntity (scene_t scene) = #0;
|
||||||
void Scene_DestroyEntity (entity_t ent) = #0;
|
void Scene_DestroyEntity (entity_t ent) = #0;
|
||||||
|
void Scene_SetLighting (scene_t scene, lightingdata_t ldata) = #0;
|
||||||
|
|
||||||
transform_t Entity_GetTransform (entity_t ent) = #0;
|
transform_t Entity_GetTransform (entity_t ent) = #0;
|
||||||
void Entity_SetModel (entity_t ent, model_t model) = #0;
|
void Entity_SetModel (entity_t ent, model_t model) = #0;
|
||||||
|
@ -36,5 +37,11 @@ vec4 Transform_Forward (transform_t transform) = #0;
|
||||||
vec4 Transform_Right (transform_t transform) = #0;
|
vec4 Transform_Right (transform_t transform) = #0;
|
||||||
vec4 Transform_Up (transform_t transform) = #0;
|
vec4 Transform_Up (transform_t transform) = #0;
|
||||||
|
|
||||||
|
lightingdata_t Light_CreateLightingData (scene_t scene) = #0;
|
||||||
|
void Light_DestroyLightingData (lightingdata_t ldata) = #0;
|
||||||
|
void Light_ClearLights (lightingdata_t ldata) = #0;
|
||||||
|
void Light_AddLight (lightingdata_t ldata, light_t light) = #0;
|
||||||
|
void Light_EnableSun (lightingdata_t ldata) = #0;
|
||||||
|
|
||||||
model_t Model_Load (string path) = #0;
|
model_t Model_Load (string path) = #0;
|
||||||
void Model_Unload (model_t model) = #0;
|
void Model_Unload (model_t model) = #0;
|
||||||
|
|
Loading…
Reference in a new issue