コード例 #1
0
ファイル: rtdemo.cpp プロジェクト: BackupTheBerlios/sgraph
int main(int argc, char **argv)
{ 
  opts=new SGraphOptions();
  
  d=new DemoData(opts);
  
  plotter = new SDLPlotter(opts,d);
  
  SDL_Thread *controller = SDL_CreateThread (control,NULL);
  SDL_Thread *plotThread= SDL_CreateThread (plot,NULL);
  SDL_SetEventFilter(pollforquit);
  
  while(!done)
  {
    SDL_Delay(50);
    if(opts->follow) 
    {
      d->SetEofReached(0);
      SDL_Delay(1000);
      plotter->PlotData(d);
    } 
    if(opts->update)
    {
      d->ResetData();
      SDL_Delay(1000);
      plotter->PlotData(d);
    }
  }
  plotter->QuitPlotting();
  SDL_KillThread(controller);
  SDL_KillThread(plotThread);
  SDL_Quit();
  exit(0);
}
コード例 #2
0
int main(int argc ,char* argv[]){
//    freopen( "CON", "wt", stdout );
//    SelfMadeBlocks(0);
    GameInitial();

    Sint32 key;
    SDL_Event gameEvent;

    MultThread = SDL_CreateThread(ThreadFunc,NULL);
    AIThread   = SDL_CreateThread(AIMain,NULL);
    while( gameOver == false ){
        //press ESC or click X to quit.
        while( SDL_PollEvent(&gameEvent) != 0 ){
            if ( gameEvent.type == SDL_QUIT ){
                gameOver = true;
            }
            if ( gameEvent.type == SDL_KEYDOWN ){
                if ( gameEvent.key.keysym.sym == SDLK_ESCAPE ){
                    gameOver = true;
                    return 0;
                }
                key = gameEvent.key.keysym.sym;
                if( key==SDLK_BACKSPACE ){
                    AIMode ^= 1;
                    Operation.ClearQ();
                    if( AIMode ){
                        Search();
                    }
                }
//                if( AIMode ){
//                    continue;
//                }
                switch( key ){
                    case SDLK_DOWN: AIPlayer.Operation.AddQ(MOVEDOWN);
                                    break;
                    case SDLK_LEFT: AIPlayer.Operation.AddQ(MOVELEFT);
                                    break;
                    case SDLK_RIGHT:AIPlayer.Operation.AddQ(MOVERIGHT);
                                    break;
                    case SDLK_UP  : AIPlayer.Operation.AddQ(ROTATE);
                                    break;
                    case SDLK_TAB : AIPlayer.Operation.AddQ(TURNNEXT);
                                    break;
                }
            }
        }
//        key = SDL_GetKeyState(NULL);                          //实现长按效果的第一个方法
//        if( key[SDLK_DOWN] )  Operation.AddQ(MOVEDOWN);
//        if( key[SDLK_LEFT] )  Operation.AddQ(MOVELEFT);
//        if( key[SDLK_RIGHT] ) Operation.AddQ(MOVERIGHT);
//        if( key[SDLK_UP] )    Operation.AddQ(ROTATE);

        SDL_Delay(1);                 //减轻CPU负担
    }
    SDL_KillThread(MultThread);
    SDL_KillThread(AIThread);
	pressESCtoQuit();
    return 0;
}
コード例 #3
0
ファイル: ChatState.cpp プロジェクト: KaSt/mojogram
void ChatState::finalize() {
	if (_instance != NULL) {
		if (_sentinelThread != NULL)
			SDL_KillThread(_sentinelThread);
		if (_reconnectThread != NULL)
			SDL_KillThread(_reconnectThread);
		delete _instance;
		_instance = NULL;
	}
}
コード例 #4
0
// the principal program sequence
void PortVideoSDL::run() {

	if( !setupCamera() ) {
		if( !setupWindow() ) return;
		showError("No camera found!");
		teardownWindow();
		return;
	}

	if( !setupWindow() ) return;

	allocateBuffers();
	initFrameProcessors();

	bool success = camera_->startCamera();

	if( success ){
		SDL_FillRect(window_,0,0);
		SDL_Flip(window_);
	
		// add the help message from all FrameProcessors
		for (frame = processorList.begin(); frame!=processorList.end(); frame++) {
                        std::vector<std::string> processor_text = (*frame)->getOptions();
			if (processor_text.size()>0) help_text.push_back("");
			for(std::vector<std::string>::iterator processor_line = processor_text.begin(); processor_line!=processor_text.end(); processor_line++) {
				help_text.push_back(*processor_line);
			} 
		}
		
		//print the help message
		for(std::vector<std::string>::iterator help_line = help_text.begin(); help_line!=help_text.end(); help_line++) {
			std::cout << *help_line << std::endl;
		} std::cout << std::endl;

		running_=true;
		cameraThread = SDL_CreateThread(getFrameFromCamera,this);
		controlThread= SDL_CreateThread(getControlMessage,this);
		mainLoop();
		
		SDL_KillThread(cameraThread);
		SDL_KillThread(controlThread);
		teardownCamera();
	} else {
		showError("Could not start camera!");
	}	

	teardownWindow();
	freeBuffers();
	
}
コード例 #5
0
ファイル: thread.cpp プロジェクト: EffWun/xoreos
bool Thread::destroyThread() {
	if (!_threadRunning)
		return true;

	// Signal the thread that it should die
	_killThread = true;

	// Wait a whole second for the thread to finish on its own
	for (int i = 0; _threadRunning && (i < 100); i++)
		SDL_Delay(10);

	if (!_threadRunning) {
		// Wait for everything to settle
		SDL_WaitThread(_thread, 0);

		_killThread    = false;
		_threadRunning = false;

		return true;
	}

	// Still running? Just kill the bugger, then
	SDL_KillThread(_thread);

	_killThread    = false;
	_threadRunning = false;

	return false;
}
コード例 #6
0
ファイル: main.cpp プロジェクト: ben401/OpenEmu
static void CloseStuff(int signum)
{
        printf(_("\nSignal %d has been caught and dealt with...\n"),signum);

	for(unsigned int x = 0; x < sizeof(SignalDefs) / sizeof(SignalInfo); x++)
	{
	 if(SignalDefs[x].number == signum)
	 {
	  printf("%s", _(SignalDefs[x].message));
	  if(SignalDefs[x].SafeTryExit)
	  {
	   SDL_Event evt;

	   memset(&evt, 0, sizeof(SDL_Event));

	   evt.user.type = SDL_QUIT;
	   SDL_PushEvent(&evt);
	   return;
	  }

	  break;
	 }
	}
        if(GameThread && SDL_ThreadID() == MainThreadID)
	{
	 SDL_KillThread(GameThread);
	 GameThread = NULL;
	}
        exit(1);
}
コード例 #7
0
ファイル: NetClient.cpp プロジェクト: Raptor007/RaptorEngine
NetClient::~NetClient()
{
	Connected = false;
	
	// Sleep until the other thread has finished (max 4 sec).
	Clock wait_for_thread;
	while( Thread && (wait_for_thread.ElapsedSeconds() < 4.) )
		SDL_Delay( 1 );
	
	// If the thread didn't finish, kill it.
	if( Thread )
	{
		SDL_KillThread( Thread );
		Thread = NULL;
	}
	
	// Clean up old data and socket.
	Cleanup();
	
	if( Lock )
	{
		SDL_DestroyMutex( Lock );
		Lock = NULL;
	}
	
	if( Initialized )
		SDLNet_Quit();
}
コード例 #8
0
int receiveMessages(void* socka)
{	int len;
	char message[1024];
	UDPsoc sock = *(UDPsoc*)(socka);
	
	while(1)
	{	len=sock.Recv(message, 1024); 
		if(len) 
		{	for(int n=0; n<onTheTable_len; n++)
				printf("\b");
			for(int n=0; n<onTheTable_len; n++)
				printf(" ");	
			printf("\rReceiving: %s\n", message); 
			if(onTheTable_len)
			{	for(int n=0; n<onTheTable_len; n++)
					printf("%c",onTheTable[n]);
				onTheTable_len=0;
			}
		} else 
		{	printf("AIR OR\n"); 
		} 
		if(message[0]=='e' && message[1]=='n' && message[2]=='d' && message[3]==0)
		{	out=1;
			break;
		}
	}
	printf("\tConnection has been closed from the other side. Press enter to quit.\n");
	SDL_KillThread(sendThread);
}
コード例 #9
0
int sendMessages(void* socka)
{	int len, temp, n;
	char message[1024];
	UDPsoc sock = *(UDPsoc*)(socka);
	
	while(1)
    {	if(khit())
		{	printf("Send: ");
			onTheTable_len=6;
			for(n=0; (temp=gech())!='\n'; n++)
	        {	if(temp == '\b')
				{	n-=2;
					onTheTable_len--;
				}
				else
				{	message[n]=temp;
		        	onTheTable[6+n] = temp;
		        	onTheTable_len++;
				}
			}
			message[n]=0;			
			onTheTable_len=0;
			
	        //send message to client 
		    if(sock.Send(message,n+1)) 
		    	printf("\t\tEr ur\n"); 
		    
		    if(message[0]=='e' && message[1]=='n' && message[2]=='d' && message[3]==0)
		    	break;
		}
		SDL_Delay(10);
	}
	printf("Connection has been closed (by you). Press enter to quit.\n");
	SDL_KillThread(recvThread);
}
コード例 #10
0
ファイル: clientconnection.cpp プロジェクト: FrimJo/WolfSheep
ClientConnection::~ClientConnection()
{
	// Signal to stop
	status = -1;
	SDL_WaitThread(send_thread, NULL);

	// We don't need to lock because the send_thread is terminated
	while (data_to_send.size() > 0)
	{
		delete data_to_send.front().data;
		data_to_send.pop_front();
	}

	// make sure we don't trash messages when killing the thread.
	SDL_LockMutex(messages_mutex);
	SDL_KillThread(recieve_thread);
	SDL_UnlockMutex(messages_mutex);

	SDLNet_TCP_Close(socket);

	SDL_DestroyMutex(send_mutex);
	SDL_DestroyMutex(messages_mutex);

	// Remove this client from the world
	//entity->world->delete_entity(entity);
	//entity = 0;
}
コード例 #11
0
ファイル: BGApp.cpp プロジェクト: KaSt/mojogram
void BGApp::finalize() {
    SDL_mutexP(this->_mutex);
    if (this->_initialized) {
        if (this->_xmpprunner != NULL && this->_xmpprunner->_connection != NULL) {
            try {
                this->_xmpprunner->_connection->sendClose();
            } catch (exception& ex) {
                _LOGDATA("Error sending BGApp::finalize:sendingClose: %s", ex.what());
            }
        }
        if (this->_xmpprunner != NULL)
            this->_xmpprunner->killWithConfirmation();

        SDL_KillThread(this->_xmppthread);

        ChatState::finalize();

        if (this->_xmpprunner != NULL)
            delete _xmpprunner;

        this->_lastXMPPRunnerKill = time(NULL);
        this->_chatState = NULL;
        this->_xmpprunner = NULL;
        this->_initialized = false;
    }
    SDL_mutexV(this->_mutex);
}
コード例 #12
0
void thread::kill()
{
	if(thread_ != NULL) {
		SDL_KillThread(thread_);
		thread_ = NULL;
	}
}
コード例 #13
0
ファイル: midi-core.c プロジェクト: CharlesLio/schismtracker
void midi_engine_stop(void)
{
        struct midi_provider *n, *p;
        struct midi_port *q;

        if (!_connected) return;
        if (!midi_mutex) return;

        SDL_mutexP(midi_mutex);
        for (n = port_providers; n;) {
                p = n->next;

                q = NULL;
                while (midi_port_foreach(p, &q)) {
                        midi_port_unregister(q->num);
                }

                if (n->thread) {
                        SDL_KillThread(n->thread);
                }
                free(n->name);
                free(n);
                n = p;
        }
        _connected = 0;
        SDL_mutexV(midi_mutex);
}
コード例 #14
0
ファイル: logmill.cpp プロジェクト: DavidSimons/Gource
RLogMill::~RLogMill() {

    abort();

    if(thread) SDL_KillThread(thread);
    if(clog) delete clog;
}
コード例 #15
0
ファイル: threads.cpp プロジェクト: Salamek/Shadow-of-Dust
/*
==================
Sys_ShutdownThreads
==================
*/
void Sys_ShutdownThreads() {
	// threads
	for (int i = 0; i < MAX_THREADS; i++) {
		if (!thread[i])
			continue;

		Sys_Printf("WARNING: Thread '%s' still running\n", thread[i]->name);
		SDL_KillThread(thread[i]->threadHandle);
		thread[i] = NULL;
	}

	// events
	for (int i = 0; i < MAX_TRIGGER_EVENTS; i++) {
		SDL_DestroyCond(cond[i]);
		cond[i] = NULL;
		signaled[i] = false;
		waiting[i] = false;
	}

	// critical sections
	for (int i = 0; i < MAX_CRITICAL_SECTIONS; i++) {
		SDL_DestroyMutex(mutex[i]);
		mutex[i] = NULL;
	}
}
コード例 #16
0
ファイル: player_space.c プロジェクト: kyeah/VizChat
int main(int argc, char** argv){
  if(!argv[1]){
    puts("No IP input found. Please initiate in the form ' ./Player <Server IP> '");
    exit(1);
  }

  //fgets from stdin to get clientname (and pass that into run, ezpz)
  printf("Please enter your name: ");

  fgets(clientname, 64, stdin);
  clientname[strlen(clientname) - 1] = '\0';

  printf("Hello %s!\n", clientname);

  strcat(clientname, " : ");
  namelen = strlen(clientname);
  ///


  SDL_Surface* screen = initScreen(); 

  //Initiate the semaphores and chatserver thread
  msgbuf_sem = SDL_CreateSemaphore(1);
  textSem = SDL_CreateSemaphore(1);
  chatserv = SDL_CreateThread(chatserver, screen);


  //Initiate the server connection
  int socket_id = server_setup(argv[1]);
    
  
  //Initiate the client's sprite
  Uint32 colorkey = SDL_MapRGB( screen->format, 255, 255, 255);
  initiate(socket_id, colorkey); 



  TTF_Init();
  run(screen, socket_id);


  //CEASE AND DESIST

  SDL_KillThread(chatserv);

  SDL_FreeSurface(screen);
  SDL_Quit();
  TTF_Quit();

  int i;
  for(i=0; i<numMessages; i++)
    if(text[i] != NULL)
      SDL_FreeSurface(text[i]);

  SDL_DestroySemaphore(msgbuf_sem);
  SDL_DestroySemaphore(textSem);

  return 1;
}
コード例 #17
0
ファイル: main.c プロジェクト: kissthink/notes
void chess_exit(struct chess_t *chess)
{
    SDL_KillThread(chess->conn);
    free(chess->packet);
    free(chess->cli_list);
    close(chess->fd);
    sdl_exit(&chess->sdl);
}
コード例 #18
0
ファイル: main.cpp プロジェクト: lucasgautheron/orbit
void callback_quit()
{
    TTF_Quit();
    glDeleteTextures( 1, &buttons_tex );
    SDL_KillThread(compute_thread);
    SDL_Quit();
    exit(EXIT_SUCCESS);
}
コード例 #19
0
ファイル: KikiPlayback.cpp プロジェクト: Mistress-Anna/kiki
// __________________________________________________________________________________________________
void KikiPlayback::start (const std::string filename)
{
    static std::vector<KikiKeyRecord*> key_records;
    std::string record_string;
    record_string = kFileReadStringFromFile (filename);
    std::vector<std::string> lines = kStringGetComponents (record_string, "\n");
    std::vector<std::string>::iterator iter;

    if (thread) SDL_KillThread (thread);
    key_records.clear();

    iter = lines.begin();
    std::string world_name = (*iter).substr ((*iter).find (":") + 2);
    if (world_name != Controller.world->getName())
    {
        Controller.python->execute (kStringPrintf ("KikiPyWorld().create (\"%s\")",
                                    world_name.substr (0,world_name.size()-1).c_str())); // hack alert!
    }
    iter++;

    Controller.world->setCameraMode (atoi ((*iter).substr ((*iter).find (":") + 2).c_str()));
    iter++;

    unsigned int open  = (*iter).find("[")+1;
    unsigned int close = (*iter).find("]");

    std::vector<std::string> values = kStringGetComponents ((*iter).substr(open, close-open), " ");
    KikiPos pos (atoi(values[0].c_str()), atoi(values[1].c_str()), atoi(values[2].c_str()));
    Controller.world->moveObjectToPos (Controller.player, pos);
    iter++;

    open = (*iter).find("<")+1;
    close = (*iter).find(">");
    values = kStringGetComponents ((*iter).substr(open, close-open), " ");
    KQuaternion orientation (atof(values[0].c_str()), atof(values[1].c_str()),
                             atof(values[2].c_str()), atof(values[3].c_str()));
    Controller.player->setOrientation (orientation);
    iter++;

    for (; iter != lines.end(); iter++)
    {
        if (iter->empty() == false)
        {
            if (iter->find("world:") == 0)
            {
                next_world = (*iter).substr ((*iter).find (":") + 2);
            }
            else
            {
                std::vector<std::string> v = kStringGetComponents ((*iter), " ");
                key_records.push_back (new KikiKeyRecord (atoi(v[0].c_str()), v[1], atoi(v[2].c_str())));
            }
        }
    }

    halt = false;
    thread = SDL_CreateThread (KikiPlayback::playback, &key_records);
}
コード例 #20
0
ファイル: thread-sdl.c プロジェクト: a-martinez/rockbox
void remove_thread(unsigned int thread_id)
#endif
{
    struct thread_entry *current = cores[CURRENT_CORE].running;
    struct thread_entry *thread = thread_id_entry(thread_id);

    SDL_Thread *t;
    SDL_sem *s;

    if (thread_id != THREAD_ID_CURRENT && thread->id != thread_id)
        return;

    int oldlevel = disable_irq_save();

    t = thread->context.t;
    s = thread->context.s;
    thread->context.t = NULL;

    if (thread != current)
    {
        switch (thread->state)
        {
        case STATE_BLOCKED:
        case STATE_BLOCKED_W_TMO:
            /* Remove thread from object it's waiting on */
            remove_from_list_l(thread->bqp, thread);

#ifdef HAVE_WAKEUP_EXT_CB
            if (thread->wakeup_ext_cb != NULL)
                thread->wakeup_ext_cb(thread);
#endif
            break;
        }

        SDL_SemPost(s);
    }

    THREAD_SDL_DEBUGF("Removing thread: %d (%s)\n",
        thread - threads, THREAD_SDL_GET_NAME(thread));

    new_thread_id(thread->id, thread);
    thread->state = STATE_KILLED;
    thread_queue_wake(&thread->queue);

    SDL_DestroySemaphore(s);

    if (thread == current)
    {
        /* Do a graceful exit - perform the longjmp back into the thread
           function to return */
        restore_irq(oldlevel);
        longjmp(thread_jmpbufs[current - threads], 1);
    }

    SDL_KillThread(t);
    restore_irq(oldlevel);
}
コード例 #21
0
ファイル: rj_interface.c プロジェクト: luqmana/RemoteJoyPlus
void rj_interface_cleanup() {
	
	if (rj_reader_thread)
		SDL_KillThread(rj_reader_thread);

	if (rj_sock >= 0)
		close(rj_sock);

}
コード例 #22
0
ファイル: serverbrowser.cpp プロジェクト: r-lyeh-forks/mini.q
static void resolverstop(ResolverThread &rt, bool restart) {
  SDL_LockMutex(resolvermutex);
  SDL_KillThread(rt.thread);
  rt.query = NULL;
  rt.starttime = 0;
  rt.thread = NULL;
  if (restart) rt.thread = SDL_CreateThread(resolverloop, &rt);
    SDL_UnlockMutex(resolvermutex);
}
コード例 #23
0
ファイル: t4k_tts.c プロジェクト: Nalin-x-Linux/t4kcommon
//Stop the speech if it is speaking
void T4K_Tts_stop(){
	extern SDL_Thread *tts_thread;
	if (tts_thread)
	{
		SDL_KillThread(tts_thread);
		tts_thread = NULL;
		espeak_Cancel();
	}
}
コード例 #24
0
ServerConsole::~ServerConsole()
{
    if(thread && running) {
        // TODO avoid KillThread here...
        SDL_KillThread(thread);
    } else {
        SDL_WaitThread(thread, 0);
    }
}
コード例 #25
0
ファイル: StartState.cpp プロジェクト: kalxas/OpenXcom
/**
 * Kill the thread in case the game is quit early.
 */
