Commit ad8def49 authored by Richard Gobeille's avatar Richard Gobeille
Browse files

Duke3d: animate menus independently from totalclock

Fixes #83
parent 1bc4006f
......@@ -24,6 +24,7 @@ uint64_t timerGetPerformanceCounter(void);
uint64_t timerGetPerformanceFrequency(void);
double timerGetHiTicks(void);
uint32_t timerGetTicks(void);
uint32_t timer120(void);
void (*timerSetCallback(void (*callback)(void)))(void);
......
......@@ -113,6 +113,7 @@ template<typename T> T timerGetTicks(T freq)
return ts.tv_sec * freq + (T)((uint64_t)ts.tv_nsec * freq / (T)1000000000);
}
uint32_t timer120(void) { return timerGetTicks<uint32_t>(120); }
uint32_t timerGetTicks(void) { return timerGetTicks<uint32_t>(1000); }
double timerGetHiTicks(void) { return timerGetTicks<double>(1000.0); }
......
......@@ -153,7 +153,7 @@ static void Menu_DrawTopBarCaption(const char *caption, const vec2_t origin)
static FORCE_INLINE int32_t Menu_CursorShade(void)
{
return VM_OnEventWithReturn(EVENT_MENUCURSORSHADE, -1, myconnectindex, 4-(sintable[((int32_t) totalclock<<4)&2047]>>11));
return VM_OnEventWithReturn(EVENT_MENUCURSORSHADE, -1, myconnectindex, 4-(sintable[(timer120()<<4)&2047]>>11));
}
static void Menu_DrawCursorCommon(int32_t x, int32_t y, int32_t z, int32_t picnum, int32_t ydim_upper = 0, int32_t ydim_lower = ydim-1)
{
......@@ -162,12 +162,12 @@ static void Menu_DrawCursorCommon(int32_t x, int32_t y, int32_t z, int32_t picnu
static void Menu_DrawCursorLeft(int32_t x, int32_t y, int32_t z)
{
if (FURY) return;
Menu_DrawCursorCommon(x, y, z, VM_OnEventWithReturn(EVENT_MENUCURSORLEFT, -1, myconnectindex, SPINNINGNUKEICON+(((int32_t) totalclock>>3)%7)));
Menu_DrawCursorCommon(x, y, z, VM_OnEventWithReturn(EVENT_MENUCURSORLEFT, -1, myconnectindex, SPINNINGNUKEICON+((timer120()>>3)%7)));
}
static void Menu_DrawCursorRight(int32_t x, int32_t y, int32_t z)
{
if (FURY) return;
Menu_DrawCursorCommon(x, y, z, VM_OnEventWithReturn(EVENT_MENUCURSORRIGHT, -1, myconnectindex, SPINNINGNUKEICON+6-((6+((int32_t) totalclock>>3))%7)));
Menu_DrawCursorCommon(x, y, z, VM_OnEventWithReturn(EVENT_MENUCURSORRIGHT, -1, myconnectindex, SPINNINGNUKEICON+6-((6+(timer120()>>3))%7)));
}
static void Menu_DrawCursorTextTile(int32_t x, int32_t y, int32_t h, int32_t picnum, vec2_16_t const & siz, int32_t ydim_upper = 0, int32_t ydim_lower = ydim-1)
{
......@@ -184,7 +184,7 @@ static void Menu_DrawCursorText(int32_t x, int32_t y, int32_t h, int32_t ydim_up
return;
}
Menu_DrawCursorTextTile(x, y, h, SPINNINGNUKEICON+(((int32_t) totalclock>>3)%7), siz, ydim_upper, ydim_lower);
Menu_DrawCursorTextTile(x, y, h, SPINNINGNUKEICON+((timer120()>>3)%7), siz, ydim_upper, ydim_lower);
}
......@@ -2538,12 +2538,12 @@ static void Menu_PreDraw(MenuID_t cm, MenuEntry_t *entry, const vec2_t origin)
{
rotatesprite_fs(origin.x + (MENU_MARGIN_CENTER<<16), origin.y + ((28+l)<<16), 65536L,0,INGAMEDUKETHREEDEE,0,0,10);
if (PLUTOPAK) // JBF 20030804
rotatesprite_fs(origin.x + ((MENU_MARGIN_CENTER+100)<<16), origin.y + (36<<16), 65536L,0,PLUTOPAKSPRITE+2,(sintable[((int32_t) totalclock<<4)&2047]>>11),0,2+8);
rotatesprite_fs(origin.x + ((MENU_MARGIN_CENTER+100)<<16), origin.y + (36<<16), 65536L,0,PLUTOPAKSPRITE+2,(sintable[(timer120()<<4)&2047]>>11),0,2+8);
}
break;
case MENU_PLAYER:
rotatesprite_fs(origin.x + (260<<16), origin.y + ((24+(tilesiz[APLAYER].y>>1))<<16), 49152L,0,1441-((((4-((int32_t) totalclock>>4)))&3)*5),0,entry == &ME_PLAYER_TEAM ? G_GetTeamPalette(ud.team) : ud.color,10);
rotatesprite_fs(origin.x + (260<<16), origin.y + ((24+(tilesiz[APLAYER].y>>1))<<16), 49152L,0,1441-((((4-(timer120()>>4)))&3)*5),0,entry == &ME_PLAYER_TEAM ? G_GetTeamPalette(ud.team) : ud.color,10);
break;
case MENU_MACROS:
......@@ -4377,19 +4377,19 @@ MenuAnimation_t m_animation;
int32_t Menu_Anim_SinOutRight(MenuAnimation_t *animdata)
{
return sintable[divscale10((int32_t) totalclock - animdata->start, animdata->length) + 512] - 16384;
return sintable[divscale10(timer120() - animdata->start, animdata->length) + 512] - 16384;
}
int32_t Menu_Anim_SinInRight(MenuAnimation_t *animdata)
{
return sintable[divscale10((int32_t) totalclock - animdata->start, animdata->length) + 512] + 16384;
return sintable[divscale10(timer120() - animdata->start, animdata->length) + 512] + 16384;
}
int32_t Menu_Anim_SinOutLeft(MenuAnimation_t *animdata)
{
return -sintable[divscale10((int32_t) totalclock - animdata->start, animdata->length) + 512] + 16384;
return -sintable[divscale10(timer120() - animdata->start, animdata->length) + 512] + 16384;
}
int32_t Menu_Anim_SinInLeft(MenuAnimation_t *animdata)
{
return -sintable[divscale10((int32_t) totalclock - animdata->start, animdata->length) + 512] - 16384;
return -sintable[divscale10(timer120() - animdata->start, animdata->length) + 512] - 16384;
}
void Menu_AnimateChange(int32_t cm, MenuAnimationType_t animtype)
......@@ -4412,7 +4412,7 @@ void Menu_AnimateChange(int32_t cm, MenuAnimationType_t animtype)
{
m_animation.out = Menu_Anim_SinOutRight;
m_animation.in = Menu_Anim_SinInRight;
m_animation.start = (int32_t) totalclock;
m_animation.start = timer120();
m_animation.length = 30;
m_animation.previous = previousMenu;
......@@ -4429,7 +4429,7 @@ void Menu_AnimateChange(int32_t cm, MenuAnimationType_t animtype)
{
m_animation.out = Menu_Anim_SinOutLeft;
m_animation.in = Menu_Anim_SinInLeft;
m_animation.start = (int32_t) totalclock;
m_animation.start = timer120();
m_animation.length = 30;
m_animation.previous = previousMenu;
......@@ -4984,7 +4984,7 @@ enum MenuTextFlags_t
static void Menu_GetFmt(const MenuFont_t *font, uint8_t const status, int32_t *s, int32_t *z)
{
if (status & MT_Selected)
*s = VM_OnEventWithReturn(EVENT_MENUSHADESELECTED, -1, myconnectindex, sintable[((int32_t) totalclock<<5)&2047]>>12);
*s = VM_OnEventWithReturn(EVENT_MENUSHADESELECTED, -1, myconnectindex, sintable[(timer120()<<5)&2047]>>12);
else
*s = font->shade_deselected;
// sum shade values
......@@ -5963,7 +5963,7 @@ static void Menu_Run_MouseReturn(Menu_t *cm, const vec2_t origin)
uint32_t const posx = tilesiz[SELECTDIR].y * SELECTDIR_z;
rotatesprite_(origin.x + posx, 0, SELECTDIR_z, 512, SELECTDIR,
Menu_RunInput_MouseReturn_status ? 4 - (sintable[((int32_t) totalclock << 4) & 2047] >> 11) : 6, 0,
Menu_RunInput_MouseReturn_status ? 4 - (sintable[(timer120() << 4) & 2047] >> 11) : 6, 0,
2 | 8 | 16 | RS_ALIGN_L, MOUSEALPHA, 0, xdim_from_320_16(origin.x + x_widescreen_left()), 0,
xdim_from_320_16(origin.x + x_widescreen_left() + ((posx>>17)<<16)), ydim - 1);
}
......@@ -7452,7 +7452,7 @@ void M_DisplayMenus(void)
}
// Determine animation values.
if (totalclock < m_animation.start + m_animation.length)
if (timer120() < m_animation.start + m_animation.length)
{
const int32_t screenwidth = scale(240<<16, xdim, ydim);
......@@ -7494,7 +7494,7 @@ void M_DisplayMenus(void)
videoFadeToBlack(1);
// Display the menu, with a transition animation if applicable.
if (totalclock < m_animation.start + m_animation.length)
if (timer120() < m_animation.start + m_animation.length)
{
Menu_Run(m_animation.previous, previousOrigin);
Menu_Run(m_animation.current, origin);
......@@ -7520,7 +7520,7 @@ void M_DisplayMenus(void)
VM_OnEventWithReturn(EVENT_DISPLAYINACTIVEMENUREST, g_player[screenpeek].ps->i, screenpeek, m_parentMenu->menuID);
}
if (totalclock < m_animation.start + m_animation.length)
if (timer120() < m_animation.start + m_animation.length)
{
ud.returnvar[0] = previousOrigin.x;
ud.returnvar[1] = previousOrigin.y;
......@@ -7557,7 +7557,7 @@ void M_DisplayMenus(void)
if (MOUSEACTIVECONDITIONAL(mouseAdvanceClickState()) || m_mousepos.x != m_prevmousepos.x || m_mousepos.y != m_prevmousepos.y)
{
m_prevmousepos = m_mousepos;
m_mouselastactivity = (int32_t) totalclock;
m_mouselastactivity = timer120();
}
#if !defined EDUKE32_TOUCH_DEVICES
else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment