summaryrefslogtreecommitdiff
path: root/sdl-test/SDL_tuto/TestParserLemmingsLVL/fonctions_integrees.c
blob: d40638b8e36e0f2037caf836837ab3735e829239 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Est inclus en direct dans parse_ini.yy
int init()
{

	//Initialisation de tous les sous-systèmes de SDL
	if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
	{
		return 90;
	}

	//Mise en place de l'écran
	screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_ASYNCBLIT);

	//-DEBUG-printf("DEBUG ludo :  screen->w==%i,  screen->h==%i\n",  screen->w,  screen->h);
	//S'il y a une erreur lors de la mise en place de l'écran
	if( screen == NULL ) {
		//-DEBUG-printf("problème\n");
		return 2;
	}

	pTerrain = SDL_CreateRGBSurface(SDL_HWSURFACE|SDL_HWACCEL|SDL_ASYNCBLIT|SDL_RLEACCEL, LEVEL_WIDTH, LEVEL_HEIGHT,
			SCREEN_BPP,0,0,0,0);//(ccc_black>> 16) & 0xff, (ccc_black>> 8)&0xff,(ccc_black& 0xff),0);
	if( pTerrain == NULL ) {
		return 3;
	}

	pSpr_Lem = SDL_CreateRGBSurface(SDL_HWSURFACE|SDL_HWACCEL|SDL_ASYNCBLIT|SDL_RLEACCEL, LEVEL_WIDTH, LEVEL_HEIGHT,
			SCREEN_BPP,0,0,0,0);

	if( pSpr_Lem == NULL ) {
		return 3;
	}
	
	pSprLemBack = SDL_CreateRGBSurface(SDL_HWSURFACE|SDL_HWACCEL|SDL_ASYNCBLIT|SDL_RLEACCEL , LEVEL_WIDTH, LEVEL_HEIGHT,
			SCREEN_BPP,0,0,0,0);

	if( pSprLemBack == NULL ) {
		return 3;
	}
	pStencil = SDL_CreateRGBSurface(SDL_HWSURFACE|SDL_HWACCEL|SDL_ASYNCBLIT|SDL_RLEACCEL, LEVEL_WIDTH, LEVEL_HEIGHT,
			SCREEN_BPP,0,0,0,0);
	if( pStencil == NULL ) {
		return 3;
	}

	pStencilFixe = SDL_CreateRGBSurface(SDL_HWSURFACE|SDL_HWACCEL|SDL_ASYNCBLIT|SDL_RLEACCEL, LEVEL_WIDTH, LEVEL_HEIGHT,
			SCREEN_BPP,0,0,0,0);
	if( pStencil == NULL ) {
		return 3;
	}
	
	pInterface = SDL_CreateRGBSurface(SDL_HWSURFACE|SDL_HWACCEL|SDL_ASYNCBLIT|SDL_RLEACCEL, SCREEN_WIDTH, INTERFACE_HEIGHT,
			SCREEN_BPP,0,0,0,0);
	if( pInterface == NULL ) {
		return 3;
	}
	//Mise en place de la barre caption
	SDL_WM_SetCaption( "Test_LVL", NULL );
	//No pointer of mouse
	SDL_ShowCursor(0);

	//Si tout s'est bien passé
	return 0;
}

Uint32 string_to_Uint32 (char* c,int taille){

	Uint32 u32c;
	int i,n,lc = strlen(c);
	int t[taille];
	if(lc-3 != taille){
		//-DEBUG-printf("ERREUR: wrong format .. expect (strlen[%s] - 3)==%d but it's = %d\n",c,taille,lc-3);
		return(ccc_error);
	}
	u32c = 0;
	for(i=0;i<taille;++i){
		n = c[i+2];
		//-DEBUG-printf("n = %d, %c\n",n);
		if (n > 47 && n < 58 ) { t[i]=(n - 48) ;}
		if (n > 64 && n < 71 ) { t[i]=(n - 55) ;}
		if (n > 96 && n < 103 ){ t[i]=(n - 87) ;}
	}
	n=0;
	for(i=0;i<taille;++i){
		//-DEBUG-printf("t[%d]= %d, *(%d), %d\n",i,t[i],(1<<(4*(taille-i-1))),t[i]*(1<<(4*(taille-i-1))) );

		n+=t[i]*(1<<(4*(taille-i-1)));


		//-DEBUG-printf("n= %d\n",n);
	}
	u32c= n & 0xffffff;
	return u32c;
}


// "4,5,6,7" -> un tableau de Uint32
Uint32* tab_of_string_to_Uint32 (char* c, int taille){
	int i,lc = strlen(c);
	char t[10];
	int cpt=0;
	int cpt2=0;
	Uint32* tab=malloc(sizeof(Uint32)*(lc/(taille+3)));
	t[0]='0';t[1]='x';t[8]=',';t[9]=0;

	for(i=0;i<lc;++i){
		// token
		if(c[i]=='x'){cpt=0;}
		if(cpt<6){
			t[cpt+2]=c[i+1];		
			++cpt;
			if(cpt==6){
				tab[cpt2]=string_to_Uint32(t,taille);
				cpt2++;		
			}
		}
	}
	return tab;
}