Make engine_event_get() return a pointer
This commit is contained in:
parent
cecb06903c
commit
32fef09e83
9
main.c
9
main.c
@ -5,8 +5,8 @@
|
||||
#include "modules/engine/frontend/generic/textures.c"
|
||||
#include "modules/engine/addon/lua.c"
|
||||
|
||||
void handleEvent(struct ENGINE_EVENT event) {
|
||||
if (event.type == ENGINE_EVENT_TYPE_EXIT) {
|
||||
void handleEvent(struct ENGINE_EVENT * event) {
|
||||
if (event->type == ENGINE_EVENT_TYPE_EXIT) {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
@ -39,11 +39,12 @@ int main(int argc, char **argv) {
|
||||
engine_luaInit();
|
||||
|
||||
while (1) {
|
||||
struct ENGINE_EVENT event = engine_event_get();
|
||||
if (event.type != ENGINE_EVENT_TYPE_NONE) {
|
||||
struct ENGINE_EVENT * event = engine_event_get();
|
||||
if (event->type != ENGINE_EVENT_TYPE_NONE) {
|
||||
handleEvent(event);
|
||||
} else {
|
||||
tick();
|
||||
}
|
||||
engine_free(event);
|
||||
}
|
||||
}
|
||||
|
@ -26,10 +26,9 @@ type = "void"
|
||||
arguments = ["long long"]
|
||||
|
||||
# LOGIC
|
||||
# TODO: Make this into a pointer
|
||||
#[engine_event_get]
|
||||
#type = "struct ENGINE_EVENT"
|
||||
#arguments = []
|
||||
[engine_event_get]
|
||||
type = "struct ENGINE_EVENT *"
|
||||
arguments = []
|
||||
|
||||
# TEXTURES
|
||||
[engine_texture_create]
|
||||
|
@ -78,21 +78,21 @@ SDL_Window * engine_sdl_window;
|
||||
int engine_width = 0;
|
||||
int engine_height = 0;
|
||||
|
||||
struct ENGINE_EVENT engine_event_get() {
|
||||
struct ENGINE_EVENT event;
|
||||
struct ENGINE_EVENT * engine_event_get() {
|
||||
struct ENGINE_EVENT * event = engine_malloc(NULL,sizeof(struct ENGINE_EVENT));
|
||||
SDL_Event sdlevent;
|
||||
|
||||
if (!SDL_PollEvent(&sdlevent)) {
|
||||
struct ENGINE_EVENT_NONE data;
|
||||
event.type = ENGINE_EVENT_TYPE_NONE;
|
||||
event.data = &data;
|
||||
event->type = ENGINE_EVENT_TYPE_NONE;
|
||||
event->data = &data;
|
||||
return event;
|
||||
}
|
||||
|
||||
if (sdlevent.type == SDL_QUIT) {
|
||||
struct ENGINE_EVENT_EXIT data;
|
||||
event.type = ENGINE_EVENT_TYPE_EXIT;
|
||||
event.data = &data;
|
||||
event->type = ENGINE_EVENT_TYPE_EXIT;
|
||||
event->data = &data;
|
||||
return event;
|
||||
}
|
||||
|
||||
@ -101,15 +101,15 @@ struct ENGINE_EVENT engine_event_get() {
|
||||
struct ENGINE_EVENT_INPUTKB data;
|
||||
data.pressed = (sdlevent.type == SDL_KEYDOWN);
|
||||
data.key = sdlevent.key.keysym.scancode;
|
||||
event.type = ENGINE_EVENT_TYPE_INPUTKB;
|
||||
event.data = &data;
|
||||
event->type = ENGINE_EVENT_TYPE_INPUTKB;
|
||||
event->data = &data;
|
||||
return event;
|
||||
}
|
||||
|
||||
unknown:
|
||||
struct ENGINE_EVENT_UNKNOWN data;
|
||||
event.type = ENGINE_EVENT_TYPE_UNKNOWN;
|
||||
event.data = &data;
|
||||
event->type = ENGINE_EVENT_TYPE_UNKNOWN;
|
||||
event->data = &data;
|
||||
return event;
|
||||
}
|
||||
|
||||
|
9
test.c
9
test.c
@ -5,8 +5,8 @@
|
||||
#include "modules/engine/frontend/generic/textures.c"
|
||||
//#include "modules/engine/frontend/sdl/textures.c" // TODO
|
||||
|
||||
void handleEvent(struct ENGINE_EVENT event) {
|
||||
if (event.type == ENGINE_EVENT_TYPE_EXIT) {
|
||||
void handleEvent(struct ENGINE_EVENT * event) {
|
||||
if (event->type == ENGINE_EVENT_TYPE_EXIT) {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
@ -134,11 +134,12 @@ int main(int argc, char **argv) {
|
||||
engine_window_init(256,256,"Game");
|
||||
|
||||
while (1) {
|
||||
struct ENGINE_EVENT event = engine_event_get();
|
||||
if (event.type != ENGINE_EVENT_TYPE_NONE) {
|
||||
struct ENGINE_EVENT * event = engine_event_get();
|
||||
if (event->type != ENGINE_EVENT_TYPE_NONE) {
|
||||
handleEvent(event);
|
||||
} else {
|
||||
tick();
|
||||
}
|
||||
engine_free(event);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user