Пример #1
0
void simple_programB(cyg_addrword_t data)
{
    int msg = (int) data;
    int delay;
    printf("Starting thread : %d\n",msg);
    cyg_thread_delay(200);
    for(;;)
    {
        delay = 200 + (rand()%50);
        resFree(resAllocated);
        cyg_mutex_lock(&mut_t);
        printf("Allocating resource for thread %d\n", msg);
        cyg_mutex_unlock(&mut_t);
        cyg_thread_delay(delay);
    }
}
Пример #2
0
tMenuOption playAnimation(int id) {

	/* Declare variables */
	int imgCount,         objCount,              sndCount,               i;
	animImage*  img;      animObject* obj;       animSound* snd;
	titleImage* imgArray; titleObject* objArray; /*animSound* sndArray;*/
	int imgsActive=0;     int objsActive=0;      /*int sndsActive=0;*/
	int imgTotal,         objTotal,              sndTotal;

	tKey key=inputCreateKey();
	tKey nullKey=inputCreateKey();

	/* Initialize animation and allocate memory */
	animStart(id,&imgTotal,&objTotal,&sndTotal);
	imgArray=(titleImage*)malloc(imgTotal*sizeof(titleImage));
	objArray=(titleObject*)malloc(objTotal*sizeof(titleObject));
	/*sndArray=(animSound*)malloc(sndTotal*sizeof(animSound));*/

	/* main animation kernel loop */
	while (animGetFrame(&imgCount,&objCount,&sndCount,&img,&obj,&snd)) {
		int reprocessInput=1;

		while(reprocessInput) {
		if (!inputGetEvent(&key)) {
			/* key pressed */
		 	/*  if there is an action      and  the action wasn't control key */
			if (key.actionPerformed!=none  &&   !(inputGetCtrl(key.status)&&key.actionPerformed==other))
				return getAction(key);
		} else {
			reprocessInput=0;
			/* create new images/objects/sounds */
			for (i=0;i<imgCount;i++) { /*images*/
				imgArray[imgsActive].img=resLoad(img[i].res);
				if (!imgArray[imgsActive].img) {
					fprintf(stderr,"resource coudn't be loaded.");
					return menuQuit;
				}
				imgArray[imgsActive].y=img[i].y;
				imgArray[imgsActive].x=img[i].x;
				imgArray[imgsActive].layer=img[i].layer;
				imgArray[imgsActive].duration=img[i].duration;
				imgsActive++;
			}
			for (i=0;i<objCount;i++) { /*objects*/
				objArray[objsActive].obj=objectCreate(obj[i].location,obj[i].floor,DIR_LEFT,obj[i].state,obj[i].res,obj[i].cacheMirror,oGeneric);
				objArray[objsActive].active=1;
				objArray[objsActive].duration=obj[i].duration;
				objsActive++;
			}
/*		TODO: code sounds	
 *		for (i=0;i<sndCount;i++) {
				sndArray[sndsActive]=snd[i];
				sndsActive++;
			}*/

			outputClearScreen();

			/* The bottom layer */
			for (i=0;i<imgsActive;i++) {
				if (imgArray[i].layer==ANIMS_LAYERTYPE_BOTTOM)
					outputDrawBitmap(imgArray[i].img->pFrames[0], imgArray[i].x, imgArray[i].y);
			}
			
			/* move objects */
			for (i=0;i<objsActive;i++) {
				/*TODO: detect exits */
				if (objArray[i].active) {
					int exitCode;
		  		exitCode=objectMove(&(objArray[i].obj),nullKey,NULL);
					if (objArray[i].duration) objArray[i].duration--;

					/* detect exited states and destroy them */

					/* if the time is over or exit code detected */
					if ((objArray[i].duration==1)||(exitCode<0)) {
						/*printf("exit Code detected: i=%d exit=%d \n",i,exitCode);*/
						objectFree(&objArray[i].obj);
						objArray[i].active=0; /* remember it is destroyed */
					} else {
		  			objectDraw(&objArray[i].obj);
					}
				}
			}
			
			/* The top layer */
			for (i=0;i<imgsActive;i++) {
				if (imgArray[i].layer==ANIMS_LAYERTYPE_TOP) {
					outputDrawBitmap(imgArray[i].img->pFrames[0], imgArray[i].x, imgArray[i].y);
				}
			}
			outputUpdateScreen();

			/* caducied backgrounds destruction */
			i=imgsActive;
			while(i) {
				i--;
				if (imgArray[i].duration) { /* if not 0 (infinite) */
					imgArray[i].duration--;
					if (!imgArray[i].duration) { /* time is over for this images */
						imgsActive--;
						resFree(imgArray[i].img);
						imgArray[i]=imgArray[imgsActive];
					}
				}
			}	}
		}
	}

	for (i=0;i<objsActive;i++) if (objArray[i].active) objectFree(&objArray[i].obj);
	for (i=0;i<imgsActive;i++) resFree(imgArray[i].img);
	free(imgArray);
	free(objArray);
	/*free(sndArray);*/
	return menuQuit;
}