mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-04-04 08:25:34 +00:00
[scene] Add more entity component helper functions
Cleans up the code and removes more opportunities for UB.
This commit is contained in:
parent
c512af4f21
commit
63bec6d67f
33 changed files with 122 additions and 141 deletions
|
@ -120,6 +120,10 @@ ENTINLINE transform_t Entity_Transform (entity_t ent);
|
|||
ENTINLINE colormap_t *Entity_GetColormap (entity_t ent);
|
||||
ENTINLINE void Entity_SetColormap (entity_t ent, colormap_t *colormap);
|
||||
ENTINLINE void Entity_RemoveColormap (entity_t ent);
|
||||
ENTINLINE animation_t *Entity_GetAnimation (entity_t ent);
|
||||
ENTINLINE void Entity_SetAnimation (entity_t ent, animation_t *animation);
|
||||
ENTINLINE renderer_t *Entity_GetRenderer (entity_t ent);
|
||||
ENTINLINE void Entity_SetRenderer (entity_t ent, renderer_t *renderer);
|
||||
|
||||
#undef ENTINLINE
|
||||
#ifndef IMPLEMENT_ENTITY_Funcs
|
||||
|
@ -184,6 +188,40 @@ Entity_RemoveColormap (entity_t ent)
|
|||
return Ent_RemoveComponent (ent.id, ent.base + scene_colormap, ent.reg);
|
||||
}
|
||||
|
||||
ENTINLINE
|
||||
animation_t *
|
||||
Entity_GetAnimation (entity_t ent)
|
||||
{
|
||||
if (Ent_HasComponent (ent.id, ent.base + scene_animation, ent.reg)) {
|
||||
return Ent_GetComponent (ent.id, ent.base + scene_animation, ent.reg);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ENTINLINE
|
||||
void
|
||||
Entity_SetAnimation (entity_t ent, animation_t *animation)
|
||||
{
|
||||
Ent_SetComponent (ent.id, ent.base + scene_animation, ent.reg, animation);
|
||||
}
|
||||
|
||||
ENTINLINE
|
||||
renderer_t *
|
||||
Entity_GetRenderer (entity_t ent)
|
||||
{
|
||||
if (Ent_HasComponent (ent.id, ent.base + scene_renderer, ent.reg)) {
|
||||
return Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ENTINLINE
|
||||
void
|
||||
Entity_SetRenderer (entity_t ent, renderer_t *renderer)
|
||||
{
|
||||
Ent_SetComponent (ent.id, ent.base + scene_renderer, ent.reg, renderer);
|
||||
}
|
||||
|
||||
struct mod_brush_s;
|
||||
efrag_t **R_LinkEfrag (struct mleaf_s *leaf, entity_t ent, uint32_t queue,
|
||||
efrag_t **lastlink);
|
||||
|
|
|
@ -200,7 +200,7 @@ void
|
|||
CL_ModelEffects (entity_t ent, int glow_color, double time)
|
||||
{
|
||||
transform_t transform = Entity_Transform (ent);
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, + ent.base + scene_renderer, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
model_t *model = renderer->model;
|
||||
vec4f_t *old_origin = Ent_GetComponent (ent.id, + ent.base + scene_old_origin, ent.reg);
|
||||
vec4f_t ent_origin = Transform_GetWorldPosition (transform);
|
||||
|
|
|
@ -368,8 +368,7 @@ CL_TransformEntity (entity_t ent, float scale, const vec3_t angles,
|
|||
} else {
|
||||
vec3_t ang;
|
||||
VectorCopy (angles, ang);
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer,
|
||||
ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
if (renderer->model && renderer->model->type == mod_alias) {
|
||||
// stupid quake bug
|
||||
// why, oh, why, do alias models pitch in the opposite direction
|
||||
|
|
|
@ -171,8 +171,8 @@ void
|
|||
CL_Init_Entity (entity_t ent)
|
||||
{
|
||||
qfZoneScoped (true);
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
byte *active = Ent_GetComponent (ent.id, ent.base + scene_active, ent.reg);
|
||||
vec4f_t *old_origin = Ent_GetComponent (ent.id, ent.base + scene_old_origin, ent.reg);
|
||||
memset (animation, 0, sizeof (*animation));
|
||||
|
@ -281,7 +281,7 @@ beam_setup (beam_t *b, bool settransform, double time, TEntContext_t *ctx)
|
|||
vec4f_t position = org + d * dist;
|
||||
d += 1.0;
|
||||
transform_t transform = Entity_Transform (tent->ent);
|
||||
renderer_t *renderer = Ent_GetComponent (tent->ent.id, tent->ent.base + scene_renderer, tent->ent.reg);
|
||||
auto renderer = Entity_GetRenderer (tent->ent);
|
||||
renderer->model = b->model;
|
||||
if (settransform) {
|
||||
seed = seed * BEAM_SEED_PRIME;
|
||||
|
@ -418,7 +418,7 @@ parse_tent (qmsg_t *net_message, double time, TEntContext_t *ctx,
|
|||
cl_spr_explod = Mod_ForName ("progs/s_explod.spr", true);
|
||||
}
|
||||
transform_t transform = Entity_Transform (ex->tent->ent);
|
||||
renderer_t *renderer = Ent_GetComponent (ex->tent->ent.id, ex->tent->ent.base + scene_renderer, ex->tent->ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ex->tent->ent);
|
||||
renderer->model = cl_spr_explod;
|
||||
Transform_SetLocalPosition (transform, position);
|
||||
color = (vec4f_t) {0.86, 0.31, 0.24, 0.7};
|
||||
|
@ -657,8 +657,8 @@ CL_UpdateExplosions (double time, TEntContext_t *ctx)
|
|||
ex = &(*to)->to.ex;
|
||||
ent = ex->tent->ent;
|
||||
f = 10 * (time - ex->start);
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
if (f >= renderer->model->numframes) {
|
||||
tent_obj_t *_to;
|
||||
free_temp_entities (ex->tent);
|
||||
|
@ -745,7 +745,7 @@ CL_ParseProjectiles (qmsg_t *net_message, bool nail2, TEntContext_t *ctx)
|
|||
tail = &tent->next;
|
||||
|
||||
pr = tent->ent;
|
||||
renderer_t *renderer = Ent_GetComponent (pr.id, pr.base + scene_renderer, pr.reg);
|
||||
auto renderer = Entity_GetRenderer (pr);
|
||||
renderer->model = cl_spike;
|
||||
position[0] = ((bits[0] + ((bits[1] & 15) << 8)) << 1) - 4096;
|
||||
position[1] = (((bits[1] >> 4) + (bits[2] << 4)) << 1) - 4096;
|
||||
|
|
|
@ -780,7 +780,7 @@ V_CalcIntermissionRefdef (viewstate_t *vs)
|
|||
|
||||
Transform_SetWorldPosition (vs->camera_transform, origin);
|
||||
Transform_SetWorldRotation (vs->camera_transform, rotation);
|
||||
renderer_t *renderer = Ent_GetComponent (view.id, view.base + scene_renderer, view.reg);
|
||||
auto renderer = Entity_GetRenderer (view);
|
||||
renderer->model = NULL;
|
||||
|
||||
// always idle in intermission
|
||||
|
@ -801,8 +801,8 @@ V_CalcRefdef (viewstate_t *vs)
|
|||
vec4f_t origin = vs->player_origin;
|
||||
vec_t *viewangles = vs->player_angles;
|
||||
|
||||
renderer_t *renderer = Ent_GetComponent (view.id, view.base + scene_renderer, view.reg);
|
||||
animation_t *animation = Ent_GetComponent (view.id, view.base + scene_animation, view.reg);
|
||||
auto renderer = Entity_GetRenderer (view);
|
||||
auto animation = Entity_GetAnimation (view);
|
||||
|
||||
V_DriftPitch (vs);
|
||||
|
||||
|
|
|
@ -138,8 +138,8 @@ CL_ParseStatic (qmsg_t *msg, int version)
|
|||
CL_ParseBaseline (msg, &es, version);
|
||||
DARRAY_APPEND (&cl_static_entities, es);
|
||||
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
|
||||
// copy it to the current state
|
||||
renderer->model = cl_world.models.a[es.modelindex];
|
||||
|
|
|
@ -324,7 +324,7 @@ bi_Entity_SetModel (progs_t *pr, void *_res)
|
|||
// bad scene caught above
|
||||
rua_scene_t *scene = rua_scene_get (res, scene_id);
|
||||
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
renderer->model = model;
|
||||
R_AddEfrags (&scene->scene->worldmodel->brush, ent);
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ R_AddEfrags (mod_brush_t *brush, entity_t ent)
|
|||
model_t *entmodel;
|
||||
vec3_t emins, emaxs;
|
||||
transform_t transform = Entity_Transform (ent);
|
||||
renderer_t *rend = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
auto rend = Entity_GetRenderer (ent);
|
||||
|
||||
if (!rend->model) {
|
||||
Ent_RemoveComponent (ent.id, ent.base + scene_visibility, ent.reg);
|
||||
|
|
|
@ -275,7 +275,7 @@ GL_DrawAliasShadow (transform_t transform, const aliashdr_t *ahdr,
|
|||
static inline vert_order_t *
|
||||
GL_GetAliasFrameVerts16 (aliashdr_t *ahdr, entity_t e)
|
||||
{
|
||||
animation_t *animation = Ent_GetComponent (e.id, e.base + scene_animation, e.reg);
|
||||
auto animation = Entity_GetAnimation (e);
|
||||
float blend = R_AliasGetLerpedFrames (animation, ahdr);
|
||||
int count, i;
|
||||
trivertx16_t *verts;
|
||||
|
@ -339,7 +339,7 @@ GL_GetAliasFrameVerts16 (aliashdr_t *ahdr, entity_t e)
|
|||
static inline vert_order_t *
|
||||
GL_GetAliasFrameVerts (aliashdr_t *ahdr, entity_t e)
|
||||
{
|
||||
animation_t *animation = Ent_GetComponent (e.id, e.base + scene_animation, e.reg);
|
||||
auto animation = Entity_GetAnimation (e);
|
||||
float blend = R_AliasGetLerpedFrames (animation, ahdr);
|
||||
int count, i;
|
||||
trivertx_t *verts;
|
||||
|
@ -410,8 +410,7 @@ gl_get_skin (entity_t e, renderer_t *renderer, aliashdr_t *ahdr)
|
|||
}
|
||||
}
|
||||
maliasskindesc_t *skindesc;
|
||||
animation_t *animation = Ent_GetComponent (e.id, e.base + scene_animation,
|
||||
e.reg);
|
||||
auto animation = Entity_GetAnimation (e);
|
||||
skindesc = R_AliasGetSkindesc (animation, renderer->skinnum, ahdr);
|
||||
if (!skindesc->texnum) {
|
||||
auto tex = (tex_t *) ((byte *) ahdr + skindesc->skin);
|
||||
|
@ -435,7 +434,7 @@ gl_R_DrawAliasModel (entity_t e)
|
|||
vec3_t dist, scale;
|
||||
vec4f_t origin;
|
||||
vert_order_t *vo;
|
||||
renderer_t *renderer = Ent_GetComponent (e.id, e.base + scene_renderer, e.reg);
|
||||
auto renderer = Entity_GetRenderer (e);
|
||||
model_t *model = renderer->model;
|
||||
|
||||
if (renderer->onlyshadows) {
|
||||
|
|
|
@ -88,7 +88,7 @@ gl_draw_iqm_frame (iqm_t *iqm, gliqm_t *gl, iqmframe_t *frame, iqmmesh *mesh)
|
|||
void
|
||||
gl_R_DrawIQMModel (entity_t ent)
|
||||
{
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
model_t *model = renderer->model;
|
||||
iqm_t *iqm = (iqm_t *) model->aliashdr;
|
||||
gliqm_t *gl = (gliqm_t *) iqm->extra_data;
|
||||
|
@ -96,8 +96,7 @@ gl_R_DrawIQMModel (entity_t ent)
|
|||
iqmframe_t *frame;
|
||||
int i;
|
||||
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
|
||||
ent.reg);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
blend = R_IQMGetLerpedFrames (animation, iqm);
|
||||
frame = R_IQMBlendPalette (iqm, animation->pose1, animation->pose2,
|
||||
blend, 0, gl->blend_palette, gl->palette_size);
|
||||
|
|
|
@ -58,7 +58,7 @@ void (*gl_R_DrawSpriteModel) (struct entity_s ent);
|
|||
static void
|
||||
R_DrawSpriteModel_f (entity_t e)
|
||||
{
|
||||
renderer_t *renderer = Ent_GetComponent (e.id, e.base + scene_renderer, e.reg);
|
||||
auto renderer = Entity_GetRenderer (e);
|
||||
msprite_t *sprite = renderer->model->cache.data;
|
||||
float modelalpha, color[4];
|
||||
vec4f_t cameravec = {};
|
||||
|
@ -71,7 +71,7 @@ R_DrawSpriteModel_f (entity_t e)
|
|||
cameravec = r_refdef.frame.position - origin;
|
||||
|
||||
// don't bother culling, it's just a single polygon without a surface cache
|
||||
animation_t *animation = Ent_GetComponent (e.id, e.base + scene_animation, e.reg);
|
||||
auto animation = Entity_GetAnimation (e);
|
||||
frame = R_GetSpriteFrame (sprite, animation);
|
||||
|
||||
if (!R_BillboardFrame (transform, sprite->type, cameravec,
|
||||
|
@ -118,7 +118,7 @@ R_DrawSpriteModel_f (entity_t e)
|
|||
static void
|
||||
R_DrawSpriteModel_VA_f (entity_t e)
|
||||
{
|
||||
renderer_t *renderer = Ent_GetComponent (e.id, e.base + scene_renderer, e.reg);
|
||||
auto renderer = Entity_GetRenderer (e);
|
||||
msprite_t *psprite = renderer->model->cache.data;
|
||||
unsigned char modelalpha, color[4];
|
||||
vec4f_t up = {}, right = {};
|
||||
|
@ -131,7 +131,7 @@ R_DrawSpriteModel_VA_f (entity_t e)
|
|||
VA = gl_spriteVertexArray; // FIXME: Despair
|
||||
|
||||
// don't bother culling, it's just a single polygon without a surface cache
|
||||
animation_t *animation = Ent_GetComponent (e.id, e.base + scene_animation, e.reg);
|
||||
auto animation = Entity_GetAnimation (e);
|
||||
frame = R_GetSpriteFrame (psprite, animation);
|
||||
|
||||
qfglBindTexture (GL_TEXTURE_2D, frame->gl_texturenum); // FIXME: DESPAIR
|
||||
|
|
|
@ -163,7 +163,7 @@ R_DrawViewModel (void)
|
|||
if (!Entity_Valid (ent)) {
|
||||
return;
|
||||
}
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
if (vr_data.inhibit_viewmodel
|
||||
|| !r_drawviewmodel
|
||||
|| !r_drawentities
|
||||
|
|
|
@ -507,12 +507,12 @@ gl_R_DrawBrushModel (entity_t e)
|
|||
bool rotated;
|
||||
vec3_t mins, maxs;
|
||||
mat4f_t worldMatrix;
|
||||
renderer_t *renderer = Ent_GetComponent (e.id, e.base + scene_renderer, e.reg);
|
||||
auto renderer = Entity_GetRenderer (e);
|
||||
model_t *model = renderer->model;
|
||||
mod_brush_t *brush = &model->brush;
|
||||
glbspctx_t bspctx = {
|
||||
brush,
|
||||
Ent_GetComponent (e.id, e.base + scene_animation, e.reg),
|
||||
Entity_GetAnimation (e),
|
||||
ent_transforms.a[ent_transforms.size++],
|
||||
renderer->colormod,
|
||||
};
|
||||
|
|
|
@ -164,7 +164,7 @@ calc_lighting (entity_t ent, float *ambient, float *shadelight,
|
|||
|
||||
VectorSet ( -1, 0, 0, lightvec); //FIXME
|
||||
light = R_LightPoint (&r_refdef.worldmodel->brush, entorigin);
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
*ambient = max (light, max (renderer->model->min_light,
|
||||
renderer->min_light) * 128);
|
||||
*shadelight = *ambient;
|
||||
|
@ -242,7 +242,7 @@ glsl_R_DrawAlias (entity_t ent)
|
|||
|
||||
calc_lighting (ent, &ambient, &shadelight, lightvec);
|
||||
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
if (renderer->onlyshadows) {
|
||||
return;
|
||||
}
|
||||
|
@ -268,8 +268,7 @@ glsl_R_DrawAlias (entity_t ent)
|
|||
mmulf (mvp_mat, worldMatrix, mvp_mat);
|
||||
mmulf (mvp_mat, alias_vp, mvp_mat);
|
||||
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
|
||||
ent.reg);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
GLuint cmap_tex = glsl_colormap;
|
||||
auto colormap = Entity_GetColormap (ent);
|
||||
if (colormap) {
|
||||
|
|
|
@ -653,7 +653,7 @@ static void
|
|||
R_DrawBrushModel (entity_t e)
|
||||
{
|
||||
float dot, radius;
|
||||
renderer_t *renderer = Ent_GetComponent (e.id, e.base + scene_renderer, e.reg);
|
||||
auto renderer = Entity_GetRenderer (e);
|
||||
model_t *model = renderer->model;
|
||||
mod_brush_t *brush = &model->brush;
|
||||
plane_t *plane;
|
||||
|
@ -663,7 +663,7 @@ R_DrawBrushModel (entity_t e)
|
|||
vec4f_t org;
|
||||
glslbspctx_t bctx = {
|
||||
brush,
|
||||
Ent_GetComponent (e.id, e.base + scene_animation, e.reg),
|
||||
Entity_GetAnimation (e),
|
||||
Transform_GetWorldMatrixPtr (Entity_Transform (e)),
|
||||
renderer->colormod,
|
||||
};
|
||||
|
|
|
@ -204,7 +204,7 @@ set_arrays (iqm_t *iqm)
|
|||
void
|
||||
glsl_R_DrawIQM (entity_t ent)
|
||||
{
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
model_t *model = renderer->model;
|
||||
static quat_t color = { 1, 1, 1, 1};
|
||||
iqm_t *iqm = (iqm_t *) model->aliashdr;
|
||||
|
@ -231,8 +231,7 @@ glsl_R_DrawIQM (entity_t ent)
|
|||
VectorScale (ambientcolor, 1/255.0, ambientcolor);
|
||||
R_FindNearLights (entorigin, MAX_IQM_LIGHTS, lights);
|
||||
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
|
||||
ent.reg);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
blend = R_IQMGetLerpedFrames (animation, iqm);
|
||||
frame = R_IQMBlendFrames (iqm, animation->pose1, animation->pose2,
|
||||
blend, 0);
|
||||
|
|
|
@ -119,7 +119,7 @@ R_DrawViewModel (void)
|
|||
if (!Entity_Valid (ent)) {
|
||||
return;
|
||||
}
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
if (vr_data.inhibit_viewmodel
|
||||
|| !r_drawviewmodel
|
||||
|| !r_drawentities
|
||||
|
|
|
@ -131,8 +131,7 @@ static void
|
|||
R_GetSpriteFrames (entity_t ent, msprite_t *sprite, mspriteframe_t **frame1,
|
||||
mspriteframe_t **frame2, float *blend)
|
||||
{
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
|
||||
ent.reg);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
int framenum = animation->frame;
|
||||
int pose;
|
||||
int i, numframes;
|
||||
|
@ -209,7 +208,7 @@ make_quad (mspriteframe_t *frame, vec4f_t origin, vec4f_t sright, vec4f_t sup, f
|
|||
void
|
||||
glsl_R_DrawSprite (entity_t ent)
|
||||
{
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
msprite_t *sprite = (msprite_t *) renderer->model->cache.data;
|
||||
mspriteframe_t *frame1, *frame2;
|
||||
float blend;
|
||||
|
|
|
@ -105,9 +105,7 @@ R_AliasCheckBBox (entity_t ent)
|
|||
ent.reg);
|
||||
visibility->trivial_accept = 0;
|
||||
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id,
|
||||
ent.base + scene_renderer,
|
||||
ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
pmodel = renderer->model;
|
||||
if (!(pahdr = pmodel->aliashdr))
|
||||
pahdr = Cache_Get (&pmodel->cache);
|
||||
|
@ -116,9 +114,7 @@ R_AliasCheckBBox (entity_t ent)
|
|||
R_AliasSetUpTransform (ent, 0);
|
||||
|
||||
// construct the base bounding box for this frame
|
||||
animation_t *animation = Ent_GetComponent (ent.id,
|
||||
ent.base + scene_animation,
|
||||
ent.reg);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
frame = animation->frame;
|
||||
// TODO: don't repeat this check when drawing?
|
||||
if ((frame >= pmdl->numframes) || (frame < 0)) {
|
||||
|
@ -534,9 +530,7 @@ R_AliasPrepareUnclippedPoints (void)
|
|||
static void
|
||||
R_AliasSetupSkin (entity_t ent)
|
||||
{
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id,
|
||||
ent.base + scene_renderer,
|
||||
ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
int skinnum = renderer->skinnum;
|
||||
if ((skinnum >= pmdl->numskins) || (skinnum < 0)) {
|
||||
Sys_MaskPrintf (SYS_dev, "R_AliasSetupSkin: no such skin # %d\n",
|
||||
|
@ -544,9 +538,7 @@ R_AliasSetupSkin (entity_t ent)
|
|||
skinnum = 0;
|
||||
}
|
||||
|
||||
animation_t *animation = Ent_GetComponent (ent.id,
|
||||
ent.base + scene_animation,
|
||||
ent.reg);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
pskindesc = R_AliasGetSkindesc (animation, skinnum, paliashdr);
|
||||
|
||||
a_skinwidth = pmdl->skinwidth;
|
||||
|
@ -607,9 +599,7 @@ R_AliasSetupFrame (entity_t ent)
|
|||
{
|
||||
maliasframedesc_t *frame;
|
||||
|
||||
animation_t *animation = Ent_GetComponent (ent.id,
|
||||
ent.base + scene_animation,
|
||||
ent.reg);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
frame = R_AliasGetFramedesc (animation, paliashdr);
|
||||
r_apverts = (trivertx_t *) ((byte *) paliashdr + frame->frame);
|
||||
}
|
||||
|
@ -623,9 +613,7 @@ R_AliasDrawModel (entity_t ent, alight_t *lighting)
|
|||
|
||||
r_amodels_drawn++;
|
||||
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id,
|
||||
ent.base + scene_renderer,
|
||||
ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
if (renderer->onlyshadows) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -291,7 +291,7 @@ R_IQMSetUpTransform (entity_t ent, int trivial_accept)
|
|||
void
|
||||
R_IQMDrawModel (entity_t ent, alight_t *plighting)
|
||||
{
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
model_t *model = renderer->model;
|
||||
iqm_t *iqm = (iqm_t *) model->aliashdr;
|
||||
swiqm_t *sw = (swiqm_t *) iqm->extra_data;
|
||||
|
@ -303,8 +303,7 @@ R_IQMDrawModel (entity_t ent, alight_t *plighting)
|
|||
+ sizeof (finalvert_t) * (iqm->num_verts + 1)
|
||||
+ sizeof (auxvert_t) * iqm->num_verts;
|
||||
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
|
||||
ent.reg);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
blend = R_IQMGetLerpedFrames (animation, iqm);
|
||||
frame = R_IQMBlendPalette (iqm, animation->pose1, animation->pose2,
|
||||
blend, size, sw->blend_palette,
|
||||
|
|
|
@ -162,9 +162,9 @@ SW_AddEntity (entity_t ent)
|
|||
transform_t transform = Entity_Transform (ent);
|
||||
Ent_SetComponent (ent.id, ent.base + scene_sw_matrix, reg,
|
||||
Transform_GetWorldMatrixPtr (transform));
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation, reg);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
Ent_SetComponent (ent.id, ent.base + scene_sw_frame, reg, &animation->frame);
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
mod_brush_t *brush = &renderer->model->brush;
|
||||
Ent_SetComponent (ent.id, ent.base + scene_sw_brush, reg, &brush);
|
||||
|
||||
|
@ -275,7 +275,7 @@ setup_lighting (entity_t ent, alight_t *lighting)
|
|||
float add;
|
||||
float lightvec[3] = { -1, 0, 0 };
|
||||
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
minlight = max (renderer->model->min_light, renderer->min_light);
|
||||
|
||||
// 128 instead of 255 due to clamping below
|
||||
|
@ -380,9 +380,7 @@ R_DrawViewModel (void)
|
|||
return;
|
||||
}
|
||||
|
||||
renderer_t *renderer = Ent_GetComponent (viewent.id,
|
||||
viewent.base + scene_renderer,
|
||||
viewent.reg);
|
||||
auto renderer = Entity_GetRenderer (viewent);
|
||||
if (!renderer->model)
|
||||
return;
|
||||
|
||||
|
@ -502,8 +500,7 @@ R_DrawBrushEntitiesOnList (entqueue_t *queue)
|
|||
vec4f_t *transform = Ent_GetComponent (ent.id, ent.base + scene_sw_matrix,
|
||||
ent.reg);
|
||||
VectorCopy (transform[3], origin);
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer,
|
||||
ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
model_t *model = renderer->model;
|
||||
|
||||
// see if the bounding box lets us trivially reject, also
|
||||
|
|
|
@ -243,11 +243,10 @@ R_SetupAndDrawSprite (const vec3_t relvieworg)
|
|||
void
|
||||
R_DrawSprite (entity_t ent)
|
||||
{
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
msprite_t *sprite = renderer->model->cache.data;
|
||||
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
|
||||
ent.reg);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
r_spritedesc.pspriteframe = R_GetSpriteFrame (sprite, animation);
|
||||
|
||||
sprite_width = r_spritedesc.pspriteframe->width;
|
||||
|
|
|
@ -68,18 +68,6 @@ typedef struct {
|
|||
uint32_t matrix_base;
|
||||
} shadow_push_constants_t;
|
||||
|
||||
static renderer_t *
|
||||
alias_get_renderer (entity_t ent)
|
||||
{
|
||||
return Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
}
|
||||
|
||||
static animation_t *
|
||||
alias_get_animation (entity_t ent)
|
||||
{
|
||||
return Ent_GetComponent (ent.id, ent.base + scene_animation, ent.reg);
|
||||
}
|
||||
|
||||
static void
|
||||
alias_depth_range (qfv_taskctx_t *taskctx, float minDepth, float maxDepth)
|
||||
{
|
||||
|
@ -184,7 +172,7 @@ alias_draw_ent (qfv_taskctx_t *taskctx, entity_t ent, bool pass,
|
|||
hdr = Cache_Get (&model->cache);
|
||||
}
|
||||
|
||||
auto animation = alias_get_animation (ent);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
float blend = R_AliasGetLerpedFrames (animation, hdr);
|
||||
|
||||
transform_t transform = Entity_Transform (ent);
|
||||
|
@ -279,7 +267,7 @@ alias_draw (const exprval_t **params, exprval_t *result, exprctx_t *ectx)
|
|||
auto queue = r_ent_queue; //FIXME fetch from scene
|
||||
for (size_t i = 0; i < queue->ent_queues[mod_alias].size; i++) {
|
||||
entity_t ent = queue->ent_queues[mod_alias].a[i];
|
||||
auto renderer = alias_get_renderer (ent);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
if ((stage == alias_shadow && renderer->noshadows)
|
||||
|| (stage == alias_main && renderer->onlyshadows)) {
|
||||
continue;
|
||||
|
|
|
@ -660,7 +660,7 @@ static int
|
|||
R_DrawBrushModel (entity_t ent, bsp_pass_t *pass, vulkan_ctx_t *ctx)
|
||||
{
|
||||
qfZoneScoped (true);
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
model_t *model = renderer->model;
|
||||
bspctx_t *bctx = ctx->bsp_context;
|
||||
|
||||
|
@ -668,8 +668,7 @@ R_DrawBrushModel (entity_t ent, bsp_pass_t *pass, vulkan_ctx_t *ctx)
|
|||
return 0;
|
||||
}
|
||||
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
|
||||
ent.reg);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
pass->ent_frame = animation->frame & 1;
|
||||
pass->inst_id = model->render_id;
|
||||
pass->inst_id |= renderer->colormod[3] < 1 ? INST_ALPHA : 0;
|
||||
|
|
|
@ -192,7 +192,7 @@ iqm_draw_ent (qfv_taskctx_t *taskctx, entity_t ent, bool pass)
|
|||
auto ctx = taskctx->ctx;
|
||||
auto device = ctx->device;
|
||||
auto dfunc = device->funcs;
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
auto model = renderer->model;
|
||||
auto iqm = (iqm_t *) model->aliashdr;
|
||||
qfv_iqm_t *mesh = iqm->extra_data;
|
||||
|
@ -200,8 +200,7 @@ iqm_draw_ent (qfv_taskctx_t *taskctx, entity_t ent, bool pass)
|
|||
iqmframe_t *frame;
|
||||
uint16_t *matrix_base = taskctx->data;
|
||||
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
|
||||
ent.reg);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
iqm_push_constants_t constants = {
|
||||
.blend = R_IQMGetLerpedFrames (animation, iqm),
|
||||
.matrix_base = matrix_base ? *matrix_base : 0,
|
||||
|
|
|
@ -90,16 +90,12 @@ Vulkan_Scene_AddEntity (vulkan_ctx_t *ctx, entity_t entity)
|
|||
if (!Entity_Valid (entity)) {
|
||||
return 0; //FIXME see below
|
||||
} else {
|
||||
renderer_t *renderer = Ent_GetComponent (entity.id,
|
||||
entity.base + scene_renderer,
|
||||
entity.reg);
|
||||
auto renderer = Entity_GetRenderer (entity);
|
||||
return renderer->render_id;
|
||||
}
|
||||
}
|
||||
if (Entity_Valid (entity)) {
|
||||
renderer_t *renderer = Ent_GetComponent (entity.id,
|
||||
entity.base + scene_renderer,
|
||||
entity.reg);
|
||||
auto renderer = Entity_GetRenderer (entity);
|
||||
renderer->render_id = render_id;
|
||||
}
|
||||
//unlock
|
||||
|
@ -108,9 +104,7 @@ Vulkan_Scene_AddEntity (vulkan_ctx_t *ctx, entity_t entity)
|
|||
vec4f_t color;
|
||||
if (Entity_Valid (entity)) { //FIXME give world entity an entity :P
|
||||
transform_t transform = Entity_Transform (entity);
|
||||
renderer_t *renderer = Ent_GetComponent (entity.id,
|
||||
entity.base + scene_renderer,
|
||||
entity.reg);
|
||||
auto renderer = Entity_GetRenderer (entity);
|
||||
mat4ftranspose (f, Transform_GetWorldMatrixPtr (transform));
|
||||
entdata->xform[0] = f[0];
|
||||
entdata->xform[1] = f[1];
|
||||
|
@ -153,7 +147,7 @@ scene_draw_viewmodel (const exprval_t **params, exprval_t *result,
|
|||
if (!Entity_Valid (ent)) {
|
||||
return;
|
||||
}
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
if (vr_data.inhibit_viewmodel
|
||||
|| !r_drawviewmodel
|
||||
|| !r_drawentities
|
||||
|
|
|
@ -150,7 +150,7 @@ Vulkan_Sprite_FreeDescriptors (vulkan_ctx_t *ctx, qfv_sprite_t *sprite)
|
|||
static void
|
||||
sprite_draw_ent (qfv_taskctx_t *taskctx, entity_t ent)
|
||||
{
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
auto model = renderer->model;
|
||||
msprite_t *sprite = model->cache.data;
|
||||
|
||||
|
@ -162,8 +162,7 @@ sprite_draw_ent (qfv_taskctx_t *taskctx, entity_t ent)
|
|||
64, sizeof (frame), &frame },
|
||||
};
|
||||
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
|
||||
ent.reg);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
frame = (ptrdiff_t) R_GetSpriteFrame (sprite, animation);
|
||||
|
||||
transform_t transform = Entity_Transform (ent);
|
||||
|
|
|
@ -140,8 +140,8 @@ static void
|
|||
set_entity_model (int ent_ind, int modelindex)
|
||||
{
|
||||
entity_t ent = cl_entities[ent_ind];
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
renderer->model = cl_world.models.a[modelindex];
|
||||
// automatic animation (torches, etc) can be either all together
|
||||
// or randomized
|
||||
|
@ -216,8 +216,8 @@ CL_RelinkEntities (void)
|
|||
SET_ADD (&cl_forcelink, i);
|
||||
}
|
||||
transform_t transform = Entity_Transform (ent);
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
vec4f_t *old_origin = Ent_GetComponent (ent.id, ent.base + scene_old_origin, ent.reg);
|
||||
|
||||
if (SET_TEST_MEMBER (&cl_forcelink, i)) {
|
||||
|
|
|
@ -300,9 +300,7 @@ CL_ClearState (void)
|
|||
|
||||
cl.viewstate.weapon_entity = Scene_CreateEntity (cl_world.scene);
|
||||
CL_Init_Entity (cl.viewstate.weapon_entity);
|
||||
renderer_t *renderer = Ent_GetComponent (cl.viewstate.weapon_entity.id,
|
||||
cl_world.scene->base + scene_renderer,
|
||||
cl_world.scene->reg);
|
||||
auto renderer = Entity_GetRenderer (cl.viewstate.weapon_entity);
|
||||
renderer->depthhack = 1;
|
||||
renderer->noshadows = cl_player_shadows;
|
||||
r_data->view_model = cl.viewstate.weapon_entity;
|
||||
|
@ -489,8 +487,8 @@ CL_PrintEntities_f (void)
|
|||
for (i = 0; i < cl.num_entities; i++) {
|
||||
entity_t ent = cl_entities[i];
|
||||
transform_t transform = Entity_Transform (ent);
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer, ent.reg);
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation, ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
Sys_Printf ("%3i:", i);
|
||||
if (!Entity_Valid (ent) || !renderer->model) {
|
||||
Sys_Printf ("EMPTY\n");
|
||||
|
|
|
@ -683,7 +683,7 @@ CL_ParseClientdata (void)
|
|||
if (bits & SU_WEAPONFRAME2)
|
||||
cl.stats[STAT_WEAPONFRAME] |= MSG_ReadByte (net_message) << 8;
|
||||
|
||||
renderer_t *renderer = Ent_GetComponent (cl.viewstate.weapon_entity.id, cl_world.scene->base + scene_renderer, cl_world.scene->reg);
|
||||
auto renderer = Entity_GetRenderer (cl.viewstate.weapon_entity);
|
||||
if (bits & SU_WEAPONALPHA) {
|
||||
byte alpha = MSG_ReadByte (net_message);
|
||||
float a = ENTALPHA_DECODE (alpha);
|
||||
|
|
|
@ -485,8 +485,7 @@ CL_ParsePlayerinfo (void)
|
|||
entity_t ent;
|
||||
|
||||
ent = CL_GetEntity (num + 1);
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer,
|
||||
cl_world.scene->reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
bits = MSG_ReadByte (net_message);
|
||||
if (bits & PF_ALPHA) {
|
||||
val = MSG_ReadByte (net_message);
|
||||
|
|
|
@ -138,10 +138,8 @@ is_gib (entity_state_t *s1)
|
|||
static void
|
||||
set_entity_model (entity_t ent, int modelindex)
|
||||
{
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer,
|
||||
cl_world.scene->reg);
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
|
||||
cl_world.scene->reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
renderer->model = cl_world.models.a[modelindex];
|
||||
// automatic animation (torches, etc) can be either all together
|
||||
// or randomized
|
||||
|
@ -188,10 +186,8 @@ CL_LinkPacketEntities (void)
|
|||
forcelink = true;
|
||||
}
|
||||
transform_t transform = Entity_Transform (ent);
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer,
|
||||
ent.reg);
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
|
||||
ent.reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
vec4f_t *old_origin = Ent_GetComponent (ent.id, ent.base + scene_old_origin,
|
||||
ent.reg);
|
||||
|
||||
|
@ -313,8 +309,7 @@ CL_UpdateFlagModels (entity_t ent, int key)
|
|||
if (!*active) {
|
||||
return;
|
||||
}
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
|
||||
cl_world.scene->reg);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
|
||||
f = 14.0;
|
||||
if (animation->frame >= 29 && animation->frame <= 40) {
|
||||
|
@ -359,8 +354,7 @@ CL_AddFlagModels (entity_t ent, int team, int key)
|
|||
}
|
||||
CL_UpdateFlagModels (ent, key);
|
||||
|
||||
renderer_t *renderer = Ent_GetComponent (fent.id, fent.base + scene_renderer,
|
||||
cl_world.scene->reg);
|
||||
auto renderer = Entity_GetRenderer (fent);
|
||||
renderer->model = cl_world.models.a[cl_flagindex];
|
||||
renderer->skinnum = team;
|
||||
|
||||
|
@ -437,10 +431,8 @@ CL_LinkPlayers (void)
|
|||
if (!Entity_Valid (ent)) {
|
||||
ent = CL_GetEntity (j + 1);
|
||||
}
|
||||
renderer_t *renderer = Ent_GetComponent (ent.id, ent.base + scene_renderer,
|
||||
cl_world.scene->reg);
|
||||
animation_t *animation = Ent_GetComponent (ent.id, ent.base + scene_animation,
|
||||
cl_world.scene->reg);
|
||||
auto renderer = Entity_GetRenderer (ent);
|
||||
auto animation = Entity_GetAnimation (ent);
|
||||
|
||||
// spawn light flashes, even ones coming from invisible objects
|
||||
if (j == cl.playernum) {
|
||||
|
|
|
@ -664,9 +664,7 @@ CL_ClearState (void)
|
|||
|
||||
cl.viewstate.weapon_entity = Scene_CreateEntity (cl_world.scene);
|
||||
CL_Init_Entity (cl.viewstate.weapon_entity);
|
||||
renderer_t *renderer = Ent_GetComponent (cl.viewstate.weapon_entity.id,
|
||||
cl_world.scene->base + scene_renderer,
|
||||
cl_world.scene->reg);
|
||||
auto renderer = Entity_GetRenderer (cl.viewstate.weapon_entity);
|
||||
renderer->depthhack = 1;
|
||||
renderer->noshadows = cl_player_shadows;
|
||||
r_data->view_model = cl.viewstate.weapon_entity;
|
||||
|
|
Loading…
Reference in a new issue