mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-04-11 20:03:11 +00:00
[scene] Add support for a scene camera
Used only by qwaq, but I can fly around my little test scene now :)
This commit is contained in:
parent
1bcc4dddb6
commit
e619b4524e
6 changed files with 29 additions and 3 deletions
|
@ -76,6 +76,8 @@ typedef struct scene_s {
|
|||
struct model_s **models;
|
||||
struct mleaf_s *viewleaf;
|
||||
struct lightingdata_s *lights;
|
||||
|
||||
uint32_t camera;
|
||||
} scene_t;
|
||||
|
||||
typedef struct scene_system_s {
|
||||
|
|
|
@ -301,6 +301,18 @@ bi_Scene_SetLighting (progs_t *pr, void *_res)
|
|||
scene->scene->lights = ldata->ldata;
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Scene_SetCamera (progs_t *pr, void *_res)
|
||||
{
|
||||
qfZoneScoped (true);
|
||||
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 ent_id = P_ULONG (pr, 1);
|
||||
entity_t ent = rua_entity_get (res, ent_id);
|
||||
scene->scene->camera = ent.id;
|
||||
}
|
||||
|
||||
static void
|
||||
bi_Entity_GetTransform (progs_t *pr, void *_res)
|
||||
{
|
||||
|
@ -650,7 +662,8 @@ static builtin_t builtins[] = {
|
|||
bi(Scene_DeleteScene, 1, p(ulong)),
|
||||
bi(Scene_CreateEntity, 1, p(ulong)),
|
||||
bi(Scene_DestroyEntity, 1, p(ulong)),
|
||||
bi(Scene_SetLighting , 2, p(ulong), p(ulong)),
|
||||
bi(Scene_SetLighting, 2, p(ulong), p(ulong)),
|
||||
bi(Scene_SetCamera, 2, p(ulong), p(ulong)),
|
||||
|
||||
bi(Entity_GetTransform, 1, p(ulong)),
|
||||
bi(Entity_SetModel, 2, p(ulong), p(int)),
|
||||
|
|
|
@ -269,6 +269,7 @@ Scene_NewScene (scene_system_t *extra_systems)
|
|||
ECS_CreateComponentPools (scene->reg);
|
||||
|
||||
scene->worldmodel = &empty_world;
|
||||
scene->camera = nullent;
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ typedef struct light_s {
|
|||
vec4 attenuation;
|
||||
} light_t;
|
||||
|
||||
//FIXME need a handle type
|
||||
typedef @handle(long) scene_h scene_t;
|
||||
typedef @handle(long) entity_h entity_t;
|
||||
typedef @handle(long) transform_h transform_t;
|
||||
|
@ -25,6 +24,7 @@ void Scene_DeleteScene (scene_t scene);
|
|||
entity_t Scene_CreateEntity (scene_t scene);
|
||||
void Scene_DestroyEntity (entity_t ent);
|
||||
void Scene_SetLighting (scene_t scene, lightingdata_t ldata);
|
||||
void Scene_SetCamera (scene_t scene, entity_t ent);
|
||||
|
||||
transform_t Entity_GetTransform (entity_t ent);
|
||||
void Entity_SetModel (entity_t ent, model_t model);
|
||||
|
|
|
@ -5,6 +5,7 @@ void Scene_DeleteScene (scene_t scene) = #0;
|
|||
entity_t Scene_CreateEntity (scene_t scene) = #0;
|
||||
void Scene_DestroyEntity (entity_t ent) = #0;
|
||||
void Scene_SetLighting (scene_t scene, lightingdata_t ldata) = #0;
|
||||
void Scene_SetCamera (scene_t scene, entity_t ent) = #0;
|
||||
|
||||
transform_t Entity_GetTransform (entity_t ent) = #0;
|
||||
void Entity_SetModel (entity_t ent, model_t model) = #0;
|
||||
|
|
|
@ -126,7 +126,16 @@ bi_refresh (progs_t *pr, void *_res)
|
|||
IN_ProcessEvents ();
|
||||
//GIB_Thread_Execute ();
|
||||
Cbuf_Execute_Stack (qwaq_cbuf);
|
||||
SCR_UpdateScreen (nulltransform, con_realtime, bi_2dfuncs);
|
||||
auto scene = Scene_GetScene (pr, P_ULONG (pr, 0));
|
||||
transform_t camera = nulltransform;
|
||||
if (scene && scene->camera != nullent) {
|
||||
entity_t ent = { .reg = scene->reg, .id = scene->camera,
|
||||
.base = scene->base };
|
||||
if (Ent_HasComponent (ent.id, ent.base + scene_href, ent.reg)) {
|
||||
camera = Entity_Transform (ent);
|
||||
}
|
||||
}
|
||||
SCR_UpdateScreen (camera, con_realtime, bi_2dfuncs);
|
||||
R_FLOAT (pr) = con_frametime;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue