Add support for model scale

This commit is contained in:
JosiahJack 2022-08-07 05:47:50 -05:00
parent 87835bc3e3
commit 6ebf6f097a
10 changed files with 99 additions and 17 deletions

View file

@ -586,7 +586,9 @@ void CL_ParseUpdate (int bits)
else else
ent->alpha = ent->baseline.alpha; ent->alpha = ent->baseline.alpha;
if (bits & U_SCALE) if (bits & U_SCALE)
MSG_ReadByte(); // PROTOCOL_RMQ: currently ignored ent->scale = MSG_ReadByte();
else
ent->scale = ent->baseline.scale;
if (bits & U_FRAME2) if (bits & U_FRAME2)
ent->frame = (ent->frame & 0x00FF) | (MSG_ReadByte() << 8); ent->frame = (ent->frame & 0x00FF) | (MSG_ReadByte() << 8);
if (bits & U_MODEL2) if (bits & U_MODEL2)
@ -681,6 +683,7 @@ void CL_ParseBaseline (entity_t *ent, int version) //johnfitz -- added argument
} }
ent->baseline.alpha = (bits & B_ALPHA) ? MSG_ReadByte() : ENTALPHA_DEFAULT; //johnfitz -- PROTOCOL_FITZQUAKE ent->baseline.alpha = (bits & B_ALPHA) ? MSG_ReadByte() : ENTALPHA_DEFAULT; //johnfitz -- PROTOCOL_FITZQUAKE
ent->baseline.scale = (bits & B_SCALE) ? MSG_ReadByte() : ENTSCALE_DEFAULT;
} }
@ -920,7 +923,7 @@ void CL_ParseStatic (int version) //johnfitz -- added a parameter
ent->skinnum = ent->baseline.skin; ent->skinnum = ent->baseline.skin;
ent->effects = ent->baseline.effects; ent->effects = ent->baseline.effects;
ent->alpha = ent->baseline.alpha; //johnfitz -- alpha ent->alpha = ent->baseline.alpha; //johnfitz -- alpha
ent->scale = ent->baseline.scale;
VectorCopy (ent->baseline.origin, ent->origin); VectorCopy (ent->baseline.origin, ent->origin);
VectorCopy (ent->baseline.angles, ent->angles); VectorCopy (ent->baseline.angles, ent->angles);
R_AddEfrags (ent); R_AddEfrags (ent);

View file

@ -278,7 +278,7 @@ entity_t *CL_NewTempEntity (void)
num_temp_entities++; num_temp_entities++;
cl_visedicts[cl_numvisedicts] = ent; cl_visedicts[cl_numvisedicts] = ent;
cl_numvisedicts++; cl_numvisedicts++;
ent->scale = ENTSCALE_DEFAULT;
ent->colormap = vid.colormap; ent->colormap = vid.colormap;
return ent; return ent;
} }

View file

