Esempio n. 1
0
/**
 * Adds the element to the configuration.
 *
 * @pre configCanHandle(element) == true
 * @post (display of same name already loaded) ==> old display closed, new one opened<br>
 *       (display is new) ==> (new display is added)<br>
 *       Draw Manager is notified of the display change.
 */
bool DisplayManager::configAddDisplay(jccl::ConfigElementPtr element)
{
   vprASSERT(configCanHandle(element)); // We must be able to handle it first of all

   vprDEBUG_BEGIN(vrjDBG_DISP_MGR,vprDBG_STATE_LVL) << "------- DisplayManager::configAddDisplay -------\n" << vprDEBUG_FLUSH;

   // Find out if we already have a window of this name
   // If so, then close it before we open a new one of the same name
   // This basically allows re-configuration of a window
   DisplayPtr cur_disp = findDisplayNamed(element->getName());
   if (cur_disp != NULL)                         // We have an old display
   {
      vprDEBUG(vrjDBG_DISP_MGR,vprDBG_CONFIG_LVL) << "Removing old window: " << cur_disp->getName().c_str() << vprDEBUG_FLUSH;
      closeDisplay(cur_disp,true);              // Close the display and notify the draw manager to close the window
   }

   // --- Add a display (of the correct type) ---- //
   if (element->getID() == std::string("display_window"))       // Display window
   {
      DisplayPtr newDisp = Display::create();      // Create the display
      newDisp->config(element);
      addDisplay(newDisp,true);                    // Add it
      vprDEBUG(vrjDBG_DISP_MGR,vprDBG_STATE_LVL) << "Adding display: " << newDisp->getName().c_str() << std::endl << vprDEBUG_FLUSH;
      vprDEBUG(vrjDBG_DISP_MGR,vprDBG_STATE_LVL) << "Display: "  << newDisp << std::endl << vprDEBUG_FLUSH;
   }

   vprDEBUG_END(vrjDBG_DISP_MGR,vprDBG_STATE_LVL) << "------- DisplayManager::configAddDisplay Done. --------\n" << vprDEBUG_FLUSH;
   return true;
}
Esempio n. 2
0
DeviceGraphicsDX11Renderer::~DeviceGraphicsDX11Renderer (void)
{
	closeDisplay();

    SAFE_RELEASE(_vertices);
    SAFE_RELEASE(_normals);
    SAFE_RELEASE(_texcoords1);
    SAFE_RELEASE(_texcoords2);
    SAFE_RELEASE(_colors);
}
    int DisplayDispatcher::setDispProp(int cmd,int param0,int param1,int param2)
    {
        switch(cmd)
        {
            case  DISPLAY_CMD_SETDISPPARA:
                return  setDisplayParameter(param0,param1,param2);

            case  DISPLAY_CMD_CHANGEDISPMODE:
                return  changeDisplayMode(param0,param1,param2);

            case  DISPLAY_CMD_CLOSEDISP:
                return  closeDisplay(param0);

            case  DISPLAY_CMD_OPENDISP:
                return  openDisplay(param0);

            case  DISPLAY_CMD_GETDISPCOUNT:
                return  getDisplayCount();

            case DISPLAY_CMD_GETDISPLAYMODE:
                return  getDisplayMode();

            case DISPLAY_CMD_GETDISPPARA:
                return  getDisplayParameter(param0,param1);

            case DISPLAY_CMD_GETHDMISTATUS:
                return  getHdmiStatus();

            case DISPLAY_CMD_GETMASTERDISP:
                return  getMasterDisplay();

            case DISPLAY_CMD_GETMAXHDMIMODE:
                return  getMaxHdmiMode();

            case DISPLAY_CMD_GETMAXWIDTHDISP:
                return  getMaxWidthDisplay();

            case DISPLAY_CMD_GETTVSTATUS:
                return  getTvDacStatus();

            case DISPLAY_CMD_SETMASTERDISP:
                return  setMasterDisplay(param0);

            case DISPLAY_CMD_SETDISPMODE:
                return  setDisplayMode(param0);

            default:
                LOGE("Display Cmd not Support!\n");
                return  -1;
        }
    }
