From 62813111a0da8feaf0fb51be4114c230e811e035 Mon Sep 17 00:00:00 2001 From: Adam Olsen Date: Thu, 16 Aug 2001 23:34:49 +0000 Subject: [PATCH] yet more IE stuff --- include/QF/in_event.h | 10 ++++--- libs/video/targets/in_event.c | 53 ++++++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/include/QF/in_event.h b/include/QF/in_event.h index fe9ed981c..a6d013029 100644 --- a/include/QF/in_event.h +++ b/include/QF/in_event.h @@ -64,13 +64,12 @@ typedef struct ie_timevaluepair_s { typedef struct ie_translation_table_s { int maxevents; - ie_event_t *events; + 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; + int maxtables; + ie_translation_table_t **tables; } ie_translation_index_t; typedef struct ie_translation_data_s { @@ -91,6 +90,9 @@ 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 IE_Translation_Table_Modify (ie_translation_table_t *table, int offset, ie_event_t *event); +ie_translation_index_t *IE_Translation_Index_Create (); /* typedef struct { diff --git a/libs/video/targets/in_event.c b/libs/video/targets/in_event.c index b033e6ec4..0af526ba5 100644 --- a/libs/video/targets/in_event.c +++ b/libs/video/targets/in_event.c @@ -82,20 +82,59 @@ 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; - while (!nextevent) { - if (!index) - break; - if (index->table->maxevents > data->offset) - nextevent = &index->table->events[data->offset]; - index = index->next; - } + 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 () +{ + 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) +{ + if (offset >= 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"); + } + table->events[offset] = event; +} + +ie_translation_index_t * +IE_Translation_Index_Create () +{ + 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) {