Beispiel #1
0
static __inline__ int sendEvent(Uint8 code, int data1, int data2) {
	SDL_Event event;

	event.type = SDL_USEREVENT;
	event.user.code = code;
	event.user.data1 = (void *)data1;
	event.user.data2 = (void *)data2;

	SDL_assert(dataLocked);

	unlockData();
	FE_PushEvent(&event);
	lockData();

	return 0;
}
Beispiel #2
0
static __inline__ int sendEvent(Uint8 code, int data1, int data2)
{
  SDL_Event event;

  event.type = SDL_USEREVENT;
  event.user.code = code;
  event.user.data1 = (void *)data1;
  event.user.data2 = (void *)data2;

  if (dataLocked)
  {
    unlockData();
    FE_PushEvent(&event);
    lockData();
  }
  else
  {
    //printf("this should not happen\n"); fflush(NULL);
    exit(1);
  }

  return 0;
}
Beispiel #3
0
void DefluxBinPushEvent(MAHandle handle, Stream& s) {
	SDL_UserEvent event = { FE_DEFLUX_BINARY, handle, &s, NULL };
	FE_PushEvent((SDL_Event*)&event);
}
Beispiel #4
0
void ConnPushEvent(MAEvent* ep) {
	SDL_UserEvent event = { FE_ADD_EVENT, 0, ep, NULL };
	FE_PushEvent((SDL_Event*)&event);
}
Beispiel #5
0
int rj_reader_handler(void *p) {
	
	int err = 0;
	int frame = 0;
	fd_set saveset, readset;
	int count;
	int sock = *(int *) p;
	struct JoyScrHeader head;

	FD_ZERO(&saveset);
	FD_SET(sock, &saveset);

	while (!err) {
		
		readset = saveset;

		count = select(FD_SETSIZE, &readset, NULL, NULL, NULL);

		if (count > 0) {
			
			int ret;
			int mode;
			int size;

			if (FD_ISSET(sock, &readset)) {
				
				ret = read(sock, &head, sizeof(head));

				// Confirm the magic!
				if ((ret != sizeof(head)) || (LE32(head.magic) != JOY_MAGIC)) {
					
					fprintf(stderr, "Error in socket %d magic %08X.\n", ret, head.magic);

					break;

				}
				
				mode = LE32(head.mode);
				size = LE32(head.size);
				g_context.scr_buffers[frame].head.mode = mode;
				g_context.scr_buffers[frame].head.size = size;

				if (mode < 0) {
					
					SDL_Event event;
					event.type = SDL_USEREVENT;
					event.user.code = EVENT_ENABLE_SCREEN;
					event.user.data1 = NULL;
					event.user.data2 = NULL;

					FE_PushEvent(&event);

				} else if (mode > 3) {
					
					// Something about flushing should go here...

				} else {
					
					int loc = 0;

					while (1) {
						
						readset = saveset;

						count = select(FD_SETSIZE, &readset, NULL, NULL, NULL);

						if (count > 0) {
							
							ret = read(sock, &(g_context.scr_buffers[frame].buf[loc]), size - loc);

							if (ret < 0) {
								
								if (errno != EINTR) {
									
									perror("read");
									err = 1;
									break;

								}

							} else if (ret == 0) {
								
								fprintf(stderr, "EOF\n");
								break;

							}

							loc += ret;
							if (loc == size)
								break;

						} else if (count < 0) {
							
							if (errno != EINTR) {
								
								perror("select");
								err = 1;
								break;

							}

						}

					}

					if (!err) {
						
						SDL_Event event;
						event.type = SDL_USEREVENT;
						event.user.code = (frame) ? EVENT_RENDER_FRAME_2 : EVENT_RENDER_FRAME_1;
						event.user.data1 = NULL;
						event.user.data2 = NULL;

						FE_PushEvent(&event);

					}

				}

			}

		} else if (count < 0) {
			
			if (errno != EINTR) {
				
				perror("select");
				err = 1;

			}

		}

	}

	return 0;

}