Skip to content

Commit

Permalink
Add entity scalefactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MotoLegacy committed Dec 29, 2023
1 parent c0326bf commit 23a9dc0
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 77 deletions.
6 changes: 6 additions & 0 deletions source/cl_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,12 @@ void CL_ParseUpdate (int bits)
else
ent->rendercolor[2] = 0;
// Tomaz - QC Alpha Scale Glow End

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

if ( bits & U_NOLERP )//there's no data for nolerp, it is the value itself
ent->forcelink = true;

Expand Down
1 change: 1 addition & 0 deletions source/progdefs.h
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;
} entvars_t;

#define PROGHEADER_CRC 14116
5 changes: 5 additions & 0 deletions source/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define U_EXTEND2 (1<<21) // another byte to follow
#define U_FRAMETIME (1<<22) // another byte to follow
// Tomaz - QC Alpha Scale Glow Control End
#define U_SCALE (1<<23)


#define SU_VIEWHEIGHT (1<<0)
Expand All @@ -76,6 +77,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define SND_ATTENUATION (1<<1) // a byte
#define SND_LOOPING (1<<2) // a long

#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 22
Expand Down
4 changes: 2 additions & 2 deletions source/psp/video_hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ int R_FrustumCheckSphere (vec3_t centre, float radius);
int R_CullBox (vec3_t emins, vec3_t emaxs);
qboolean R_CullSphere (vec3_t centre, float radius);
void R_MarkLights (dlight_t *light, int bit, mnode_t *node);
void R_RotateForEntity (entity_t *e, int shadow);
void R_BlendedRotateForEntity (entity_t *e, int shadow);
void R_RotateForEntity (entity_t *e, int shadow, unsigned char scale);
void R_BlendedRotateForEntity (entity_t *e, int shadow, unsigned char scale);
void R_RotateForViewEntity (entity_t *ent); //clone (R_RotateForEntity)
void R_RotateForTagEntity (tagentity_t *tagent, md3tag_t *tag, float *m); //for q3 models
void R_StoreEfrags (efrag_t **ppefrag);
Expand Down
2 changes: 1 addition & 1 deletion source/psp/video_hardware_hlmdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ void R_DrawHLModel(entity_t *curent)
shadevector[2] = 1;
VectorNormalize (shadevector);

R_BlendedRotateForEntity(curent, 0);
R_BlendedRotateForEntity(curent, 0, curent->scale);

HL_SetupBones(&model); /* Setup the bones */
SetupLighting(&model); /* Setup the light */
Expand Down
116 changes: 43 additions & 73 deletions source/psp/video_hardware_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,22 +406,14 @@ qboolean R_CullSphere (vec3_t centre, float radius)
R_RotateForEntity
=============
*/
void R_RotateForEntity (entity_t *e, int shadow)
void R_RotateForEntity (entity_t *e, int shadow, unsigned char scale)
{
// Translate.
const ScePspFVector3 translation =
{
e->origin[0], e->origin[1], e->origin[2]
};
sceGumTranslate(&translation);
/*
// Scale.
const ScePspFVector3 scale =
{
e->scale, e->scale, e->scale
};
sceGumScale(&scale);
*/

// Rotate.
sceGumRotateZ(e->angles[YAW] * (GU_PI / 180.0f));
Expand All @@ -431,6 +423,16 @@ void R_RotateForEntity (entity_t *e, int shadow)
sceGumRotateX (e->angles[ROLL] * (GU_PI / 180.0f));
}

// Scale.
if (scale != ENTSCALE_DEFAULT) {
float scalefactor = ENTSCALE_DECODE(scale);
const ScePspFVector3 scale =
{
scalefactor, scalefactor, scalefactor
};
sceGumScale(&scale);
}

sceGumUpdateMatrix();
}

Expand Down Expand Up @@ -465,46 +467,6 @@ void R_InterpolateEntity(entity_t *e, int shadow) // Tomaz - New Shadow
//if I get this method to work well, make sure we go back and check for r_i_model_transforms again, (because vmodel and other models that don't use interpolation)
//probably go back and edit animations too as I redo the last 2 textures..


