コード例 #1
0
ファイル: touch.c プロジェクト: 4rzael/DWAVDriver
// Read the command line and start the driver
int main(int ac, char **av)
{
    t_context sys;
    int touchFile;

    memset(&sys, 0, sizeof(sys));

    // Init X11
    sys.display = XOpenDisplay(NULL);
    if (!sys.display)
    {
        fprintf(stderr, "Cannot open display\n");
        exit(EXIT_FAILURE);
    }
    sys.root = DefaultRootWindow(sys.display);
    XSelectInput(sys.display, sys.root, KeyReleaseMask);

    // Read the command line
    if (ac <= 2) {
        sys.screen.X = T_RES;
        sys.screen.Y = T_RES;
    }
    else {
        sys.screen.X = atoi(av[1]);
        sys.screen.X = sys.screen.X > 0 ? sys.screen.X : 1;
        sys.screen.Y = atoi(av[2]);
        sys.screen.Y = sys.screen.Y > 0 ? sys.screen.Y : 1;
    }

    // Open the touchscreen file. Retry every 10 seconds
    while ((touchFile = open("/dev/usb/hiddev0", O_RDONLY)) <= 0)
    {
        perror("open()");
        sleep(10);
    }

    calibrate(&sys, "./.calibration");

    listenInput(&sys, touchFile, &onInput);
}
コード例 #2
0
ファイル: client.c プロジェクト: naknut/Project-Puzzle
/**
 * Author: 	 	Joel Denke, Marcus Isaksson
 * Description:		Run the game on client
 */
int main(int argc, char *argv[])
{
	int i, j, no, yb, keysHeld[323] = {0};
	int result = 0;
	SDL_Thread * eventBuffer;
	SDL_Thread * runBuffer;
	struct timer_t2 fps;
	
	char * server_ip = malloc(sizeof(char) * 16);
	char * elem = malloc(sizeof(char) * MESSAGE_SIZE);

	pColor = malloc(sizeof(SDL_Color));
	oColor = malloc(sizeof(SDL_Color));
	connection = malloc(sizeof(connection_data));

	for (i = 0; i < NO_BUFFERS; i++) {
		cb[i] = malloc(sizeof(cBuffer));
		b_lock[i] = SDL_CreateMutex();
	}

	strcpy(server_ip, "127.0.0.1");

	pColor->r = 0;
	pColor->g = 255;
	pColor->b = 255;
	oColor->r = 0;
	oColor->g = 0;
	oColor->b = 255;

	initGraphics();
	initSound();

	printf("Render menu\n");
	graphicsMenu(&gameWorld, server_ip);

	initSlots(cb[0], BUFFER_SIZE);
	initSlots(cb[1], NO_OBJECTS);
	initSlots(cb[2], BUFFER_SIZE);

	state = gStart;

	if (clientConnect(connection, server_ip) == 0)
	{
		eventBuffer = SDL_CreateThread(listenEventBuffer, &connection);

		while (1) {
			switch (state) {
				case gStart:
					runData(2);
					break;
				case gInit:
					timer_start(&fps);
					startDraw();
					drawLoadScr(SCREEN_WIDTH, SCREEN_HEIGHT);
					endDraw();

					initWorld();
					
					if (timer_get_ticks(&fps) < 1000 / FPS)
					{
						//delay the as much time as we need to get desired frames per second
						SDL_Delay( ( 1000 / FPS ) - timer_get_ticks(&fps) );
					}
					break;
				case gRunning :
					timer_start(&fps);
					drawGraphics();
					listenInput(keysHeld);

					// i = 0: players; i = 1: objects; i = 2: messages
					for (i = 0; i < NO_BUFFERS; i++) {
						runData(i);
					}

					if (timer_get_ticks(&fps) < 1000 / FPS)
					{
						//delay the as much time as we need to get desired frames per second
						SDL_Delay( ( 1000 / FPS ) - timer_get_ticks(&fps) );
					}

					break;
				case gExit :
					//sprintf(string, "%d,quit", connection->client_id);
					printf("Freeing music now\n");
					pauseMusic();
					freeMusic();
					end_session(connection);
					printf("Player is exit game now\n");
					exitClient(eventBuffer);
					break;
				default :
					printf("test\n");
					break;
			}
		}
	} else {
		printf("Misslyckade med att kontakta servern på ip-adress: '%s'\n", server_ip);
		state = gExit;
		pauseMusic();
		freeMusic();
		exitClient(eventBuffer);
	}

	return 0;
}