コード例 #1
0
ファイル: creeping.cpp プロジェクト: ror13/diplom
void * Creeping::
redraw_window(void * _this)
{
	DEBUG_PRINT_LINE;
	Creeping * self = (Creeping *) _this;
	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
	
	pthread_cleanup_push(&Creeping::exit_redraw_window, _this);
	int current_pos = 0;
	int window_x, window_y, window_width, window_height;
	self->mutex.lock();
	CTimer  timer;
	timer.set_interval(1000000/self->conf.get_conf()->ScrollingSpeed);
	self->wnd->open(&self->conf);
	self->wnd->get_current_rect(&window_x, &window_y, &window_width, &window_height);
	self->init();
	self->wnd->draw();
	timer.start();
	self->mutex.unlock();
	
	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
	
	for(;;)
	{
		pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
		
		self->mutex.lock();

		self->wnd->clear();
		
		CSurface  * logo = self->wnd->get_logo();
		std::vector<CSurface*> * surfaces =  self->wnd->get_surfaces();
		std::vector<CSurface*>::iterator i = surfaces->begin();
		current_pos = timer.get_val();
		int length = window_width - current_pos;
		if(!surfaces->empty() &&  (current_pos - (*i)->get_width()) > window_width)
		{
			
			timer.offset( (*i)->get_width());
			length += (*i)->get_width();
			delete (*i);
			surfaces = self->wnd->get_surfaces();
		}
		for (i = surfaces->begin(); i != surfaces->end(); i++)
		{
			(*i)->draw(length);
			length += (*i)->get_width() ;
			if(length > window_width)
				break;
		}
		
		if(logo != NULL)
			logo->draw(0);

		self->wnd->draw();

		self->mutex.unlock();
		
		pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
		pthread_testcancel();
		if(surfaces->empty() && self->is_once)
			pthread_exit(NULL);
		
		if(surfaces->empty() && self->is_once == false)
		{
			self->init();
			timer.set_val(0);
		}
	}
	pthread_cleanup_pop(0);
	DEBUG_PRINT_LINE;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: NoahKlabo/Seizure-Ships
int main(int argc, char *argv[])
{
 init(); //init SDL
 g_CWindow.SSurface = SDL_SetVideoMode( WIDTH , HEIGHT , 32 , SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_ANYFORMAT); //assign surface 
 g_pCMenu          = MD2Model::load("menu.md2");
 g_SPlayer.pCModel = MD2Model::load("player.md2");
 g_SPlayer.pCLaser = MD2Model::load("laser.md2");
 g_pCLoop          = MD2Model::load("loop.md2");

 Uint32 u32Start;
 while (g_bRunning)
 {
   u32Start = SDL_GetTicks(); //Get the tick this cycle started on

  
  if(g_dAngle>360)
    g_dAngle = 0;
  if(g_dAngle < 0 )
    g_dAngle = 360;
 
  control(); //get user input
  if(!g_bStart)
     draw_menu(); //Draw 'Seizure Ships!
  else
      if(!lost) 
      game(); //Update game status
	  else
	      lose();
 if(!lost) {
   if(g_bThreadVisualization) {  //Shows triangles drawn by each thread
     g_CWindow.draw_text("Work thread 1",0,24*2,RED);
	 g_CWindow.draw_text("Work thread 2",0,24*3,GREEN);
	 g_CWindow.draw_text("Work thread 3",0,24*4,BLUE);
	 g_CWindow.draw_text("Work thread 4",0,24*5,CYAN);
	 g_CWindow.draw_text("Work thread 5",0,24*6,PURPLE);
	 g_CWindow.draw_text("Work thread 6",0,24*7,YELLOW);
	 g_CWindow.draw_text("Press 'v' to disable Thread Visualization mode",0,24*19,WHITE);
	 
   }
   else {
         g_CWindow.draw_text("Press 'v' to enable Thread Visualization mode",0,24*19,WHITE);
	   }
  g_CWindow.draw_text("Press 'p' to pause",0,24*17,WHITE);	   
  g_CWindow.draw_text("Controls: ARROWS to move and ENTER to fire",0,24*18,WHITE);
   backdrop(); //Draw our g_pCLoop backdrop
  }
  if((g_bRestart)&&(lost)) { //you suck at this game
     thread a(system,"start.exe");
	 SDL_Delay(100); //Give system enough time to execute new instance
	 exit(0);
	}
	else
	    g_bRestart = false;
		
  g_CWindow.draw(); //Update screen
  if(1000/60>(SDL_GetTicks()-u32Start)) //Always keep constant framerate (60fps)
    SDL_Delay(1000/60-(SDL_GetTicks()-u32Start)); 
 }
 
return 0;
}