More changes to input events

This commit is contained in:
Adam Olsen 2001-08-16 22:27:22 +00:00
parent 916b503f14
commit 92729ff6b2
2 changed files with 40 additions and 4 deletions

View file

@ -35,12 +35,17 @@
#include "QF/qtypes.h"
#include "QF/joystick.h" // needed for JOY_MAX_AXES
struct ie_event_s;
typedef void (*ie_handler) (struct ie_event_s *event, float value);
typedef struct ie_event_s {
union {
void *p;
int i;
float f;
} data;
void (*handler) (struct ie_event_s *key, float value);
ie_handler handler;
} ie_event_t;
typedef struct ie_threshold_data_s {
@ -49,7 +54,7 @@ typedef struct ie_threshold_data_s {
struct ie_timevaluepair_s *history;
int history_count;
ie_event_t *nextevent;
void (*handler) (struct ie_event_s *key, float value);
ie_handler handler;
} ie_threshold_data_t;
typedef struct ie_timevaluepair_s {
@ -73,9 +78,18 @@ typedef struct ie_translation_data_s {
ie_translation_index_t *index;
} ie_translation_data_t;
typedef struct ie_multiply_data_s {
float multiplier;
ie_event_t *nextevent;
ie_handler handler;
} ie_multiplier_data_t;
void IE_Threshold_Event (ie_event_t *event, float value);
void IE_Translation_Event (ie_event_t *event, float value);
void IE_Multiplier_Event (ie_event_t *event, float value);
void IE_CallHandler (ie_handler handler, ie_event_t *event, float value);
/*

View file

@ -45,6 +45,8 @@
#include "QF/sys.h"
#include "QF/in_event.h"
#define IE_MAX_DEPTH 100
float ie_time;
void
@ -71,7 +73,7 @@ IE_Threshold_Event (ie_event_t *event, float value)
// call the handler
if (total >= data->threshold)
data->handler (data->nextevent, total);
IE_CallHandler (data->handler, data->nextevent, total);
}
void
@ -91,7 +93,27 @@ IE_Translation_Event (ie_event_t *event, float value)
if (!nextevent) // no handler for it
return;
nextevent->handler (nextevent, value);
IE_CallHandler (nextevent->handler, nextevent, value);
}
void
IE_Multiplier_Event (ie_event_t *event, float value)
{
ie_multiplier_data_t *data = event->data.p;
IE_CallHandler (data->handler, data->nextevent, value * data->multiplier);
}
void
IE_CallHandler (ie_handler handler, ie_event_t *event, float value)
{
static int depth = 0;
depth++;
if (depth > IE_MAX_DEPTH)
// FIXME: we may want to just issue a warning here
Sys_Error ("IE_CallHandler: max recursion depth hit");
else
handler (event, value);
depth--;
}