mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
revert the inappropriately complicated event code for the simpler version.
even that's not likely to be final
This commit is contained in:
parent
255a7522bd
commit
d3b6fcbd61
2 changed files with 1 additions and 187 deletions
|
@ -35,66 +35,6 @@
|
|||
#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;
|
||||
ie_handler handler;
|
||||
} 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;
|
||||
ie_handler handler;
|
||||
} 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 {
|
||||
int maxtables;
|
||||
ie_translation_table_t **tables;
|
||||
} ie_translation_index_t;
|
||||
|
||||
typedef struct ie_translation_data_s {
|
||||
int offset;
|
||||
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);
|
||||
|
||||
ie_translation_table_t *IE_Translation_Table_Create (void);
|
||||
void IE_Translation_Table_Modify (ie_translation_table_t *table, int offset, ie_event_t *event);
|
||||
ie_translation_index_t *IE_Translation_Index_Create (void);
|
||||
|
||||
/*
|
||||
typedef struct {
|
||||
float x, y;
|
||||
unsigned int buttons;
|
||||
|
@ -127,15 +67,13 @@ 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
|
||||
|
|
|
@ -40,141 +40,19 @@ static __attribute__ ((unused)) const char rcsid[] =
|
|||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "QF/sys.h"
|
||||
#include "QF/in_event.h"
|
||||
|
||||
#define IE_MAX_DEPTH 100
|
||||
|
||||
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)
|
||||
IE_CallHandler (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;
|
||||
int i;
|
||||
|
||||
for (i = 0; !nextevent && i < index->maxtables; i++)
|
||||
if (index->tables[i]->maxevents > data->offset)
|
||||
nextevent = index->tables[i]->events[data->offset];
|
||||
if (!nextevent) // no handler for it
|
||||
return;
|
||||
|
||||
IE_CallHandler (nextevent->handler, nextevent, value);
|
||||
}
|
||||
|
||||
ie_translation_table_t *
|
||||
IE_Translation_Table_Create (void)
|
||||
{
|
||||
ie_translation_table_t *table;
|
||||
|
||||
table = malloc (sizeof (ie_translation_table_t));
|
||||
if (!table)
|
||||
Sys_Error ("IE_Translation_Table_Create: memory allocation failure");
|
||||
|
||||
table->maxevents = 0;
|
||||
table->events = 0;
|
||||
return table;
|
||||
}
|
||||
|
||||
void
|
||||
IE_Translation_Table_Modify (ie_translation_table_t *table, int offset,
|
||||
ie_event_t *event)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (offset >= table->maxevents) {
|
||||
i = table->maxevents;
|
||||
table->maxevents++;
|
||||
table->events = realloc (table->events, sizeof (ie_translation_table_t
|
||||
*) * table->maxevents);
|
||||
if (!table->events)
|
||||
Sys_Error ("IE_Translation_Table_Modify: memory allocation "
|
||||
"failure");
|
||||
for (; i < table->maxevents; i++)
|
||||
table->events[i] = 0;
|
||||
}
|
||||
table->events[offset] = event;
|
||||
}
|
||||
|
||||
ie_translation_index_t *
|
||||
IE_Translation_Index_Create (void)
|
||||
{
|
||||
ie_translation_index_t *index;
|
||||
|
||||
index = malloc (sizeof (ie_translation_index_t));
|
||||
if (!index)
|
||||
Sys_Error ("IE_Translation_Index_Create: memory allocation failure");
|
||||
|
||||
index->maxtables = 0;
|
||||
index->tables = 0;
|
||||
return index;
|
||||
}
|
||||
|
||||
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)
|
||||
Sys_Error ("IE_CallHandler: max recursion depth hit");
|
||||
else
|
||||
handler (event, value);
|
||||
depth--;
|
||||
}
|
||||
|
||||
/*
|
||||
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
|
||||
|
@ -187,7 +65,6 @@ IE_Shutdown (void)
|
|||
{
|
||||
}
|
||||
|
||||
/*
|
||||
int
|
||||
IE_Send_Event (const IE_event_t *event)
|
||||
{
|
||||
|
@ -239,4 +116,3 @@ IE_Set_Focus (int handle)
|
|||
IE_Send_Event (&event);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue