예제 #1
0
파일: post.c 프로젝트: knusbaum/Wily
void
nDeliver(rdWin *w, nGroup *g, int first, int last, char *arg)
{
	nWin *nw;
	char *filename = tmpnam((char *)0);

	assert(w);
	assert(w->userp);
	assert(filename);
	DPRINT("Delivering message");
	if ((nw = findNWin(w->userp)) == 0) {
		DPRINT("Couldn't find associated composition window - aborting");
		return;
	}
	if (nw->kind != nCompArt) {
		DPRINT("Deliver not applied to composition window - ignored");
		return;
	}
	rdBodyToFile(w, filename);
	if (nw->isrep)
		dodeliver(w,filename);
	if (nw->ispost)
		nntpPost(filename);
	(void)remove(filename);
	DPRINT("Deliver done");
	closeWin(w);
	freeNWin(nw);
	return;
}
예제 #2
0
void MyVis::popupMenu()
{
	p.clear();
	p.addAction( "Zamknij",this,SLOT(closeWin()));
	p.addAction( "Wyłącz",this,SLOT(turnOff()));
	p.addSeparator();
	if ( !okienko )
	{
		fsAct->setChecked( isFullScreen() );
		p.addAction( fsAct );
		p.addSeparator();
	}
	if ( okienko )
	{
		p.addAction( "Odłącz od QMPlay",this,SLOT(odlacz()));
		p.addSeparator();
	}
	else if ( okienkoParent != NULL && okno )
	{
		p.addAction( "Podłącz do QMPlay",this,SLOT(podlacz()));
		p.addSeparator();
	}
	p.addAction( "Opcje",this,SLOT(_opcje()));
	p.popup( QCursor::pos() );
}
예제 #3
0
파일: reader.c 프로젝트: knusbaum/Wily
static void
DelWin(rdWin *w, char *arg)
{
	assert(w);
	user_delWin(w);
	closeWin(w);
}
예제 #4
0
파일: post.c 프로젝트: knusbaum/Wily
void
nAbort(rdWin *w, nGroup *g, int first, int last, char *arg)
{
	nWin *nw;

	assert(w);
	assert(w->userp);
	DPRINT("Aborting reply/comp");
	if ((nw = findNWin(w->userp)) == 0) {
		DPRINT("Can't find associated window - aborting abort");
		return;
	}
	if (nw->kind != nCompArt) {
		DPRINT("Abort isn't applied to a composition window - ignoring");
		return;
	}
	fprintf(stderr,"Message aborted\n");
	closeWin(w);
	freeNWin(nw);
	DPRINT("Abort done");
	return;
}
예제 #5
0
파일: mandel.c 프로젝트: siderisng/prog3
int main(int argc, char *argv[]) {
	mandelPars pars;
	int i,k,x,y,level,*res,check;
	int xoff,yoff, thrCheck;
	long double reStep,imStep;
	Toolbox **Tool;
	pthread_t *thrP;
	
	printf("\n");
	printf("This program starts by drawing the default Mandelbrot region\n");
	printf("When done, you can click with the mouse on an area of interest\n");
	printf("and the program will zoom at this point\n");
	printf("\n");
	printf("Press enter to continue\n");
	getchar();
	
	pars.rePixels = WinW; /* never changes */
	pars.imPixels = WinH; /* never changes */
	
	/* default mandelbrot region */
	
	pars.reBeg = (long double) -2.0;
	pars.reEnd = (long double) 1.0;
	pars.imBeg = (long double) -1.5;
	pars.imEnd = (long double) 1.5;
	
	reStep = (pars.reEnd - pars.reBeg) / pars.rePixels;
	imStep = (pars.imEnd - pars.imBeg) / pars.imPixels;
	
	printf("enter max iterations (50): ");
	scanf("%d",&pars.maxIterations);
	printf("enter no of slices: ");
	scanf("%d",&pars.slices);
	
	/* adjust slices to divide win height */
	
	while (WinH % pars.slices != 0) { pars.slices++;}
	
	/* allocate result and ready arrays */
	
	res = (int *) malloc(sizeof(int)*pars.rePixels*pars.imPixels);
	
	
	/* open window for drawing results */
	
	openDisplay();
	openWin(argv[0], WinW, WinH);
	
	
	level = 1;
	
	if (NULL== (Tool=(Toolbox**)malloc(sizeof(Toolbox)*pars.slices))){
		perror ("Memory Error");
	}
	
	
	
	for (i=0; i<pars.slices; i++){
		
		if (NULL== (Tool[i]=(Toolbox*)malloc(sizeof(Toolbox)*pars.slices))){
			perror ("Memory Error");
		}
		
		
		
		if (NULL==(Tool[i]->mand=(mandelPars*)malloc(sizeof(mandelPars)))){
			
			perror ("Memory error");
		}
		Tool[i]->mand=&pars;
		
		
		
		
		if (NULL==(Tool[i]->res=(int*)malloc(sizeof(int)))){
			perror ("Memory error");
		}
		Tool[i]->res= res;
		Tool[i]->count=i;
		Tool[i]->rd=-1;	
		
		
		
		
		
		if (NULL== (thrP=(pthread_t*)malloc(sizeof(pthread_t)*pars.slices))){
			perror ("Memory Error");
		}
		thrCheck = pthread_create( &thrP[i], NULL,calcMandel , (void *)Tool[i]);
		if(thrCheck)
		{
			fprintf(stderr,"Error - pthread_create() return code: %d\n",thrCheck);
			exit(EXIT_FAILURE);
		}
		
	}
	
	
	while (1) {
		
		clearWin();
		
		printf("computing for level %d:\n",level);
		printf("reBeg=%Lf reEnd=%Lf reStep=%Lf\n",pars.reBeg,pars.reEnd,reStep);
		printf("imBeg=%Lf imEnd=%Lf imStep=%Lf\n",pars.imBeg,pars.imEnd,imStep);
		printf("maxIterations=%d\n",pars.maxIterations);
		
		
		for (i=0; i<pars.slices; i++) { 
			Tool[i]->level=&level;
			Tool[i]->rd=0;
			
		}
		
		
		
		/* busywait (and draw results) until all slices done */
		
		k=0;
		while (k!=pars.slices) {
			for (i=0; i<pars.slices; i++) {
				
				while (Tool[i]->rd!=1){
					if (0!=(check= sched_yield())){
						perror ("Thread");
					}
					
				}
					
					for (y=i*(pars.imPixels/pars.slices); y<(i+1)*(pars.imPixels/pars.slices); y++) {
						
						for (x=0; x<pars.rePixels; x++) {
							setColor(pickColor(res[y*pars.rePixels+x],pars.maxIterations));
							drawPoint(x,y);
							
						}
					}
					
					k++; Tool[i]->rd=2;
			}
		}
		
		
		/* get next focus/zoom point */
		
		
		
		getMouseCoords(&x,&y);
		xoff = WinW/2 - x;
		yoff = WinH/2 - (WinH-y);
		
		/* adjust focus */
		
		pars.reBeg = pars.reBeg - xoff*reStep;
		pars.reEnd = pars.reBeg + reStep*pars.rePixels;
		pars.imBeg = pars.imBeg - yoff*reStep;
		pars.imEnd = pars.imBeg + reStep*pars.imPixels;
		
		/* zoom in */
		
		reStep = reStep*ZoomStepFactor; 
		imStep = imStep*ZoomStepFactor;
		pars.reBeg = pars.reBeg + (pars.reEnd-pars.reBeg)/2 - reStep*pars.rePixels/2;
		pars.reEnd = pars.reBeg+reStep*pars.rePixels;
		pars.imBeg = pars.imBeg + (pars.imEnd-pars.imBeg)/2 - imStep*pars.imPixels/2;
		pars.imEnd = pars.imBeg+imStep*pars.imPixels;
		pars.maxIterations = pars.maxIterations*ZoomIterationFactor;
		
		level++;
		
	} 
	
	/* never reach this point; for cosmetic reasons */
	
	free(res);
	
	
	closeWin();
	closeDisplay();
	
}
예제 #6
0
파일: main.c 프로젝트: BrankaPekez/MY_GAME
int main(int argc, char* args[])
{
		srand(time(NULL));
		PLAYER* player = createPlayer();
		BACKGROUND* background = createBackground();

    LTexture lt;
		BANANA* bananaArray[MAX_NUM_OF_BANANA];
		BARRIER* barrierArray[MAX_NUM_OF_BARRIER];

		int i;
		for(i = 0; i < MAX_NUM_OF_BANANA; i++)
		{
				bananaArray[i] = createBanana();
		}

		for(i = 0; i < MAX_NUM_OF_BARRIER; i++)
		{
				barrierArray[i] = createBarrier();
		}


		if( !init() )
		{
			printf( "Failed to initialize!\n" );
		}
		else
		{

			if( !loadBackground("./media/background.png", &background->background_tex, gRenderer) || !loadPlayer("./media/minion.png", &player->player_tex, gRenderer, gSpriteClips))
			{
      	printf( "Failed to load media!\n" );
			}
			else
			{
				for(i = 0; i < MAX_NUM_OF_BANANA; i++)
				{
						loadBanana("./media/banana.png", &bananaArray[i]->banana_tex, gRenderer);
						setPosRectBanana(bananaArray[i]);
				}

				for(i = 0; i < MAX_NUM_OF_BARRIER; i++)
				{
						loadBarrier("./media/barrier.png", &barrierArray[i]->barrier_tex, gRenderer);
						setPosRectBarrier(barrierArray[i]);
				}

				bool quit = false;
				SDL_Event e;
				player->frame = 0;
				background->scrollingOffset = 0;

				while( !quit )
				{
					while( SDL_PollEvent( &e ) != 0 )
					{
						if( e.type == SDL_QUIT )
						{
							quit = true;
						}

						if(e.key.type == SDL_KEYDOWN)
						{
							switch( e.key.keysym.sym )
							{
									case SDLK_UP:
										if(canMoveUp(player))
										{
											moveUp(player);
										}
										 break;
									case SDLK_DOWN:
										if(canMoveDown(player))
										{
											moveDown(player);
										}
										break;
							}
						}


					}

					--(background->scrollingOffset);
					if( background->scrollingOffset < -background->background_tex.mWidth )
					{
						background->scrollingOffset = 0;
					}

					SDL_Rect* currentClip;

					SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
					SDL_RenderClear( gRenderer );
					renderBackground(background, background->scrollingOffset, gRenderer);

					currentClip = &gSpriteClips[ player->frame / 16 ];
					renderPlayer(player, currentClip, gRenderer);
					setPosRectPlayer(player);

					for (i = 0; i < MAX_NUM_OF_BANANA; i++)
					{
						if( checkCollision(player->mPlayer, bananaArray[i]->mBanana, background->scrollingOffset))
						{
							increaseTotalScore();
							eraseBanana(bananaArray[i]);
						}

						renderBanana(bananaArray[i], background->scrollingOffset + bananaArray[i]->posX, gRenderer);
					}



					for (i = 0; i < MAX_NUM_OF_BARRIER; i++)
					{
						if( checkCollisionEnd(player->mPlayer, barrierArray[i]->mBarrier, background->scrollingOffset))
						{
							closeWin(player, background, bananaArray, barrierArray);
							return 0;
						}

						renderBarrier(barrierArray[i], background->scrollingOffset + barrierArray[i]->posX, gRenderer);
					}



					++player->frame;

					if( player->frame / 4 >= WALKING_ANIMATION_FRAMES )
					{
						player->frame = 0;
					}


					SDL_RenderPresent(gRenderer);


				}
					closeWin(player, background, bananaArray, barrierArray);

			}
		}
		return 0;
}
예제 #7
0
파일: mandelGUI.c 프로젝트: angkyria/CE326
int main(int argc, char *argv[]) {
  mandel_Pars pars;
  int i, j, x, y, k, nofslices, level, thread_status;
  int xoff,yoff;
  long double reEnd,imEnd,reCenter,imCenter;
  pthread_t *thread_workers;

  printf("\n");
  printf("This program starts by drawing the default Mandelbrot region\n");
  printf("When done, you can click with the mouse on an area of interest\n");
  printf("and the program will automatically zoom around this point\n");
  printf("\n");
  printf("Press enter to continue\n");
  getchar();

  pars.reSteps = WinW; /* never changes */
  pars.imSteps = WinH; /* never changes */

  /* default mandelbrot region */

  pars.reBeg = (long double) -2.0;
  reEnd = (long double) 1.0;
  pars.imBeg = (long double) -1.5;
  imEnd = (long double) 1.5;
  pars.reInc = (reEnd - pars.reBeg) / pars.reSteps;
  pars.imInc = (imEnd - pars.imBeg) / pars.imSteps;

  printf("enter max iterations (50): ");
  scanf("%d",&maxIterations);
  printf("enter no of slices: ");
  scanf("%d",&nofslices);

  /* adjust slices to divide win height */

  while (WinH % nofslices != 0) { nofslices++;}

  /* allocate slice parameter and result arrays */

  slices = (mandel_Pars *) malloc(sizeof(mandel_Pars)*nofslices);
  res = (int *) malloc(sizeof(int)*pars.reSteps*pars.imSteps);


  //workers init
  thread_workers = (pthread_t*)malloc(sizeof(pthread_t)*nofslices);
  work_status=(int *)malloc(sizeof(int)*nofslices);
  for(i=0;i<nofslices;i++)work_status[i]=-1;
  for(i=0;i<nofslices;i++){
      thread_status=pthread_create(&thread_workers[i], NULL, workers, (void*)(intptr_t)i);
      if(thread_status){
          perror("Fail create thread\n");
          exit(1);
      }
  }

  /* open window for drawing results */

  openDisplay();
  openWin(argv[0], WinW, WinH);

  level = 1;

  while (1) {

    clearWin();

    mandel_Slice(&pars,nofslices,slices);

    for(i=0;i<nofslices;i++)work_status[i]=0;

    i=0;
    y=0;
    while(i<nofslices){

        for(k=0;work_status[k]!=1;k++)if((k+1)==nofslices)k=-1;

        for(i++, work_status[k]=2, j=0;j<slices[k].imSteps;j++,y++){
            for(x=0;x<slices[k].reSteps;x++){
                setColor(pickColor(res[y*slices[k].reSteps+x],maxIterations));
                drawPoint(x, y);
            }
        }

        printf("thread no. %d finish draw\n", k);

    }

    /* get next focus/zoom point */

    getMouseCoords(&x,&y);
    xoff = x;
    yoff = WinH-y;

    /* adjust region and zoom factor  */

    reCenter = pars.reBeg + xoff*pars.reInc;
    imCenter = pars.imBeg + yoff*pars.imInc;
    pars.reInc = pars.reInc*ZoomStepFactor;
    pars.imInc = pars.imInc*ZoomStepFactor;
    pars.reBeg = reCenter - (WinW/2)*pars.reInc;
    pars.imBeg = imCenter - (WinH/2)*pars.imInc;

    maxIterations = maxIterations*ZoomIterationFactor;
    level++;

  }

  /* never reach this point; for cosmetic reasons */

  free(work_status);
  free(thread_workers);
  free(slices);
  free(res);

  closeWin();
  closeDisplay();

}