mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-02-09 23:26:08 +00:00
New Rescale functions
First use in cleanup of K_GetEXP
This commit is contained in:
parent
bc328e5040
commit
092f8a63e6
3 changed files with 101 additions and 12 deletions
20
src/k_kart.c
20
src/k_kart.c
|
|
@ -16063,20 +16063,16 @@ fixed_t K_GetGradingFactorMinMax(player_t *player, boolean max)
|
|||
UINT16 K_GetEXP(player_t *player)
|
||||
{
|
||||
UINT32 numgradingpoints = K_GetNumGradingPoints();
|
||||
UINT16 targetminexp = (MINEXP*player->gradingpointnum/max(1,numgradingpoints)); // about what a last place player should be at this stage of the race
|
||||
UINT16 targetexp = (MAXEXP*player->gradingpointnum/max(1,numgradingpoints)); // about what a 1.0 factor should be at this stage of the race
|
||||
fixed_t targetminexp = (MINEXP*player->gradingpointnum<<FRACBITS) / max(1,numgradingpoints); // about what a last place player should be at this stage of the race
|
||||
fixed_t targetmaxexp = (MAXEXP*player->gradingpointnum<<FRACBITS) / max(1,numgradingpoints); // about what a 1.0 factor should be at this stage of the race
|
||||
fixed_t factormin = K_GetGradingFactorMinMax(player, false);
|
||||
fixed_t factormax = K_GetGradingFactorMinMax(player, true);
|
||||
fixed_t clampedfactor = max(factormin, min(factormax, player->gradingfactor));
|
||||
fixed_t range = factormax - factormin;
|
||||
fixed_t normalizedfactor = FixedDiv(clampedfactor - factormin, range);
|
||||
fixed_t easedexp = Easing_Linear(normalizedfactor, targetminexp, targetexp);
|
||||
// fixed_t easedexp = Easing_Linear(normalizedfactor, MINEXP*FRACUNIT, MAXEXP*FRACUNIT);
|
||||
UINT16 exp = easedexp;
|
||||
// CONS_Printf("Player %s numgradingpoints=%d targetminexp=%d targetexp=%d factormin=%.2f factormax=%.2f clampedfactor=%.2f normalizedfactor=%.2f easedexp=%d\n",
|
||||
// player_names[player - players], numgradingpoints, targetminexp, targetexp, FIXED_TO_FLOAT(factormin), FIXED_TO_FLOAT(factormax),
|
||||
// FIXED_TO_FLOAT(clampedfactor), FIXED_TO_FLOAT(normalizedfactor), easedexp);
|
||||
// UINT16 exp = (player->gradingfactor*100)>>FRACBITS;
|
||||
|
||||
UINT16 exp = FixedRescale(player->gradingfactor, factormin, factormax, Easing_Linear, targetminexp, targetmaxexp)>>FRACBITS;
|
||||
|
||||
// CONS_Printf("Player %s numgradingpoints=%d gradingpoint=%d targetminexp=%d targetmaxexp=%d factor=%.2f factormin=%.2f factormax=%.2f exp=%d\n",
|
||||
// player_names[player - players], numgradingpoints, player->gradingpointnum, targetminexp, targetmaxexp, FIXED_TO_FLOAT(player->gradingfactor), FIXED_TO_FLOAT(factormin), FIXED_TO_FLOAT(factormax), exp);
|
||||
|
||||
return exp;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -430,3 +430,93 @@ const char *easing_funcnames[EASE_MAX] =
|
|||
|
||||
#undef COMMA
|
||||
#undef EASINGFUNC
|
||||
|
||||
// ==================
|
||||
// FEATURE RESCALING
|
||||
// ==================
|
||||
|
||||
/*--------------------------------------------------
|
||||
fixed_t Rescale(fixed_t value, fixed_t inmin, fixed_t inmax, easingfunc_t easing_func, fixed_t outmin, fixed_t outmax)
|
||||
|
||||
Rescales a feature value from [min, max] to [start, end] using
|
||||
a custom easing function pointer.
|
||||
|
||||
Input Arguments:-
|
||||
value - The input value to rescale
|
||||
inmin - Minimum value of the input range
|
||||
inmax - Maximum value of the input range
|
||||
easing_func - Pointer to the easing function to use
|
||||
outmin - Start value of the output range
|
||||
outmax - End value of the output range
|
||||
|
||||
Return:-
|
||||
The rescaled value using the specified easing function.
|
||||
--------------------------------------------------*/
|
||||
fixed_t FixedRescale(fixed_t value, fixed_t inmin, fixed_t inmax, easingfunc_t easing_func, fixed_t outmin, fixed_t outmax)
|
||||
{
|
||||
// Handle edge case where min == max
|
||||
if (inmin == inmax)
|
||||
return outmin;
|
||||
|
||||
// Clamp the input value to the range
|
||||
max(inmin, min(inmax, value));
|
||||
|
||||
// Normalize the value to [0, FRACUNIT] range
|
||||
fixed_t t = FixedDiv(value - inmin, inmax - inmin);
|
||||
|
||||
// Apply the easing function if provided
|
||||
if (easing_func != NULL)
|
||||
{
|
||||
return easing_func(t, outmin, outmax);
|
||||
}
|
||||
|
||||
// Fallback to linear if no function provided
|
||||
return Easing_Linear(t, outmin, outmax);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------
|
||||
INT16 IntRescale(INT16 value, INT16 inmin, INT16 inmax, easingfunc_t easing_func, INT16 outmin, INT16 outmax)
|
||||
|
||||
Rescales a feature value from [min, max] to [start, end] using
|
||||
a custom easing function pointer.
|
||||
Can only take in up to INT16 because it uses fixed_t internally
|
||||
|
||||
Input Arguments:-
|
||||
value - The input value to rescale
|
||||
inmin - Minimum value of the input range
|
||||
inmax - Maximum value of the input range
|
||||
easing_func - Pointer to the easing function to use
|
||||
outmin - Start value of the output range
|
||||
outmax - End value of the output range
|
||||
|
||||
Return:-
|
||||
The rescaled value using the specified easing function.
|
||||
--------------------------------------------------*/
|
||||
INT16 IntRescale(INT16 value, INT16 inmin, INT16 inmax, easingfunc_t easing_func, INT16 outmin, INT16 outmax)
|
||||
{
|
||||
// Handle edge case where min == max
|
||||
if (inmin == inmax)
|
||||
return outmin;
|
||||
|
||||
// Clamp the input value to the range
|
||||
max(inmin, min(inmax, value));
|
||||
|
||||
// Conversion shit
|
||||
value = value<<FRACBITS;
|
||||
inmin = inmin<<FRACBITS;
|
||||
inmax = inmax<<FRACBITS;
|
||||
outmin = outmin<<FRACBITS;
|
||||
outmax = outmax<<FRACBITS;
|
||||
|
||||
// Normalize the value to [0, FRACUNIT] range
|
||||
fixed_t t = FixedDiv(value - inmin, inmax - inmin);
|
||||
|
||||
// Apply the easing function if provided
|
||||
if (easing_func != NULL)
|
||||
{
|
||||
return easing_func(t, outmin, outmax)>>FRACBITS;
|
||||
}
|
||||
|
||||
// Fallback to linear if no function provided
|
||||
return Easing_Linear(t, outmin, outmax)>>FRACBITS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,6 +105,9 @@ EASINGFUNC(InOutBackParameterized) /* Easing_InOutBackParameterized */
|
|||
|
||||
#undef EASINGFUNC
|
||||
|
||||
fixed_t FixedRescale(fixed_t value, fixed_t inmin, fixed_t inmax, easingfunc_t easing_func, fixed_t outmin, fixed_t outmax);
|
||||
INT16 IntRescale(INT16 value, INT16 inmin, INT16 inmax, easingfunc_t easing_func, INT16 outmin, INT16 outmax);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue