Skip to content

Commit

Permalink
NX/VITA: Add entity scalefactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MotoLegacy committed Dec 29, 2023
1 parent 9127ae4 commit 3c15d7d
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 20 deletions.
7 changes: 5 additions & 2 deletions source/cl_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,15 +614,18 @@ void CL_ParseUpdate (int bits)
ent->light_lev = MSG_ReadByte();
// NZP END

if (bits & U_SCALE)
ent->scale = MSG_ReadByte();
else
ent->scale = ENTSCALE_DEFAULT;

//johnfitz -- PROTOCOL_FITZQUAKE and PROTOCOL_NEHAHRA
if (cl.protocol == PROTOCOL_FITZQUAKE || cl.protocol == PROTOCOL_RMQ)
{
if (bits & U_ALPHA)
ent->alpha = MSG_ReadByte();
else
ent->alpha = ent->baseline.alpha;
if (bits & U_SCALE)
MSG_ReadByte(); // PROTOCOL_RMQ: currently ignored
if (bits & U_FRAME2)
ent->frame = (ent->frame & 0x00FF) | (MSG_ReadByte() << 8);
if (bits & U_MODEL2)
Expand Down
7 changes: 6 additions & 1 deletion source/gl_rmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,17 @@ qboolean R_CullModelForEntity (entity_t *e)
R_RotateForEntity -- johnfitz -- modified to take origin and angles instead of pointer to entity
===============
*/
void R_RotateForEntity (vec3_t origin, vec3_t angles)
void R_RotateForEntity (vec3_t origin, vec3_t angles, unsigned char scale)
{
glTranslatef (origin[0], origin[1], origin[2]);
glRotatef (angles[1], 0, 0, 1);
glRotatef (-angles[0], 0, 1, 0);
glRotatef (angles[2], 1, 0, 0);

if (scale != ENTSCALE_DEFAULT) {
float scalefactor = ENTSCALE_DECODE(scale);
glScalef(scalefactor, scalefactor, scalefactor);
}
}

/*
Expand Down
2 changes: 1 addition & 1 deletion source/glquake.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void R_CullSurfaces (void);
qboolean R_CullBox (vec3_t emins, vec3_t emaxs);
void R_StoreEfrags (efrag_t **ppefrag);
qboolean R_CullModelForEntity (entity_t *e);
void R_RotateForEntity (vec3_t origin, vec3_t angles);
void R_RotateForEntity (vec3_t origin, vec3_t angle, unsigned char scale);
void R_MarkLights (dlight_t *light, int num, mnode_t *node);

void R_InitParticles (void);
Expand Down
1 change: 1 addition & 0 deletions source/progdefs.q1
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ typedef struct
float currentmag2;
float maxspeed;
float facingenemy;
float scale;
vec3_t colormod;
vec3_t glowmod;
float light_lev;
Expand Down
5 changes: 5 additions & 0 deletions source/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define ENTALPHA_TOSAVE(a) (((a)==ENTALPHA_DEFAULT)?0.0f:(((a)==ENTALPHA_ZERO)?-1.0f:((float)(a)-1)/(254))) //server convert to float for savegame
//johnfitz

#define ENTSCALE_DEFAULT 16 // Equivalent to float 1.0f due to byte packing.
#define ENTSCALE_ENCODE(a) ((a) ? ((a) * ENTSCALE_DEFAULT) : ENTSCALE_DEFAULT) // Convert to byte
#define ENTSCALE_DECODE(a) ((float)(a) / ENTSCALE_DEFAULT) // Convert to float for rendering


// defaults for clientinfo messages
#define DEFAULT_VIEWHEIGHT 32

Expand Down
15 changes: 9 additions & 6 deletions source/r_alias.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ void R_DrawTransparentAliasModel (entity_t *e)
// transform it
//
glPushMatrix ();
R_RotateForEntity (lerpdata.origin, lerpdata.angles);
R_RotateForEntity (lerpdata.origin, lerpdata.angles, e->scale);

glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1], paliashdr->scale_origin[2]);
glScalef (paliashdr->scale[0], paliashdr->scale[1], paliashdr->scale[2]);
Expand Down Expand Up @@ -985,7 +985,7 @@ void R_DrawZombieLimb (entity_t *e,int which)

glPushMatrix ();

R_RotateForEntity (lerpdata.origin, lerpdata.angles);
R_RotateForEntity (lerpdata.origin, lerpdata.angles, e->scale);

paliashdr = (aliashdr_t *)Mod_Extradata (e->model);
rs_aliaspolys += paliashdr->numtris;
Expand Down Expand Up @@ -1080,7 +1080,7 @@ void R_DrawAliasModel (entity_t *e)
// transform it
//
glPushMatrix ();
R_RotateForEntity (lerpdata.origin, lerpdata.angles);
R_RotateForEntity (lerpdata.origin, lerpdata.angles, ENTSCALE_DEFAULT);
/* //sB needs fixing in Quakespasm but fuck GL bro
//specChar = clmodel->name[strlen(clmodel->name) - 5];
if(doZHack && specChar == '#')
Expand Down Expand Up @@ -1113,11 +1113,14 @@ void R_DrawAliasModel (entity_t *e)
// Special handling of view model to keep FOV from altering look. Pretty good. Not perfect but rather close.
if ((e == &cl.viewent || e == &cl.viewent2) && scr_fov_viewmodel.value) {
float scale = 1.0f / tan (DEG2RAD (scr_fov.value / 2.0f)) * scr_fov_viewmodel.value / 90.0f;
if (e->scale != ENTSCALE_DEFAULT && e->scale != 0) scale *= ENTSCALE_DECODE(e->scale);
glTranslatef (paliashdr->scale_origin[0] * scale, paliashdr->scale_origin[1], paliashdr->scale_origin[2]);
glScalef (paliashdr->scale[0] * scale, paliashdr->scale[1], paliashdr->scale[2]);
} else {
glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1], paliashdr->scale_origin[2]);
glScalef (paliashdr->scale[0], paliashdr->scale[1], paliashdr->scale[2]);
float scale = 1.0f;
if (e->scale != ENTSCALE_DEFAULT && e->scale != 0) scale *= ENTSCALE_DECODE(e->scale);
glTranslatef (paliashdr->scale_origin[0] * scale, paliashdr->scale_origin[1] * scale, paliashdr->scale_origin[2] * scale);
glScalef (paliashdr->scale[0] * scale, paliashdr->scale[1] * scale, paliashdr->scale[2] * scale);
}

//
Expand Down Expand Up @@ -1454,7 +1457,7 @@ void R_DrawAliasModel_ShowTris (entity_t *e)
R_SetupEntityTransform (e, &lerpdata);

glPushMatrix ();
R_RotateForEntity (lerpdata.origin,lerpdata.angles);
R_RotateForEntity (lerpdata.origin,lerpdata.angles, e->scale);
glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1], paliashdr->scale_origin[2]);
glScalef (paliashdr->scale[0], paliashdr->scale[1], paliashdr->scale[2]);

Expand Down
4 changes: 2 additions & 2 deletions source/r_brush.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ void R_DrawBrushModel (entity_t *e)
e->origin[1] -= DIST_EPSILON;
e->origin[2] -= DIST_EPSILON;
}
R_RotateForEntity (e->origin, e->angles);
R_RotateForEntity (e->origin, e->angles, e->scale);
if (gl_zfix.value)
{
e->origin[0] += DIST_EPSILON;
Expand Down Expand Up @@ -673,7 +673,7 @@ void R_DrawBrushModel_ShowTris (entity_t *e)

glPushMatrix ();
e->angles[0] = -e->angles[0]; // stupid quake bug
R_RotateForEntity (e->origin, e->angles);
R_RotateForEntity (e->origin, e->angles, e->scale);
e->angles[0] = -e->angles[0]; // stupid quake bug

//
Expand Down
18 changes: 10 additions & 8 deletions source/r_sprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ void R_DrawSpriteModel (entity_t *e)
mspriteframe_t *frame;
float *s_up, *s_right;
float angle, sr, cr;
float scale = ENTSCALE_DECODE(e->scale);
if (scale == 0) scale = 1.0f;

//TODO: frustum cull it?

Expand Down Expand Up @@ -156,23 +158,23 @@ void R_DrawSpriteModel (entity_t *e)
glBegin (GL_TRIANGLE_FAN); //was GL_QUADS, but changed to support r_showtris

glTexCoord2f (0, frame->tmax);
VectorMA (e->origin, frame->down, s_up, point);
VectorMA (point, frame->left, s_right, point);
VectorMA (e->origin, frame->down * scale, s_up, point);
VectorMA (point, frame->left * scale, s_right, point);
glVertex3fv (point);

glTexCoord2f (0, 0);
VectorMA (e->origin, frame->up, s_up, point);
VectorMA (point, frame->left, s_right, point);
VectorMA (e->origin, frame->up * scale, s_up, point);
VectorMA (point, frame->left * scale, s_right, point);
glVertex3fv (point);

glTexCoord2f (frame->smax, 0);
VectorMA (e->origin, frame->up, s_up, point);
VectorMA (point, frame->right, s_right, point);
VectorMA (e->origin, frame->up * scale, s_up, point);
VectorMA (point, frame->right * scale, s_right, point);
glVertex3fv (point);

glTexCoord2f (frame->smax, frame->tmax);
VectorMA (e->origin, frame->down, s_up, point);
VectorMA (point, frame->right, s_right, point);
VectorMA (e->origin, frame->down * scale, s_up, point);
VectorMA (point, frame->right * scale, s_right, point);
glVertex3fv (point);

glEnd ();
Expand Down
2 changes: 2 additions & 0 deletions source/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ typedef struct entity_s
int dlightbits;
float light_lev;

unsigned char scale;

// FIXME: could turn these into a union
int trivial_accept;
struct mnode_s *topnode; // for bmodels, first world node
Expand Down
6 changes: 6 additions & 0 deletions source/sv_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,9 @@ void SV_WriteEntitiesToClient (edict_t *clent, sizebuf_t *msg)
if (ent->baseline.light_lev != ent->v.light_lev)
bits |= U_LIGHTLEVEL;

if (ent->v.scale != ENTSCALE_DEFAULT && ent->v.scale != 0)
bits |= U_SCALE;

//johnfitz -- alpha
if (pr_alpha_supported)
{
Expand Down Expand Up @@ -736,6 +739,9 @@ void SV_WriteEntitiesToClient (edict_t *clent, sizebuf_t *msg)
MSG_WriteByte(msg, ent->v.light_lev);
// NZP END

if (bits & U_SCALE)
MSG_WriteByte(msg, ENTSCALE_ENCODE(ent->v.scale));

//johnfitz -- PROTOCOL_FITZQUAKE
if (bits & U_ALPHA)
MSG_WriteByte(msg, ent->alpha);
Expand Down

0 comments on commit 3c15d7d

Please sign in to comment.