Exemple #1
0
static void* tcpThread(void* data) {
    UNUSED(data);

    dyad_init();
    dyad_setTickInterval(0.2f);
    dyad_setUpdateTimeout(0.5f);

    while (workerRunning) {
        dyad_update();
    }

    dyad_shutdown();
    printf("tcpThread end!!\n");
    return NULL;
}
Exemple #2
0
/// \brief  Main executable
/// \return 0
int main()
{
    srand((int)time(0));
    initscr();
    clear();
    curs_set(0);
    noecho();
    raw();
    if(has_colors())start_color();
    settings();
    dyad_init();
    pthread_attr_init (&AThread);
    pthread_attr_setdetachstate (&AThread, PTHREAD_CREATE_JOINABLE);
    bool cho=true;
    while(cho){
        pthread_mutex_init (&MBoard, NULL);
        pthread_cond_init (&CBoard, NULL);
        pthread_mutex_init (&MInfo, NULL);
        pthread_cond_init (&CInfo, NULL);
        pthread_mutex_init (&MScr, NULL);
        pthread_mutex_init (&MNet, NULL);
        pthread_mutex_init (&MNetC, NULL);
        pthread_cond_init (&CNet, NULL);
        Clrboard(curs);
        welcome();
        if(isnetworking){
            dyad_setUpdateTimeout(0.05);
            pthread_create (&TNetworkPlay, &AThread, t_NetworkPlay, NULL);
            while (dyad_getStreamCount() > 0 && isconnected) {
                pthread_mutex_lock(&MNet);
                dyad_update();
                pthread_mutex_unlock(&MNet);
                usleep(10000);
            }
            if(result){
                if(score[0]>score[1])
					c_info("You Win!");
				else if(score[0]<score[1])
					c_info("You Lost!");
				else
					c_info("Neck and neck!");
                pthread_cancel(TNetworkPlay);
                pthread_join(TNetworkPlay, NULL);
                pthread_cancel(TNetworkSend);
                pthread_cancel(TNetworkShow);
                pthread_cond_signal (&CBoard);
                pthread_cond_signal (&CNet);
                pthread_join(TNetworkSend, NULL);
                pthread_join(TNetworkShow, NULL);
                pthread_cancel(TInfo);
                pthread_cond_signal (&CInfo);
                pthread_join(TInfo, NULL);
                getch();
            }
            cho=0;
        }else{
            cho=play();
        }
        if(result){
            pthread_mutex_destroy (&MScr);
            pthread_mutex_destroy (&MInfo);
            pthread_cond_destroy (&CInfo);
            pthread_mutex_destroy (&MBoard);
            pthread_cond_destroy (&CBoard);
            pthread_mutex_destroy (&MNet);
            pthread_mutex_destroy (&MNetC);
            pthread_cond_destroy (&CNet);
        }
    }
    if(result){c_forceQuit();}
    return 0;
}
Exemple #3
0
		static void setUpdateTimeout(double seconds) {
			dyad_setUpdateTimeout(seconds);
		}