Coalesce duplicate fade-out codepaths

This commit is contained in:
Aaron Culliney 2016-01-02 14:23:09 -08:00
parent 8b3f288018
commit 691dbd5ac2
5 changed files with 57 additions and 79 deletions

View File

@ -308,3 +308,24 @@ void glhud_quadModelToScreen(const GLModel *model, const int screenW, const int
screenCoords[3] = yFlip1;
}
float glhud_getTimedVisibility(struct timespec timingBegin, float minAlpha, float maxAlpha) {
struct timespec now = { 0 };
struct timespec deltat = { 0 };
clock_gettime(CLOCK_MONOTONIC, &now);
float alpha = minAlpha;
deltat = timespec_diff(timingBegin, now, NULL);
if (deltat.tv_sec == 0) {
alpha = maxAlpha;
if (deltat.tv_nsec >= NANOSECONDS_PER_SECOND/2) {
alpha -= ((float)deltat.tv_nsec-(NANOSECONDS_PER_SECOND/2)) / (float)(NANOSECONDS_PER_SECOND/2);
if (alpha < 0) {
alpha = 0;
}
}
}
return alpha;
}

View File

@ -32,6 +32,8 @@
bool blackIsTransparent; \
bool opaquePixelHalo; \
\
struct timespec timingBegin; \
\
__VA_ARGS__ \
)
@ -58,4 +60,7 @@ void glhud_screenToModel(const float x, const float y, const int screenW, const
// orthographic translation of model coordinates to screen coordinates
void glhud_quadModelToScreen(const GLModel *model, const int screenW, const int screenH, float screenCoords[4]);
// helper method to sync timing of fade out
float glhud_getTimedVisibility(struct timespec timingBegin, float minAlpha, float maxAlpha);
#endif

View File

@ -74,27 +74,6 @@ static struct {
// ----------------------------------------------------------------------------
#warning FIXME TODO ... this can become a common helper function ...
static inline float _get_component_visibility(struct timespec timingBegin) {
struct timespec now = { 0 };
struct timespec deltat = { 0 };
clock_gettime(CLOCK_MONOTONIC, &now);
float alpha = joyglobals.minAlpha;
deltat = timespec_diff(timingBegin, now, NULL);
if (deltat.tv_sec == 0) {
alpha = 1.0;
if (deltat.tv_nsec >= NANOSECONDS_PER_SECOND/2) {
alpha -= ((float)deltat.tv_nsec-(NANOSECONDS_PER_SECOND/2)) / (float)(NANOSECONDS_PER_SECOND/2);
if (alpha < joyglobals.minAlpha) {
alpha = joyglobals.minAlpha;
}
}
}
return alpha;
}
static void _setup_axis_object(GLModel *parent) {
if (UNLIKELY(!parent)) {
LOG("gltouchjoy WARN : cannot setup axis object without parent");
@ -308,7 +287,10 @@ static void gltouchjoy_render(void) {
// draw axis
float alpha = _get_component_visibility(axes.timingBegin);
float alpha = glhud_getTimedVisibility(axes.timingBegin, joyglobals.minAlpha, 1.0);
if (alpha < joyglobals.minAlpha) {
alpha = joyglobals.minAlpha;
}
if (alpha > 0.0) {
glUniform1f(alphaValue, alpha);
@ -330,7 +312,10 @@ static void gltouchjoy_render(void) {
// draw button(s)
alpha = _get_component_visibility(buttons.timingBegin);
alpha = glhud_getTimedVisibility(buttons.timingBegin, joyglobals.minAlpha, 1.0);
if (alpha < joyglobals.minAlpha) {
alpha = joyglobals.minAlpha;
}
if (alpha > 0.0) {
glUniform1f(alphaValue, alpha);

View File

@ -237,30 +237,6 @@ static inline void _switch_keyboard(GLModel *parent, uint8_t *template) {
}
}
#warning FIXME TODO ... this can become a common helper function ...
static inline float _get_keyboard_visibility(void) {
struct timespec now = { 0 };
struct timespec deltat = { 0 };
clock_gettime(CLOCK_MONOTONIC, &now);
float alpha = minAlpha;
deltat = timespec_diff(kbd.timingBegin, now, NULL);
if (deltat.tv_sec == 0) {
alpha = maxAlpha;
if (deltat.tv_nsec >= NANOSECONDS_PER_SECOND/2) {
alpha -= ((float)deltat.tv_nsec-(NANOSECONDS_PER_SECOND/2)) / (float)(NANOSECONDS_PER_SECOND/2);
if (alpha < minAlpha) {
alpha = minAlpha;
_rerender_selected(kbd.selectedCol, kbd.selectedRow);
kbd.selectedCol = -1;
kbd.selectedRow = -1;
}
}
}
return alpha;
}
static inline bool _is_point_on_keyboard(float x, float y) {
return (x >= touchport.kbdX && x <= touchport.kbdXMax && y >= touchport.kbdY && y <= touchport.kbdYMax);
}
@ -560,7 +536,13 @@ static void gltouchkbd_render(void) {
gltouchkbd_setup();
}
float alpha = _get_keyboard_visibility();
float alpha = glhud_getTimedVisibility(kbd.timingBegin, minAlpha, maxAlpha);
if (alpha < minAlpha) {
alpha = minAlpha;
_rerender_selected(kbd.selectedCol, kbd.selectedRow);
kbd.selectedCol = -1;
kbd.selectedRow = -1;
}
if (alpha > 0.0) {
// draw touch keyboard

View File

@ -35,8 +35,6 @@ HUD_CLASS(GLModelHUDMenu,
static bool isAvailable = false; // Were there any OpenGL/memory errors on initialization?
static bool isEnabled = true; // Does player want this enabled?
static float minAlpha = 1/4.f; // Minimum alpha value of components (at zero, will not render)
static float maxAlpha = 1.f;
// NOTE : intent is to match touch keyboard width
static uint8_t topMenuTemplate[MENU_TEMPLATE_ROWS][MENU_TEMPLATE_COLS+1] = {
@ -76,12 +74,14 @@ static struct {
bool topLeftShowing;
bool topRightShowing;
struct timespec timingBegin;
float minAlpha; // Minimum alpha value of components (at zero, will not render)
float maxAlpha;
// pending changes requiring reinitialization
unsigned int nextGlyphMultiplier;
} menu = { 0 };
static struct timespec timingBegin = { 0 };
// ----------------------------------------------------------------------------
static inline void _present_menu(GLModel *parent) {
@ -145,26 +145,6 @@ static inline void _hide_top_right(void) {
_present_menu(menu.model);
}
static float _get_menu_visibility(void) {
struct timespec now = { 0 };
struct timespec deltat = { 0 };
float alpha = minAlpha;
clock_gettime(CLOCK_MONOTONIC, &now);
deltat = timespec_diff(timingBegin, now, NULL);
if (deltat.tv_sec == 0) {
alpha = maxAlpha;
if (deltat.tv_nsec >= NANOSECONDS_PER_SECOND/2) {
alpha -= ((float)deltat.tv_nsec-(NANOSECONDS_PER_SECOND/2)) / (float)(NANOSECONDS_PER_SECOND/2);
if (alpha < minAlpha) {
alpha = minAlpha;
}
}
}
return alpha;
}
static inline bool _is_point_on_left_menu(float x, float y) {
if (menu.topLeftShowing) {
return (x >= touchport.topLeftX && x <= touchport.topLeftXMax && y >= touchport.topLeftY && y <= touchport.topLeftYMax);
@ -422,7 +402,7 @@ static void gltouchmenu_setup(void) {
return;
}
clock_gettime(CLOCK_MONOTONIC, &timingBegin);
clock_gettime(CLOCK_MONOTONIC, &menu.timingBegin);
isAvailable = true;
@ -443,7 +423,10 @@ static void gltouchmenu_render(void) {
gltouchmenu_setup();
}
float alpha = _get_menu_visibility();
float alpha = glhud_getTimedVisibility(menu.timingBegin, menu.minAlpha, menu.maxAlpha);
if (alpha < menu.minAlpha) {
alpha = menu.minAlpha;
}
if (alpha <= 0.0) {
return;
}
@ -533,7 +516,7 @@ static int64_t gltouchmenu_onTouchEvent(interface_touch_event_t action, int poin
}
if (handled) {
clock_gettime(CLOCK_MONOTONIC, &timingBegin);
clock_gettime(CLOCK_MONOTONIC, &menu.timingBegin);
flags |= TOUCH_FLAGS_HANDLED;
}
@ -552,18 +535,18 @@ static void gltouchmenu_setTouchMenuEnabled(bool enabled) {
}
static void _animation_showTouchMenu(void) {
clock_gettime(CLOCK_MONOTONIC, &timingBegin);
clock_gettime(CLOCK_MONOTONIC, &menu.timingBegin);
}
static void _animation_hideTouchMenu(void) {
_hide_top_left();
_hide_top_right();
timingBegin = (struct timespec){ 0 };
menu.timingBegin = (struct timespec){ 0 };
}
static void gltouchmenu_setTouchMenuVisibility(float inactiveAlpha, float activeAlpha) {
minAlpha = inactiveAlpha;
maxAlpha = activeAlpha;
menu.minAlpha = inactiveAlpha;
menu.maxAlpha = activeAlpha;
}
static void gltouchmenu_setGlyphScale(int glyphScale) {
@ -589,6 +572,8 @@ static void _init_gltouchmenu(void) {
interface_setGlyphScale = &gltouchmenu_setGlyphScale;
menu.glyphMultiplier = 1;
menu.minAlpha = 1/4.f; // Minimum alpha value of components (at zero, will not render)
menu.maxAlpha = 1.f;
glnode_registerNode(RENDER_TOP, (GLNode){
.setup = &gltouchmenu_setup,