remove the event_buf from the wiimote structure, allocating it on demand instead
This commit is contained in:
@@ -139,19 +139,21 @@ void wiiuse_os_disconnect(struct wiimote_t* wm) {
|
||||
#pragma mark poll, read, write
|
||||
|
||||
int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) {
|
||||
int i, evnt = 0;
|
||||
int i;
|
||||
byte read_buffer[MAX_PAYLOAD];
|
||||
int evnt = 0;
|
||||
|
||||
if (!wm) return 0;
|
||||
|
||||
for (i = 0; i < wiimotes; ++i) {
|
||||
wm[i]->event = WIIUSE_NONE;
|
||||
|
||||
if (wiiuse_os_read(wm[i], wm[i]->event_buf, sizeof(wm[i]->event_buf))) {
|
||||
/* clear out the buffer */
|
||||
memset(read_buffer, 0, sizeof(read_buffer));
|
||||
/* read */
|
||||
if (wiiuse_os_read(wm[i], read_buffer, sizeof(read_buffer))) {
|
||||
/* propagate the event, messages should be read as in linux, starting from the second element */
|
||||
propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2);
|
||||
|
||||
/* clear out the event buffer */
|
||||
memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf));
|
||||
propagate_event(wm[i], read_buffer[1], read_buffer+2);
|
||||
} else {
|
||||
/* send out any waiting writes */
|
||||
wiiuse_send_next_pending_write_request(wm[i]);
|
||||
|
||||
@@ -237,6 +237,7 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) {
|
||||
fd_set fds;
|
||||
int r;
|
||||
int i;
|
||||
byte read_buffer[MAX_PAYLOAD];
|
||||
int highest_fd = -1;
|
||||
|
||||
evnt = 0;
|
||||
@@ -279,13 +280,13 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) {
|
||||
|
||||
if (FD_ISSET(wm[i]->in_sock, &fds)) {
|
||||
/* clear out the event buffer */
|
||||
memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf));
|
||||
memset(read_buffer, 0, sizeof(read_buffer));
|
||||
|
||||
/* clear out any old read requests */
|
||||
/* clear out any old read data */
|
||||
clear_dirty_reads(wm[i]);
|
||||
|
||||
/* read the pending message into the buffer */
|
||||
r = read(wm[i]->in_sock, wm[i]->event_buf, sizeof(wm[i]->event_buf));
|
||||
r = read(wm[i]->in_sock, read_buffer, sizeof(read_buffer));
|
||||
if (r == -1) {
|
||||
/* error reading data */
|
||||
WIIUSE_ERROR("Receiving wiimote data (id %i).", wm[i]->unid);
|
||||
@@ -309,7 +310,7 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) {
|
||||
}
|
||||
|
||||
/* propagate the event */
|
||||
propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2);
|
||||
propagate_event(wm[i], read_buffer[1], read_buffer+2);
|
||||
evnt += (wm[i]->event != WIIUSE_NONE);
|
||||
} else {
|
||||
/* send out any waiting writes */
|
||||
|
||||
11
src/os_win.c
11
src/os_win.c
@@ -181,6 +181,7 @@ void wiiuse_os_disconnect(struct wiimote_t* wm) {
|
||||
|
||||
int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) {
|
||||
int i;
|
||||
byte read_buffer[MAX_PAYLOAD];
|
||||
int evnt = 0;
|
||||
|
||||
if (!wm) return 0;
|
||||
@@ -188,13 +189,13 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) {
|
||||
for (i = 0; i < wiimotes; ++i) {
|
||||
wm[i]->event = WIIUSE_NONE;
|
||||
|
||||
if (wiiuse_os_read(wm[i], wm[i]->event_buf, sizeof(wm[i]->event_buf))) {
|
||||
/* clear out the buffer */
|
||||
memset(read_buffer, 0, sizeof(read_buffer));
|
||||
/* read */
|
||||
if (wiiuse_os_read(wm[i], read_buffer, sizeof(read_buffer))) {
|
||||
/* propagate the event */
|
||||
propagate_event(wm[i], wm[i]->event_buf[0], wm[i]->event_buf+1);
|
||||
propagate_event(wm[i], read_buffer[0], read_buffer+1);
|
||||
evnt += (wm[i]->event != WIIUSE_NONE);
|
||||
|
||||
/* clear out the event buffer */
|
||||
memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf));
|
||||
} else {
|
||||
/* send out any waiting writes */
|
||||
wiiuse_send_next_pending_write_request(wm[i]);
|
||||
|
||||
@@ -187,7 +187,6 @@ void wiiuse_disconnected(struct wiimote_t* wm) {
|
||||
wm->btns = 0;
|
||||
wm->btns_held = 0;
|
||||
wm->btns_released = 0;
|
||||
memset(wm->event_buf, 0, sizeof(wm->event_buf));
|
||||
|
||||
wm->event = WIIUSE_DISCONNECT;
|
||||
}
|
||||
|
||||
@@ -785,7 +785,6 @@ typedef struct wiimote_t {
|
||||
WCONST struct wiimote_state_t lstate; /**< last saved state */
|
||||
|
||||
WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occurred */
|
||||
WCONST byte event_buf[MAX_PAYLOAD]; /**< event buffer */
|
||||
WCONST byte motion_plus_id[6];
|
||||
} wiimote;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user