summaryrefslogtreecommitdiff
path: root/src/netlem.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/netlem.c')
-rw-r--r--src/netlem.c89
1 files changed, 73 insertions, 16 deletions
diff --git a/src/netlem.c b/src/netlem.c
index 8e43d13..9628050 100644
--- a/src/netlem.c
+++ b/src/netlem.c
@@ -51,6 +51,10 @@ void processLocalEvents(SDL_Rect *viewport, SDL_Rect *screen, SDL_Rect *terrain)
int act(tick_t *tick, int loadProgress, TCPsocket sockClient, int *dirtRectsCount, SDL_Rect **dirtRects);
int updateGraphics(gameGraphics_t *gGraph);
+int repaint(gameGraphSurfaces_t *srcSurfs, SDL_Rect *srcRect, SDL_Surface *dstSurf, SDL_Rect dstRect);
+int findAndZSortObjects(gameGraphObjState_t *objectsStat, SDL_Rect *offsetRect, gameGraphObjState_t **objectsFound);
+int paintObject(gameGraphObjState_t *obj, SDL_Rect *srcRect, SDL_Surface *dstSurf);
+
int main(int argc, char **argv) {
@@ -161,7 +165,7 @@ int main(int argc, char **argv) {
// Process local player keyboard and mouse events
// (note: remote events are processed by network read thread)
- processLocalEvents(&(gGraph.viewport), &(gGraph.screen->clip_rect), &(gGraph.terrain->clip_rect));
+ processLocalEvents(&(gGraph.viewport), &(gGraph.screen->clip_rect), &(gGraph.surfaces.terrain->clip_rect));
endMainLoop=act(&tick, loadProgress, client.sockClient, &(gGraph.dirtRectsCount), &(gGraph.dirtRects));
@@ -247,14 +251,14 @@ int init(gameConfig_t *conf, gameGraphics_t *gGraph) {
SDL_ShowCursor(0);
// Memory allocation and initialization for all display layers
- gGraph->terrain = createSurface(LEVEL_WIDTH, LEVEL_HEIGHT);
- if( gGraph->terrain == NULL ) {
+ gGraph->surfaces.terrain = createSurface(LEVEL_WIDTH, LEVEL_HEIGHT);
+ if( gGraph->surfaces.terrain == NULL ) {
logs2(LOG_ERROR, "init(), SDL_createSurface()", SDL_GetError());
return 3;
}
- gGraph->stencil = createSurface(LEVEL_WIDTH, LEVEL_HEIGHT);
- if( gGraph->stencil == NULL ) {
+ gGraph->surfaces.stencil = createSurface(LEVEL_WIDTH, LEVEL_HEIGHT);
+ if( gGraph->surfaces.stencil == NULL ) {
logs2(LOG_ERROR, "init(), SDL_createSurface()", SDL_GetError());
return 3;
}
@@ -546,25 +550,21 @@ int updateGraphics(gameGraphics_t *gGraph) {
memcpy(gGraph->dirtRects, &(gGraph->screen->clip_rect), sizeof(SDL_Rect));
gGraph->dirtRectsCount=1;
}
- // We use a dirt rectangle method for performance
+ // We use a dirt rectangle method for performance
for(i=0; i<gGraph->dirtRectsCount; i++) {
- //FIXME : faire une vrai procedure qui va chercher les objets sur une zone donnée, qui paint tout dans l'ordre
srcRect.x=gGraph->dirtRects[i].x+lastViewport.x;
srcRect.y=gGraph->dirtRects[i].y+lastViewport.y;
srcRect.w=gGraph->dirtRects[i].w;
srcRect.h=gGraph->dirtRects[i].h;
- res=SDL_BlitSurface(gGraph->terrain, &srcRect, gGraph->screen, gGraph->dirtRects+i);
- if ( res!=0 ) {
- logs2(LOG_DEBUG, "updateGraphics(), SDL_BlitSurface()", SDL_GetError());
- return res;
- }
+ res=repaint(&gGraph->surfaces, &srcRect, gGraph->screen, gGraph->dirtRects[i]);
+ if ( res != 0 ) {
+ logs(LOG_WARN, "updateGraphics(), repain() failed");
+ }
SDL_UpdateRect(gGraph->screen,
- gGraph->dirtRects[i].x,
- gGraph->dirtRects[i].y,
- gGraph->dirtRects[i].w,
- gGraph->dirtRects[i].h);
+ gGraph->dirtRects[i].x, gGraph->dirtRects[i].y,
+ gGraph->dirtRects[i].w, gGraph->dirtRects[i].h);
}
gGraph->dirtRectsCount=0;
free(gGraph->dirtRects);
@@ -575,3 +575,60 @@ int updateGraphics(gameGraphics_t *gGraph) {
return 0;
}
+
+int repaint(gameGraphSurfaces_t *srcSurfs, SDL_Rect *srcRect, SDL_Surface *dstSurf, SDL_Rect dstRect) {
+ int objToRepaintCount, i, res;
+ gameGraphObjState_t *objToRepaint;
+ SDL_Surface *tmpSurf;
+
+ tmpSurf=createSurface(srcRect->w, srcRect->h);
+ if (tmpSurf==NULL) {
+ logs(LOG_ERROR, "repain(), createSurface() has failed");
+ return 1;
+ }
+ objToRepaintCount=findAndZSortObjects(srcSurfs->objectsStat, srcRect, &objToRepaint);
+
+ for(i=0;i<objToRepaintCount;++i) {
+ if(objToRepaint[i].zOrder>0) break;
+ res=paintObject(objToRepaint+i, srcRect, tmpSurf);
+ if ( res!=0 ) {
+ logs(LOG_DEBUG, "repaint(), paintObject() failed");
+ return res;
+ }
+ }
+
+ res=SDL_BlitSurface(srcSurfs->terrain, srcRect, tmpSurf, NULL);
+ if ( res!=0 ) {
+ logs2(LOG_DEBUG, "repaint(), SDL_BlitSurface()", SDL_GetError());
+ return res;
+ }
+
+ for(;i<objToRepaintCount;++i) {
+ res=paintObject(objToRepaint+i, srcRect, tmpSurf);
+ if ( res!=0 ) {
+ logs(LOG_DEBUG, "repaint(), paintObject() failed");
+ return res;
+ }
+ }
+
+ res=SDL_BlitSurface(tmpSurf, NULL, dstSurf, &dstRect);
+ if ( res!=0 ) {
+ logs2(LOG_DEBUG, "repaint(), SDL_BlitSurface()", SDL_GetError());
+ return res;
+ }
+
+ return 0;
+}
+
+int findAndZSortObjects(gameGraphObjState_t *objectsStat, SDL_Rect *offsetRect, gameGraphObjState_t **objectsFound) {
+ //TODO
+ fprintf(stderr, "TODO findAndZSortObjects(%p, %p, %p)\n", (void *)objectsStat,(void *)offsetRect,(void *)objectsFound);
+ *objectsFound=NULL;
+ return 0;
+}
+
+int paintObject(gameGraphObjState_t *obj, SDL_Rect *srcRect, SDL_Surface *dstSurf) {
+ //TODO
+ fprintf(stderr, "TODO paintObject(%p, %p, %p)\n", (void *)obj,(void *)srcRect,(void *)dstSurf);
+ return 0;
+}