@ -170,6 +170,8 @@ void R_AddEfrags (entity_t *ent)
{ {
qmodel_t *entmodel; qmodel_t *entmodel;
int i; int i;
vec3_t boundVec, scaledVec;
vec_t scalefactor;
if (!ent->model) if (!ent->model)
return; return;
@ -179,11 +181,21 @@ void R_AddEfrags (entity_t *ent)
r_pefragtopnode = NULL; r_pefragtopnode = NULL;
entmodel = ent->model; entmodel = ent->model;
scalefactor = ENTSCALE_DECODE(ent->scale);
for (i=0 ; i<3 ; i++) if (scalefactor != 1.0f)
{ {
r_emins[i] = ent->origin[i] + entmodel->mins[i]; VectorCopy (entmodel->mins, boundVec);
r_emaxs[i] = ent->origin[i] + entmodel->maxs[i]; VectorScale (boundVec, scalefactor, scaledVec);
VectorAdd (ent->origin, scaledVec, r_emins);
VectorCopy (entmodel->maxs, boundVec);
VectorScale (boundVec, scalefactor, scaledVec);
VectorAdd (ent->origin, scaledVec, r_emaxs);
}
else
{
VectorAdd (ent->origin, entmodel->mins, r_emins);
VectorAdd (ent->origin, entmodel->maxs, r_emaxs);
} }
R_SplitEntityOnNode (cl.worldmodel->nodes); R_SplitEntityOnNode (cl.worldmodel->nodes);

View file

@ -293,22 +293,39 @@ R_CullModelForEntity -- johnfitz -- uses correct bounds based on rotation
*/ */
qboolean R_CullModelForEntity (entity_t *e) qboolean R_CullModelForEntity (entity_t *e)
{ {
vec3_t mins, maxs; vec3_t mins, maxs, minbounds, maxbounds;
vec3_t scaledVec;
vec_t scalefactor;
if (e->angles[0] || e->angles[2]) //pitch or roll if (e->angles[0] || e->angles[2]) //pitch or roll
{ {
VectorAdd (e->origin, e->model->rmins, mins); VectorCopy (e->model->rmins, minbounds);
VectorAdd (e->origin, e->model->rmaxs, maxs); VectorCopy (e->model->rmaxs, maxbounds);
} }
else if (e->angles[1]) //yaw else if (e->angles[1]) //yaw
{ {
VectorAdd (e->origin, e->model->ymins, mins); VectorCopy (e->model->ymins, minbounds);
VectorAdd (e->origin, e->model->ymaxs, maxs); VectorCopy (e->model->ymaxs, maxbounds);
} }
else //no rotation else //no rotation
{ {
VectorAdd (e->origin, e->model->mins, mins); VectorCopy (e->model->mins, minbounds);
VectorAdd (e->origin, e->model->maxs, maxs); VectorCopy (e->model->maxs, maxbounds);
}
scalefactor = ENTSCALE_DECODE(e->scale);
if (scalefactor != 1.0f)
{
VectorScale (minbounds, scalefactor, scaledVec);
VectorAdd (e->origin, scaledVec, mins);
VectorScale (maxbounds, scalefactor, scaledVec);
VectorAdd (e->origin, scaledVec, maxs);
}
else
{
VectorAdd (e->origin, minbounds, mins);
VectorAdd (e->origin, maxbounds, maxs);
} }
return R_CullBox (mins, maxs); return R_CullBox (mins, maxs);

View file

@ -1580,6 +1580,7 @@ static void PF_makestatic (void)
edict_t *ent; edict_t *ent;
int i; int i;
int bits = 0; //johnfitz -- PROTOCOL_FITZQUAKE int bits = 0; //johnfitz -- PROTOCOL_FITZQUAKE
eval_t *val;
ent = G_EDICT(OFS_PARM0); ent = G_EDICT(OFS_PARM0);
@ -1607,6 +1608,15 @@ static void PF_makestatic (void)
bits |= B_LARGEFRAME; bits |= B_LARGEFRAME;
if (ent->alpha != ENTALPHA_DEFAULT) if (ent->alpha != ENTALPHA_DEFAULT)
bits |= B_ALPHA; bits |= B_ALPHA;
val = GetEdictFieldValue(ent, "scale");
if (val)
ent->scale = ENTSCALE_ENCODE(val->_float);
else
ent->scale = ENTSCALE_DEFAULT;
if (ent->scale != ENTSCALE_DEFAULT)
bits |= B_SCALE;
} }
if (bits) if (bits)
@ -1641,6 +1651,9 @@ static void PF_makestatic (void)
MSG_WriteByte (&sv.signon, ent->alpha); MSG_WriteByte (&sv.signon, ent->alpha);
//johnfitz //johnfitz
if (bits & B_SCALE)
MSG_WriteByte (&sv.signon, ent->scale);
// throw the entity away now // throw the entity away now
ED_Free (ent); ED_Free (ent);
} }

View file

