summaryrefslogtreecommitdiff
path: root/apps/plugins/rockboy/events.c
blob: c018f7ce53610725e54c4fe3772dc15044f8966e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 * events.c
 *
 * Event queue.
 */


#include "rockmacros.h"
#include "input.h"

#define MAX_EVENTS 32

static event_t eventqueue[MAX_EVENTS];
static int eventhead, eventpos;


int ev_postevent(event_t *ev)
{
    int nextevent;
    nextevent = (eventhead+1)%MAX_EVENTS;
    if (nextevent == eventpos)
        return 0;
    eventqueue[eventhead] = *ev;
    eventhead = nextevent;
    return 1;
}

int ev_getevent(event_t *ev)
{
    if (eventpos == eventhead)
    {
        ev->type = EV_NONE;
        return 0;
    }
    *ev = eventqueue[eventpos];
    eventpos = (eventpos+1)%MAX_EVENTS;
    return 1;
}