/*if (e->translate_start_time == 0 || timepassed > 1)
{
e->translate_start_time = realtime;
VectorCopy (e->origin, e->origin1);
VectorCopy (e->origin, e->origin2);
}
//our origin has been updated
if (!VectorCompare (e->origin, e->origin2))
{
e->translate_start_time = realtime;
VectorCopy (e->origin2, e->origin1);
VectorCopy (e->origin, e->origin2);
blend = 0;
}
else
{
blend = 1;
if (cl.paused)
blend = 0;
e->origin1[0] += (blend * 0.25 * (e->origin2[0] - e->origin1[0]));
e->origin1[1] += (blend * 0.25 * (e->origin2[1] - e->origin1[1]));
e->origin1[2] += (blend * 0.25 * (e->origin2[2] - e->origin1[2]));
}
//VectorSubtract (e->origin2, e->origin1, deltaVec);
// Translate.
const ScePspFVector3 translation =
{*/
/*e->origin[0] + (blend * deltaVec[0]),
e->origin[1] + (blend * deltaVec[1]),
e->origin[2] + (blend * deltaVec[2])*/
/*
e->origin1[0], e->origin1[1], e->origin1[2]
};
*/

if (e->translate_start_time == 0 || timepassed > 1)
{
e->translate_start_time = realtime;
Expand Down Expand Up @@ -538,7 +500,7 @@ void R_InterpolateEntity(entity_t *e, int shadow) // Tomaz - New Shadow
e->origin[2] + (blend * deltaVec[2])
};
sceGumTranslate(&translation);


// orientation interpolation (Euler angles, yuck!)
timepassed = realtime - e->rotate_start_time;
Expand Down Expand Up @@ -599,7 +561,7 @@ R_BlendedRotateForEntity
fenix@io.com: model transform interpolation
=============
*/
void R_BlendedRotateForEntity (entity_t *e, int shadow) // Tomaz - New Shadow
void R_BlendedRotateForEntity (entity_t *e, int shadow, unsigned char scale) // Tomaz - New Shadow
{
float timepassed;
float blend;
Expand Down Expand Up @@ -640,15 +602,17 @@ void R_BlendedRotateForEntity (entity_t *e, int shadow) // Tomaz - New Shadow
e->origin[2] + (blend * d[2])
};
sceGumTranslate(&translation);
/*
// Scale.
const ScePspFVector3 scale = {
e->scale + (blend * d[0]),
e->scale + (blend * d[1]),
e->scale + (blend * d[2]
};
sceGumScale(&scale);
*/

// Scale.
if (scale != ENTSCALE_DEFAULT) {
float scalefactor = ENTSCALE_DECODE(scale);
const ScePspFVector3 scale =
{
scalefactor, scalefactor, scalefactor
};
sceGumScale(&scale);
}

// orientation interpolation (Euler angles, yuck!)
timepassed = realtime - e->rotate_start_time;

Expand Down Expand Up @@ -774,6 +738,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;
bool additive = false;
bool filter = false;

Expand Down Expand Up @@ -867,35 +833,35 @@ void R_DrawSpriteModel (entity_t *e)
glvert_t* const vertices =
static_cast<glvert_t*>(sceGuGetMemory(sizeof(glvert_t) * 4));

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);

vertices[0].st[0] = 0.0f;
vertices[0].st[1] = 1.0f;
vertices[0].xyz[0] = point[0];
vertices[0].xyz[1] = point[1];
vertices[0].xyz[2] = point[2];

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);

vertices[1].st[0] = 0.0f;
vertices[1].st[1] = 0.0f;
vertices[1].xyz[0] = point[0];
vertices[1].xyz[1] = point[1];
vertices[1].xyz[2] = point[2];

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);

vertices[2].st[0] = 1.0f;
vertices[2].st[1] = 0.0f;
vertices[2].xyz[0] = point[0];
vertices[2].xyz[1] = point[1];
vertices[2].xyz[2] = point[2];

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);

