From 374a77a4b3cd8dcf8859904ffb1bbf7274ab4719 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Fri, 24 Dec 2010 13:36:03 +0000 Subject: Bon le painting avec les dirty-rectangles commence à permettre d'affichier des choses. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit J'ai bricolé un peu à la fin pour que ça marche, il y a des noms de SDL_Rect à changer à droite à gauche et il y a un tas de trucs pas encore fini (z-sorting à faire et qu'une seule fois, redraw de tous les objets, pas juste celui qui demande le paint...) git-svn-id: file:///var/svn/2010-netlemmings/trunk@212 077b3477-7977-48bd-8428-443f22f7bfda --- src/graphic.c | 34 ++++++++++++--------- src/include/graphic.h | 4 +-- src/netlem.c | 85 ++++++++++++++++++++++++++------------------------- 3 files changed, 65 insertions(+), 58 deletions(-) diff --git a/src/graphic.c b/src/graphic.c index a444819..fbe1ae7 100644 --- a/src/graphic.c +++ b/src/graphic.c @@ -89,6 +89,9 @@ int init(char *winCaption, gameConfig_t *conf, gameGraphics_t *gGraph) { return 2; } + gGraph->viewport.w = gGraph->screen->clip_rect.w; + gGraph->viewport.h = LEVEL_HEIGHT; + // SDL main window caption SDL_WM_SetCaption(winCaption, NULL); @@ -113,6 +116,7 @@ int init(char *winCaption, gameConfig_t *conf, gameGraphics_t *gGraph) { logs2(LOG_ERROR, "init(), SDL_createSurface()", SDL_GetError()); return 3; } + SDL_FillRect(gGraph->surfaces.tmpSurf, &(gGraph->surfaces.tmpSurf->clip_rect), 0xcccccccc); return 0; } @@ -221,34 +225,36 @@ int paintTerrain(gameIni_t *gIni, gameRess_t *gRess, gameGraphics_t *gGraph) { return 0; } -int repaint(gameObjectsState_t *objStates, gameGraphSurfaces_t *srcSurfs, SDL_Rect *srcRect, SDL_Surface *dstSurf, SDL_Rect dstRect) { +int repaint(gameObjectsState_t *objStates, gameGraphSurfaces_t *srcSurfs, SDL_Rect *srcRect, SDL_Surface *dstSurf) { int res; gameObjectsState_t objToRepaint; -// int i; + int i; + + ///findAndZSortObjects(objStates, srcRect, &objToRepaint); + objToRepaint=*objStates; - findAndZSortObjects(objStates, srcRect, &objToRepaint); -/* for(i=0;i0) break; - res=paintObject(objToRepaint.allObj+i, srcRect, dstSurf, &dstRect); + res=paintObject(objToRepaint.allObj+i, dstSurf, *srcRect); if ( res!=0 ) { logs(LOG_DEBUG, "repaint(), paintObject() failed"); } } -*/ - res=SDL_BlitSurface(srcSurfs->terrain, srcRect, dstSurf, &dstRect); + printf("res=SDL_BlitSurface(%p, %p, %p, %p);\n", (void*)srcSurfs->terrain, (void*)srcRect, (void*)dstSurf, (void*)srcRect); + + res=SDL_BlitSurface(srcSurfs->terrain, srcRect, dstSurf, srcRect); if ( res!=0 ) { logs2(LOG_DEBUG, "repaint(), SDL_BlitSurface()", SDL_GetError()); } -/* + for(;is, NULL, dstSurf, &dstRect); } int refresh(SDL_Surface *tmpSurf, SDL_Rect *srcRect, SDL_Surface *screen, SDL_Rect dstRect) { diff --git a/src/include/graphic.h b/src/include/graphic.h index 7d7761e..5b59600 100644 --- a/src/include/graphic.h +++ b/src/include/graphic.h @@ -21,9 +21,9 @@ SDL_Surface * loadGif(char *filePath); int init(char *winCaption, gameConfig_t *conf, gameGraphics_t *gGraph); int paintTerrain(gameIni_t *gIni, gameRess_t *gRess, gameGraphics_t *gGraph); -int repaint(gameObjectsState_t *objStates, gameGraphSurfaces_t *srcSurfs, SDL_Rect *srcRect, SDL_Surface *dstSurf, SDL_Rect dstRect); +int repaint(gameObjectsState_t *objStates, gameGraphSurfaces_t *srcSurfs, SDL_Rect *srcRect, SDL_Surface *dstSurf); int findAndZSortObjects(gameObjectsState_t *objectsStat, SDL_Rect *offsetRect, gameObjectsState_t *objectsFound); -int paintObject(struct gameObjectState *obj, SDL_Rect *srcRect, SDL_Surface *dstSurf, SDL_Rect *dstRect); +int paintObject(struct gameObjectState *obj, SDL_Surface *dstSurf, SDL_Rect dstRect); int refresh(SDL_Surface *tmpSurf, SDL_Rect *srcRect, SDL_Surface *screen, SDL_Rect dstRect); #endif /*GRAPHIC_H*/ diff --git a/src/netlem.c b/src/netlem.c index a6d6c38..630bae9 100644 --- a/src/netlem.c +++ b/src/netlem.c @@ -116,6 +116,14 @@ int main(int argc, char **argv) { atexit(SDL_Quit); signal(2,signals); +//TODO TESTS + gObjStates.cursor.s = createSurface(32, 32); + SDL_FillRect(gObjStates.cursor.s, &(gObjStates.cursor.s->clip_rect), 0x11223344); + gObjStates.cursor.zOrder=999; + + gObjStates.allObj=&gObjStates.cursor; + gObjStates.objCount=1; + // Synchronization tools intialization semGameStart=SDL_CreateSemaphore(0); semLoadLevel=SDL_CreateSemaphore(0); @@ -462,9 +470,10 @@ void processLocalEvents(SDL_Rect *terrain, SDL_Rect *viewport, gameObjectsState_ case SDL_MOUSEMOTION: mouseX = event.motion.x; mouseY = event.motion.y; - objStates->cursor.pos.x = mouseX; - objStates->cursor.pos.y = mouseY; + objStates->cursor.pos.x = mouseX - objStates->cursor.s->w/2; + objStates->cursor.pos.y = mouseY - objStates->cursor.s->h/2; objStates->cursor.dirty=1; + break; case SDL_MOUSEBUTTONDOWN: //err=mouse_action(&gInit, mouseX, mouseY,camera.x,camera.y ); @@ -505,6 +514,7 @@ int updateGraphics(gameObjectsState_t *objStates, localParams_t *params, gameGra SDL_Rect srcRect, dstRect; SDL_Surface *tmpSurf; struct gameObjectState *o; +//static Uint32 tmpColor=0; //TODO : modifier les calques switch(getState()) { @@ -514,69 +524,60 @@ int updateGraphics(gameObjectsState_t *objStates, localParams_t *params, gameGra case eMultiGame: // If we had a camera movement, we have to refesh all the screen tmpSurf=gGraph->surfaces.tmpSurf; - SDL_FillRect(tmpSurf, &(tmpSurf->clip_rect), 0xcccccccc); - if ( lastViewport.x != gGraph->viewport.x ) { - lastViewport.x=gGraph->viewport.x; - dstRect.x=0; - dstRect.y=0; - // dstRect.w=0; - // dstRect.h=0; - srcRect.x=lastViewport.x; - srcRect.y=lastViewport.y; - srcRect.w=gGraph->screen->clip_rect.w; - srcRect.h=gGraph->screen->clip_rect.h; - res=repaint(objStates, &gGraph->surfaces, &srcRect, tmpSurf, dstRect); - if ( res != 0 ) { - logs(LOG_WARN, "updateGraphics(), repaint() failed"); - } - refresh(tmpSurf, &srcRect, gGraph->screen, dstRect); - } else { +// SDL_FillRect(tmpSurf, &(tmpSurf->clip_rect), tmpColor); +// tmpColor+=0x11223344; + if ( lastViewport.x == gGraph->viewport.x && (params->debugFlags & DEBUG_DIRTYRECTANGLES) == 0 ) { // We use a dirty rectangle method for performance for(i=0; iobjCount; i++) { o=objStates->allObj+i; - - dstRect.x=o->pos.x; - dstRect.y=o->pos.y; - dstRect.w=o->s->clip_rect.w; - dstRect.h=o->s->clip_rect.h; if ( /*TODO intersect(viewport, dstRect) &&*/ o->dirty == 1 ) { + dstRect.x=o->pos.x; + dstRect.y=o->pos.y; +//TODO : pas cencé setter w et h ici + dstRect.w=o->s->clip_rect.w; + dstRect.h=o->s->clip_rect.h; + srcRect.x=o->pos.x+lastViewport.x; srcRect.y=o->pos.y+lastViewport.y; srcRect.w=o->s->clip_rect.w; srcRect.h=o->s->clip_rect.h; - res=repaint(objStates, &gGraph->surfaces, &srcRect, tmpSurf, srcRect); + res=repaint(objStates, &gGraph->surfaces, &srcRect, tmpSurf); if ( res != 0 ) { logs(LOG_WARN, "updateGraphics(), repaint() failed"); } - if ( (params->debugFlags & DEBUG_DIRTYRECTANGLES) == 0 ) { - res=SDL_BlitSurface(tmpSurf, &srcRect, gGraph->screen, &dstRect); - if ( res!=0 ) { - logs2(LOG_DEBUG, "repaint(), SDL_BlitSurface()", SDL_GetError()); - } - SDL_UpdateRect(gGraph->screen, dstRect.x, dstRect.y, dstRect.w, dstRect.h); + if ( (params->debugFlags & DEBUG_DIRTYRECTANGLES) == 0 ) { + refresh(tmpSurf, &srcRect, gGraph->screen, dstRect); } + o->dirty=0; } } - } - - if ( (params->debugFlags & DEBUG_DIRTYRECTANGLES) == DEBUG_DIRTYRECTANGLES ) { + } else { + dstRect.x=0; + dstRect.y=0; srcRect.x=lastViewport.x; srcRect.y=lastViewport.y; srcRect.w=gGraph->screen->clip_rect.w; srcRect.h=gGraph->screen->clip_rect.h; - res=SDL_BlitSurface(tmpSurf, &srcRect, gGraph->screen, NULL); - if ( res!=0 ) { - logs2(LOG_DEBUG, "repaint(), SDL_BlitSurface()", SDL_GetError()); + + if ( lastViewport.x != gGraph->viewport.x ) { + lastViewport.x=gGraph->viewport.x; + res=repaint(objStates, &gGraph->surfaces, &srcRect, tmpSurf); + if ( res != 0 ) { + logs(LOG_WARN, "updateGraphics(), repaint() failed"); + } } - SDL_UpdateRect(gGraph->screen, 0,0,0,0); - SDL_LockSurface(tmpSurf); - for(i=0; i < tmpSurf->pitch * tmpSurf->h ; ++i) { - ((Uint8 *)tmpSurf->pixels)[i] *= 0.9; + refresh(tmpSurf, &srcRect, gGraph->screen, dstRect); + + if ( (params->debugFlags & DEBUG_DIRTYRECTANGLES) == DEBUG_DIRTYRECTANGLES ) { + SDL_LockSurface(tmpSurf); + for(i=0; i < tmpSurf->pitch * tmpSurf->h ; ++i) { + ((Uint8 *)tmpSurf->pixels)[i] *= 0.9; + } + SDL_UnlockSurface(tmpSurf); } - SDL_UnlockSurface(tmpSurf); } break; default: -- cgit v1.2.3