summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2010-12-09 22:14:58 +0000
committerLudovic Pouzenc <ludovic@pouzenc.fr>2010-12-09 22:14:58 +0000
commita1a8ffa6a66367db634065a94a6eec2b36f63864 (patch)
tree6a44078de1ed72fa30cfb2b315110e5ecd39bcf8 /src
parentf643ff055c5017833f17dc620c4f0a98b10940fa (diff)
download2010-netlemmings-a1a8ffa6a66367db634065a94a6eec2b36f63864.tar.gz
2010-netlemmings-a1a8ffa6a66367db634065a94a6eec2b36f63864.tar.bz2
2010-netlemmings-a1a8ffa6a66367db634065a94a6eec2b36f63864.zip
Optimisation graphiques (options surfaces, 32bits plutôt que 24, code vraiment correct pour l'algo des dirty rectangles. Passage de non_integre à intregre de quelques fonctions du code de Dams.
git-svn-id: file:///var/svn/2010-netlemmings/trunk@188 077b3477-7977-48bd-8428-443f22f7bfda
Diffstat (limited to 'src')
-rw-r--r--src/graphic.c13
-rw-r--r--src/include/data_localgame.h1
-rw-r--r--src/include/graphic.h3
-rw-r--r--src/netlem.c50
-rw-r--r--src/parser/parse_ini.yy13
5 files changed, 51 insertions, 29 deletions
diff --git a/src/graphic.c b/src/graphic.c
index a0587bc..b9990f6 100644
--- a/src/graphic.c
+++ b/src/graphic.c
@@ -6,16 +6,17 @@
#define ccc_nooverride 0x00cc0000
#define ccc_terrain 0x0000cc00
#define ccc_nothing 0x00000000
-#define SDLSURF_OPTS SDL_HWSURFACE|SDL_HWACCEL|/*SDL_ASYNCBLIT|*/SDL_RLEACCEL
Uint32 getPixel(SDL_Surface *s, int x, int y) {
+/* 24 bits retournés
Uint32 res=0;
//FIXME : Big Endian
res |= ((Uint8 *)s->pixels)[y*s->pitch + x*s->format->BytesPerPixel+0] << 0;
res |= ((Uint8 *)s->pixels)[y*s->pitch + x*s->format->BytesPerPixel+1] << 8;
res |= ((Uint8 *)s->pixels)[y*s->pitch + x*s->format->BytesPerPixel+2] << 16;
-
return res;
+*/
+ return ((Uint32 *)s->pixels)[y*s->w + x];
}
Uint32 getPixel8BitPalette(SDL_Surface *s, int x, int y) {
@@ -41,11 +42,7 @@ int isTransparent(SDL_Surface *s, int x, int y) {
}
void putPixel(SDL_Surface *s, int x, int y, Uint32 p) {
- //printf("putPixel(s, %i, %i, 0x%x)\n", x, y, p);
- //FIXME : Big Endian
- ((Uint8 *)s->pixels)[y*s->pitch + x*s->format->BytesPerPixel+0] = (p & 0x000000ff) >> 0;
- ((Uint8 *)s->pixels)[y*s->pitch + x*s->format->BytesPerPixel+1] = (p & 0x0000ff00) >> 8;
- ((Uint8 *)s->pixels)[y*s->pitch + x*s->format->BytesPerPixel+2] = (p & 0x00ff0000) >> 16;
+ ((Uint32 *)s->pixels)[y*s->w + x]=p;
}
SDL_Surface * createSurface(int width, int height) {
@@ -65,7 +62,7 @@ SDL_Surface * createSurface(int width, int height) {
amask = 0x00000000;
#endif
- return SDL_CreateRGBSurface(SDL_HWSURFACE|SDL_HWACCEL|/*SDL_ASYNCBLIT|*/SDL_RLEACCEL, width, height, 24, rmask, gmask, bmask, amask);
+ return SDL_CreateRGBSurface(MY_SDLSURFACE_OPTS, width, height, SCREEN_BPP, rmask, gmask, bmask, amask);
}
diff --git a/src/include/data_localgame.h b/src/include/data_localgame.h
index b740b27..9153d6e 100644
--- a/src/include/data_localgame.h
+++ b/src/include/data_localgame.h
@@ -3,7 +3,6 @@
#include "data_types.h"
-#define SCREEN_BPP 24
typedef struct {
SDL_Rect screen;
diff --git a/src/include/graphic.h b/src/include/graphic.h
index 2e40301..32046aa 100644
--- a/src/include/graphic.h
+++ b/src/include/graphic.h
@@ -6,6 +6,9 @@
#include "data_ress.h"
#include "data_localgame.h"
+#define SCREEN_BPP 32
+#define MY_SDLSURFACE_OPTS SDL_HWSURFACE|SDL_HWACCEL|SDL_SRCCOLORKEY|SDL_ASYNCBLIT|SDL_RLEACCEL
+
Uint32 getPixel(SDL_Surface *s, int x, int y);
Uint32 getPixel8BitPalette(SDL_Surface *s, int x, int y);
int isTransparent(SDL_Surface *s, int x, int y);
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;
diff --git a/src/parser/parse_ini.yy b/src/parser/parse_ini.yy
index 4fb00d8..0927011 100644
--- a/src/parser/parse_ini.yy
+++ b/src/parser/parse_ini.yy
@@ -15,6 +15,7 @@ int yylex();
void yyerror(gameIni_t *gIni, char *s);
void yyassert(int condition, char what[], char why[]);
void callocIfNull(void **ptr, size_t nmemb, size_t size);
+uint32_t convrgb(uint32_t in);
%}
@@ -48,8 +49,8 @@ ini: /*epsilon*/
| EOL ini
/* styles/...ini */
-decl: BGCOLOR AFF INTHEX { gIni->style.bgColor = $3; }
-| DEBRISCOLOR AFF INTHEX { gIni->style.debrisColor = $3; }
+decl: BGCOLOR AFF INTHEX { gIni->style.bgColor = convrgb($3); }
+| DEBRISCOLOR AFF INTHEX { gIni->style.debrisColor = convrgb($3); }
| PARTICLECOLOR AFF particles {
gIni->style.particleColorCount=16;
gIni->style.particleColor = $3;
@@ -219,6 +220,7 @@ decl: BGCOLOR AFF INTHEX { gIni->style.bgColor = $3; }
particles: INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX VIR INTHEX {
$$=malloc(16*sizeof(uint32_t));
+// TODO : use of convrgb
$$[0]=$1; $$[1]=$3; $$[2]=$5; $$[3]=$7; $$[4]=$9; $$[5]=$11; $$[6]=$13; $$[7]=$15 ;$$[8]=$17; $$[9]=$19; $$[10]=$21; $$[11]=$23; $$[12]=$25; $$[13]=$27; $$[14]=$29; $$[15]=$31;
}
%%
@@ -260,3 +262,10 @@ void callocIfNull(void **ptr, size_t nmemb, size_t size) {
}
}
+uint32_t convrgb(uint32_t in) {
+ uint32_t res=0;
+ res |= (in & 0x000000ff) << 16;
+ res |= (in & 0x0000ff00);
+ res |= (in & 0x00ff0000) >> 16;
+ return res;
+}