Esempio n. 4
0
int TEST_closeDisplay()
{
  Display *d;
  d=newDisplay();
  closeDisplay(d);
  d=NULL;
  if(d!=NULL){
    printf("%25s %s\n",__func__, FAIL );
    return ERROR;
  }
  else{
    printf("%25s %s\n",__func__, PASS);
    return SUCCESS;
  }
}
Esempio n. 5
0
err_t X11UIEngine::openDisplay()
{
  err_t err = ERR_OK;

  // Open X11 Display.
  _display = _XLib._XOpenDisplay("");
  if (_display == NULL)
  {
    Logger::debug("Fog::X11UIEngine", "openDisplay", "Can't open display.");
    return ERR_UI_X11_ENGINE_CANT_OPEN_DISPLAY;
  }

  _fd = ConnectionNumber(_display);
  _screen = _XLib._XDefaultScreen(_display);
  _visual = _XLib._XDefaultVisual(_display, _screen);
  _colorMap = _XLib._XDefaultColormap(_display, _screen);
  _root = _XLib._XRootWindow(_display, _screen);
  _gc = _XLib._XCreateGC(_display, _root, 0, NULL);

  _xShm = false;
  _xPrivateColorMap = false;

  // Create wakeup pipe.
  if (::pipe(_wakeUpPipe) < 0)
  {
    Logger::error("Fog::X11UIEngine", "openDisplay", "Failed to create pipe using pipe(), errno=%d.", errno);

    err = ERR_UI_X11_ENGINE_CANT_CREATE_PIPE;
    goto _Fail;
  }

  // Intern atoms.
  _atomNames = X11UIEngine_atomNames;
  _XLib._XInternAtoms(_display, (char **)_atomNames, X11_ATOM_COUNT, false, _atomList);

  // Open XIM.
  _xim = _XLib._XOpenIM(_display, NULL, NULL, NULL);

  // Get whether the X-SHM pixmap extension is supported.
  _xShm = _XExtLibrary.isOpen();
  return ERR_OK;

_Fail:
  closeDisplay();
  return err;
}
Esempio n. 6
0
/**
 * Removes the element from the current configuration.
 *
 * @pre configCanHandle(element) == true
 * @return success
 */