@ -47,6 +47,7 @@ typedef struct edict_s
entity_state_t baseline; entity_state_t baseline;
unsigned char alpha; /* johnfitz -- hack to support alpha since it's not part of entvars_t */ unsigned char alpha; /* johnfitz -- hack to support alpha since it's not part of entvars_t */
unsigned char scale;
qboolean sendinterval; /* johnfitz -- send time until nextthink to client for better lerp timing */ qboolean sendinterval; /* johnfitz -- send time until nextthink to client for better lerp timing */
float freetime; /* sv.time when the object was freed */ float freetime; /* sv.time when the object was freed */

View file

@ -125,6 +125,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define B_LARGEMODEL (1<<0) // modelindex is short instead of byte #define B_LARGEMODEL (1<<0) // modelindex is short instead of byte
#define B_LARGEFRAME (1<<1) // frame is short instead of byte #define B_LARGEFRAME (1<<1) // frame is short instead of byte
#define B_ALPHA (1<<2) // 1 byte, uses ENTALPHA_ENCODE, not sent if ENTALPHA_DEFAULT #define B_ALPHA (1<<2) // 1 byte, uses ENTALPHA_ENCODE, not sent if ENTALPHA_DEFAULT
#define B_SCALE (1<<3)
//johnfitz //johnfitz
//johnfitz -- PROTOCOL_FITZQUAKE -- alpha encoding //johnfitz -- PROTOCOL_FITZQUAKE -- alpha encoding
@ -136,6 +137,10 @@ 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 #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 //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 // defaults for clientinfo messages
#define DEFAULT_VIEWHEIGHT 22 #define DEFAULT_VIEWHEIGHT 22
@ -257,6 +262,7 @@ typedef struct
unsigned char colormap; //johnfitz -- was int unsigned char colormap; //johnfitz -- was int
unsigned char skin; //johnfitz -- was int unsigned char skin; //johnfitz -- was int
unsigned char alpha; //johnfitz -- added unsigned char alpha; //johnfitz -- added
unsigned char scale;
int effects; int effects;
} entity_state_t; } entity_state_t;

View file

@ -637,6 +637,7 @@ void R_DrawAliasModel (entity_t *e)
lerpdata_t lerpdata; lerpdata_t lerpdata;
qboolean alphatest = !!(e->model->flags & MF_HOLEY); qboolean alphatest = !!(e->model->flags & MF_HOLEY);
float fovscale = 1.0f; float fovscale = 1.0f;
float scalefactor = 1.0f;
// //
// setup pose/lerp data -- do it first so we don't miss updates due to culling // setup pose/lerp data -- do it first so we don't miss updates due to culling
@ -659,6 +660,11 @@ void R_DrawAliasModel (entity_t *e)
glPushMatrix (); glPushMatrix ();
R_RotateForEntity (lerpdata.origin, lerpdata.angles); R_RotateForEntity (lerpdata.origin, lerpdata.angles);
scalefactor = ENTSCALE_DECODE(e->scale);
if (scalefactor != 1.0f)
{
glScalef (scalefactor, scalefactor, scalefactor);
}
glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1] * fovscale, paliashdr->scale_origin[2] * fovscale); glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1] * fovscale, paliashdr->scale_origin[2] * fovscale);
glScalef (paliashdr->scale[0], paliashdr->scale[1] * fovscale, paliashdr->scale[2] * fovscale); glScalef (paliashdr->scale[0], paliashdr->scale[1] * fovscale, paliashdr->scale[2] * fovscale);
@ -980,6 +986,7 @@ void R_DrawAliasModel_ShowTris (entity_t *e)
{ {
aliashdr_t *paliashdr; aliashdr_t *paliashdr;
lerpdata_t lerpdata; lerpdata_t lerpdata;
float scalefactor;
if (R_CullModelForEntity(e)) if (R_CullModelForEntity(e))
return; return;
@ -990,6 +997,11 @@ void R_DrawAliasModel_ShowTris (entity_t *e)
glPushMatrix (); glPushMatrix ();
R_RotateForEntity (lerpdata.origin,lerpdata.angles); R_RotateForEntity (lerpdata.origin,lerpdata.angles);
scalefactor = ENTSCALE_DECODE(e->scale);
if (scalefactor != 1.0f)
{
glScalef (scalefactor, scalefactor, scalefactor);
}
glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1], paliashdr->scale_origin[2]); glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1], paliashdr->scale_origin[2]);
glScalef (paliashdr->scale[0], paliashdr->scale[1], paliashdr->scale[2]); glScalef (paliashdr->scale[0], paliashdr->scale[1], paliashdr->scale[2]);