vertices[3].st[0] = 1.0f;
vertices[3].st[1] = 1.0f;
Expand Down Expand Up @@ -1563,7 +1529,7 @@ void R_SetupQ2AliasFrame (entity_t *e, md2_t *pheader)
frame = e->frame;

sceGumPushMatrix ();
R_RotateForEntity (e, 0);
R_RotateForEntity (e, 0, e->scale);

if ((frame >= pheader->num_frames) || (frame < 0))
{
Expand Down Expand Up @@ -1992,6 +1958,7 @@ 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);

const ScePspFVector3 translation = {
paliashdr->scale_origin[0] * scale, paliashdr->scale_origin[1], paliashdr->scale_origin[2]
Expand All @@ -2003,11 +1970,14 @@ void R_DrawAliasModel (entity_t *e)
sceGumTranslate(&translation);
sceGumScale(&scaling);
} else {
float scale = 128.0f;
if (e->scale != ENTSCALE_DEFAULT && e->scale != 0) scale *= ENTSCALE_DECODE(e->scale);

const ScePspFVector3 translation = {
paliashdr->scale_origin[0], paliashdr->scale_origin[1], paliashdr->scale_origin[2]
};
const ScePspFVector3 scaling = {
paliashdr->scale[0] * 128.f, paliashdr->scale[1] * 128.f, paliashdr->scale[2] * 128.f
paliashdr->scale[0] * scale, paliashdr->scale[1] * scale, paliashdr->scale[2] * scale
};

sceGumTranslate(&translation);
Expand Down Expand Up @@ -2962,7 +2932,7 @@ void R_DrawQ3Model (entity_t *ent)
if (ent == &cl.viewent)
R_RotateForViewEntity (ent);
else
R_RotateForEntity(ent, 0);
R_RotateForEntity(ent, 0, ent->scale);

if ((ent == &cl.viewent) && (scr_fov.value != 0))
{
Expand Down Expand Up @@ -3044,7 +3014,7 @@ void R_DrawQ3Model (entity_t *ent)

sceGumPushMatrix ();

R_RotateForEntity (ent, 0);
R_RotateForEntity (ent, 0, ent->scale);

VectorCopy (ent->origin, downmove);
downmove[2] -= farclip;
Expand Down Expand Up @@ -3125,7 +3095,7 @@ void R_DrawNullModel(void)
sceGuDisable(GU_TEXTURE_2D);
sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGBA);
sceGuShadeModel (GU_SMOOTH);
R_RotateForEntity(currententity, 0);
R_RotateForEntity(currententity, 0, currententity->scale);
typedef struct VERT_t
{
float x, y, z;
Expand Down
2 changes: 1 addition & 1 deletion source/psp/video_hardware_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ void R_DrawBrushModel (entity_t *e)


e->angles[0] = -e->angles[0]; // stupid quake bug
R_BlendedRotateForEntity (e, 0); //blend transform
R_BlendedRotateForEntity (e, 0, e->scale); //blend transform
clipping::begin_brush_model();
e->angles[0] = -e->angles[0]; // stupid quake bug

Expand Down
1 change: 1 addition & 0 deletions source/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef struct entity_s
float rendercolor[3];
//Crow_bar

unsigned char scale;
struct model_s *model; // NULL = no model
char old_model[128]; // NULL = no model
struct efrag_s *efrag; // linked list of efrags
Expand Down
7 changes: 7 additions & 0 deletions source/sv_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ void SV_WriteEntitiesToClient (edict_t *clent, sizebuf_t *msg, qboolean nomap)

if (ent->baseline.modelindex != ent->v.modelindex)
bits |= U_MODEL;

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

// Tomaz - QC Alpha Scale Glow Begin

{
Expand Down Expand Up @@ -627,6 +631,9 @@ void SV_WriteEntitiesToClient (edict_t *clent, sizebuf_t *msg, qboolean nomap)
if (bits & U_RENDERCOLOR3)
MSG_WriteFloat(msg, rendercolor[2]);
// Tomaz - QC Alpha Scale Glow End

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

Expand Down

0 comments on commit 23a9dc0

Please sign in to comment.