Skip to content

Commit

Permalink
Control Panel|Fixed: Slider/list buttons ineffective and fade away mi…
Browse files Browse the repository at this point in the history
…ssing

Re-instated trigger_t and the associated timing functions. Not all
subsystems are timed according to game's sharp tics. The control panel
for one, needs its own independent timing mechanism.
  • Loading branch information
danij-deng committed Jan 20, 2012
1 parent 19db470 commit 0a8f19a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
28 changes: 28 additions & 0 deletions doomsday/engine/portable/include/m_misc.h
Expand Up @@ -147,6 +147,34 @@ double M_SlopeToAngle(double dx, double dy);
double M_Length(double x, double y);
int M_NumDigits(int num);

typedef struct trigger_s {
timespan_t duration;
timespan_t accum;
} trigger_t;

/**
* Advances time and return true if the trigger is triggered.
*
* @param trigger Time trigger.
* @param advanceTime Amount of time to advance the trigger.
*
* @return @c true, if the trigger has accumulated enough time
* to fill the trigger's time threshold.
*/
boolean M_RunTrigger(trigger_t* trigger, timespan_t advanceTime);

/**
* Checks if the trigger will trigger after @a advanceTime seconds.
* The trigger itself is not modified in any way.
*
* @param trigger Time trigger.
* @param advanceTime Amount of time to advance the trigger.
*
* @return @c true, if the trigger will accumulate enough time after @a advanceTime
* to fill the trigger's time threshold.
*/
boolean M_CheckTrigger(const trigger_t* trigger, timespan_t advanceTime);

/**
* Calculate CRC-32 for an arbitrary data buffer. @ingroup math
*/
Expand Down
24 changes: 24 additions & 0 deletions doomsday/engine/portable/src/m_misc.c
Expand Up @@ -1122,6 +1122,30 @@ void M_ReadBits(uint numBits, const uint8_t** src, uint8_t* cb, uint8_t* out)
}
}

boolean M_RunTrigger(trigger_t *trigger, timespan_t advanceTime)
{
// Either use the trigger's duration, or fall back to the default.
timespan_t duration = (trigger->duration? trigger->duration : 1.0f/35);

trigger->accum += advanceTime;

if(trigger->accum >= duration)
{
trigger->accum -= duration;
return true;
}

// It wasn't triggered.
return false;
}

boolean M_CheckTrigger(const trigger_t *trigger, timespan_t advanceTime)
{
// Either use the trigger's duration, or fall back to the default.
timespan_t duration = (trigger->duration? trigger->duration : 1.0f/35);
return (trigger->accum + advanceTime>= duration);
}

uint M_CRC32(byte *data, uint length)
{
/* ====================================================================== */
Expand Down
10 changes: 4 additions & 6 deletions doomsday/engine/portable/src/ui_main.c
Expand Up @@ -509,15 +509,13 @@ void UI_Ticker(timespan_t time)
{
#define UIALPHA_FADE_STEP .07

static trigger_t fixed = { 1 / 35.0, 0 };
float diff = 0;

if(!uiActive)
return;
if(!uiCurrentPage)
return;
if(!uiActive || !uiCurrentPage) return;

if(!DD_IsSharpTick())
return;
// Time to think?
if(!M_RunTrigger(&fixed, time)) return;

// Move towards the target alpha level for the entire UI.
diff = uiTargetAlpha - uiAlpha;
Expand Down

0 comments on commit 0a8f19a

Please sign in to comment.