StartState::~StartState()
{
	if (_thread != 0)
	{
		SDL_KillThread(_thread);
	}
	delete _font;
	delete _timer;
	delete _lang;
}
コード例 #26
0
ファイル: ChatState.cpp プロジェクト: KaSt/mojogram
ChatState* ChatState::initialize() {
	if (_instance != NULL) {
		if (_sentinelThread != NULL)
			SDL_KillThread(_sentinelThread);
		if (_reconnectThread != NULL)
			SDL_KillThread(_reconnectThread);
		delete _instance;
	}

	ChatState* curState = new ChatState();
	curState->setState(ChatState::CHAT_STATE_DISCONNECTED);
	_instance = curState;
	if (SEND_PING) {
		_sentinelThread = SDL_CreateThread(ChatState::sentinelTaskCallBack, (void*) ((Uint32) (MAX_SILENT_INTERVAL * 1000)));
		if (_sentinelThread == NULL)
			_LOGDATA("Error adding timer sentinelTask");
	}
	return curState;
}
コード例 #27
0
void SDLThread::end()
{
	if (_handle != NULL){
		_isRunning = false;

		// kill the thread
		SDL_KillThread(_handle);

		_handle = NULL;
	}
}
コード例 #28
0
ファイル: client.cpp プロジェクト: rasmusgo/Emergence
    Client::~Client()
    {
        if (listener_thread != 0)
            SDL_KillThread(listener_thread);

        // close the connection on sock
        SDLNet_TCP_Close(sock);

        if (mutex != 0)
            SDL_DestroyMutex(mutex);
    }
コード例 #29
0
ファイル: hmiplay.c プロジェクト: paud/d2x-xl
void seqbuf_dump()
{
	if (_seqbufptr)
	{
		if (write(seqfd, _seqbuf, _seqbufptr) == -1)
		{
			perror ("Error writing sequencer device");
			SDL_KillThread(player_thread);
		}
	}
	_seqbufptr = 0;
}
コード例 #30
0
ファイル: z64mv.c プロジェクト: kholdfuzion/vg64tools
/*
** Destroy a model viewing context
*/
void z64mv_destroy ( Z64MV * handle )
{	
	/* Free pointers */
	pfree( (void**)&handle->contents );
	pfree( (void**)&handle->filename );
	
	/* End the thread */
	SDL_KillThread( handle->proc );
	
	/* Free the context */
	free( handle );
}