mirror of https://github.com/bjornbytes/lovr.git
Clean up event module;
This commit is contained in:
parent
3267bad4fa
commit
a4e563fe6f
|
@ -1,6 +1,8 @@
|
|||
#include "api.h"
|
||||
#include "api/event.h"
|
||||
#include "event/event.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
const char* EventTypes[] = {
|
||||
[EVENT_QUIT] = "quit",
|
||||
|
@ -93,7 +95,7 @@ static int nextEvent(lua_State* L) {
|
|||
return 3;
|
||||
|
||||
case EVENT_CUSTOM:
|
||||
for (int i = 0; i < event.data.custom.count; i++) {
|
||||
for (uint32_t i = 0; i < event.data.custom.count; i++) {
|
||||
Variant* variant = &event.data.custom.data[i];
|
||||
luax_pushvariant(L, variant);
|
||||
lovrVariantDestroy(variant);
|
||||
|
@ -125,7 +127,7 @@ static int l_lovrEventPush(lua_State* L) {
|
|||
const char* name = luaL_checkstring(L, 1);
|
||||
strncpy(eventData.name, name, MAX_EVENT_NAME_LENGTH - 1);
|
||||
eventData.count = MIN(lua_gettop(L) - 1, 4);
|
||||
for (int i = 0; i < eventData.count; i++) {
|
||||
for (uint32_t i = 0; i < eventData.count; i++) {
|
||||
luax_checkvariant(L, 2 + i, &eventData.data[i]);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
#include "event/event.h"
|
||||
#include "platform.h"
|
||||
#include "types.h"
|
||||
#include "lib/vec/vec.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static EventState state;
|
||||
static struct {
|
||||
bool initialized;
|
||||
vec_t(EventPump) pumps;
|
||||
vec_t(Event) events;
|
||||
} state;
|
||||
|
||||
void lovrVariantDestroy(Variant* variant) {
|
||||
switch (variant->type) {
|
||||
|
@ -25,7 +31,7 @@ void lovrEventDestroy() {
|
|||
if (!state.initialized) return;
|
||||
vec_deinit(&state.pumps);
|
||||
vec_deinit(&state.events);
|
||||
memset(&state, 0, sizeof(EventState));
|
||||
memset(&state, 0, sizeof(state));
|
||||
}
|
||||
|
||||
void lovrEventAddPump(EventPump pump) {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "lib/vec/vec.h"
|
||||
#include "types.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
#define MAX_EVENT_NAME_LENGTH 32
|
||||
|
||||
struct Ref;
|
||||
struct Thread;
|
||||
|
||||
typedef enum {
|
||||
|
@ -27,7 +27,7 @@ typedef union {
|
|||
bool boolean;
|
||||
double number;
|
||||
char* string;
|
||||
Ref* ref;
|
||||
struct Ref* ref;
|
||||
} VariantValue;
|
||||
|
||||
typedef struct {
|
||||
|
@ -52,7 +52,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
char name[MAX_EVENT_NAME_LENGTH];
|
||||
Variant data[4];
|
||||
int count;
|
||||
uint32_t count;
|
||||
} CustomEvent;
|
||||
|
||||
typedef union {
|
||||
|
@ -69,12 +69,6 @@ typedef struct {
|
|||
|
||||
typedef void (*EventPump)(void);
|
||||
|
||||
typedef struct {
|
||||
bool initialized;
|
||||
vec_t(EventPump) pumps;
|
||||
vec_t(Event) events;
|
||||
} EventState;
|
||||
|
||||
void lovrVariantDestroy(Variant* variant);
|
||||
|
||||
bool lovrEventInit(void);
|
||||
|
|
|
@ -56,7 +56,7 @@ typedef struct {
|
|||
|
||||
extern const TypeInfo lovrTypeInfo[T_MAX];
|
||||
|
||||
typedef struct {
|
||||
typedef struct Ref {
|
||||
Type type;
|
||||
int count;
|
||||
} Ref;
|
||||
|
|
Loading…
Reference in New Issue