remove the event_buf from the wiimote structure, allocating it on demand instead

This commit is contained in:
Lysann Schlegel
2012-12-08 20:34:13 +01:00
parent 866b124d35
commit 72647a56b1
5 changed files with 19 additions and 17 deletions

View File

@@ -139,19 +139,21 @@ void wiiuse_os_disconnect(struct wiimote_t* wm) {
#pragma mark poll, read, write #pragma mark poll, read, write
int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { 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; if (!wm) return 0;
for (i = 0; i < wiimotes; ++i) { for (i = 0; i < wiimotes; ++i) {
wm[i]->event = WIIUSE_NONE; 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 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); propagate_event(wm[i], read_buffer[1], read_buffer+2);
/* clear out the event buffer */
memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf));
} else { } else {
/* send out any waiting writes */ /* send out any waiting writes */
wiiuse_send_next_pending_write_request(wm[i]); wiiuse_send_next_pending_write_request(wm[i]);

View File

@@ -237,6 +237,7 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) {
fd_set fds; fd_set fds;
int r; int r;
int i; int i;
byte read_buffer[MAX_PAYLOAD];
int highest_fd = -1; int highest_fd = -1;
evnt = 0; evnt = 0;
@@ -279,13 +280,13 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) {
if (FD_ISSET(wm[i]->in_sock, &fds)) { if (FD_ISSET(wm[i]->in_sock, &fds)) {
/* clear out the event buffer */ /* 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]); clear_dirty_reads(wm[i]);
/* read the pending message into the buffer */ /* 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) { if (r == -1) {
/* error reading data */ /* error reading data */
WIIUSE_ERROR("Receiving wiimote data (id %i).", wm[i]->unid); 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 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); evnt += (wm[i]->event != WIIUSE_NONE);
} else { } else {
/* send out any waiting writes */ /* send out any waiting writes */

View File

@@ -181,6 +181,7 @@ void wiiuse_os_disconnect(struct wiimote_t* wm) {
int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) { int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) {
int i; int i;
byte read_buffer[MAX_PAYLOAD];
int evnt = 0; int evnt = 0;
if (!wm) return 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) { for (i = 0; i < wiimotes; ++i) {
wm[i]->event = WIIUSE_NONE; 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 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); evnt += (wm[i]->event != WIIUSE_NONE);
/* clear out the event buffer */
memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf));
} else { } else {
/* send out any waiting writes */ /* send out any waiting writes */
wiiuse_send_next_pending_write_request(wm[i]); wiiuse_send_next_pending_write_request(wm[i]);

View File

@@ -187,7 +187,6 @@ void wiiuse_disconnected(struct wiimote_t* wm) {
wm->btns = 0; wm->btns = 0;
wm->btns_held = 0; wm->btns_held = 0;
wm->btns_released = 0; wm->btns_released = 0;
memset(wm->event_buf, 0, sizeof(wm->event_buf));
wm->event = WIIUSE_DISCONNECT; wm->event = WIIUSE_DISCONNECT;
} }

View File

@@ -785,7 +785,6 @@ typedef struct wiimote_t {
WCONST struct wiimote_state_t lstate; /**< last saved state */ WCONST struct wiimote_state_t lstate; /**< last saved state */
WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occurred */ WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occurred */
WCONST byte event_buf[MAX_PAYLOAD]; /**< event buffer */
WCONST byte motion_plus_id[6]; WCONST byte motion_plus_id[6];
} wiimote; } wiimote;