Esempio n. 1
0
/* only for async commands on the non prio head */
int32_t cmdqueue_flush(cmdqueue_t handle,
                       void (*flush_callback)(void *cookie, struct cmd *cmd, uint32_t *count),
                       void *cookie,
                       uint32_t *count)
{
    list_t src, dest, node;

    PTHREAD_CHK(pthread_mutex_lock(&handle->queues[CMDTODO].mutex));
    PTHREAD_CHK(pthread_mutex_lock(&handle->queues[CMDFREE].mutex));

    src = &handle->queues[CMDTODO].head;
    dest = &handle->queues[CMDFREE].head;
    node = src->next;

    while (node != src) {
        list_t const tmp_node = node;
        node = node->next;
        list_remove(tmp_node);
        flush_callback(cookie, (struct cmd*)tmp_node, count);
        list_add_tail(dest, tmp_node);
    }

    PTHREAD_CHK(pthread_mutex_unlock(&handle->queues[CMDFREE].mutex));
    PTHREAD_CHK(pthread_mutex_unlock(&handle->queues[CMDTODO].mutex));

    // always returns 0, make void?
    return 0;
}
Esempio n. 2
0
// Show and loop main menu
void show_menu_loop() {
    char *ip = "";
    FILE *han;
    SDL_Event event;
    int createserver = 0;
    SDL_Thread *ReadThread;
    //GConfClient *gcc = NULL;

    // Init GConf
    //g_type_init();
    //gcc = gconf_client_get_default();
    //createserver = gconf_client_get_bool(gcc, BATTLEGWELED_CREATESERVER, NULL);
    //ip = gconf_client_get_string(gcc, BATTLEGWELED_SERVERIP, NULL);

    // Single player
    if (!createserver && !strcmp(ip, "")) {
	han = fopen("/tmp/.battlegweled-save", "rb");
	if (han) {
		fread(&total_score, sizeof(int), 1, han);
		fread(&single_timer, sizeof(int), 1, han);
		fread(&timer_delay, sizeof(int), 1, han);
		fread(&score, sizeof(int), 1, han);
       		fread(nb_of_tiles, sizeof(nb_of_tiles), 1, han);
       		fread(matrix, BOARD_WIDTH * BOARD_HEIGHT, sizeof(int), han);
       		fclose(han);
       		new_game(true, GM_SINGLE, true);
    	} else new_game(true, GM_SINGLE, false); 
       	if (game_loop()) {
		flush_callback(0);
		quit_callback(0);
	} else exit_callback(0);
    } else {
	    int joined;
	    if (createserver) create_game();
	    else joined = join_game(ip);

            while (1) {

	        // If connected then start the game
	        if (ss == SS_CONNECTED) {
	            new_game(true, GM_MULTIPLAYER, false);
	            ReadThread = SDL_CreateThread(multi_player_loop, "ReadThread", NULL);
	            game_loop();
	            //SDL_KillThread(ReadThread);
                    SDL_WaitThread(ReadThread, NULL);
		    break;
                }

		if (ss == SS_ERROR || (SDL_PollEvent(&event) && ((event.key.state == SDL_PRESSED && (event.key.keysym.sym == SDLK_ESCAPE
			|| event.key.keysym.sym == SDLK_F4 || event.key.keysym.sym == SDLK_F5 || event.key.keysym.sym == SDLK_F6))
			|| event.type == SDL_QUIT || (event.type == SDL_MOUSEBUTTONDOWN && event.button.x >= BACK_OFFSETX
			&& event.button.y >= BACK_OFFSETY && event.button.x < BACK_OFFSETX2 && event.button.y < BACK_OFFSETY2)))) {
                        SDL_WaitThread(ThreadConnect, NULL);
                        SDL_WaitThread(ThreadAccept, NULL);
			//if (ThreadConnect) SDL_KillThread(ThreadConnect);
                        //if (ThreadAccept) SDL_KillThread(ThreadAccept);
			break;
                }

		// Update screen
        	draw_waiting_screen();
        }
	quit_callback(0);
    }
}