diff options
author | Damien Appert <dappert> | 2010-11-09 14:21:28 +0000 |
---|---|---|
committer | Damien Appert <dappert> | 2010-11-09 14:21:28 +0000 |
commit | 108bf7d9f6087807595f1febd09d59d5d705ff59 (patch) | |
tree | cace8c1a641d7944883b152b60e7552bc1373549 /sdl-test | |
parent | b53ecb91a9b7458e0ed11eeb4586c4fa71094478 (diff) | |
download | 2010-netlemmings-108bf7d9f6087807595f1febd09d59d5d705ff59.tar.gz 2010-netlemmings-108bf7d9f6087807595f1febd09d59d5d705ff59.tar.bz2 2010-netlemmings-108bf7d9f6087807595f1febd09d59d5d705ff59.zip |
boost FPS ... en travaux mais j'atteind le 300 facile et 420-430 en croisière
git-svn-id: file:///var/svn/2010-netlemmings/trunk@146 077b3477-7977-48bd-8428-443f22f7bfda
Diffstat (limited to 'sdl-test')
3 files changed, 174 insertions, 75 deletions
diff --git a/sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_integrees.c b/sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_integrees.c index 493f16a..ee48f19 100644 --- a/sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_integrees.c +++ b/sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_integrees.c @@ -9,7 +9,7 @@ int init() } //Mise en place de l'écran - screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE); + screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE | SDL_ASYNCBLIT); //-DEBUG-printf("DEBUG ludo : screen->w==%i, screen->h==%i\n", screen->w, screen->h); //S'il y a une erreur lors de la mise en place de l'écran @@ -30,7 +30,13 @@ int init() if( pSpr_Lem == NULL ) { return 3; } + + pSpr_LemBackup = SDL_CreateRGBSurface(SDL_SWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, + SCREEN_BPP,0,0,0,0); + if( pSpr_LemBackup == NULL ) { + return 3; + } pStencil = SDL_CreateRGBSurface(SDL_SWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0); if( pStencil == NULL ) { diff --git a/sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_non_integrees.c b/sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_non_integrees.c index 9fc777a..7e3cf29 100644 --- a/sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_non_integrees.c +++ b/sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_non_integrees.c @@ -1748,7 +1748,7 @@ int stateLemming(struct gameInit *gInit){ //DEBUT TEST CREATION UN LEMMING // DEBUT DEBUG: LEMMING COLLISION - //gInit->mapI.paraMap[1]=2; + //gInit->mapI.paraMap[1]=1; // FIN DEBUG: LEMMING COLLISION nbLem=gInit->mapI.paraMap[1]; @@ -1803,6 +1803,13 @@ int stateLemming(struct gameInit *gInit){ gInit->l.ll->data.pl->cptBoom=-1; gInit->l.ll->data.pl->cptFall2=0; gInit->l.ll->data.pl->cptBrick=0; + gInit->l.ll->data.pl->oldX=k->x; + gInit->l.ll->data.pl->oldY=k->y; + gInit->l.ll->data.pl->imgF=SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 20, + SCREEN_BPP,0,0,0,0); + SDL_SetColorKey(gInit->l.ll->data.pl->imgF, SDL_SRCCOLORKEY|SDL_RLEACCEL, 0); + //SDL_SetColorKey(gInit->l.ll->data.pl->imgF, SDL_SRCCOLORKEY|SDL_RLEACCEL, gInit->mapI.map.cmap.bgColor); + gInit->l.ll->next=NULL; if(gInit->mapI.nbrEntry==1){i=0;} @@ -1840,6 +1847,12 @@ int stateLemming(struct gameInit *gInit){ gInit->l.ll->data.pl->cptBoom=-1; gInit->l.ll->data.pl->cptFall2=0; gInit->l.ll->data.pl->cptBrick=0; + gInit->l.ll->data.pl->oldX=k->x; + gInit->l.ll->data.pl->oldY=k->y; + gInit->l.ll->data.pl->imgF=SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 20, + SCREEN_BPP,0,0,0,0); + SDL_SetColorKey(gInit->l.ll->data.pl->imgF, SDL_SRCCOLORKEY|SDL_RLEACCEL, 0); + //SDL_SetColorKey(gInit->l.ll->data.pl->imgF, SDL_SRCCOLORKEY|SDL_RLEACCEL, gInit->mapI.map.cmap.bgColor); if(gInit->mapI.nbrEntry==1){i=0;} else {++i;} } @@ -2450,13 +2463,47 @@ int stateLemming(struct gameInit *gInit){ /* if((err=paint_manip(sf,rStencil,pSpr_Lem,offset,gInit->mapI.map.cmap.bgColor,ccc_keyGif,mode,NULL))!=0){ return err; }*/ - if ((err=test_blit(sf, &rStencil, pSpr_Lem, &offset,0)) != 0){ + offset.w=rStencil.w; + offset.h=rStencil.h; + err=test_FillRect( pSpr_Lem, &offset, gInit->mapI.map.cmap.bgColor, 0); + if(err!=0){return err;} + + /*err=test_FillRect( pSpr_LemBackup, &offset, gInit->mapI.map.cmap.bgColor, 0); + if(err!=0){return err;}*/ + + /*test_blit(sf, &rStencil, pSpr_Lem, &offset,0)) != 0){ + //-DEBUG-printf("ERREUR [%d] test_blit : ",err); + return err; + }*/ + err=test_blit(sf, &rStencil, pSpr_Lem, &offset,0); + if(err != 0){ //-DEBUG-printf("ERREUR [%d] test_blit : ",err); return err; } + /* + err=test_blit(sf, &rStencil, pSpr_LemBackup, &offset,0); + if(err != 0){ + //-DEBUG-printf("ERREUR [%d] test_blit : ",err); + return err; + }*/ + } k=k->next; } + /* + k=gInit->l.ll; + while(k!=NULL){ + k->data.pl->oldX=k->x; + k->data.pl->oldY=k->y; + rStencil.x=k->x; //data.pl->oldX; + rStencil.y=k->y; //data.pl->oldX; + rStencil.w=k->data.pl->imgF->w; + rStencil.h=k->data.pl->imgF->h; + test_blit(pSpr_Lem,&rStencil, k->data.pl->imgF, NULL,0); + k=k->next; + }*/ + + }//for passage ///FIN TEST: SPR return 0; @@ -2529,6 +2576,7 @@ int stateLemming(struct gameInit *gInit){ } } } + //gInit->mapI.map.cmap.bgColor k=k->next; } ///FIN TEST: SPR @@ -2814,8 +2862,8 @@ int paint_lemming (struct gameInit *gInit, int cptFps){ objetAnim.h = sf->h/ls; objetAnim.y = (anim_objet((la+90),0,cptFps,ls,&k->data.pl->cptState,gInit))*(objetAnim.h); // +3 : 0 == loop et dans anim_objet c'est 3 pas 0 (fichier de conf) FIXME objetAnim.w = sf->w; - // offset.w = objetAnim.w; - // offset.h = objetAnim.h; + //offset.w = objetAnim.w; + //offset.h = objetAnim.h; switch(newID){ case 0: {// WALK_ON //putPixel(pStencil,k->x+fx+fs,k->y+fy,ccc_lWalk_on); @@ -2838,14 +2886,28 @@ int paint_lemming (struct gameInit *gInit, int cptFps){ } default:break; } - if ((res=test_blit(sf, &objetAnim, pSpr_Lem, &offset,0)) != 0){ - //-DEBUG-printf("ERREUR [%d] test_blit : ",res); - } + + rect.x=k->data.pl->oldX; + rect.y=k->data.pl->oldY; + rect.w=k->data.pl->imgF->w; + rect.h=k->data.pl->imgF->h; + test_blit(k->data.pl->imgF,NULL, pSpr_Lem, &rect,0); + + k->data.pl->oldX=k->x; + k->data.pl->oldY=k->y; + rect.x=k->data.pl->oldX; + rect.y=k->data.pl->oldY; + test_FillRect(pSpr_Lem, &rect, gInit->mapI.map.cmap.bgColor,0); + test_blit(pTerrain,&rect, pSpr_Lem, &rect,0); + test_blit(pSpr_Lem,&rect, k->data.pl->imgF, NULL,0); + + test_blit(sf, &objetAnim, pSpr_Lem, &offset,0); + } k=k->next; } - ///FIN TEST: LEM + ///FIN TEST: LEM err=stateLemming(gInit); if(err!=0){return err;} @@ -2948,8 +3010,8 @@ int findTerrain( struct gameInit *gInit,int x, int y, int x0){ (y+15 <= k->y + sf->h)&& (y+15 > k->y)){//on the terrain ++cpt; - print_num(screen, gInit->mapI.map.tabGif[1], 5 , screen->h-10, cpt); - print_num(screen, gInit->mapI.map.tabGif[1], 5 + cpt*40, screen->h-10, i); + print_num(pInterface, gInit->mapI.map.tabGif[1], 5 , pInterface->h-10, cpt); + print_num(pInterface, gInit->mapI.map.tabGif[1], 5 + cpt*40, pInterface->h-10, i); to.x=k->x; to.y=k->y; to.w=sf->w; @@ -2981,7 +3043,7 @@ int findTerrain( struct gameInit *gInit,int x, int y, int x0){ return 0; } -int paint_cursor(SDL_Surface *dst1,SDL_Surface *dst2, SDL_Surface *src, int x, int y, int x0, struct gameInit *gInit) +int paint_cursor(SDL_Surface *dst1, SDL_Surface *src, int x, int y, int x0, struct gameInit *gInit) { SDL_Rect from, to; int f=0; @@ -2996,8 +3058,9 @@ int paint_cursor(SDL_Surface *dst1,SDL_Surface *dst2, SDL_Surface *src, int x, i to.x = (y>LEVEL_HEIGHT)? x0 : x; to.y = y; - if (y>LEVEL_HEIGHT){// cursor in pSpr_Lem - test_blit(src, &from, dst2, &to,0); + if (y>LEVEL_HEIGHT){// cursor in pIterface + to.y = y - LEVEL_HEIGHT ; + test_blit(src, &from, pInterface, &to,0); } else { k=gInit->l.ll; while(k != NULL){ @@ -3039,16 +3102,11 @@ int paint_cursor(SDL_Surface *dst1,SDL_Surface *dst2, SDL_Surface *src, int x, i } to.y -= 4; test_blit(src, &from, dst1, &to,0); + if(y+from.h>LEVEL_HEIGHT){ to.x = (f==1)? k->x-x + x0:x0; - to.y = (f==1)? k->y -4 :y -4; - test_blit(src, &from, dst2, &to,0); - } else { - if(f==1){ - to.x = k->x-x + x0; - to.y = k->y -4 ; - test_blit(src, &from, dst2, &to,0); - } + to.y = (f==1)? k->y - 4 - LEVEL_HEIGHT :y -4 - LEVEL_HEIGHT; + test_blit(src, &from, pInterface, &to,0); } } gInit->cptGame[18]=0; @@ -3312,7 +3370,7 @@ int lancement (){ int err=0; //Ce qui va nous permettre de quitter int quit = 0; - SDL_Rect camera,inter,miniMapR,test; + SDL_Rect camera,inter,miniMapR,test,rect; int mouseX,mouseY=0; long tick,temps=0; float fps = 0.0; @@ -3325,6 +3383,7 @@ int lancement (){ //La structure d'evenement SDL_Event event; event.type=0; + struct listeSimplementChainee *k; //event.key.keysym.sym=0; //paint_stencil=1; @@ -3394,16 +3453,14 @@ int lancement (){ test_FillRect( pStencil, NULL, ccc_bgStencil,0); //paint_terrain => pTerrain - err=paint_terrain(&gInit,0); if(err!=0){return err;} err=miniMapLemming(&gInit); if(err!=0){return err;} - SDL_SetColorKey(pTerrain, SDL_SRCCOLORKEY|SDL_RLEACCEL, gInit.mapI.map.cmap.bgColor); - - + //SDL_SetColorKey(pTerrain, SDL_SRCCOLORKEY|SDL_RLEACCEL, gInit.mapI.map.cmap.bgColor); + err=paint_objet_Init (&gInit); if(err!=0){return err;} @@ -3416,6 +3473,14 @@ int lancement (){ test_blit(pStencil, NULL, pStencilFixe, NULL,0); //<-- //Tant que l'utilisateur n'a pas quitter + test_FillRect( pSpr_Lem, NULL, gInit.mapI.map.cmap.bgColor,0); + test_FillRect( pSpr_LemBackup, NULL, gInit.mapI.map.cmap.bgColor,0); + test_blit(pTerrain, NULL, pSpr_Lem, NULL,0); + test_blit(pTerrain, NULL, pSpr_LemBackup, NULL,0); + test_FillRect( screen, &inter, ccc_black,0); + test_FillRect( pInterface, NULL , ccc_black,0); + test_FillRect( pStencil, NULL, ccc_bgStencil,0); + test_blit(pStencilFixe, NULL, pStencil, NULL,0); while( quit == 0 ) { @@ -3476,14 +3541,13 @@ int lancement (){ } } - test_FillRect( pSpr_Lem, NULL, gInit.mapI.map.cmap.bgColor,0); - test_blit(pTerrain, NULL, pSpr_Lem, NULL,0); - - test_FillRect( screen, &inter, ccc_black,0); - test_FillRect( pInterface, NULL , ccc_black,0); - - test_FillRect( pStencil, NULL, ccc_bgStencil,0); - test_blit(pStencilFixe, NULL, pStencil, NULL,0); + //test_FillRect( pSpr_Lem, NULL, gInit.mapI.map.cmap.bgColor,0); + //test_blit(pTerrain, NULL, pSpr_Lem, NULL,0); + //test_FillRect( screen, &inter, ccc_black,0); + //test_FillRect( pInterface, NULL , ccc_black,0); + //test_FillRect( pStencil, NULL, ccc_bgStencil,0); + //test_blit(pStencilFixe, NULL, pStencil, NULL,0); + // SPR => pSpr_Lem err=paint_objet (&gInit,cptFps); @@ -3495,9 +3559,34 @@ int lancement (){ // LEM => pSpr_Lem //if(paint_stencil==0){ + + + /* k=gInit.l.ll; + while(k!=NULL){ + rect.x=k->data.pl->oldX; + rect.y=k->data.pl->oldY; + rect.w=k->data.pl->imgF->w; + rect.h=k->data.pl->imgF->h; + test_blit(k->data.pl->imgF,NULL, pSpr_Lem, &rect,0); + k=k->next; + } + */ + err=paint_lemming (&gInit,cptFps); if(err!=0){return err;} //} + + /* k=gInit.l.ll; + while(k!=NULL){ + rect.x=k->data.pl->oldX; + rect.y=k->data.pl->oldY; + k->data.pl->oldX=k->x; + k->data.pl->oldY=k->y; + rect.w=k->data.pl->imgF->w; + rect.h=k->data.pl->imgF->h; + test_blit(pSpr_Lem,&rect, k->data.pl->imgF, NULL,0); + k=k->next; + }*/ // INTERFACE => screen if(paint_stencil==0){ @@ -3509,47 +3598,44 @@ int lancement (){ if(err!=0){return err;} } - // CURSOR => pSpr_Lem, screen - if(paint_stencil==0){ - err=paint_cursor (pSpr_Lem,pSpr_Lem, gInit.mapI.map.tabGif[3], mouseX+camera.x, mouseY+camera.y, mouseX, &gInit); - if(err!=0){return err;} - } else { - err=findTerrain(&gInit,mouseX+camera.x, mouseY+camera.y, mouseX); - if(err!=0){return err;} - err=paint_cursor (pStencil,pSpr_Lem, gInit.mapI.map.tabGif[3], mouseX+camera.x, mouseY+camera.y, mouseX, &gInit); - if(err!=0){return err;} - //-DEBUG-printf("x=%d y=%d\n",mouseX+camera.x,mouseY+camera.y); - } - //get_pixel32( event.motion.x + camera.x, event.motion.y, pTerrain ); //get_pixel32( event.motion.x + camera.x, event.motion.y, pSpr_Lem ); //get_pixel32( event.motion.x + camera.x , event.motion.y, screen ); - if(switchMiniMapMode==2){ if(paint_stencil==0){ - // printf("test %p\n",pSpr_Lem); - test_blit(pSpr_Lem, &camera, screen, NULL,0); err=miniMap (pSpr_Lem,mouseX+camera.x,mouseY+camera.y,zoomX,zoomY);//0.10,0.10); 5.,5.); if( err != 0){ return err;} } else { - test_blit(pStencil, &camera, screen, NULL,0); err=miniMap (pStencil,mouseX+camera.x,mouseY+camera.y,zoomX,zoomY); if( err != 0){ return err;} }} else { if(paint_stencil==0){ - // printf("test %p\n",pSpr_Lem); - test_blit(pSpr_Lem, &camera, screen, NULL,0); test_blit(gInit.mapI.miniMapLem,NULL , pInterface, &miniMapR,0); } else { - test_blit(pStencil, &camera, screen, NULL,0); test_blit(gInit.mapI.miniMapLem,NULL , pInterface, &miniMapR,0); } } - test_blit(pInterface, NULL , screen, &inter,0); - + // CURSOR => pSpr_Lem, screen + if(paint_stencil==0){ + err=paint_cursor (pSpr_Lem, gInit.mapI.map.tabGif[3], mouseX+camera.x, mouseY+camera.y, mouseX, &gInit); + if(err!=0){return err;} + } else { + err=findTerrain(&gInit,mouseX+camera.x, mouseY+camera.y, mouseX); + if(err!=0){return err;} + err=paint_cursor (pStencil, gInit.mapI.map.tabGif[3], mouseX+camera.x, mouseY+camera.y, mouseX, &gInit); + if(err!=0){return err;} + //-DEBUG-printf("x=%d y=%d\n",mouseX+camera.x,mouseY+camera.y); + } + if(paint_stencil==0){ + test_blit(pSpr_Lem, &camera, screen, NULL,0); + } else { + test_blit(pStencil, &camera, screen, NULL,0); + } + + /* FPS counter */ //-DEBUG-printf("(tick %ld > fps_start %d +500)\n",tick,fps_start); // refresh fps all 500 ms @@ -3569,34 +3655,37 @@ int lancement (){ } // limte fps - - if(FPS<=decalFps){//-DEBUG-printf("BUG: FPS < 0 : (FPS %d - decalFps %d) < 0",FPS,decalFps); - return(42); - } else { - while((FPS>decalFps)&&(((float)fps_count * 1000.0 / (SDL_GetTicks()-fps_start)) > FPS-decalFps) ){ - if((FPS-decalFps)<=120){// useless ? - SDL_Delay(3); - } - }} - temps = SDL_GetTicks(); //heure - err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-160, screen->h-40, temps/(1000*3600)); + err=print_num(pInterface, gInit.mapI.map.tabGif[1], pInterface->w-160, pInterface->h-40, temps/(1000*3600)); if(err!=0){return err;} //minute - err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-130, screen->h-40, (temps/(1000*60))%60); + err=print_num(pInterface, gInit.mapI.map.tabGif[1], pInterface->w-130, pInterface->h-40, (temps/(1000*60))%60); if(err!=0){return err;} //seconde - err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-100, screen->h-40, (temps/1000)%60); + err=print_num(pInterface, gInit.mapI.map.tabGif[1], pInterface->w-100, pInterface->h-40, (temps/1000)%60); if(err!=0){return err;} - err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-150, screen->h-10, cptFps); + err=print_num(pInterface, gInit.mapI.map.tabGif[1], pInterface->w-150, pInterface->h-10, cptFps); if(err!=0){return err;} - err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-87, screen->h-10, fps); + err=print_num(pInterface, gInit.mapI.map.tabGif[1], pInterface->w-87, pInterface->h-10, fps); if(err!=0){return err;} - err=print_num(screen, gInit.mapI.map.tabGif[1], screen->w-37, screen->h-10, FPS); + err=print_num(pInterface, gInit.mapI.map.tabGif[1], pInterface->w-37, pInterface->h-10, FPS); if(err!=0){return err;} + + test_blit(pInterface, NULL , screen, &inter,0); + + if(FPS<=decalFps){//-DEBUG-printf("BUG: FPS < 0 : (FPS %d - decalFps %d) < 0",FPS,decalFps); + return(42); + } else { + while((FPS>decalFps)&&(((float)fps_count * 1000.0 / (SDL_GetTicks()-fps_start)) > FPS-decalFps) ){ + if((FPS-decalFps)<=120){// useless ? + SDL_Delay(3); + } + }} + + //Mise à jour de l'écran if( SDL_Flip( screen ) == -1 ) { return 4; diff --git a/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy b/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy index fca0945..a5006fe 100644 --- a/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy +++ b/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.yy @@ -12,7 +12,7 @@ #include <stdlib.h> /** time per frame in microseconds - this is the timing everything else is based on */ -#define FPS 150 +#define FPS 1500 /** redraw animated level obejcts every 3rd frame (about 100ms) */ #define ANIM_STEP_FPS 3 @@ -157,7 +157,8 @@ //Les surfaces SDL_Surface *pTerrain = NULL; //Fond avec juste la map - SDL_Surface *pSpr_Lem = NULL; // Fond + lemmings + animations + SDL_Surface *pSpr_Lem = NULL; // Fond + animations + Lemming + SDL_Surface *pSpr_LemBackup = NULL; // Fond + animations SDL_Surface *screen = NULL; // Ecran via la caméra SDL_Surface *pInterface = NULL; // Ecran du bas SDL_Surface *pStencil= NULL; // Ecran Stencil @@ -395,6 +396,9 @@ int cptBrick; // count number of brick ;default = 0; int cptBoom; // count number of boom ;default = -1; int cptState; // count number of frame for an animation at once, default=0; + int oldX; //positionX de l'ancien font; default=x; + int oldY; //positionY de l'ancien font; default=y; + SDL_Surface *imgF; // font de l'image avant d'être écrasée par celle du lemming; default=NULL; }; struct listeSimplementChainee { @@ -537,7 +541,7 @@ int findTerrain( struct gameInit *gInit,int x, int y, int x0); - int paint_cursor(SDL_Surface *dst1,SDL_Surface *dst2, SDL_Surface *src, int x, int y, int x0, struct gameInit *gInit); + int paint_cursor(SDL_Surface *dst1, SDL_Surface *src, int x, int y, int x0, struct gameInit *gInit); int print_num(SDL_Surface *dst, SDL_Surface *font, int x, int y, int value); |