Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Shared] fix UI transition/fade effects being framerate dependent #1223

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 36 additions & 34 deletions code/ui/ui_shared.cpp
Expand Up @@ -7788,6 +7788,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
int xPos,textWidth;
vec4_t red;
menuDef_t *parent;
const float tAdjust = DC->frameTime / (1000.0 / UI_TARGET_FPS);
red[0] = red[3] = 1;
red[1] = red[2] = 0;

Expand All @@ -7812,17 +7813,17 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
if (DC->realTime > item->window.nextTime)
{
float rx, ry, a, c, s, w, h;
item->window.nextTime = DC->realTime + item->window.offsetTime;
item->window.nextTime = DC->realTime + (item->window.offsetTime * tAdjust);
Copy link
Member Author

@Razish Razish Mar 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if also adjusting the debouncer is correct since we're adjusting the translation based on the current frametime / 60fps frametime.

// translate
w = item->window.rectClient.w / 2;
h = item->window.rectClient.h / 2;
rx = item->window.rectClient.x + w - item->window.rectEffects.x;
ry = item->window.rectClient.y + h - item->window.rectEffects.y;
rx = item->window.rectClient.x + ((w - item->window.rectEffects.x) * tAdjust);
ry = item->window.rectClient.y + ((h - item->window.rectEffects.y) * tAdjust);
a = (float) (3 * M_PI / 180);
c = cos(a);
s = sin(a);
item->window.rectClient.x = (rx * c - ry * s) + item->window.rectEffects.x - w;
item->window.rectClient.y = (rx * s + ry * c) + item->window.rectEffects.y - h;
item->window.rectClient.x = (rx * c - ry * s) + ((item->window.rectEffects.x - w) * tAdjust);
item->window.rectClient.y = (rx * s + ry * c) + ((item->window.rectEffects.y - h) * tAdjust);
Item_UpdatePosition(item);

}
Expand All @@ -7834,7 +7835,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
if (DC->realTime > item->window.nextTime)
{
int done = 0;
item->window.nextTime = DC->realTime + item->window.offsetTime;
item->window.nextTime = DC->realTime + (item->window.offsetTime * tAdjust);

// transition the x,y
if (item->window.rectClient.x == item->window.rectEffects.x)
Expand All @@ -7845,7 +7846,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
{
if (item->window.rectClient.x < item->window.rectEffects.x)
{
item->window.rectClient.x += item->window.rectEffects2.x;
item->window.rectClient.x += item->window.rectEffects2.x * tAdjust;
if (item->window.rectClient.x > item->window.rectEffects.x)
{
item->window.rectClient.x = item->window.rectEffects.x;
Expand All @@ -7854,7 +7855,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
}
else
{
item->window.rectClient.x -= item->window.rectEffects2.x;
item->window.rectClient.x -= item->window.rectEffects2.x * tAdjust;
if (item->window.rectClient.x < item->window.rectEffects.x)
{
item->window.rectClient.x = item->window.rectEffects.x;
Expand All @@ -7871,7 +7872,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
{
if (item->window.rectClient.y < item->window.rectEffects.y)
{
item->window.rectClient.y += item->window.rectEffects2.y;
item->window.rectClient.y += item->window.rectEffects2.y * tAdjust;
if (item->window.rectClient.y > item->window.rectEffects.y)
{
item->window.rectClient.y = item->window.rectEffects.y;
Expand All @@ -7880,7 +7881,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
}
else
{
item->window.rectClient.y -= item->window.rectEffects2.y;
item->window.rectClient.y -= item->window.rectEffects2.y * tAdjust;
if (item->window.rectClient.y < item->window.rectEffects.y)
{
item->window.rectClient.y = item->window.rectEffects.y;
Expand All @@ -7897,7 +7898,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
{
if (item->window.rectClient.w < item->window.rectEffects.w)
{
item->window.rectClient.w += item->window.rectEffects2.w;
item->window.rectClient.w += item->window.rectEffects2.w * tAdjust;
if (item->window.rectClient.w > item->window.rectEffects.w)
{
item->window.rectClient.w = item->window.rectEffects.w;
Expand All @@ -7906,7 +7907,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
}
else
{
item->window.rectClient.w -= item->window.rectEffects2.w;
item->window.rectClient.w -= item->window.rectEffects2.w * tAdjust;
if (item->window.rectClient.w < item->window.rectEffects.w)
{
item->window.rectClient.w = item->window.rectEffects.w;
Expand All @@ -7923,7 +7924,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
{
if (item->window.rectClient.h < item->window.rectEffects.h)
{
item->window.rectClient.h += item->window.rectEffects2.h;
item->window.rectClient.h += item->window.rectEffects2.h * tAdjust;
if (item->window.rectClient.h > item->window.rectEffects.h)
{
item->window.rectClient.h = item->window.rectEffects.h;
Expand All @@ -7932,7 +7933,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
}
else
{
item->window.rectClient.h -= item->window.rectEffects2.h;
item->window.rectClient.h -= item->window.rectEffects2.h * tAdjust;
if (item->window.rectClient.h < item->window.rectEffects.h)
{
item->window.rectClient.h = item->window.rectEffects.h;
Expand Down Expand Up @@ -7967,7 +7968,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
if (DC->realTime > item->window.nextTime)
{
int done = 0;
item->window.nextTime = DC->realTime + item->window.offsetTime;
item->window.nextTime = DC->realTime + (item->window.offsetTime * tAdjust);


// transition the x,y,z max
Expand All @@ -7979,7 +7980,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
{
if (modelptr->g2maxs[0] < modelptr->g2maxs2[0])
{
modelptr->g2maxs[0] += modelptr->g2maxsEffect[0];
modelptr->g2maxs[0] += modelptr->g2maxsEffect[0] * tAdjust;
if (modelptr->g2maxs[0] > modelptr->g2maxs2[0])
{
modelptr->g2maxs[0] = modelptr->g2maxs2[0];
Expand All @@ -7988,7 +7989,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
}
else
{
modelptr->g2maxs[0] -= modelptr->g2maxsEffect[0];
modelptr->g2maxs[0] -= modelptr->g2maxsEffect[0] * tAdjust;
if (modelptr->g2maxs[0] < modelptr->g2maxs2[0])
{
modelptr->g2maxs[0] = modelptr->g2maxs2[0];
Expand All @@ -8005,7 +8006,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
{
if (modelptr->g2maxs[1] < modelptr->g2maxs2[1])
{
modelptr->g2maxs[1] += modelptr->g2maxsEffect[1];
modelptr->g2maxs[1] += modelptr->g2maxsEffect[1] * tAdjust;
if (modelptr->g2maxs[1] > modelptr->g2maxs2[1])
{
modelptr->g2maxs[1] = modelptr->g2maxs2[1];
Expand All @@ -8014,7 +8015,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
}
else
{
modelptr->g2maxs[1] -= modelptr->g2maxsEffect[1];
modelptr->g2maxs[1] -= modelptr->g2maxsEffect[1] * tAdjust;
if (modelptr->g2maxs[1] < modelptr->g2maxs2[1])
{
modelptr->g2maxs[1] = modelptr->g2maxs2[1];
Expand All @@ -8034,7 +8035,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
{
if (modelptr->g2maxs[2] < modelptr->g2maxs2[2])
{
modelptr->g2maxs[2] += modelptr->g2maxsEffect[2];
modelptr->g2maxs[2] += modelptr->g2maxsEffect[2] * tAdjust;
if (modelptr->g2maxs[2] > modelptr->g2maxs2[2])
{
modelptr->g2maxs[2] = modelptr->g2maxs2[2];
Expand All @@ -8043,7 +8044,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
}
else
{
modelptr->g2maxs[2] -= modelptr->g2maxsEffect[2];
modelptr->g2maxs[2] -= modelptr->g2maxsEffect[2] * tAdjust;
if (modelptr->g2maxs[2] < modelptr->g2maxs2[2])
{
modelptr->g2maxs[2] = modelptr->g2maxs2[2];
Expand All @@ -8061,7 +8062,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
{
if (modelptr->g2mins[0] < modelptr->g2mins2[0])
{
modelptr->g2mins[0] += modelptr->g2minsEffect[0];
modelptr->g2mins[0] += modelptr->g2minsEffect[0] * tAdjust;
if (modelptr->g2mins[0] > modelptr->g2mins2[0])
{
modelptr->g2mins[0] = modelptr->g2mins2[0];
Expand All @@ -8070,7 +8071,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
}
else
{
modelptr->g2mins[0] -= modelptr->g2minsEffect[0];
modelptr->g2mins[0] -= modelptr->g2minsEffect[0] * tAdjust;
if (modelptr->g2mins[0] < modelptr->g2mins2[0])
{
modelptr->g2mins[0] = modelptr->g2mins2[0];
Expand All @@ -8087,7 +8088,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
{
if (modelptr->g2mins[1] < modelptr->g2mins2[1])
{
modelptr->g2mins[1] += modelptr->g2minsEffect[1];
modelptr->g2mins[1] += modelptr->g2minsEffect[1] * tAdjust;
if (modelptr->g2mins[1] > modelptr->g2mins2[1])
{
modelptr->g2mins[1] = modelptr->g2mins2[1];
Expand All @@ -8096,7 +8097,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
}
else
{
modelptr->g2mins[1] -= modelptr->g2minsEffect[1];
modelptr->g2mins[1] -= modelptr->g2minsEffect[1] * tAdjust;
if (modelptr->g2mins[1] < modelptr->g2mins2[1])
{
modelptr->g2mins[1] = modelptr->g2mins2[1];
Expand All @@ -8116,7 +8117,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
{
if (modelptr->g2mins[2] < modelptr->g2mins2[2])
{
modelptr->g2mins[2] += modelptr->g2minsEffect[2];
modelptr->g2mins[2] += modelptr->g2minsEffect[2] * tAdjust;
if (modelptr->g2mins[2] > modelptr->g2mins2[2])
{
modelptr->g2mins[2] = modelptr->g2mins2[2];
Expand All @@ -8125,7 +8126,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
}
else
{
modelptr->g2mins[2] -= modelptr->g2minsEffect[2];
modelptr->g2mins[2] -= modelptr->g2minsEffect[2] * tAdjust;
if (modelptr->g2mins[2] < modelptr->g2mins2[2])
{
modelptr->g2mins[2] = modelptr->g2mins2[2];
Expand All @@ -8145,7 +8146,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
{
if (modelptr->fov_x < modelptr->fov_x2)
{
modelptr->fov_x += modelptr->fov_Effectx;
modelptr->fov_x += modelptr->fov_Effectx * tAdjust;
if (modelptr->fov_x > modelptr->fov_x2)
{
modelptr->fov_x = modelptr->fov_x2;
Expand All @@ -8154,7 +8155,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
}
else
{
modelptr->fov_x -= modelptr->fov_Effectx;
modelptr->fov_x -= modelptr->fov_Effectx * tAdjust;
if (modelptr->fov_x < modelptr->fov_x2)
{
modelptr->fov_x = modelptr->fov_x2;
Expand All @@ -8172,7 +8173,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
{
if (modelptr->fov_y < modelptr->fov_y2)
{
modelptr->fov_y += modelptr->fov_Effecty;
modelptr->fov_y += modelptr->fov_Effecty * tAdjust;
if (modelptr->fov_y > modelptr->fov_y2)
{
modelptr->fov_y = modelptr->fov_y2;
Expand All @@ -8181,7 +8182,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
}
else
{
modelptr->fov_y -= modelptr->fov_Effecty;
modelptr->fov_y -= modelptr->fov_Effecty * tAdjust;
if (modelptr->fov_y < modelptr->fov_y2)
{
modelptr->fov_y = modelptr->fov_y2;
Expand Down Expand Up @@ -8422,18 +8423,19 @@ void Fade(int *flags, float *f, float clamp, int *nextTime, int offsetTime, qboo
{
if (DC->realTime > *nextTime)
{
*nextTime = DC->realTime + offsetTime;
const float tAdjust = DC->frameTime / (1000.0 / UI_TARGET_FPS);
*nextTime = DC->realTime + (offsetTime * tAdjust);
if (*flags & WINDOW_FADINGOUT)
{
*f -= fadeAmount;
*f -= fadeAmount * tAdjust;
if (bFlags && *f <= 0.0)
{
*flags &= ~(WINDOW_FADINGOUT | WINDOW_VISIBLE);
}
}
else
{
*f += fadeAmount;
*f += fadeAmount * tAdjust;
if (*f >= clamp)
{
*f = clamp;
Expand Down
1 change: 1 addition & 0 deletions code/ui/ui_shared.h
Expand Up @@ -30,6 +30,7 @@ enum {
SSF_PNG
};

#define UI_TARGET_FPS 60
#define MAX_TOKENLENGTH 1024
#define MAX_OPEN_MENUS 16
#define MAX_TEXTSCROLL_LINES 256
Expand Down