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/qtypes.h"
#include "QF/joystick.h" // needed for JOY_MAX_AXES #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 { typedef struct ie_event_s {
union { union {
void *p; void *p;
int i; int i;
float f;
} data; } data;
void (*handler) (struct ie_event_s *key, float value); ie_handler handler;
} ie_event_t; } ie_event_t;
typedef struct ie_threshold_data_s { typedef struct ie_threshold_data_s {
@ -49,7 +54,7 @@ typedef struct ie_threshold_data_s {
struct ie_timevaluepair_s *history; struct ie_timevaluepair_s *history;
int history_count; int history_count;
ie_event_t *nextevent; ie_event_t *nextevent;
void (*handler) (struct ie_event_s *key, float value); ie_handler handler;
} ie_threshold_data_t; } ie_threshold_data_t;
typedef struct ie_timevaluepair_s { typedef struct ie_timevaluepair_s {
@ -73,9 +78,18 @@ typedef struct ie_translation_data_s {
ie_translation_index_t *index; ie_translation_index_t *index;
} ie_translation_data_t; } 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_Threshold_Event (ie_event_t *event, float value);
void IE_Translation_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/sys.h"
#include "QF/in_event.h" #include "QF/in_event.h"
#define IE_MAX_DEPTH 100
float ie_time; float ie_time;
void void
@ -71,7 +73,7 @@ IE_Threshold_Event (ie_event_t *event, float value)
// call the handler // call the handler
if (total >= data->threshold) if (total >= data->threshold)
data->handler (data->nextevent, total); IE_CallHandler (data->handler, data->nextevent, total);
} }
void void
@ -91,7 +93,27 @@ IE_Translation_Event (ie_event_t *event, float value)
if (!nextevent) // no handler for it if (!nextevent) // no handler for it
return; 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--;
} }