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