summaryrefslogtreecommitdiff
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
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
-rw-r--r--CMakeLists.txt3
-rw-r--r--sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_integrees.c910
-rw-r--r--sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_non_integrees.c731
-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
8 files changed, 965 insertions, 759 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7f89e94..7f9af19 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,6 +16,9 @@ set(INCLUDE_DIRECTORIES src/include)
include_directories("${INCLUDE_DIRECTORIES}" "${PROJECT_BINARY_DIR}")
add_definitions(-Wall -Wextra -pedantic -Werror -std=c99 -D_POSIX_SOURCE -g)
+add_definitions(-pg)
+set (CMAKE_EXE_LINKER_FLAGS -pg)
+
add_subdirectory(src)
add_subdirectory(src/test)
diff --git a/sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_integrees.c b/sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_integrees.c
index d40638b..0b9cc5b 100644
--- a/sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_integrees.c
+++ b/sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_integrees.c
@@ -117,3 +117,913 @@ Uint32* tab_of_string_to_Uint32 (char* c, int taille){
}
return tab;
}
+
+ int putBrickPx(int x,int y,SDL_Surface *s,Uint32 bgColor,Uint32 debrisColor){
+ int err;
+ SDL_Rect from,to;
+
+ from.x=0;
+ from.y=0;
+ from.w=s->w;
+ from.h=s->h;
+
+ to.x=x;
+ to.y=y;
+ to.w=x+s->w;
+ to.h=y+s->h;
+
+ if((err=paint_manip(s,from,pTerrain,to,bgColor,ccc_lemming,17,pStencilFixe))!=0){
+ return err;
+ }
+ if((err=paint_manip(s,from,pStencilFixe,to,ccc_bgStencil,ccc_lemming,18,NULL))!=0){
+ return err;
+ }
+
+ return 0;
+ }
+
+ int ereasePx(int x,int y,SDL_Surface *s,Uint32 bgColor){
+ int err;
+ SDL_Rect from,to;
+
+ from.x=0;
+ from.y=0;
+ from.w=s->w;
+ from.h=s->h;
+
+ to.x=x;
+ to.y=y;
+ to.w=x+s->w;
+ to.h=y+s->h;
+
+ if((err=paint_manip(s,from,pTerrain,to,bgColor,ccc_lemming,17,pStencil))!=0){
+ return err;
+ }
+
+ if((err=paint_manip(s,from,pSpr_Lem,to,bgColor,ccc_lemming,17,pStencil))!=0){
+ return err;
+ }
+
+ if((err=paint_manip(s,from,pSprLemBack,to,bgColor,ccc_lemming,17,pStencil))!=0){
+ return err;
+ }
+
+ if((err=paint_manip(s,from,pStencil,to,ccc_bgStencil,ccc_lemming,18,NULL))!=0){
+ return err;
+ }
+
+
+ return 0;
+ }
+
+ SDL_Surface* flipSurfaceUD_LR(SDL_Surface* src, enum sens sensO, Uint32 c) {
+ int i,j;
+
+ SDL_Surface* copy_surface = NULL;
+
+ // This only works for 32 bit pixel format
+ if( src->format->BitsPerPixel == 32 ) {
+ // This surface must be freed by the caller.
+ copy_surface = SDL_CreateRGBSurface(src->flags, src->w, src->h,
+ src->format->BitsPerPixel,
+
+ src->format->Rmask,
+ src->format->Gmask,
+ src->format->Bmask,
+ src->format->Amask);
+
+ SDL_SetColorKey( copy_surface,
+ SDL_RLEACCEL | SDL_SRCCOLORKEY,
+ //src->format->colorkey
+ SDL_MapRGB( copy_surface->format,
+ (c >> 16) & 0xff,
+ (c >> 8) & 0xff,
+ (c & 0xff))
+ );
+
+ //FIXME : lock surface
+ Uint32 *source = src->pixels;
+ Uint32 *dest = copy_surface->pixels;
+
+ for(i = 0; i < src->h; i++) {
+ for(j = 0; j < src->w; j++) {
+ if (sensO == UD){// Sens UD
+ dest[ (src->h-i-1)*src->w + j ] = source[ i*src->w + j];
+ }
+ if (sensO == LR){// Sens LR
+ dest[ i*src->w + (src->w-j-1) ] = source[ i*src->w + j];
+ }
+ }
+ }
+ }
+
+ return copy_surface;
+ }
+
+ SDL_Surface *load_image( char* filename, Uint32 cbg )
+ {
+ //L'image qui est chargée
+ SDL_Surface* loadedImage = NULL;
+
+ //L'image optimisée qu'on va utiliser
+ SDL_Surface* optimizedImage = NULL;
+
+ //Chargement de l'image
+ loadedImage = IMG_Load( filename );
+
+ //Si l'image est chargée
+ if( loadedImage != NULL )
+ {
+ //Création de l'image optimisée
+ optimizedImage = SDL_DisplayFormat( loadedImage );
+
+
+
+ //Si la création de l'image optimisée s'est bien passée
+ if( optimizedImage != NULL )
+ {
+ SDL_SetColorKey( optimizedImage,
+ SDL_RLEACCEL | SDL_SRCCOLORKEY,
+ SDL_MapRGB( optimizedImage->format,
+ (cbg >> 16) & 0xff,
+ (cbg >> 8) & 0xff,
+ (cbg & 0xff)
+ )
+ );
+ }
+ //Libération de l'ancienne image
+ SDL_FreeSurface( loadedImage );
+ }
+
+ //On retourne l'image optimisée
+ return optimizedImage;
+
+ //return loadedImage;
+ }
+
+
+ int load_files(struct gameInit *gInit)
+ {
+ int lt,ltt,ltlem;
+ int err=0;
+ int res, lterrain, lobjet, lsteel;
+ char *folder;
+ char *spriteINI;
+ char *lemINI;
+ char *terrainGif;
+ char *objetGif;
+ char *steelGif;
+ char *temp;
+ int tabNum[255];
+ int i,tempi,max,j;
+ struct dirent *lecture;
+ DIR *rep;
+
+ yyparse(gInit);
+
+ fclose(yyin);
+ //-DEBUG-printf("CLOSE 1\n");
+
+
+ lt = (strlen("../../../styles/"));
+ ltlem = (strlen("../../../misc/lemming.ini"));
+ ltt = (strlen(tabString_eMapStyle[gInit->mapI.map.style]));
+
+ folder = malloc(sizeof(char)*(lt+ltt+1));
+ spriteINI = malloc(sizeof(char)*(lt+ltt*2+5));// *2:dossier/fichier, +4: .ini, +1: string
+ lemINI = malloc(sizeof(char)*ltlem+1);
+
+
+ //folder = "/home/jazzblue/Bureau/Projet-Lemmings/trunk/styles/dirt";
+ //-DEBUG-printf("test segFault\n");
+ sprintf(folder,"../../../styles/%s",tabString_eMapStyle[gInit->mapI.map.style]);
+ sprintf(spriteINI,"%s/%s.ini",folder,tabString_eMapStyle[gInit->mapI.map.style]);
+ sprintf(lemINI,"%s","../../../misc/lemming.ini");
+ //-DEBUG-printf("test2\n");
+
+ temp = tabString_eMapStyle[gInit->mapI.map.style];
+ lt = strlen(temp);
+ lterrain = lt+1;
+ lobjet = lt+2;
+ lsteel = lt+3;
+ terrainGif=malloc(sizeof(char)*(lterrain+1));
+ objetGif=malloc(sizeof(char)*(lobjet+1));
+ steelGif=malloc(sizeof(char)*(lsteel+1));
+ sprintf(terrainGif,"%s_",temp);
+ sprintf(objetGif,"%so_",temp);
+ sprintf(steelGif,"%som_",temp);
+
+ // Compter les textures de terrain
+ rep = opendir(folder);
+ if (rep==NULL) {
+ //-DEBUG-printf("Erreur opendir('%s')\n", folder);
+ return(31);
+ }
+
+ while ((lecture = readdir(rep))) {
+ if( (res=strncmp(terrainGif, lecture->d_name,lterrain)) == 0 ){
+ ++(gInit->mapI.map.tiles);
+ } else {
+ if( (res=strncmp(objetGif, lecture->d_name,lobjet)) == 0 ) {
+ ++(gInit->mapI.map.tilesObjet);
+ } else {
+ if ( (res=strncmp(steelGif, lecture->d_name,lsteel)) == 0 ) {
+ sscanf(lecture->d_name+lsteel, "%i", &(tabNum[gInit->mapI.map.tilesSteel]));
+ ++(gInit->mapI.map.tilesSteel);
+
+ } else {
+ //-DEBUG-printf("BUG : type de fichier non reconnu [%s] \n", lecture->d_name);
+ }
+ }
+ }
+ }
+ closedir(rep);
+
+ //tri tableau
+ for(j=0;j<2;++j){
+ for(i=0;i<gInit->mapI.map.tilesSteel-1;++i){
+ max=tabNum[i];
+ tempi=tabNum[i+1];
+
+ if(max > tempi){
+ tabNum[i]=tempi;
+ tabNum[i+1]=max;
+ i=0;
+ }
+ }
+ }
+
+ yyin=fopen(spriteINI, "r");
+ if (yyin==NULL) { fprintf(stderr,"Filename INVALIDE: %s\n",spriteINI);
+ perror("Impossible d'ouvrir le fichier de configuration des sprite"); return(32);
+ }
+ yyparse(gInit);
+ fclose(yyin);
+ //-DEBUG-printf("CLOSE 2\n");
+
+ yyin=fopen(lemINI, "r");
+ if (yyin==NULL) { fprintf(stderr,"Filename INVALIDE: %s\n",lemINI);
+ perror("Impossible d'ouvrir le fichier de configuration des lemmings"); return(33);
+ }
+ yyparse(gInit);
+ fclose(yyin);
+ //-DEBUG-printf("CLOSE 3\n");
+
+ //-DEBUG-printf("REVERSE t.lt\n");
+ gInit->t.lt=(struct listeSimplementChainee*)rev_listeO(gInit->t.lt);
+ //-DEBUG-printf("REVERSE o.lo\n");
+ gInit->o.lo=(struct listeSimplementChainee*)rev_listeO(gInit->o.lo);
+ //-DEBUG-printf("REVERSE s.ls\n");
+ gInit->s.ls=(struct listeSimplementChainee*)rev_listeO(gInit->s.ls);
+
+ err=load_fields(folder, gInit, tabNum);
+ if(err!=0){return err;}
+
+
+ // AFFICHAGE DES INFOS DE LA MAP
+ //err=afficher(gInit);
+ //if(err!=0){return err;}
+
+ //Si tout s'est bien passé
+ free(terrainGif);
+ free(objetGif);
+ free(steelGif);
+ free(folder);
+ free(spriteINI);
+ free(lemINI);
+
+ return 0;
+ }
+
+
+
+ int afficher(struct gameInit *gInit){
+
+ int i;
+ struct listeSimplementChainee *k;
+
+ printf("AFFICHAGE DE GAME INIT\n");
+ printf("LES PARAMETRES:\n");
+ for(i=0;i<IDENT_COUNT;++i){
+ printf("\t%s = %d\n",tabString_eParaMap[i],gInit->mapI.paraMap[i]);
+ }
+ printf("\txPos = %d\n",gInit->mapI.xPos);
+ printf("\tstyle = %s\n",tabString_eMapStyle[gInit->mapI.map.style]);
+
+ printf("LE NOM DU NIVEAU:\n");
+ printf("name = %s\n",gInit->mapI.name);
+ printf("LES COULEURS DU NIVEAU:\n");
+ printf("bgColor R = %X G = %X B = %X\n",
+ ((gInit->mapI.map.cmap.bgColor>>16) & 0xff),
+ ((gInit->mapI.map.cmap.bgColor>>8) & 0xff),
+ (gInit->mapI.map.cmap.bgColor & 0xff) );
+ printf("debrisColor R = %X G = %X B = %X\n",
+ ((gInit->mapI.map.cmap.debrisColor>>16) & 0xff),
+ ((gInit->mapI.map.cmap.debrisColor>>8) & 0xff),
+ (gInit->mapI.map.cmap.debrisColor & 0xff) );
+ printf("debrisColor:\n");
+ for(i=0;i<PARTICULE_COUNT;++i){
+ printf("\tP%d: R = %X G = %X B = %X\n",i,
+ ((gInit->mapI.map.cmap.particleColor[i]>>16) & 0xff),
+ ((gInit->mapI.map.cmap.particleColor[i]>>8) & 0xff),
+ (gInit->mapI.map.cmap.particleColor[i] & 0xff) );
+
+ }
+
+ printf("TERRAINS:\n");
+ k=gInit->t.lt;
+ i=0;
+ while ( k !=NULL ) {
+ if(k->data.pt != NULL){//{printf("paraTerrain non initialiser\n");return(34);}
+ printf("\tterrain_%d = %d, %d, %d, %d\n",i,k->ID, k->x, k->y,k->data.pt->modif);
+ }
+ ++i;
+ k=k->next;
+ }
+
+ printf("OBJETS:\n");
+
+ k=gInit->o.lo;
+ i=0;
+ while ( k !=NULL ) {
+ if(k->data.po != NULL){ //{printf("paraObjet non initialiser\n");return(35);}
+ printf("\tobject_%d = %d, %d, %d, %d, %d\n",i,k->ID, k->x, k->y, k->data.po->paintMode,k->data.po->UD);
+ }
+ ++i;
+ k=k->next;
+ }
+
+
+ printf("STEELS:\n");
+ k=gInit->s.ls;
+ i=0;
+ while ( k !=NULL ) {
+ if(k->data.ps != NULL){//{printf("paraSteel non initialiser\n");return(36);}
+ printf("\tsteel_%d = %d, %d, %d, %d, %d\n",i,k->ID=i, k->x, k->y, k->data.ps->w,k->data.ps->h); // FIXME big fuck here with "="
+ }
+ ++i;
+ k=k->next;
+ }
+
+ printf("DATA SPRITES OBJET:\n");
+ for(i=0;i<gInit->mapI.map.tilesObjet;++i){
+ printf("spr_%d:\n\tframes_%d = %d\n\tanim_%d = %d\n\ttype_%d = %d\n\tsound_%d = %d\n",i,i,gInit->mapI.map.tabDataSprO[i].state,i,gInit->mapI.map.tabDataSprO[i].anim,i,gInit->mapI.map.tabDataSprO[i].type,i,gInit->mapI.map.tabDataSprO[i].sound);
+ }
+
+ printf("DATA JOB LEMMINGS:\n");
+ for(i=0;i<LEM_JOB;++i){
+ printf("lem_%d:\n\tlemm_%d = %d, %d, %d\n\tpos_%d = %d, %d, %d\n",i,i,gInit->mapI.lemmingDATA[i].state,gInit->mapI.lemmingDATA[i].dir,gInit->mapI.lemmingDATA[i].anim,i,gInit->mapI.lemmingDATA[i].footX,gInit->mapI.lemmingDATA[i].footY,gInit->mapI.lemmingDATA[i].footSize);
+
+ if (gInit->mapI.lemmingDATA[i].mask != NULL){
+ printf("\tmask_%d = %d, %d, %d\n",i,gInit->mapI.lemmingDATA[i].mask->stateM,gInit->mapI.lemmingDATA[i].mask->dirM,gInit->mapI.lemmingDATA[i].mask->cooldown);
+ }
+
+ if (gInit->mapI.lemmingDATA[i].imask != NULL){
+ printf("\timask_%d = %d , %d\n",i,gInit->mapI.lemmingDATA[i].imask->stateI,gInit->mapI.lemmingDATA[i].imask->dirI);
+ }
+ }
+ return 0;
+ }
+
+ int afficher(struct gameInit *gInit){
+
+ int i;
+ struct listeSimplementChainee *k;
+
+ printf("AFFICHAGE DE GAME INIT\n");
+ printf("LES PARAMETRES:\n");
+ for(i=0;i<IDENT_COUNT;++i){
+ printf("\t%s = %d\n",tabString_eParaMap[i],gInit->mapI.paraMap[i]);
+ }
+ printf("\txPos = %d\n",gInit->mapI.xPos);
+ printf("\tstyle = %s\n",tabString_eMapStyle[gInit->mapI.map.style]);
+
+ printf("LE NOM DU NIVEAU:\n");
+ printf("name = %s\n",gInit->mapI.name);
+ printf("LES COULEURS DU NIVEAU:\n");
+ printf("bgColor R = %X G = %X B = %X\n",
+ ((gInit->mapI.map.cmap.bgColor>>16) & 0xff),
+ ((gInit->mapI.map.cmap.bgColor>>8) & 0xff),
+ (gInit->mapI.map.cmap.bgColor & 0xff) );
+ printf("debrisColor R = %X G = %X B = %X\n",
+ ((gInit->mapI.map.cmap.debrisColor>>16) & 0xff),
+ ((gInit->mapI.map.cmap.debrisColor>>8) & 0xff),
+ (gInit->mapI.map.cmap.debrisColor & 0xff) );
+ printf("debrisColor:\n");
+ for(i=0;i<PARTICULE_COUNT;++i){
+ printf("\tP%d: R = %X G = %X B = %X\n",i,
+ ((gInit->mapI.map.cmap.particleColor[i]>>16) & 0xff),
+ ((gInit->mapI.map.cmap.particleColor[i]>>8) & 0xff),
+ (gInit->mapI.map.cmap.particleColor[i] & 0xff) );
+
+ }
+
+ printf("TERRAINS:\n");
+ k=gInit->t.lt;
+ i=0;
+ while ( k !=NULL ) {
+ if(k->data.pt != NULL){//{printf("paraTerrain non initialiser\n");return(34);}
+ printf("\tterrain_%d = %d, %d, %d, %d\n",i,k->ID, k->x, k->y,k->data.pt->modif);
+ }
+ ++i;
+ k=k->next;
+ }
+
+ printf("OBJETS:\n");
+
+ k=gInit->o.lo;
+ i=0;
+ while ( k !=NULL ) {
+ if(k->data.po != NULL){ //{printf("paraObjet non initialiser\n");return(35);}
+ printf("\tobject_%d = %d, %d, %d, %d, %d\n",i,k->ID, k->x, k->y, k->data.po->paintMode,k->data.po->UD);
+ }
+ ++i;
+ k=k->next;
+ }
+
+
+ printf("STEELS:\n");
+ k=gInit->s.ls;
+ i=0;
+ while ( k !=NULL ) {
+ if(k->data.ps != NULL){//{printf("paraSteel non initialiser\n");return(36);}
+ printf("\tsteel_%d = %d, %d, %d, %d, %d\n",i,k->ID=i, k->x, k->y, k->data.ps->w,k->data.ps->h); // FIXME big fuck here with "="
+ }
+ ++i;
+ k=k->next;
+ }
+
+ printf("DATA SPRITES OBJET:\n");
+ for(i=0;i<gInit->mapI.map.tilesObjet;++i){
+ printf("spr_%d:\n\tframes_%d = %d\n\tanim_%d = %d\n\ttype_%d = %d\n\tsound_%d = %d\n",i,i,gInit->mapI.map.tabDataSprO[i].state,i,gInit->mapI.map.tabDataSprO[i].anim,i,gInit->mapI.map.tabDataSprO[i].type,i,gInit->mapI.map.tabDataSprO[i].sound);
+ }
+
+ printf("DATA JOB LEMMINGS:\n");
+ for(i=0;i<LEM_JOB;++i){
+ printf("lem_%d:\n\tlemm_%d = %d, %d, %d\n\tpos_%d = %d, %d, %d\n",i,i,gInit->mapI.lemmingDATA[i].state,gInit->mapI.lemmingDATA[i].dir,gInit->mapI.lemmingDATA[i].anim,i,gInit->mapI.lemmingDATA[i].footX,gInit->mapI.lemmingDATA[i].footY,gInit->mapI.lemmingDATA[i].footSize);
+
+ if (gInit->mapI.lemmingDATA[i].mask != NULL){
+ printf("\tmask_%d = %d, %d, %d\n",i,gInit->mapI.lemmingDATA[i].mask->stateM,gInit->mapI.lemmingDATA[i].mask->dirM,gInit->mapI.lemmingDATA[i].mask->cooldown);
+ }
+
+ if (gInit->mapI.lemmingDATA[i].imask != NULL){
+ printf("\timask_%d = %d , %d\n",i,gInit->mapI.lemmingDATA[i].imask->stateI,gInit->mapI.lemmingDATA[i].imask->dirI);
+ }
+ }
+ return 0;
+ }
+ int afficher(struct gameInit *gInit){
+
+ int i;
+ struct listeSimplementChainee *k;
+
+ printf("AFFICHAGE DE GAME INIT\n");
+ printf("LES PARAMETRES:\n");
+ for(i=0;i<IDENT_COUNT;++i){
+ printf("\t%s = %d\n",tabString_eParaMap[i],gInit->mapI.paraMap[i]);
+ }
+ printf("\txPos = %d\n",gInit->mapI.xPos);
+ printf("\tstyle = %s\n",tabString_eMapStyle[gInit->mapI.map.style]);
+
+ printf("LE NOM DU NIVEAU:\n");
+ printf("name = %s\n",gInit->mapI.name);
+ printf("LES COULEURS DU NIVEAU:\n");
+ printf("bgColor R = %X G = %X B = %X\n",
+ ((gInit->mapI.map.cmap.bgColor>>16) & 0xff),
+ ((gInit->mapI.map.cmap.bgColor>>8) & 0xff),
+ (gInit->mapI.map.cmap.bgColor & 0xff) );
+ printf("debrisColor R = %X G = %X B = %X\n",
+ ((gInit->mapI.map.cmap.debrisColor>>16) & 0xff),
+ ((gInit->mapI.map.cmap.debrisColor>>8) & 0xff),
+ (gInit->mapI.map.cmap.debrisColor & 0xff) );
+ printf("debrisColor:\n");
+ for(i=0;i<PARTICULE_COUNT;++i){
+ printf("\tP%d: R = %X G = %X B = %X\n",i,
+ ((gInit->mapI.map.cmap.particleColor[i]>>16) & 0xff),
+ ((gInit->mapI.map.cmap.particleColor[i]>>8) & 0xff),
+ (gInit->mapI.map.cmap.particleColor[i] & 0xff) );
+
+ }
+
+ printf("TERRAINS:\n");
+ k=gInit->t.lt;
+ i=0;
+ while ( k !=NULL ) {
+ if(k->data.pt != NULL){//{printf("paraTerrain non initialiser\n");return(34);}
+ printf("\tterrain_%d = %d, %d, %d, %d\n",i,k->ID, k->x, k->y,k->data.pt->modif);
+ }
+ ++i;
+ k=k->next;
+ }
+
+ printf("OBJETS:\n");
+
+ k=gInit->o.lo;
+ i=0;
+ while ( k !=NULL ) {
+ if(k->data.po != NULL){ //{printf("paraObjet non initialiser\n");return(35);}
+ printf("\tobject_%d = %d, %d, %d, %d, %d\n",i,k->ID, k->x, k->y, k->data.po->paintMode,k->data.po->UD);
+ }
+ ++i;
+ k=k->next;
+ }
+
+
+ printf("STEELS:\n");
+ k=gInit->s.ls;
+ i=0;
+ while ( k !=NULL ) {
+ if(k->data.ps != NULL){//{printf("paraSteel non initialiser\n");return(36);}
+ printf("\tsteel_%d = %d, %d, %d, %d, %d\n",i,k->ID=i, k->x, k->y, k->data.ps->w,k->data.ps->h); // FIXME big fuck here with "="
+ }
+ ++i;
+ k=k->next;
+ }
+
+ printf("DATA SPRITES OBJET:\n");
+ for(i=0;i<gInit->mapI.map.tilesObjet;++i){
+ printf("spr_%d:\n\tframes_%d = %d\n\tanim_%d = %d\n\ttype_%d = %d\n\tsound_%d = %d\n",i,i,gInit->mapI.map.tabDataSprO[i].state,i,gInit->mapI.map.tabDataSprO[i].anim,i,gInit->mapI.map.tabDataSprO[i].type,i,gInit->mapI.map.tabDataSprO[i].sound);
+ }
+
+ printf("DATA JOB LEMMINGS:\n");
+ for(i=0;i<LEM_JOB;++i){
+ printf("lem_%d:\n\tlemm_%d = %d, %d, %d\n\tpos_%d = %d, %d, %d\n",i,i,gInit->mapI.lemmingDATA[i].state,gInit->mapI.lemmingDATA[i].dir,gInit->mapI.lemmingDATA[i].anim,i,gInit->mapI.lemmingDATA[i].footX,gInit->mapI.lemmingDATA[i].footY,gInit->mapI.lemmingDATA[i].footSize);
+
+ if (gInit->mapI.lemmingDATA[i].mask != NULL){
+ printf("\tmask_%d = %d, %d, %d\n",i,gInit->mapI.lemmingDATA[i].mask->stateM,gInit->mapI.lemmingDATA[i].mask->dirM,gInit->mapI.lemmingDATA[i].mask->cooldown);
+ }
+
+ if (gInit->mapI.lemmingDATA[i].imask != NULL){
+ printf("\timask_%d = %d , %d\n",i,gInit->mapI.lemmingDATA[i].imask->stateI,gInit->mapI.lemmingDATA[i].imask->dirI);
+ }
+ }
+ return 0;
+ }
+
+
+ int test_O_UD(int UD){
+
+ switch(UD){
+ case 4 : return 1;break;
+ case 6 : return 1;break;
+ case 12 : return 1;break;
+ case 14 : return 1;break;
+ default: return 0;break;
+ }
+ return 0;
+ }
+
+ int paint_terrain (struct gameInit *gInit, int choix){
+ struct listeSimplementChainee *k=NULL;
+ SDL_Rect offset;
+ SDL_Surface *sf;
+ int err=0;
+ int overwrite=0;
+ int remove=0;
+ int paint=0;
+ int tx,ty=0;
+ int cpt=0;
+ int ok=0;
+ Uint32 color;
+
+ // //-DEBUG-printf("LES TERRAINS : ");
+ k=gInit->t.lt;
+ while ( k !=NULL ) {
+ offset.x = k->x;
+ offset.y = k->y;
+
+ sf = gInit->mapI.map.tabGif[test_O_UD(k->data.pt->modif)+k->ID*2+ADD_OBJ];
+
+ if((k->data.pt->modif != 0)&&
+ (k->data.pt->modif != 2)&&
+ (k->data.pt->modif != 4)&&
+ (k->data.pt->modif != 6)&&
+ (k->data.pt->modif != 8)&&
+ (k->data.pt->modif != 10)&&
+ (k->data.pt->modif != 12)&&
+ (k->data.pt->modif != 14)&&
+ (k->data.pt->modif != 15)
+ ) {
+ //-DEBUG-printf("WTF ... k->data.pt->modif == %d\n",k->data.pt->modif);
+ return(40);
+ }
+ for(ty=k->y;ty<sf->h+k->y;++ty){
+
+ if(ty<0) {ty=-1;continue;}
+ if(ty>=pTerrain->h){break;}
+ if(ty>=LEVEL_HEIGHT) {break;}
+
+ for(tx=k->x;tx<sf->w+k->x;++tx){
+
+ if(tx<0) {tx=-1;continue;}
+ if(tx>=pTerrain->w){break;}
+ if(tx>=LEVEL_WIDTH) {break;}
+
+//FIXME : le bloc suivant ne dépends pas de x et y !
+ overwrite = ((k->data.pt->modif & 8) == 8)? 0 : 1;
+ remove = ((k->data.pt->modif & 2) == 2)? 1 : 0;
+ if(k->data.pt->modif == 15){
+ overwrite=0;
+ remove=0;
+ }
+
+
+ color = get_pixel32(tx-k->x,ty-k->y,sf);
+ if(color==ccc_error){return 250;}
+ if (color == ccc_black)
+ { //putPixel(pStencil,tx,ty , ccc_tEmpty );
+ continue;
+ }
+ paint=0;
+ if(!overwrite){
+ //FIXME : What the hell avec deux fois ce get_pixel ?!?
+ if((get_pixel32(tx,ty,pStencil)==ccc_error)){return 67;}
+ // don't overwrite -> only paint if background is transparent
+ if(((get_pixel32(tx,ty,pStencil)>>24) & 0xff ) == 0)
+ {// ccc_tEmpty){
+ paint=1;
+ }
+ } else if(remove){
+ // if(((get_pixel32(tx,ty,pStencil)) & ccc_tFull) != 0){
+ err=putPixel(pTerrain,tx,ty , gInit->mapI.map.cmap.bgColor);
+ if(err!=0){return err;}
+ err=putPixel(pStencil,tx,ty , ccc_tRemove );//ccc_tEmpty);
+ if(err!=0){return err;}
+ // }
+
+ } else {
+ paint=1;
+ }
+
+ if(paint==1){
+ if(!overwrite){
+ if(!remove){
+ err=putPixel(pTerrain,tx,ty ,color);
+ if(err!=0){return err;}
+ if(k->data.pt->modif==15){
+ err=putPixel(pStencil,tx,ty , ccc_tHidden );//ccc_tBrick);
+ if(err!=0){return err;}
+ } else {
+ err=putPixel(pStencil,tx,ty , ccc_tNoOverwrite );//ccc_tBrick);
+ if(err!=0){return err;}
+ }
+ } else {
+ err=putPixel(pTerrain,tx,ty ,color);
+ if(err!=0){return err;}
+ err=putPixel(pStencil,tx,ty , ccc_tRemoveNoOverwrite );//ccc_tBrick);
+ if(err!=0){return err;}
+ }
+ } else {
+ err=putPixel(pTerrain,tx,ty ,color);
+ if(err!=0){return err;}
+ err=putPixel(pStencil,tx,ty , ccc_tFull );//ccc_tBrick);
+ if(err!=0){return err;}
+ }
+ }
+ }//fin tx
+ }//fin ty
+ k=k->next;
+ cpt++;
+ ok=0;
+ //test_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0x0, 0x0, 0x0 ) ); test_blit(pTerrain, &camera, screen, NULL); if( SDL_Flip( screen ) == -1 ) { return 1;} //scanf("%d",&pas);
+ }
+ // elimination des pixel remove
+
+
+ for(ty=0;ty<LEVEL_HEIGHT;++ty){
+ for(tx=0;tx<LEVEL_WIDTH;++tx){
+ color = get_pixel32(tx,ty,pStencil);
+ if(color==ccc_tRemove){
+ err=putPixel(pStencil,tx,ty , ccc_bgStencil );
+ if(err!=0){return err;}
+ } else {
+ if(color!=ccc_bgStencil){
+ err=putPixel(pStencil,tx,ty , ccc_tBrick );
+ if(err!=0){return err;}
+ }
+ }
+ }
+ }
+
+
+ // //-DEBUG-printf("LES STEEL : ");
+ k=gInit->s.ls;
+ while ( k !=NULL ) {
+ offset.x = k->x;
+ offset.y = k->y;
+
+ sf = gInit->mapI.map.tabGif[ADD_OBJ+(gInit->mapI.map.tiles*2)+(gInit->mapI.map.tilesObjet*2)+k->ID];
+
+ offset.w = k->data.ps->w;
+ offset.h = k->data.ps->h;
+ //-DEBUG-printf("H=)> %d\n",offset.h);
+
+ for(ty=k->y;ty<offset.h+k->y;++ty){
+
+ if(ty<0) {ty=-1;continue;}
+ if(ty>pTerrain->h){break;}
+ if(ty>=LEVEL_HEIGHT) {break;}
+
+ for(tx=k->x;tx<offset.w+k->x;++tx){
+
+ if(tx<0) {tx=-1;continue;}
+ if(tx>pTerrain->w){break;}
+ if(tx>=LEVEL_WIDTH) {break;}
+
+ color = get_pixel32(tx,ty,pStencil);
+ if(color==ccc_error){return 219;}
+ if (color == ccc_black){
+ continue;
+ } else {
+ err=putPixel(pStencil,tx,ty , ccc_s );
+ if(err!=0){return err;}
+ }
+ }
+ }
+ // test_FillRect(pStencil, &offset, ccc_s);
+ k=k->next;
+ }
+ //}
+
+ return 0;
+ }
+
+ int paint_manip(SDL_Surface *spr,SDL_Rect from,SDL_Surface *t,SDL_Rect to,Uint32 ccc_t, Uint32 ccc_spr, int mode, SDL_Surface *stencil){
+
+ int size,i,j,err;
+ void *temp_pixels = NULL;
+ Uint32 ccc_temp=0x00000000;
+ Uint32 ccc_temp2=0x00000000;
+ Uint32 ccc_temp3=0x00000000;
+
+ //FULL
+ if(mode==0){
+ err=test_blit(spr,&from, t,&to,0);
+ return err;
+ }
+
+ //-DEBUG-printf("paint_manip(), from.x==%4i, from.y==%4i, from.h==%4i, from.w==%4i, from to.x==%4i, to.y==%4i\n", from.x, from.y, from.h, from.w, to.x, to.y);
+
+ if(from.y<0 || from.y > spr->h) {
+ //-DEBUG-
+ printf("paint_manip(1) rectFrom_Y out, from.x==%4i, FROM.Y==%4i, from.h==%4i, from.w==%4i, from to.x==%4i, to.y==%4i\n", from.x, from.y, from.h, from.w, to.x, to.y);
+ return 0;
+ }
+
+ if(from.x<0 || from.x > spr->w) {
+ //-DEBUG-
+ printf("paint_manip(2) rectFrom_X out, FROM.X==%4i, from.y==%4i, from.h==%4i, from.w==%4i, from to.x==%4i, to.y==%4i\n", from.x, from.y, from.h, from.w, to.x, to.y);
+ return 0;
+ }
+
+ if(to.y<0 || to.y > t->h) {
+ //-DEBUG-
+ printf("paint_manip(3) rectTO_Y out, from.x==%4i, from.y==%4i, from.h==%4i, from.w==%4i, from to.x==%4i, TO.Y==%4i\n", from.x, from.y, from.h, from.w, to.x, to.y);
+ return 0;
+ }
+
+ if(to.x<0 || to.x > t->w) {
+ //-DEBUG-
+ printf("paint_manip(4) rectTO_X out, from.x==%4i, from.y==%4i, from.h==%4i, from.w==%4i, from TO.X==%4i, to.y==%4i\n", from.x, from.y, from.h, from.w, to.x, to.y);
+ return 0;
+ }
+
+ if(from.y+from.h > spr->h) {
+ from.h=spr->h - from.y;
+ }
+
+ if(from.x+from.w > spr->w) {
+ from.w=spr->w - from.x;
+ }
+
+ if(to.y+from.h > t->h) {
+ from.h=t->h - to.y;
+ }
+
+ if(to.x + from.w > t->w) {
+ from.w=t->w - to.x;
+ }
+
+ size=spr->h*spr->pitch;
+ temp_pixels=malloc(size);
+
+ SDL_LockSurface(spr);
+ SDL_LockSurface(t);
+ if(stencil!=NULL) SDL_LockSurface(stencil);
+ memcpy(temp_pixels,spr->pixels,size);
+
+ // NO OVERWRITE
+ if(mode==4){
+
+ for(j=0;j<from.h;j++) {
+ for(i=0;i<from.w;i++) {
+ /* if((to.y+j)*t->w+(to.x+i)>=(t->w*t->h)){
+ //-DEBUG-printf("out of bound1 x=%d + i=%d, y=%d + j=%d * t->w %d == %d >= %d (t->h %d, from.h %d) \n",to.x,i,to.y,j,t->w,(to.y+j)*t->w+(to.x+i),(t->w*t->h),t->h,from.h);
+ return 56;
+ //continue;
+ }*/
+ ccc_temp=((Uint32 *)t->pixels)[(to.y+j)*t->w+(to.x+i)];
+ //-DEBUG-printf("ccc_temp1 = %p == %p t->format->colorkey\n",ccc_temp,t->format->colorkey);
+ if (ccc_temp!=ccc_t) {
+ ((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i]=ccc_temp;//spr->format->colorkey;
+ }
+ }
+ }
+ }
+ // VIS ON TERRAIN
+ if(mode==8){
+ for(j=0;j<from.h;j++) {
+ for(i=0;i<from.w;i++) {
+ /* if((to.y+j)*t->w+(to.x+i)>=(t->w*t->h)){
+ //-DEBUG-printf("out of bound2 x=%d + i=%d, y=%d + j=%d * t->w %d == %d >= %d (t->h %d, from.h %d) \n",to.x,i,to.y,j,t->w,(to.y+j)*t->w+(to.x+i),(t->w*t->h),t->h,from.h);
+ return 57;
+ //continue;
+ }*/
+ ccc_temp=((Uint32 *)t->pixels)[(to.y+j)*t->w+(to.x+i)];
+ //-DEBUG-printf("ccc_temp1 = %p == %p ccc_t\n",ccc_temp,ccc_t);
+ if (ccc_temp==ccc_t) {
+ ((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i]=ccc_t;//spr->format->colorkey;
+
+ }
+ }
+ }
+ }
+ // erease pixel
+ if(mode==17){
+ for(j=0;j<from.h;j++) {
+ for(i=0;i<from.w;i++) {
+ /* if((to.y+j)*t->w+(to.x+i)>=(t->w*t->h)){
+ //-DEBUG-printf("out of bound2 x=%d + i=%d, y=%d + j=%d * t->w %d == %d >= %d (t->h %d, from.h %d) \n",to.x,i,to.y,j,t->w,(to.y+j)*t->w+(to.x+i),(t->w*t->h),t->h,from.h);
+ return 57;
+ //continue;
+ }*/
+ ccc_temp=((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i];//((Uint32 *)t->pixels)[(to.y+j)*t->w+(to.x+i)];
+ ccc_temp2=((Uint32 *)t->pixels)[(to.y+j)*t->w+(to.x+i)];
+ ccc_temp3=((Uint32 *)stencil->pixels)[(to.y+j)*stencil->w+(to.x+i)];
+ //-DEBUG-printf("ccc_temp1 = %p == %p ccc_t\n",ccc_temp,ccc_t);
+ if ((ccc_temp!=ccc_spr)&&((ccc_tBrick==ccc_temp3)||((ccc_temp3 & 0xff)==0xcb))) {
+ ((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i]=ccc_t;//spr->format->colorkey;
+ } else {
+ ((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i]=ccc_temp2;
+ }
+ }
+ }
+ }
+ // erease pixel
+ if(mode==18){
+ for(j=0;j<from.h;j++) {
+ for(i=0;i<from.w;i++) {
+ /* if((to.y+j)*t->w+(to.x+i)>=(t->w*t->h)){
+ //-DEBUG-printf("out of bound2 x=%d + i=%d, y=%d + j=%d * t->w %d == %d >= %d (t->h %d, from.h %d) \n",to.x,i,to.y,j,t->w,(to.y+j)*t->w+(to.x+i),(t->w*t->h),t->h,from.h);
+ return 57;
+ //continue;
+ }*/
+ ccc_temp=((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i];//((Uint32 *)t->pixels)[(to.y+j)*t->w+(to.x+i)];
+ ccc_temp2=((Uint32 *)t->pixels)[(to.y+j)*t->w+(to.x+i)];
+ //-DEBUG-
+ // printf("ccc_temp = %p != %p ccc_spr && ccc_tBrick %p == %p ccc_temp2\n",ccc_temp,ccc_spr,ccc_tBrick,ccc_temp2);
+ if ((ccc_temp!=ccc_spr)&&((ccc_tBrick==ccc_temp2)||((ccc_temp2 & 0xff)==0xcb))) {
+ ((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i]=ccc_t;//spr->format->colorkey;
+ } else {
+ ((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i]=ccc_temp2;
+ }
+ }
+ }
+ }
+ // objet trap
+ if(mode==19){
+ for(j=0;j<from.h;j++) {
+ for(i=0;i<from.w;i++) {
+ /* if((to.y+j)*t->w+(to.x+i)>=(t->w*t->h)){
+ //-DEBUG-printf("out of bound2 x=%d + i=%d, y=%d + j=%d * t->w %d == %d >= %d (t->h %d, from.h %d) \n",to.x,i,to.y,j,t->w,(to.y+j)*t->w+(to.x+i),(t->w*t->h),t->h,from.h);
+ return 57;
+ //continue;
+ }*/
+ ccc_temp=((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i];//((Uint32 *)t->pixels)[(to.y+j)*t->w+(to.x+i)];
+ ccc_temp2=((Uint32 *)t->pixels)[(to.y+j)*t->w+(to.x+i)];
+ //-DEBUG-printf("ccc_temp1 = %p == %p ccc_t\n",ccc_temp,ccc_t);
+ if (ccc_temp!=ccc_spr){
+ ((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i]=ccc_t;//spr->format->colorkey;
+ } else {
+ ((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i]=ccc_temp2;
+ }
+ }
+ }
+ }
+
+
+ if(stencil!=NULL) SDL_UnlockSurface(stencil);
+ SDL_UnlockSurface(t);
+ SDL_UnlockSurface(spr);
+ test_blit(spr,&from, t,&to,0);
+
+ SDL_LockSurface(spr);
+ memcpy(spr->pixels,temp_pixels,size);
+ SDL_UnlockSurface(spr);
+
+ free(temp_pixels);
+
+ return 0;
+
+ }
+
diff --git a/sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_non_integrees.c b/sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_non_integrees.c
index 6a2a328..df0e46d 100644
--- a/sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_non_integrees.c
+++ b/sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_non_integrees.c
@@ -329,7 +329,7 @@ int reachedPlateau(int x, int y, int size, int dir) {
err=get_pixel32(x,y,pStencil);
if(err==ccc_error){return 115;}
- if((err==ccc_oNoDigLeft)||(err==ccc_oNoDigRight)){
+ if( (err==ccc_oNoDigLeft) || (err==ccc_oNoDigRight) ){
return 0;
}
@@ -1008,63 +1008,6 @@ int stateLemming(struct gameInit *gInit){
return 0;
}
- int putBrickPx(int x,int y,SDL_Surface *s,Uint32 bgColor,Uint32 debrisColor){
- int err;
- SDL_Rect from,to;
-
- from.x=0;
- from.y=0;
- from.w=s->w;
- from.h=s->h;
-
- to.x=x;
- to.y=y;
- to.w=x+s->w;
- to.h=y+s->h;
-
- if((err=paint_manip(s,from,pTerrain,to,bgColor,ccc_lemming,17,pStencilFixe))!=0){
- return err;
- }
- if((err=paint_manip(s,from,pStencilFixe,to,ccc_bgStencil,ccc_lemming,18,NULL))!=0){
- return err;
- }
-
- return 0;
- }
-
- int ereasePx(int x,int y,SDL_Surface *s,Uint32 bgColor){
- int err;
- SDL_Rect from,to;
-
- from.x=0;
- from.y=0;
- from.w=s->w;
- from.h=s->h;
-
- to.x=x;
- to.y=y;
- to.w=x+s->w;
- to.h=y+s->h;
-
- if((err=paint_manip(s,from,pTerrain,to,bgColor,ccc_lemming,17,pStencil))!=0){
- return err;
- }
-
- if((err=paint_manip(s,from,pSpr_Lem,to,bgColor,ccc_lemming,17,pStencil))!=0){
- return err;
- }
-
- if((err=paint_manip(s,from,pSprLemBack,to,bgColor,ccc_lemming,17,pStencil))!=0){
- return err;
- }
-
- if((err=paint_manip(s,from,pStencil,to,ccc_bgStencil,ccc_lemming,18,NULL))!=0){
- return err;
- }
-
-
- return 0;
- }
int print_num(SDL_Surface *dst, SDL_Surface *src, int x, int y, int value, int nbrMaxOfChiffre)
{
@@ -1180,92 +1123,6 @@ int stateLemming(struct gameInit *gInit){
}
- SDL_Surface* flipSurfaceUD_LR(SDL_Surface* src, enum sens sensO, Uint32 c) {
- int i,j;
-
- SDL_Surface* copy_surface = NULL;
-
- // This only works for 32 bit pixel format
- if( src->format->BitsPerPixel == 32 ) {
- // This surface must be freed by the caller.
- copy_surface = SDL_CreateRGBSurface(src->flags, src->w, src->h,
- src->format->BitsPerPixel,
-
- src->format->Rmask,
- src->format->Gmask,
- src->format->Bmask,
- src->format->Amask);
-
- SDL_SetColorKey( copy_surface,
- SDL_RLEACCEL | SDL_SRCCOLORKEY,
- //src->format->colorkey
- SDL_MapRGB( copy_surface->format,
- (c >> 16) & 0xff,
- (c >> 8) & 0xff,
- (c & 0xff))
- );
-
- //FIXME : lock surface
- Uint32 *source = src->pixels;
- Uint32 *dest = copy_surface->pixels;
-
- for(i = 0; i < src->h; i++) {
- for(j = 0; j < src->w; j++) {
- if (sensO == UD){// Sens UD
- dest[ (src->h-i-1)*src->w + j ] = source[ i*src->w + j];
- }
- if (sensO == LR){// Sens LR
- dest[ i*src->w + (src->w-j-1) ] = source[ i*src->w + j];
- }
- }
- }
- }
-
- return copy_surface;
- }
-
- SDL_Surface *load_image( char* filename, Uint32 cbg )
- {
- //L'image qui est chargée
- SDL_Surface* loadedImage = NULL;
-
- //L'image optimisée qu'on va utiliser
- SDL_Surface* optimizedImage = NULL;
-
- //Chargement de l'image
- loadedImage = IMG_Load( filename );
-
- //Si l'image est chargée
- if( loadedImage != NULL )
- {
- //Création de l'image optimisée
- optimizedImage = SDL_DisplayFormat( loadedImage );
-
-
-
- //Si la création de l'image optimisée s'est bien passée
- if( optimizedImage != NULL )
- {
- SDL_SetColorKey( optimizedImage,
- SDL_RLEACCEL | SDL_SRCCOLORKEY,
- SDL_MapRGB( optimizedImage->format,
- (cbg >> 16) & 0xff,
- (cbg >> 8) & 0xff,
- (cbg & 0xff)
- )
- );
- }
- //Libération de l'ancienne image
- SDL_FreeSurface( loadedImage );
- }
-
- //On retourne l'image optimisée
- return optimizedImage;
-
- //return loadedImage;
- }
-
-
int load_fields(char *folder, struct gameInit *gInit, int tabNum[255] ) {
int i, lt,total,cpt=-1,llem;
char *temp;
@@ -1508,227 +1365,6 @@ int stateLemming(struct gameInit *gInit){
}
- int load_files(struct gameInit *gInit)
- {
- int lt,ltt,ltlem;
- int err=0;
- int res, lterrain, lobjet, lsteel;
- char *folder;
- char *spriteINI;
- char *lemINI;
- char *terrainGif;
- char *objetGif;
- char *steelGif;
- char *temp;
- int tabNum[255];
- int i,tempi,max,j;
- struct dirent *lecture;
- DIR *rep;
-
- yyparse(gInit);
-
- fclose(yyin);
- //-DEBUG-printf("CLOSE 1\n");
-
-
- lt = (strlen("../../../styles/"));
- ltlem = (strlen("../../../misc/lemming.ini"));
- ltt = (strlen(tabString_eMapStyle[gInit->mapI.map.style]));
-
- folder = malloc(sizeof(char)*(lt+ltt+1));
- spriteINI = malloc(sizeof(char)*(lt+ltt*2+5));// *2:dossier/fichier, +4: .ini, +1: string
- lemINI = malloc(sizeof(char)*ltlem+1);
-
-
- //folder = "/home/jazzblue/Bureau/Projet-Lemmings/trunk/styles/dirt";
- //-DEBUG-printf("test segFault\n");
- sprintf(folder,"../../../styles/%s",tabString_eMapStyle[gInit->mapI.map.style]);
- sprintf(spriteINI,"%s/%s.ini",folder,tabString_eMapStyle[gInit->mapI.map.style]);
- sprintf(lemINI,"%s","../../../misc/lemming.ini");
- //-DEBUG-printf("test2\n");
-
- temp = tabString_eMapStyle[gInit->mapI.map.style];
- lt = strlen(temp);
- lterrain = lt+1;
- lobjet = lt+2;
- lsteel = lt+3;
- terrainGif=malloc(sizeof(char)*(lterrain+1));
- objetGif=malloc(sizeof(char)*(lobjet+1));
- steelGif=malloc(sizeof(char)*(lsteel+1));
- sprintf(terrainGif,"%s_",temp);
- sprintf(objetGif,"%so_",temp);
- sprintf(steelGif,"%som_",temp);
-
- // Compter les textures de terrain
- rep = opendir(folder);
- if (rep==NULL) {
- //-DEBUG-printf("Erreur opendir('%s')\n", folder);
- return(31);
- }
-
- while ((lecture = readdir(rep))) {
- if( (res=strncmp(terrainGif, lecture->d_name,lterrain)) == 0 ){
- ++(gInit->mapI.map.tiles);
- } else {
- if( (res=strncmp(objetGif, lecture->d_name,lobjet)) == 0 ) {
- ++(gInit->mapI.map.tilesObjet);
- } else {
- if ( (res=strncmp(steelGif, lecture->d_name,lsteel)) == 0 ) {
- sscanf(lecture->d_name+lsteel, "%i", &(tabNum[gInit->mapI.map.tilesSteel]));
- ++(gInit->mapI.map.tilesSteel);
-
- } else {
- //-DEBUG-printf("BUG : type de fichier non reconnu [%s] \n", lecture->d_name);
- }
- }
- }
- }
- closedir(rep);
-
- //tri tableau
- for(j=0;j<2;++j){
- for(i=0;i<gInit->mapI.map.tilesSteel-1;++i){
- max=tabNum[i];
- tempi=tabNum[i+1];
-
- if(max > tempi){
- tabNum[i]=tempi;
- tabNum[i+1]=max;
- i=0;
- }
- }
- }
-
- yyin=fopen(spriteINI, "r");
- if (yyin==NULL) { fprintf(stderr,"Filename INVALIDE: %s\n",spriteINI);
- perror("Impossible d'ouvrir le fichier de configuration des sprite"); return(32);
- }
- yyparse(gInit);
- fclose(yyin);
- //-DEBUG-printf("CLOSE 2\n");
-
- yyin=fopen(lemINI, "r");
- if (yyin==NULL) { fprintf(stderr,"Filename INVALIDE: %s\n",lemINI);
- perror("Impossible d'ouvrir le fichier de configuration des lemmings"); return(33);
- }
- yyparse(gInit);
- fclose(yyin);
- //-DEBUG-printf("CLOSE 3\n");
-
- //-DEBUG-printf("REVERSE t.lt\n");
- gInit->t.lt=(struct listeSimplementChainee*)rev_listeO(gInit->t.lt);
- //-DEBUG-printf("REVERSE o.lo\n");
- gInit->o.lo=(struct listeSimplementChainee*)rev_listeO(gInit->o.lo);
- //-DEBUG-printf("REVERSE s.ls\n");
- gInit->s.ls=(struct listeSimplementChainee*)rev_listeO(gInit->s.ls);
-
- err=load_fields(folder, gInit, tabNum);
- if(err!=0){return err;}
-
-
- // AFFICHAGE DES INFOS DE LA MAP
- //err=afficher(gInit);
- //if(err!=0){return err;}
-
- //Si tout s'est bien passé
- free(terrainGif);
- free(objetGif);
- free(steelGif);
- free(folder);
- free(spriteINI);
- free(lemINI);
-
- return 0;
- }
-
- int afficher(struct gameInit *gInit){
-
- int i;
- struct listeSimplementChainee *k;
-
- printf("AFFICHAGE DE GAME INIT\n");
- printf("LES PARAMETRES:\n");
- for(i=0;i<IDENT_COUNT;++i){
- printf("\t%s = %d\n",tabString_eParaMap[i],gInit->mapI.paraMap[i]);
- }
- printf("\txPos = %d\n",gInit->mapI.xPos);
- printf("\tstyle = %s\n",tabString_eMapStyle[gInit->mapI.map.style]);
-
- printf("LE NOM DU NIVEAU:\n");
- printf("name = %s\n",gInit->mapI.name);
- printf("LES COULEURS DU NIVEAU:\n");
- printf("bgColor R = %X G = %X B = %X\n",
- ((gInit->mapI.map.cmap.bgColor>>16) & 0xff),
- ((gInit->mapI.map.cmap.bgColor>>8) & 0xff),
- (gInit->mapI.map.cmap.bgColor & 0xff) );
- printf("debrisColor R = %X G = %X B = %X\n",
- ((gInit->mapI.map.cmap.debrisColor>>16) & 0xff),
- ((gInit->mapI.map.cmap.debrisColor>>8) & 0xff),
- (gInit->mapI.map.cmap.debrisColor & 0xff) );
- printf("debrisColor:\n");
- for(i=0;i<PARTICULE_COUNT;++i){
- printf("\tP%d: R = %X G = %X B = %X\n",i,
- ((gInit->mapI.map.cmap.particleColor[i]>>16) & 0xff),
- ((gInit->mapI.map.cmap.particleColor[i]>>8) & 0xff),
- (gInit->mapI.map.cmap.particleColor[i] & 0xff) );
-
- }
-
- printf("TERRAINS:\n");
- k=gInit->t.lt;
- i=0;
- while ( k !=NULL ) {
- if(k->data.pt != NULL){//{printf("paraTerrain non initialiser\n");return(34);}
- printf("\tterrain_%d = %d, %d, %d, %d\n",i,k->ID, k->x, k->y,k->data.pt->modif);
- }
- ++i;
- k=k->next;
- }
-
- printf("OBJETS:\n");
-
- k=gInit->o.lo;
- i=0;
- while ( k !=NULL ) {
- if(k->data.po != NULL){ //{printf("paraObjet non initialiser\n");return(35);}
- printf("\tobject_%d = %d, %d, %d, %d, %d\n",i,k->ID, k->x, k->y, k->data.po->paintMode,k->data.po->UD);
- }
- ++i;
- k=k->next;
- }
-
-
- printf("STEELS:\n");
- k=gInit->s.ls;
- i=0;
- while ( k !=NULL ) {
- if(k->data.ps != NULL){//{printf("paraSteel non initialiser\n");return(36);}
- printf("\tsteel_%d = %d, %d, %d, %d, %d\n",i,k->ID=i, k->x, k->y, k->data.ps->w,k->data.ps->h); // FIXME big fuck here with "="
- }
- ++i;
- k=k->next;
- }
-
- printf("DATA SPRITES OBJET:\n");
- for(i=0;i<gInit->mapI.map.tilesObjet;++i){
- printf("spr_%d:\n\tframes_%d = %d\n\tanim_%d = %d\n\ttype_%d = %d\n\tsound_%d = %d\n",i,i,gInit->mapI.map.tabDataSprO[i].state,i,gInit->mapI.map.tabDataSprO[i].anim,i,gInit->mapI.map.tabDataSprO[i].type,i,gInit->mapI.map.tabDataSprO[i].sound);
- }
-
- printf("DATA JOB LEMMINGS:\n");
- for(i=0;i<LEM_JOB;++i){
- printf("lem_%d:\n\tlemm_%d = %d, %d, %d\n\tpos_%d = %d, %d, %d\n",i,i,gInit->mapI.lemmingDATA[i].state,gInit->mapI.lemmingDATA[i].dir,gInit->mapI.lemmingDATA[i].anim,i,gInit->mapI.lemmingDATA[i].footX,gInit->mapI.lemmingDATA[i].footY,gInit->mapI.lemmingDATA[i].footSize);
-
- if (gInit->mapI.lemmingDATA[i].mask != NULL){
- printf("\tmask_%d = %d, %d, %d\n",i,gInit->mapI.lemmingDATA[i].mask->stateM,gInit->mapI.lemmingDATA[i].mask->dirM,gInit->mapI.lemmingDATA[i].mask->cooldown);
- }
-
- if (gInit->mapI.lemmingDATA[i].imask != NULL){
- printf("\timask_%d = %d , %d\n",i,gInit->mapI.lemmingDATA[i].imask->stateI,gInit->mapI.lemmingDATA[i].imask->dirI);
- }
- }
- return 0;
- }
-
int clean_up()
{
//On libère la feuille de sprites
@@ -1813,18 +1449,6 @@ int stateLemming(struct gameInit *gInit){
return 0;
}
- int test_O_UD(int UD){
-
- switch(UD){
- case 4 : return 1;break;
- case 6 : return 1;break;
- case 12 : return 1;break;
- case 14 : return 1;break;
- default: return 0;break;
- }
- return 0;
- }
-
int creationLemming(struct gameInit *gInit){
int nbLem;
struct listeSimplementChainee *k=NULL;
@@ -1952,180 +1576,6 @@ int stateLemming(struct gameInit *gInit){
return 0;
}
- int paint_terrain (struct gameInit *gInit, int choix){
- struct listeSimplementChainee *k=NULL;
- SDL_Rect offset;
- SDL_Surface *sf;
- int err=0;
- int overwrite=0;
- int remove=0;
- int paint=0;
- int tx,ty=0;
- int cpt=0;
- int ok=0;
- Uint32 color;
-
- // //-DEBUG-printf("LES TERRAINS : ");
- k=gInit->t.lt;
- while ( k !=NULL ) {
- offset.x = k->x;
- offset.y = k->y;
-
- sf = gInit->mapI.map.tabGif[test_O_UD(k->data.pt->modif)+k->ID*2+ADD_OBJ];
-
- if((k->data.pt->modif != 0)&&
- (k->data.pt->modif != 2)&&
- (k->data.pt->modif != 4)&&
- (k->data.pt->modif != 6)&&
- (k->data.pt->modif != 8)&&
- (k->data.pt->modif != 10)&&
- (k->data.pt->modif != 12)&&
- (k->data.pt->modif != 14)&&
- (k->data.pt->modif != 15)
- ) {
- //-DEBUG-printf("WTF ... k->data.pt->modif == %d\n",k->data.pt->modif);
- return(40);
- }
- for(ty=k->y;ty<sf->h+k->y;++ty){
-
- if(ty<0) {ty=-1;continue;}
- if(ty>=pTerrain->h){break;}
- if(ty>=LEVEL_HEIGHT) {break;}
-
- for(tx=k->x;tx<sf->w+k->x;++tx){
-
- if(tx<0) {tx=-1;continue;}
- if(tx>=pTerrain->w){break;}
- if(tx>=LEVEL_WIDTH) {break;}
-
-//FIXME : le bloc suivant ne dépends pas de x et y !
- overwrite = ((k->data.pt->modif & 8) == 8)? 0 : 1;
- remove = ((k->data.pt->modif & 2) == 2)? 1 : 0;
- if(k->data.pt->modif == 15){
- overwrite=0;
- remove=0;
- }
-
-
- color = get_pixel32(tx-k->x,ty-k->y,sf);
- if(color==ccc_error){return 250;}
- if (color == ccc_black)
- { //putPixel(pStencil,tx,ty , ccc_tEmpty );
- continue;
- }
- paint=0;
- if(!overwrite){
- //FIXME : What the hell avec deux fois ce get_pixel ?!?
- if((get_pixel32(tx,ty,pStencil)==ccc_error)){return 67;}
- // don't overwrite -> only paint if background is transparent
- if(((get_pixel32(tx,ty,pStencil)>>24) & 0xff ) == 0)
- {// ccc_tEmpty){
- paint=1;
- }
- } else if(remove){
- // if(((get_pixel32(tx,ty,pStencil)) & ccc_tFull) != 0){
- err=putPixel(pTerrain,tx,ty , gInit->mapI.map.cmap.bgColor);
- if(err!=0){return err;}
- err=putPixel(pStencil,tx,ty , ccc_tRemove );//ccc_tEmpty);
- if(err!=0){return err;}
- // }
-
- } else {
- paint=1;
- }
-
- if(paint==1){
- if(!overwrite){
- if(!remove){
- err=putPixel(pTerrain,tx,ty ,color);
- if(err!=0){return err;}
- if(k->data.pt->modif==15){
- err=putPixel(pStencil,tx,ty , ccc_tHidden );//ccc_tBrick);
- if(err!=0){return err;}
- } else {
- err=putPixel(pStencil,tx,ty , ccc_tNoOverwrite );//ccc_tBrick);
- if(err!=0){return err;}
- }
- } else {
- err=putPixel(pTerrain,tx,ty ,color);
- if(err!=0){return err;}
- err=putPixel(pStencil,tx,ty , ccc_tRemoveNoOverwrite );//ccc_tBrick);
- if(err!=0){return err;}
- }
- } else {
- err=putPixel(pTerrain,tx,ty ,color);
- if(err!=0){return err;}
- err=putPixel(pStencil,tx,ty , ccc_tFull );//ccc_tBrick);
- if(err!=0){return err;}
- }
- }
- }//fin tx
- }//fin ty
- k=k->next;
- cpt++;
- ok=0;
- //test_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0x0, 0x0, 0x0 ) ); test_blit(pTerrain, &camera, screen, NULL); if( SDL_Flip( screen ) == -1 ) { return 1;} //scanf("%d",&pas);
- }
- // elimination des pixel remove
-
-
- for(ty=0;ty<LEVEL_HEIGHT;++ty){
- for(tx=0;tx<LEVEL_WIDTH;++tx){
- color = get_pixel32(tx,ty,pStencil);
- if(color==ccc_tRemove){
- err=putPixel(pStencil,tx,ty , ccc_bgStencil );
- if(err!=0){return err;}
- } else {
- if(color!=ccc_bgStencil){
- err=putPixel(pStencil,tx,ty , ccc_tBrick );
- if(err!=0){return err;}
- }
- }
- }
- }
-
-
- // //-DEBUG-printf("LES STEEL : ");
- k=gInit->s.ls;
- while ( k !=NULL ) {
- offset.x = k->x;
- offset.y = k->y;
-
- sf = gInit->mapI.map.tabGif[ADD_OBJ+(gInit->mapI.map.tiles*2)+(gInit->mapI.map.tilesObjet*2)+k->ID];
-
- offset.w = k->data.ps->w;
- offset.h = k->data.ps->h;
- //-DEBUG-printf("H=)> %d\n",offset.h);
-
- for(ty=k->y;ty<offset.h+k->y;++ty){
-
- if(ty<0) {ty=-1;continue;}
- if(ty>pTerrain->h){break;}
- if(ty>=LEVEL_HEIGHT) {break;}
-
- for(tx=k->x;tx<offset.w+k->x;++tx){
-
- if(tx<0) {tx=-1;continue;}
- if(tx>pTerrain->w){break;}
- if(tx>=LEVEL_WIDTH) {break;}
-
- color = get_pixel32(tx,ty,pStencil);
- if(color==ccc_error){return 219;}
- if (color == ccc_black){
- continue;
- } else {
- err=putPixel(pStencil,tx,ty , ccc_s );
- if(err!=0){return err;}
- }
- }
- }
- // test_FillRect(pStencil, &offset, ccc_s);
- k=k->next;
- }
- //}
-
- return 0;
- }
int miniMapLemming (struct gameInit *gInit){
@@ -2316,185 +1766,6 @@ int stateLemming(struct gameInit *gInit){
}
- int paint_manip(SDL_Surface *spr,SDL_Rect from,SDL_Surface *t,SDL_Rect to,Uint32 ccc_t, Uint32 ccc_spr, int mode, SDL_Surface *stencil){
-
- int size,i,j,err;
- void *temp_pixels = NULL;
- Uint32 ccc_temp=0x00000000;
- Uint32 ccc_temp2=0x00000000;
- Uint32 ccc_temp3=0x00000000;
-
- //FULL
- if(mode==0){
- err=test_blit(spr,&from, t,&to,0);
- return err;
- }
-
- //-DEBUG-printf("paint_manip(), from.x==%4i, from.y==%4i, from.h==%4i, from.w==%4i, from to.x==%4i, to.y==%4i\n", from.x, from.y, from.h, from.w, to.x, to.y);
-
- if(from.y<0 || from.y > spr->h) {
- //-DEBUG-
- printf("paint_manip(1) rectFrom_Y out, from.x==%4i, FROM.Y==%4i, from.h==%4i, from.w==%4i, from to.x==%4i, to.y==%4i\n", from.x, from.y, from.h, from.w, to.x, to.y);
- return 0;
- }
-
- if(from.x<0 || from.x > spr->w) {
- //-DEBUG-
- printf("paint_manip(2) rectFrom_X out, FROM.X==%4i, from.y==%4i, from.h==%4i, from.w==%4i, from to.x==%4i, to.y==%4i\n", from.x, from.y, from.h, from.w, to.x, to.y);
- return 0;
- }
-
- if(to.y<0 || to.y > t->h) {
- //-DEBUG-
- printf("paint_manip(3) rectTO_Y out, from.x==%4i, from.y==%4i, from.h==%4i, from.w==%4i, from to.x==%4i, TO.Y==%4i\n", from.x, from.y, from.h, from.w, to.x, to.y);
- return 0;
- }
-
- if(to.x<0 || to.x > t->w) {
- //-DEBUG-
- printf("paint_manip(4) rectTO_X out, from.x==%4i, from.y==%4i, from.h==%4i, from.w==%4i, from TO.X==%4i, to.y==%4i\n", from.x, from.y, from.h, from.w, to.x, to.y);
- return 0;
- }
-
- if(from.y+from.h > spr->h) {
- from.h=spr->h - from.y;
- }
-
- if(from.x+from.w > spr->w) {
- from.w=spr->w - from.x;
- }
-
- if(to.y+from.h > t->h) {
- from.h=t->h - to.y;
- }
-
- if(to.x + from.w > t->w) {
- from.w=t->w - to.x;
- }
-
- size=spr->h*spr->pitch;
- temp_pixels=malloc(size);
-
- SDL_LockSurface(spr);
- SDL_LockSurface(t);
- if(stencil!=NULL) SDL_LockSurface(stencil);
- memcpy(temp_pixels,spr->pixels,size);
-
- // NO OVERWRITE
- if(mode==4){
-
- for(j=0;j<from.h;j++) {
- for(i=0;i<from.w;i++) {
- /* if((to.y+j)*t->w+(to.x+i)>=(t->w*t->h)){
- //-DEBUG-printf("out of bound1 x=%d + i=%d, y=%d + j=%d * t->w %d == %d >= %d (t->h %d, from.h %d) \n",to.x,i,to.y,j,t->w,(to.y+j)*t->w+(to.x+i),(t->w*t->h),t->h,from.h);
- return 56;
- //continue;
- }*/
- ccc_temp=((Uint32 *)t->pixels)[(to.y+j)*t->w+(to.x+i)];
- //-DEBUG-printf("ccc_temp1 = %p == %p t->format->colorkey\n",ccc_temp,t->format->colorkey);
- if (ccc_temp!=ccc_t) {
- ((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i]=ccc_temp;//spr->format->colorkey;
- }
- }
- }
- }
- // VIS ON TERRAIN
- if(mode==8){
- for(j=0;j<from.h;j++) {
- for(i=0;i<from.w;i++) {
- /* if((to.y+j)*t->w+(to.x+i)>=(t->w*t->h)){
- //-DEBUG-printf("out of bound2 x=%d + i=%d, y=%d + j=%d * t->w %d == %d >= %d (t->h %d, from.h %d) \n",to.x,i,to.y,j,t->w,(to.y+j)*t->w+(to.x+i),(t->w*t->h),t->h,from.h);
- return 57;
- //continue;
- }*/
- ccc_temp=((Uint32 *)t->pixels)[(to.y+j)*t->w+(to.x+i)];
- //-DEBUG-printf("ccc_temp1 = %p == %p ccc_t\n",ccc_temp,ccc_t);
- if (ccc_temp==ccc_t) {
- ((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i]=ccc_t;//spr->format->colorkey;
-
- }
- }
- }
- }
- // erease pixel
- if(mode==17){
- for(j=0;j<from.h;j++) {
- for(i=0;i<from.w;i++) {
- /* if((to.y+j)*t->w+(to.x+i)>=(t->w*t->h)){
- //-DEBUG-printf("out of bound2 x=%d + i=%d, y=%d + j=%d * t->w %d == %d >= %d (t->h %d, from.h %d) \n",to.x,i,to.y,j,t->w,(to.y+j)*t->w+(to.x+i),(t->w*t->h),t->h,from.h);
- return 57;
- //continue;
- }*/
- ccc_temp=((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i];//((Uint32 *)t->pixels)[(to.y+j)*t->w+(to.x+i)];
- ccc_temp2=((Uint32 *)t->pixels)[(to.y+j)*t->w+(to.x+i)];
- ccc_temp3=((Uint32 *)stencil->pixels)[(to.y+j)*stencil->w+(to.x+i)];
- //-DEBUG-printf("ccc_temp1 = %p == %p ccc_t\n",ccc_temp,ccc_t);
- if ((ccc_temp!=ccc_spr)&&((ccc_tBrick==ccc_temp3)||((ccc_temp3 & 0xff)==0xcb))) {
- ((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i]=ccc_t;//spr->format->colorkey;
- } else {
- ((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i]=ccc_temp2;
- }
- }
- }
- }
- // erease pixel
- if(mode==18){
- for(j=0;j<from.h;j++) {
- for(i=0;i<from.w;i++) {
- /* if((to.y+j)*t->w+(to.x+i)>=(t->w*t->h)){
- //-DEBUG-printf("out of bound2 x=%d + i=%d, y=%d + j=%d * t->w %d == %d >= %d (t->h %d, from.h %d) \n",to.x,i,to.y,j,t->w,(to.y+j)*t->w+(to.x+i),(t->w*t->h),t->h,from.h);
- return 57;
- //continue;
- }*/
- ccc_temp=((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i];//((Uint32 *)t->pixels)[(to.y+j)*t->w+(to.x+i)];
- ccc_temp2=((Uint32 *)t->pixels)[(to.y+j)*t->w+(to.x+i)];
- //-DEBUG-
- // printf("ccc_temp = %p != %p ccc_spr && ccc_tBrick %p == %p ccc_temp2\n",ccc_temp,ccc_spr,ccc_tBrick,ccc_temp2);
- if ((ccc_temp!=ccc_spr)&&((ccc_tBrick==ccc_temp2)||((ccc_temp2 & 0xff)==0xcb))) {
- ((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i]=ccc_t;//spr->format->colorkey;
- } else {
- ((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i]=ccc_temp2;
- }
- }
- }
- }
- // objet trap
- if(mode==19){
- for(j=0;j<from.h;j++) {
- for(i=0;i<from.w;i++) {
- /* if((to.y+j)*t->w+(to.x+i)>=(t->w*t->h)){
- //-DEBUG-printf("out of bound2 x=%d + i=%d, y=%d + j=%d * t->w %d == %d >= %d (t->h %d, from.h %d) \n",to.x,i,to.y,j,t->w,(to.y+j)*t->w+(to.x+i),(t->w*t->h),t->h,from.h);
- return 57;
- //continue;
- }*/
- ccc_temp=((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i];//((Uint32 *)t->pixels)[(to.y+j)*t->w+(to.x+i)];
- ccc_temp2=((Uint32 *)t->pixels)[(to.y+j)*t->w+(to.x+i)];
- //-DEBUG-printf("ccc_temp1 = %p == %p ccc_t\n",ccc_temp,ccc_t);
- if (ccc_temp!=ccc_spr){
- ((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i]=ccc_t;//spr->format->colorkey;
- } else {
- ((Uint32 *)spr->pixels)[(from.y+j)*spr->w+from.x+i]=ccc_temp2;
- }
- }
- }
- }
-
-
- if(stencil!=NULL) SDL_UnlockSurface(stencil);
- SDL_UnlockSurface(t);
- SDL_UnlockSurface(spr);
- test_blit(spr,&from, t,&to,0);
-
- SDL_LockSurface(spr);
- memcpy(spr->pixels,temp_pixels,size);
- SDL_UnlockSurface(spr);
-
- free(temp_pixels);
-
- return 0;
-
- }
-
int paint_objet (struct gameInit *gInit, int cptFps){
SDL_Rect offset,objetAnim,rStencil;
SDL_Surface *sf;
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;
+}