bool DisplayManager::configRemoveDisplay(jccl::ConfigElementPtr element)
{
   vprASSERT(configCanHandle(element)); // We must be able to handle it first of all

   vprDEBUG_BEGIN(vrjDBG_DISP_MGR,vprDBG_STATE_LVL) << "------- DisplayManager::configRemoveDisplay -------\n" << vprDEBUG_FLUSH;

   bool success_flag(false);

   if (element->getID() == std::string("display_window"))      // It is a display
   {
      DisplayPtr remove_disp = findDisplayNamed(element->getName());
      if (remove_disp != NULL)
      {
         closeDisplay(remove_disp, true);                            // Remove it
         success_flag = true;
      }
   }

   vprDEBUG_END(vrjDBG_DISP_MGR,vprDBG_STATE_LVL) << "------- DisplayManager::configRemoveDisplay done. --------\n" << vprDEBUG_FLUSH;
   return success_flag;
}
Esempio n. 7
0
int main(int argc, char* args[])
{
    initDisplay();
    
    struct Player player = {128, 128, (PI / 180) * 60};
    struct Input input = {false, false, false, false, false};
    

    while (!input.exit) {
        pollInput(&input);

        if (input.forward) {
            player.x += cos(player.a) * MOVE_SPEED;
            player.y -= sin(player.a) * MOVE_SPEED; 
        }
        if (input.left) {
            player.a -= TURN_SPEED;
            wrap(&player.a);
        }
        if (input.back) {
            player.x -= cos(player.a) * MOVE_SPEED;
            player.y += sin(player.a) * MOVE_SPEED; 
        }
        if (input.right) {
            player.a += TURN_SPEED;
            wrap(&player.a);
        }

        clearDisplay(); 
        drawWalls(&player);
        flipDisplay();
    }

    closeDisplay(); 

    return 0;
}
Esempio n. 8
0
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();
	
}
Esempio n. 9
0
static PyObject *
setRootResource(PyObject *s, PyObject *args)
{
    Display *dpy;
    Window  root;
    Resource **resources, **p;
    char *key, *val, *rstring;
    int fnd, nrec;

    if (!PyArg_ParseTuple(args, "ss", &key, &val)) {
	return NULL;
    }

    if (openDisplay(&dpy, &root) < 0) {
	PyErr_SetString(PyExc_SystemError, "Could not open display.");
	return NULL;
    }

    resources = getCurrentResources(dpy);
    fnd = 0;
    nrec = 0;
    if (resources) {
	p = resources;
	while (*p) {
	    if (!strcmp(key, (*p)->key)) {
		free((*p)->val);
		(*p)->val = strdup(val);
		fnd = 1;
		break;
	    }

	    p++;
	}

	p = resources;
	while (*p) {
	    nrec++;
	    p++;
	}
    }

    if (!fnd) {
	Resource *newrec;

	newrec = (Resource *) malloc(sizeof(Resource));
	newrec->key = strdup(key);
	newrec->val = strdup(val);

	if (nrec > 0)
	    resources = (Resource **) realloc(resources, (nrec+2) * sizeof(Resource *));
	else
	    resources = (Resource **) malloc(2*sizeof(Resource *));

	resources[nrec] = newrec;
	resources[nrec+1] = NULL;
    }

    rstring = NULL;
    p = resources;
    while (*p) {
	int len;
	char *tmpstr;

	len = strlen((*p)->key) + strlen((*p)->val) + 3;
	tmpstr = (char *) malloc(len*sizeof(char));
	strcpy(tmpstr, (*p)->key);
	strcat(tmpstr, ":");
	strcat(tmpstr, (*p)->val);
	strcat(tmpstr, "\n");

	if (rstring) {
	    rstring = (char *)realloc(rstring, (strlen(rstring)+len+1)*sizeof(char));
	    strcat(rstring, tmpstr);
	} else {
	    rstring = tmpstr;
	}

	p++;
    }

    XChangeProperty(dpy, root, XA_RESOURCE_MANAGER, XA_STRING, 
		    8, PropModeReplace, (unsigned char *)rstring,
		    strlen(rstring));

    free(rstring);
    freeResources(resources);

    closeDisplay(dpy);

    Py_INCREF(Py_None);
    return Py_None;
}
Esempio n. 10
0
File: backend.c Progetto: kod3r/wayV
int main(int argc, char **argv) {
	GDISPLAY *video, *feedback;
	GPOINT *gPoints;
	XEvent event;
	WSETUP *wayv;
	WGESTURE *gaction;
	MATRIX *gesture;
	VECTOR *vector;
	int gPosition = 0;
	char *file;

	printf("wayV version %s\n", VERSION);

	/* Decide what configuration file to open */
	if(argc != 2)
		file = strdup(SETUPFILE);
	else 
		file = strdup(argv[1]);

	if((wayv = readSetup(file)) == NULL)
		exit(BAD);

//	writeSetup(wayv, SETUPOUT);

	/* Setup the display */
	if(!(video = setupDrawable(wayv->pretty, wayv->pretty->window, argc, argv))) {
		printf("Cannot connected to X server\n");
		return BAD;
	}

	/* Setup the mouse/pointer as an input device */
	setupPointer(wayv, video);

	/* Allocate memory to store the gesture points */
	gPoints = setupGPoints(wayv->universe->maxgpoints);

	if(wayv->pretty->display[0] == 'i')
		handleDrawableWindow(video, MAP);

	setupSignals();

	/* Process the events */
	while(1) {
		XNextEvent(video->display, &event);

		switch(event.type) {
			case MotionNotify:
				if(gPosition < wayv->universe->maxgpoints) {
					gPoints[gPosition].x = event.xmotion.x;
					gPoints[gPosition].y = event.xmotion.y;
					
					if(wayv->pretty->display[0] == 'y')
						writePixels(video, (int)gPoints[gPosition-1].x - GDEF_BORDER, 
							(int)gPoints[gPosition-1].y - GDEF_BORDER, 
							(int)gPoints[gPosition].x - GDEF_BORDER, 
							(int)gPoints[gPosition].y - GDEF_BORDER);
					else if(wayv->pretty->display[0] == 'i')
						writePixels(video, (int)gPoints[gPosition-1].x, 
							(int)gPoints[gPosition-1].y, 
							(int)gPoints[gPosition].x, 
							(int)gPoints[gPosition].y);

					gPosition++;
				}
			break;

			case ButtonPress:
				if(wayv->pretty->display[0] == 'y')
					handleDrawableWindow(video, MAP);

				gPosition = 0;
				gPoints[gPosition].x = event.xbutton.x;
				gPoints[gPosition].y = event.xbutton.y;
				gPosition++;
			break;

			case ButtonRelease:
				if(wayv->pretty->display[0] == 'y')
					handleDrawableWindow(video, UNMAP);

				gPoints[gPosition].x = GEND;
				gPoints[gPosition].y = GEND;

				gesture = gridGPoints(gPoints, wayv->universe->xgrid,
						wayv->universe->ygrid);
				vector = vectGPoints(gPoints,  wayv->universe->xgrid,
						wayv->universe->ygrid, wayv->universe->maxvectors);
						     
				printf("\n\n=======Gesture=======");
				
				printMat(gesture);
				printVec(vector);
				
				if(wayv->pretty->display[0] != 'n')
					handleDrawableWindow(video, CLEAR);

				if((gaction = findGesture(wayv, gesture, vector, wayv->think))) {
					printf("Is Action : %s\n", gaction->name);

					performAction(wayv, gaction, video, gPoints);

					/* Fork off program to handle feedback window */
					if(wayv->pretty->feedback[0] == 'y' && fork() == 0) {
						feedback = writeText(gaction->action);
						waitMilli(wayv->pretty->wait);
						handleDrawableWindow(feedback, DESTROY);
						close(ConnectionNumber(video->display));
						setsid();
						exit(BAD);
					}
				}

				freeMat(gesture);
				free(vector);
			break;

			case ClientMessage:
				if(event.xclient.data.l[0] == video->wmdelete) {
					closeDisplay(video);
					exit(GOOD);
				}
			break;
		}
	}
}
Esempio n. 11
0
X11UIEngine::~X11UIEngine()
{
  _eventLoop.reset();
  
  closeDisplay();
}
Esempio n. 12
0
/*!
  Destructor.
*/
vpDisplayWin32::~vpDisplayWin32()
{
  closeDisplay();
}
Esempio n. 13
0
int main(void)
{
  Display *d = newDisplay();
  cell grid[H][W];
  entity *player, *door1, *door2;
  int in,gamesPlayed[2];
  srand(time(NULL));
  gamesPlayed[0]=gamesPlayed[1]=0;

  mediaLoad(d);
  intro(d);
  initGrid(grid);
   // place player
  player = grid[10][2].foreground = newEntity(passable,P_R1 ,2,10);
   // Creates the boundary walls
  makeBoundariesLobby(grid);

  door1 = grid[4][W-6].background = newEntity(passable,DOORINVIS, W-6,4);
  door2 = grid[7][W-11].background = newEntity(passable,DOORINVIS ,W-11,7);

  /* layer of floortiles -
  must be the last entity placement*/
  fillGrid(grid);


  while(in!=10){
    if(gamesPlayed[0]!=MAXPLAYTIMES||gamesPlayed[1]!=MAXPLAYTIMES){
      lobbyDraw(d, grid);
      in=input(d);
      if( (in > 0) && (in < 5) ){ /*checks for arrowkeys */
        move(&grid[player->y][player->x],player->x,player->y,(direction)in,grid);
        printGrid(grid);
      }
    }
    else{
          GameOver(d,&in);
          if(in!=10){
          gamesPlayed[0]=gamesPlayed[1]=0;
        }
        else{
          /*in==10 the same as d->finished=true;*/
          in=10;
          d->finished=(SDL_bool)true;
        }
    }
    if (grid[player->y][player->x].background == door1&&gamesPlayed[0]<MAXPLAYTIMES) {
      bgame(d);
      gamesPlayed[0]++;
      move(&grid[player->y][player->x],player->x,player->y,DOWN,grid);
      changeEntity(player, P_DOWN1);
    }
    if (grid[player->y][player->x].background == door2&&gamesPlayed[1]<MAXPLAYTIMES) {
      quizGame(d);
      gamesPlayed[1]++;
      move(&grid[player->y][player->x],player->x,player->y,DOWN,grid);
      changeEntity(player, P_DOWN1);
    }
  }
  freeEntityMem(grid);  /* free memory */
  closeDisplay(d);
  d->finished=(SDL_bool)true;
  fprintf(OUTPUT, "\n\n");
  return(0);
}
Esempio n. 14
0
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();

}
/*!
  Destructor.
*/
vpDisplayOpenCV::~vpDisplayOpenCV()
{
  closeDisplay() ;
  cvReleaseImage(&background);
}
Esempio n. 16
0
void run(){
	Display gDisplay;
	Assets gAssets;
	ControlState gControlState;

	SDL_Event e;
	bool quit = false;

	srand(time(NULL));

	if (!initDisplay(&gDisplay)) {
		fprintf(stderr, "ERROR: failed to initialize\n");
		exit(1);
	}

	if (!loadAssets(&gAssets, &gDisplay)) {
		fprintf(stderr, "ERROR: failed to load game assets\n");
		exit(1);
	}

	Player p = P_createPlayer();
	AI *ai = AI_createAI();

	LinkedList playerBulletList = LL_createLinkedList();
	LinkedList enemyBulletList = LL_createLinkedList();
	LinkedList enemyList = LL_createLinkedList();

	Timer fpsCapTimer = T_createTimer();
	Timer gameTimer = T_createTimer();

	unsigned int lastShooting = 0;
	unsigned int lastEnemenySpawn = 0;
	unsigned int check = 0;
	T_start(&gameTimer);
	
	int controlarray[4] = {0};
	SDL_Rect healthbar;
	initialisehealthbar(&healthbar);
	quit = staticscreen(gDisplay.renderer, "Assets/startmenu.bmp");
	
	SDL_Surface* temp;
	SDL_Texture* background;
	temp = SDL_LoadBMP("Assets/background.bmp");
	background = SDL_CreateTextureFromSurface(gDisplay.renderer, temp);
	SDL_FreeSurface(temp);
	temp = NULL;

	/*Event loop*/
	do{
		// start frame timer
		T_start(&fpsCapTimer);
		
		// check for exit event
		SDL_PollEvent(&e);
		quit = (e.type == SDL_QUIT);
		
		// check to open ai interface
		if(e.type == SDL_KEYDOWN){
			if(e.key.keysym.sym == SDLK_ESCAPE){
				quit = openaiscreen(gDisplay.renderer, controlarray);
				e.key.keysym.sym = SDLK_0;
				SDL_PushEvent(&e);
			}
		}

		// move player
		getKeyState(&gControlState);
		getMouseState(&gControlState);

		movePlayer(&p, &gControlState, &gAssets);
		AI_move(ai, P_getPosition(&p));

		if ((check = T_getTicks(&gameTimer)) - lastEnemenySpawn > DEFAULT_SPAWN_INTERVAL) {
			spawnEnemy(&enemyList);
			lastEnemenySpawn = check;
		}
		
		aiaction(ai, &playerBulletList, &enemyList, T_getTicks(&gameTimer), controlarray, &p);

		moveEnemies(&enemyList, P_getPosition(&p));
		enemiesShoot(&enemyList, &enemyBulletList, &p, T_getTicks(&gameTimer));


		if (leftMouseIsDown() && ((check = T_getTicks(&gameTimer)) - lastShooting) > SHOOT_DELAY) {
			double mx = (double)gControlState.mouseX / SCREEN_WIDTH;
    		double my = (double)gControlState.mouseY / SCREEN_HEIGHT;
    		Point origin = P_getPosition(&p);
    		Point destination = {mx, my};
			shootBullet(&playerBulletList, origin, getShotDirection(origin, destination), PLAYER);
			lastShooting = check;
		}

		moveBullets(&playerBulletList);
		moveBullets(&enemyBulletList);

		detectCollision(&playerBulletList, &enemyList, &gAssets);
		detectCollisionPlayer(&enemyBulletList, &p, &gAssets);
		
		/* Update Screen */
		SDL_RenderCopy(gDisplay.renderer, background, NULL, NULL);
		displayhealth(gDisplay.renderer, healthbar, p.health);
		renderBullets(&playerBulletList, &gDisplay, &gAssets, PLAYER);
		renderBullets(&enemyBulletList, &gDisplay, &gAssets, ENEMY);
		renderEnemies(&enemyList, &gDisplay, &gAssets);
		renderPlayer(&gDisplay, &gAssets, &gControlState);
		renderAI(ai, &gDisplay, &gAssets);
		
		// draw screen
		SDL_RenderPresent(gDisplay.renderer);
        delayNextFrame(T_getTicks(&fpsCapTimer));

        if (gameOver(&p)) {
        	printf("GAME OVER\n");
        	quit = staticscreen(gDisplay.renderer, "Assets/gameover.bmp");
			p.health = 100;
        }

	} while (!quit);
	
	/* Memory Cleanup */
	LL_destroyLinkedList(&playerBulletList);
	LL_destroyLinkedList(&enemyBulletList);
	AI_destroyAI(ai);
	SDL_DestroyTexture(background);
	freeAssets(&gAssets);
	closeDisplay(&gDisplay);
}
Esempio n. 17
0
/*!
  Destructor.
*/
vpDisplayGTK::~vpDisplayGTK()
{
  closeDisplay() ;
}
Esempio n. 18
0
int main(int argc, char *argv[]) {
	long lastVolume = 0;
	long actVolume  = 0;
	long pTime, dTime;
	char buff[255];
	char *sndCard = NULL;
	char *playerName = NULL;
	int  aName;

	#define LINE_NUM 4
	tagtypes_t layout[LINE_NUM][3] = {
		{COMPOSER,    ARTIST,       MAXTAG_TYPES},
		{ALBUM,       MAXTAG_TYPES, MAXTAG_TYPES},
		{TITLE,       MAXTAG_TYPES, MAXTAG_TYPES},
		{ALBUMARTIST, CONDUCTOR,    MAXTAG_TYPES},
	};

	opterr = 0;
	while ((aName = getopt (argc, argv, "o:n:tvh")) != -1) {
		switch (aName) {
			case 't':
				enableTOut();
				break;

			case 'v':
				incVerbose();
				break;

			case 'o':
				sndCard = optarg;
				break;

			case 'n':
				playerName = optarg;
				break;

			case 'h':
				printf("LMSMonitor Ver. 0.2\nUsage [options] -n Player name\noptions:\n -o Soundcard (eg. hw:CARD=IQaudIODAC)\n -t enable print info to stdout\n -v increment verbose level\n\n");
				exit(1);
				break;
		}
	}

	if((tags = initSliminfo(playerName)) == NULL)	{ exit(1); }

	// init ALSA mixer monitor
	startMimo(sndCard, NULL);

#ifdef __arm__
	// init OLED display
	if (initDisplay() == EXIT_FAILURE) {
		exit(EXIT_FAILURE);
	}
#endif

	while (true) {

		actVolume = getActVolume();
		if (actVolume != lastVolume) {
			sprintf(buff, "Vol:             %3ld%%", actVolume);
#ifdef __arm__
			putText(0, 0, buff);
			drawHorizontalBargraph(24, 2, 75, 4, actVolume);
			refreshDisplay();
#endif
			tOut(buff);
			lastVolume = actVolume;
		}

		if (isRefreshed()) {
			tOut("_____________________\n");

			for (int line = 0; line < LINE_NUM; line++) {
#ifdef __arm__
				int filled = false;
#endif
				for (tagtypes_t *t = layout[line]; *t != MAXTAG_TYPES; t++) {
					if (tags[*t].valid) {
#ifdef __arm__
						filled = true;
#endif
						if (tags[*t].changed) {
								strncpy(buff, tags[*t].tagData, maxCharacter());
#ifdef __arm__
								putTextToCenter((line + 1) * 10, buff);
#endif
						}
						sprintf(stbl, "%s\n", tags[*t].tagData);
						tOut(stbl);
						break;
					}
				}
#ifdef __arm__
				if(!filled) {
					clearLine((line + 1) * 10);
				}
#endif
			}

			pTime = tags[TIME].valid     ? strtol(tags[TIME].tagData,     NULL, 10) : 0;
			dTime = tags[DURATION].valid ? strtol(tags[DURATION].tagData, NULL, 10) : 0;

#ifdef __arm__
			sprintf(buff, "%ld:%02ld", pTime/60, pTime%60);
			int tlen = strlen(buff);
			clearLine(56);
			putText(0, 56, buff);

			sprintf(buff, "%ld:%02ld", dTime/60, dTime%60);
			int dlen = strlen(buff);
			putText(maxXPixel() - (dlen * CHAR_WIDTH), 56, buff);

			sprintf(buff, "%s", tags[MODE].valid ? tags[MODE].tagData : "");
			int mlen = strlen(buff);
			putText(((maxXPixel() - ((tlen + mlen + dlen) * CHAR_WIDTH)) / 2) + (tlen * CHAR_WIDTH), 56, buff);

			drawHorizontalBargraph(-1, 51, 0, 4, (pTime*100) / (dTime == 0 ? 1 : dTime));
#else
			sprintf(buff, "%3ld:%02ld  %5s  %3ld:%02ld", pTime/60, pTime%60, tags[MODE].valid ? tags[MODE].tagData : "",  dTime/60, dTime%60);
			sprintf(stbl, "%s\n\n", buff);
			tOut(stbl);
#endif
			for(int i = 0; i < MAXTAG_TYPES; i++) {
				tags[i].changed = false;
			}

#ifdef __arm__
			refreshDisplay();
#endif
			askRefresh();
		}

		usleep(SLEEP_TIME);
    }

#ifdef __arm__
	closeDisplay();
#endif
	closeSliminfo();
	return 0;
}