Eliminate quantisation errors from the button rotation rate.
Added a realTimeAverage() function which returns an integer which is correct on average. Fixes ticket:3082.master
parent
b7f812e423
commit
6e00044711
|
@ -143,22 +143,6 @@ extern void getTimeComponents(UDWORD time, UDWORD *hours, UDWORD *minutes, UDWOR
|
|||
extern float graphicsTimeFraction; ///< Private performance calculation. Do not use.
|
||||
extern float realTimeFraction; ///< Private performance calculation. Do not use.
|
||||
|
||||
/// Returns the value times deltaGameTime, converted to seconds. The return value is rounded down.
|
||||
static inline int32_t gameTimeAdjustedIncrement(int value)
|
||||
{
|
||||
return value * (int)deltaGameTime / GAME_TICKS_PER_SEC;
|
||||
}
|
||||
/// Returns the value times deltaGraphicsTime, converted to seconds.
|
||||
static inline float graphicsTimeAdjustedIncrement(float value)
|
||||
{
|
||||
return value * graphicsTimeFraction;
|
||||
}
|
||||
/// Returns the value times deltaGraphicsTime, converted to seconds.
|
||||
static inline float realTimeAdjustedIncrement(float value)
|
||||
{
|
||||
return value * realTimeFraction;
|
||||
}
|
||||
|
||||
/// Returns numerator/denominator * (newTime - oldTime). Rounds up or down such that the average return value is right, if oldTime is always the previous newTime.
|
||||
static inline WZ_DECL_CONST int quantiseFraction(int numerator, int denominator, int newTime, int oldTime)
|
||||
{
|
||||
|
@ -173,6 +157,29 @@ static inline WZ_DECL_CONST Vector3i quantiseFraction(Vector3i numerator, int de
|
|||
quantiseFraction(numerator.y, denominator, newTime, oldTime),
|
||||
quantiseFraction(numerator.z, denominator, newTime, oldTime));
|
||||
}
|
||||
|
||||
/// Returns the value times deltaGameTime, converted to seconds. The return value is rounded down.
|
||||
static inline int32_t gameTimeAdjustedIncrement(int value)
|
||||
{
|
||||
return value * (int)deltaGameTime / GAME_TICKS_PER_SEC;
|
||||
}
|
||||
/// Returns the value times deltaGraphicsTime, converted to seconds.
|
||||
static inline float graphicsTimeAdjustedIncrement(float value)
|
||||
{
|
||||
return value * graphicsTimeFraction;
|
||||
}
|
||||
|
||||
/// Returns the value times deltaGraphicsTime, converted to seconds, as a float.
|
||||
static inline float realTimeAdjustedIncrement(float value)
|
||||
{
|
||||
return value * realTimeFraction;
|
||||
}
|
||||
/// Returns the value times deltaRealTime, converted to seconds. The return value is rounded up or down to the nearest integer, such that it is exactly right on average.
|
||||
static inline int32_t realTimeAdjustedAverage(int value)
|
||||
{
|
||||
return quantiseFraction(value, GAME_TICKS_PER_SEC, realTime + deltaRealTime, realTime);
|
||||
}
|
||||
|
||||
/// Returns the value times deltaGameTime, converted to seconds. The return value is rounded up or down, such that it is exactly right on average.
|
||||
static inline int32_t gameTimeAdjustedAverage(int value)
|
||||
{
|
||||
|
|
|
@ -4365,7 +4365,7 @@ static void intDisplayStatForm(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset,
|
|||
/* inc rotation if highlighted */
|
||||
if ( Form->state & WCLICK_HILITE )
|
||||
{
|
||||
iRY += realTimeAdjustedIncrement(BUTTONOBJ_ROTSPEED);
|
||||
iRY += realTimeAdjustedAverage(BUTTONOBJ_ROTSPEED);
|
||||
iRY %= 360;
|
||||
}
|
||||
|
||||
|
@ -4401,7 +4401,7 @@ static void intDisplayViewForm(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset,
|
|||
Rotation.z = 0;
|
||||
|
||||
/* inc rotation */
|
||||
iRY += realTimeAdjustedIncrement(BUTTONOBJ_ROTSPEED);
|
||||
iRY += realTimeAdjustedAverage(BUTTONOBJ_ROTSPEED);
|
||||
iRY %= 360;
|
||||
|
||||
//fixed depth scale the pie
|
||||
|
|
|
@ -692,7 +692,7 @@ void intDisplayStatusButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ
|
|||
Hilight = Form->state & WCLICK_HILITE;
|
||||
|
||||
if(Hilight) {
|
||||
Buffer->ImdRotation += realTimeAdjustedIncrement(BUTTONOBJ_ROTSPEED);
|
||||
Buffer->ImdRotation += realTimeAdjustedAverage(BUTTONOBJ_ROTSPEED);
|
||||
}
|
||||
|
||||
Hilight = formIsHilite(Form); // Hilited or flashing.
|
||||
|
@ -895,7 +895,7 @@ void intDisplayObjectButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ
|
|||
Hilight = Form->state & WCLICK_HILITE;
|
||||
|
||||
if(Hilight) {
|
||||
Buffer->ImdRotation += realTimeAdjustedIncrement(BUTTONOBJ_ROTSPEED);
|
||||
Buffer->ImdRotation += realTimeAdjustedAverage(BUTTONOBJ_ROTSPEED);
|
||||
}
|
||||
|
||||
Hilight = formIsHilite(Form); // Hilited or flashing.
|
||||
|
@ -976,7 +976,7 @@ void intDisplayStatsButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ_
|
|||
Hilight = Form->state & WCLICK_HILITE;
|
||||
|
||||
if(Hilight) {
|
||||
Buffer->ImdRotation += realTimeAdjustedIncrement(BUTTONOBJ_ROTSPEED);
|
||||
Buffer->ImdRotation += realTimeAdjustedAverage(BUTTONOBJ_ROTSPEED);
|
||||
}
|
||||
|
||||
Hilight = formIsHilite(Form);
|
||||
|
@ -3005,7 +3005,7 @@ void intDisplayTransportButton(WIDGET *psWidget, UDWORD xOffset,
|
|||
|
||||
if(Hilight)
|
||||
{
|
||||
Buffer->ImdRotation += realTimeAdjustedIncrement(BUTTONOBJ_ROTSPEED);
|
||||
Buffer->ImdRotation += realTimeAdjustedAverage(BUTTONOBJ_ROTSPEED);
|
||||
}
|
||||
|
||||
Hilight = formIsHilite(Form);
|
||||
|
|
Loading…
Reference in New Issue