Small Optimization
This commit is contained in:
parent
f3eaa57041
commit
74d14ecaa6
@ -114,8 +114,8 @@ typedef struct SDL_JoyButtonEvent {
|
||||
|
||||
typedef struct SDL_ResizeEvent {
|
||||
uint8_t type;
|
||||
int w;
|
||||
int h;
|
||||
int32_t w;
|
||||
int32_t h;
|
||||
} SDL_ResizeEvent;
|
||||
|
||||
typedef struct SDL_ExposeEvent {
|
||||
@ -128,14 +128,14 @@ typedef struct SDL_QuitEvent {
|
||||
|
||||
typedef struct SDL_UserEvent {
|
||||
uint8_t type;
|
||||
int code;
|
||||
void *data1;
|
||||
void *data2;
|
||||
int32_t code;
|
||||
uint32_t data1;
|
||||
uint32_t data2;
|
||||
} SDL_UserEvent;
|
||||
|
||||
typedef struct SDL_SysWMEvent {
|
||||
uint8_t type;
|
||||
void *msg;
|
||||
uint32_t msg;
|
||||
} SDL_SysWMEvent;
|
||||
|
||||
typedef union SDL_Event {
|
||||
|
@ -9,116 +9,6 @@
|
||||
|
||||
#include "common/common.h"
|
||||
|
||||
// Read/Write SDL Events
|
||||
static void write_SDL_Event(SDL_Event event) {
|
||||
// Write EVent Type
|
||||
write_int(event.type);
|
||||
// Write Event Details
|
||||
switch (event.type) {
|
||||
// Focus Event
|
||||
case SDL_ACTIVEEVENT: {
|
||||
write_int(event.active.gain);
|
||||
write_int(event.active.state);
|
||||
break;
|
||||
}
|
||||
// Key Press Events
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP: {
|
||||
write_int(event.key.state);
|
||||
write_int(event.key.keysym.scancode);
|
||||
write_int(event.key.keysym.sym);
|
||||
write_int(event.key.keysym.mod);
|
||||
write_int(event.key.keysym.unicode);
|
||||
break;
|
||||
}
|
||||
// Mouse Motion Event
|
||||
case SDL_MOUSEMOTION: {
|
||||
write_int(event.motion.state);
|
||||
write_int(event.motion.x);
|
||||
write_int(event.motion.y);
|
||||
write_int(event.motion.xrel);
|
||||
write_int(event.motion.yrel);
|
||||
break;
|
||||
}
|
||||
// Mouse Press Events
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP: {
|
||||
write_int(event.button.button);
|
||||
write_int(event.button.state);
|
||||
write_int(event.button.x);
|
||||
write_int(event.button.y);
|
||||
break;
|
||||
}
|
||||
// User-Specified Event (Repurposed As Unicode Character Event)
|
||||
case SDL_USEREVENT: {
|
||||
write_int(event.user.code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
static SDL_Event read_SDL_Event() {
|
||||
// Create Event
|
||||
SDL_Event event;
|
||||
event.type = read_int();
|
||||
// Read Event Details
|
||||
switch (event.type) {
|
||||
// Focus Event
|
||||
case SDL_ACTIVEEVENT: {
|
||||
event.active.gain = read_int();
|
||||
event.active.state = read_int();
|
||||
break;
|
||||
}
|
||||
// Key Press Events
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP: {
|
||||
event.key.state = read_int();
|
||||
event.key.keysym.scancode = read_int();
|
||||
event.key.keysym.sym = read_int();
|
||||
event.key.keysym.mod = read_int();
|
||||
event.key.keysym.unicode = read_int();
|
||||
break;
|
||||
}
|
||||
// Mouse Motion Event
|
||||
case SDL_MOUSEMOTION: {
|
||||
event.motion.state = read_int();
|
||||
event.motion.x = read_int();
|
||||
event.motion.y = read_int();
|
||||
event.motion.xrel = read_int();
|
||||
event.motion.yrel = read_int();
|
||||
break;
|
||||
}
|
||||
// Mouse Press Events
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP: {
|
||||
event.button.button = read_int();
|
||||
event.button.state = read_int();
|
||||
event.button.x = read_int();
|
||||
event.button.y = read_int();
|
||||
break;
|
||||
}
|
||||
// Quit Event
|
||||
case SDL_QUIT: {
|
||||
break;
|
||||
}
|
||||
// User-Specified Event (Repurposed As Unicode Character Event)
|
||||
case SDL_USEREVENT: {
|
||||
event.user.code = read_int();
|
||||
break;
|
||||
}
|
||||
// Unsupported Event
|
||||
default: {
|
||||
INFO("Unsupported SDL Event: %u", event.type);
|
||||
}
|
||||
}
|
||||
// Return
|
||||
#pragma GCC diagnostic push
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#endif
|
||||
return event;
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
|
||||
// SDL Functions
|
||||
|
||||
CALL(0, SDL_Init, int, (uint32_t flags)) {
|
||||
@ -156,7 +46,7 @@ CALL(1, SDL_PollEvent, int, (SDL_Event *event)) {
|
||||
// Get Return Value
|
||||
int32_t ret = (int32_t) read_int();
|
||||
if (ret) {
|
||||
*event = read_SDL_Event();
|
||||
safe_read((void *) event, sizeof (SDL_Event));
|
||||
}
|
||||
|
||||
// Release Proxy
|
||||
@ -171,7 +61,7 @@ CALL(1, SDL_PollEvent, int, (SDL_Event *event)) {
|
||||
// Return Values
|
||||
write_int(ret);
|
||||
if (ret) {
|
||||
write_SDL_Event(event);
|
||||
safe_write((void *) &event, sizeof (SDL_Event));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -182,7 +72,7 @@ CALL(2, SDL_PushEvent, int, (SDL_Event *event)) {
|
||||
start_proxy_call();
|
||||
|
||||
// Arguments
|
||||
write_SDL_Event(*event);
|
||||
safe_write((void *) event, sizeof (SDL_Event));
|
||||
|
||||
// Get Return Value
|
||||
int32_t ret = (int32_t) read_int();
|
||||
@ -193,7 +83,8 @@ CALL(2, SDL_PushEvent, int, (SDL_Event *event)) {
|
||||
// Return Value
|
||||
return ret;
|
||||
#else
|
||||
SDL_Event event = read_SDL_Event();
|
||||
SDL_Event event;
|
||||
safe_read((void *) &event, sizeof (SDL_Event));
|
||||
// Run
|
||||
int ret = SDL_PushEvent(&event);
|
||||
// Return Value
|
||||
|
Loading…
Reference in New Issue
Block a user