diff options
Diffstat (limited to 'src/netlem.c')
-rw-r--r-- | src/netlem.c | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/src/netlem.c b/src/netlem.c index 00afcb9..8e43d13 100644 --- a/src/netlem.c +++ b/src/netlem.c @@ -56,9 +56,9 @@ int main(int argc, char **argv) { int drift_ms=0, endMainLoop, result; tick_t tick=0, lastServerTick=0; - Uint32 timeBefore_ms[10], waited[10], t; + Uint32 timeBefore_ms[10], beforeWait[10], wantWait[10], waited[10], t; Uint8 loadProgress=0; - double fps, waitPercent; + double fps, waitedMean, wantWaitMean; client_t client; serverParams_t serverParams; @@ -147,6 +147,9 @@ int main(int argc, char **argv) { } memset(timeBefore_ms, 0, 10*sizeof(Uint32)); + memset(beforeWait, 0, 10*sizeof(Uint32)); + memset(wantWait, 0, 10*sizeof(Uint32)); + memset(waited, 0, 10*sizeof(Uint32)); t=0; // Main game loop @@ -167,17 +170,25 @@ int main(int argc, char **argv) { // Delay that we have to wait for the next frame (depends on execution time and network time drift) - waited[t]=waitForNextTick(timeBefore_ms[t], drift_ms); - + beforeWait[t]=SDL_GetTicks(); + wantWait[t]=waitForNextTick(timeBefore_ms[t], drift_ms); + waited[t]=SDL_GetTicks(); + waited[t] -= beforeWait[t]; // Compute & display FPS mean value on 10 loops if (t==0) { fps=10000.0/(timeBefore_ms[t]-timeBefore_ms[(t+1)%10]); - waitPercent=0; - for(;t<10;t++) waitPercent+=waited[t]; + wantWaitMean=0; + waitedMean=0; + for(;t<10;t++) { + wantWaitMean+=wantWait[t]; + waitedMean+=waited[t]; + } t=0; - waitPercent=(double)waitPercent*10/TICK_DURATION_MS; + wantWaitMean/=10.0; + waitedMean/=10.0; - snprintf(logMsg, 128, "tick:%d\tlastServerTick:%d\tdrift_ms:%d\t\t%.1f FPS\t W:%.1f%%\n", tick, lastServerTick, drift_ms, fps, waitPercent); +// snprintf(logMsg, 128, "tick:%d\tlastServerTick:%d\tdrift_ms:%d\t\t%.1f FPS\t WW:%.1f\tW:%.1f\n", tick, lastServerTick, drift_ms, fps, wantWaitMean, waitedMean); + snprintf(logMsg, 128, "tick:%d\tlastServerTick:%d\tdrift_ms:%d\t\t%.1f FPS\t WW:%d\tW:%d\n", tick, lastServerTick, drift_ms, fps, wantWait[3], waited[3]); logs(LOG_DEBUG, logMsg); } } @@ -223,7 +234,7 @@ int init(gameConfig_t *conf, gameGraphics_t *gGraph) { signal(2,signals); // Screen setup - gGraph->screen = SDL_SetVideoMode(conf->screen.w, conf->screen.h, SCREEN_BPP, SDL_HWSURFACE); + gGraph->screen = SDL_SetVideoMode(conf->screen.w, conf->screen.h, 32, SDL_HWSURFACE | SDL_ASYNCBLIT); if( gGraph->screen == NULL ) { logs2(LOG_ERROR, "init(), SDL_SetVideoMode()", SDL_GetError()); return 2; @@ -236,15 +247,15 @@ int init(gameConfig_t *conf, gameGraphics_t *gGraph) { SDL_ShowCursor(0); // Memory allocation and initialization for all display layers - gGraph->terrain = SDL_CreateRGBSurface(SDL_HWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0); + gGraph->terrain = createSurface(LEVEL_WIDTH, LEVEL_HEIGHT); if( gGraph->terrain == NULL ) { - logs2(LOG_ERROR, "init(), SDL_CreateRGBSurface()", SDL_GetError()); + logs2(LOG_ERROR, "init(), SDL_createSurface()", SDL_GetError()); return 3; } - gGraph->stencil = SDL_CreateRGBSurface(SDL_SWSURFACE, LEVEL_WIDTH, LEVEL_HEIGHT, SCREEN_BPP,0,0,0,0); + gGraph->stencil = createSurface(LEVEL_WIDTH, LEVEL_HEIGHT); if( gGraph->stencil == NULL ) { - logs2(LOG_ERROR, "init(), SDL_CreateRGBSurface()", SDL_GetError()); + logs2(LOG_ERROR, "init(), SDL_createSurface()", SDL_GetError()); return 3; } @@ -515,6 +526,7 @@ void processLocalEvents(SDL_Rect *viewport, SDL_Rect *screen, SDL_Rect *terrain) int updateGraphics(gameGraphics_t *gGraph) { int i, res; static SDL_Rect lastViewport= {-1,-1,-1,-1}; + SDL_Rect srcRect/*, dstRect*/; //TODO : modifier les calques switch(getState()) { @@ -529,18 +541,20 @@ int updateGraphics(gameGraphics_t *gGraph) { if ( gGraph->dirtRectsCount > 0 ) { free(gGraph->dirtRects); } + // Put only one dirt rectagle, of the size of the screen gGraph->dirtRects=malloc(1*sizeof(SDL_Rect)); - gGraph->dirtRects[0].x=0; - gGraph->dirtRects[0].y=0; - gGraph->dirtRects[0].w=0; - gGraph->dirtRects[0].h=0; + memcpy(gGraph->dirtRects, &(gGraph->screen->clip_rect), sizeof(SDL_Rect)); gGraph->dirtRectsCount=1; } // 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 - res=SDL_BlitSurface(gGraph->terrain, &lastViewport, gGraph->screen, NULL); + 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; |