Some basic stuff for input events. Not yet used.

This commit is contained in:
Adam Olsen 2001-08-16 21:08:17 +00:00
parent 1c12dd804c
commit 916b503f14
2 changed files with 105 additions and 1 deletions

View File

@ -35,6 +35,50 @@
#include "QF/qtypes.h"
#include "QF/joystick.h" // needed for JOY_MAX_AXES
typedef struct ie_event_s {
union {
void *p;
int i;
} data;
void (*handler) (struct ie_event_s *key, float value);
} ie_event_t;
typedef struct ie_threshold_data_s {
float threshold;
float time;
struct ie_timevaluepair_s *history;
int history_count;
ie_event_t *nextevent;
void (*handler) (struct ie_event_s *key, float value);
} ie_threshold_data_t;
typedef struct ie_timevaluepair_s {
float time;
float value;
} ie_timevaluepair_t;
typedef struct ie_translation_table_s {
int maxevents;
ie_event_t *events;
} ie_translation_table_t;
typedef struct ie_translation_index_s {
// FIXME: I don't like this organization
struct ie_translation_index_s *next;
ie_translation_table_t *table;
} ie_translation_index_t;
typedef struct ie_translation_data_s {
int offset;
ie_translation_index_t *index;
} ie_translation_data_t;
void IE_Threshold_Event (ie_event_t *event, float value);
void IE_Translation_Event (ie_event_t *event, float value);
/*
typedef struct {
float x, y;
unsigned int buttons;
@ -67,13 +111,15 @@ typedef struct {
IE_joystick_event_t joystick;
} e;
} IE_event_t;
*/
void IE_Init (void);
void IE_Init_Cvars (void);
void IE_Shutdown (void);
/*
int IE_Send_Event (const IE_event_t *event);
int IE_Add_Handler (int (*event_handler)(const IE_event_t*));
void IE_Remove_Handler (int handle);
void IE_Set_Focus (int handle);
*/
#endif//__QF_in_event_h

View File

@ -42,17 +42,73 @@
# include <strings.h>
#endif
#include "QF/sys.h"
#include "QF/in_event.h"
float ie_time;
void
IE_Threshold_Event (ie_event_t *event, float value)
{
int i, total;
ie_threshold_data_t *data = event->data.p;
// add new value to the history
while (data->history_count
&& data->history[data->history_count - 1].time
< ie_time - data->time)
data->history_count--;
data->history_count++;
data->history = realloc (data->history, data->history_count);
if (!data->history)
Sys_Error ("IE_Event: memory allocation failure!");
data->history[data->history_count - 1].time = ie_time;
data->history[data->history_count - 1].value = value;
// total up the values in the history
for (i = 0, total = 0; i < data->history_count; i++)
total += data->history[i].value;
// call the handler
if (total >= data->threshold)
data->handler (data->nextevent, total);
}
void
IE_Translation_Event (ie_event_t *event, float value)
{
ie_translation_data_t *data = event->data.p;
ie_translation_index_t *index = data->index;
ie_event_t *nextevent = 0;
while (!nextevent) {
if (!index)
break;
if (index->table->maxevents > data->offset)
nextevent = &index->table->events[data->offset];
index = index->next;
}
if (!nextevent) // no handler for it
return;
nextevent->handler (nextevent, value);
}
/*
static int (**event_handler_list)(const IE_event_t*);
static int eh_list_size;
static int focus;
*/
void
IE_Init (void)
{
/*
eh_list_size = 8; // start with 8 slots. will grow dynamicly if needed
event_handler_list = calloc (eh_list_size, sizeof (event_handler_list[0]));
*/
}
void
@ -65,6 +121,7 @@ IE_Shutdown (void)
{
}
/*
int
IE_Send_Event (const IE_event_t *event)
{
@ -116,3 +173,4 @@ IE_Set_Focus (int handle)
IE_Send_Event (&event);
}
}
*/