View file

@ -79,6 +79,7 @@ typedef struct entity_s
// not split // not split
byte alpha; //johnfitz -- alpha byte alpha; //johnfitz -- alpha
byte scale;
byte lerpflags; //johnfitz -- lerping byte lerpflags; //johnfitz -- lerping
float lerpstart; //johnfitz -- animation lerping float lerpstart; //johnfitz -- animation lerping
float lerptime; //johnfitz -- animation lerping float lerptime; //johnfitz -- animation lerping

View file

@ -603,6 +603,7 @@ void SV_WriteEntitiesToClient (edict_t *clent, sizebuf_t *msg)
vec3_t org; vec3_t org;
float miss; float miss;
edict_t *ent; edict_t *ent;
eval_t *val;
// find the client's PVS // find the client's PVS
VectorAdd (clent->v.origin, clent->v.view_ofs, org); VectorAdd (clent->v.origin, clent->v.view_ofs, org);
@ -640,9 +641,9 @@ void SV_WriteEntitiesToClient (edict_t *clent, sizebuf_t *msg)
// johnfitz -- max size for protocol 15 is 18 bytes, not 16 as originally // johnfitz -- max size for protocol 15 is 18 bytes, not 16 as originally
// assumed here. And, for protocol 85 the max size is actually 24 bytes. // assumed here. And, for protocol 85 the max size is actually 24 bytes.
// For float coords and angles the limit is 39. // For float coords and angles the limit is 40.
// FIXME: Use tighter limit according to protocol flags and send bits. // FIXME: Use tighter limit according to protocol flags and send bits.
if (msg->cursize + 39 > msg->maxsize) if (msg->cursize + 40 > msg->maxsize)
{ {
//johnfitz -- less spammy overflow message //johnfitz -- less spammy overflow message
if (!dev_overflows.packetsize || dev_overflows.packetsize + CONSOLE_RESPAM_TIME < realtime ) if (!dev_overflows.packetsize || dev_overflows.packetsize + CONSOLE_RESPAM_TIME < realtime )
@ -695,7 +696,6 @@ void SV_WriteEntitiesToClient (edict_t *clent, sizebuf_t *msg)
if (pr_alpha_supported) if (pr_alpha_supported)
{ {
// TODO: find a cleaner place to put this code // TODO: find a cleaner place to put this code
eval_t *val;
val = GetEdictFieldValue(ent, "alpha"); val = GetEdictFieldValue(ent, "alpha");
if (val) if (val)
ent->alpha = ENTALPHA_ENCODE(val->_float); ent->alpha = ENTALPHA_ENCODE(val->_float);
@ -706,11 +706,18 @@ void SV_WriteEntitiesToClient (edict_t *clent, sizebuf_t *msg)
continue; continue;
//johnfitz //johnfitz
val = GetEdictFieldValue(ent, "scale");
if (val)
ent->scale = ENTSCALE_ENCODE(val->_float);
else
ent->scale = ENTSCALE_DEFAULT;
//johnfitz -- PROTOCOL_FITZQUAKE //johnfitz -- PROTOCOL_FITZQUAKE
if (sv.protocol != PROTOCOL_NETQUAKE) if (sv.protocol != PROTOCOL_NETQUAKE)
{ {
if (ent->baseline.alpha != ent->alpha) bits |= U_ALPHA; if (ent->baseline.alpha != ent->alpha) bits |= U_ALPHA;
if (ent->baseline.scale != ent->scale) bits |= U_SCALE;
if (bits & U_FRAME && (int)ent->v.frame & 0xFF00) bits |= U_FRAME2; if (bits & U_FRAME && (int)ent->v.frame & 0xFF00) bits |= U_FRAME2;
if (bits & U_MODEL && (int)ent->v.modelindex & 0xFF00) bits |= U_MODEL2; if (bits & U_MODEL && (int)ent->v.modelindex & 0xFF00) bits |= U_MODEL2;
if (ent->sendinterval) bits |= U_LERPFINISH; if (ent->sendinterval) bits |= U_LERPFINISH;
@ -771,6 +778,8 @@ void SV_WriteEntitiesToClient (edict_t *clent, sizebuf_t *msg)
//johnfitz -- PROTOCOL_FITZQUAKE //johnfitz -- PROTOCOL_FITZQUAKE
if (bits & U_ALPHA) if (bits & U_ALPHA)
MSG_WriteByte(msg, ent->alpha); MSG_WriteByte(msg, ent->alpha);
if (bits & U_SCALE)
MSG_WriteByte(msg, ent->scale);
if (bits & U_FRAME2) if (bits & U_FRAME2)
MSG_WriteByte(msg, (int)ent->v.frame >> 8); MSG_WriteByte(msg, (int)ent->v.frame >> 8);
if (bits & U_MODEL2) if (bits & U_MODEL2)
@ -1231,12 +1240,14 @@ void SV_CreateBaseline (void)
svent->baseline.colormap = entnum; svent->baseline.colormap = entnum;
svent->baseline.modelindex = SV_ModelIndex("progs/player.mdl"); svent->baseline.modelindex = SV_ModelIndex("progs/player.mdl");
svent->baseline.alpha = ENTALPHA_DEFAULT; //johnfitz -- alpha support svent->baseline.alpha = ENTALPHA_DEFAULT; //johnfitz -- alpha support
svent->baseline.scale = ENTSCALE_DEFAULT;
} }
else else
{ {
svent->baseline.colormap = 0; svent->baseline.colormap = 0;
svent->baseline.modelindex = SV_ModelIndex(PR_GetString(svent->v.model)); svent->baseline.modelindex = SV_ModelIndex(PR_GetString(svent->v.model));
svent->baseline.alpha = svent->alpha; //johnfitz -- alpha support svent->baseline.alpha = svent->alpha; //johnfitz -- alpha support
svent->baseline.scale = svent->scale;
} }
//johnfitz -- PROTOCOL_FITZQUAKE //johnfitz -- PROTOCOL_FITZQUAKE
@ -1248,6 +1259,7 @@ void SV_CreateBaseline (void)
if (svent->baseline.frame & 0xFF00) if (svent->baseline.frame & 0xFF00)
svent->baseline.frame = 0; svent->baseline.frame = 0;
svent->baseline.alpha = ENTALPHA_DEFAULT; svent->baseline.alpha = ENTALPHA_DEFAULT;
svent->baseline.scale = ENTSCALE_DEFAULT;
} }
else //decide which extra data needs to be sent else //decide which extra data needs to be sent
{ {
@ -1257,6 +1269,8 @@ void SV_CreateBaseline (void)
bits |= B_LARGEFRAME; bits |= B_LARGEFRAME;
if (svent->baseline.alpha != ENTALPHA_DEFAULT) if (svent->baseline.alpha != ENTALPHA_DEFAULT)
bits |= B_ALPHA; bits |= B_ALPHA;
if (svent->baseline.scale != ENTSCALE_DEFAULT)
bits |= B_SCALE;
} }
//johnfitz //johnfitz
@ -1299,6 +1313,9 @@ void SV_CreateBaseline (void)
if (bits & B_ALPHA) if (bits & B_ALPHA)
MSG_WriteByte (&sv.signon, svent->baseline.alpha); MSG_WriteByte (&sv.signon, svent->baseline.alpha);
//johnfitz //johnfitz
if (bits & B_SCALE)
MSG_WriteByte (&sv.signon, svent->baseline.scale);
} }
} }