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
|
#include <stdio.h>
#include <string.h>
#include "SDL/SDL.h"
#include "parser.h"
#include "loader.h"
#include "graphic.h"
#include "utils.h"
#define PATH_STYLE "../styles"
#define PATH_LEVEL "../level"
#define PATH_TMP "/tmp"
#define MAX_PATH_LEN 255
extern FILE *yyin;
void load_ini(gameIni_t *gIni, char *filepath) {
yyin=fopen(filepath, "r");
if (yyin == NULL ) {
fprintf(stderr, "main(), Could not open '%s'\n", filepath);
exit(2);
}
// printf("Parsing '%s'\n", filepath);
parse(gIni);
fclose(yyin);
}
int main(int argc, char **argv) {
int res;
char filepath[MAX_PATH_LEN];
gameIni_t gIni;
gameRess_t gRess;
SDL_Surface *terrain=NULL, *stencil=NULL;
if (argc != 3) {
fprintf(stderr, "Usage %s <levelpack_name> <ini_file>\n", argv[0]);
return 1;
}
openLog(NULL);
// Setting default values
memset(&gIni,0,sizeof(gameIni_t));
// Loading levelpack.ini
snprintf(filepath, MAX_PATH_LEN, "%s/%s/levelpack.ini", PATH_LEVEL, argv[1]);
load_ini(&gIni, filepath);
// Loading lvl ini file
snprintf(filepath, MAX_PATH_LEN, "%s/%s/%s", PATH_LEVEL, argv[1], argv[2]);
load_ini(&gIni, filepath);
// Check if we found a "style =" line in level ini file
if (gIni.level.style==NULL) {
fprintf(stderr, "No valid style detected\n");
exit(1);
}
gIni.style.name=gIni.level.style;
// Loading style ini file
snprintf(filepath, MAX_PATH_LEN, "%s/%s/%s.ini", PATH_STYLE, gIni.level.style, gIni.level.style);
load_ini(&gIni, filepath);
res=loadRessources(&gIni, &gRess);
SDL_Init(SDL_INIT_VIDEO);
atexit(SDL_Quit);
/*
SDL_Surface *tile;
tile=gRess.style.tiles[gIni.level.terrains[0].id];
SDL_LockSurface(tile);
for(int i=0;i<1000000;i++) {
printf("%02i ", ((Uint8*)tile->pixels)[i]);
}
SDL_UnlockSurface(tile);
*/
res=paintTerrain(&gIni, &gRess, &terrain, &stencil);
if (res!=0) {
fprintf(stderr, "Cannot paintTerrain\n");
exit(3);
}
snprintf(filepath, MAX_PATH_LEN, "%s/%s_%s.bmp", PATH_TMP, argv[1], argv[2]);
res=SDL_SaveBMP(terrain, filepath);
if (res!=0) {
fprintf(stderr, "Cannot SaveBMP\n");
exit(4);
}
snprintf(filepath, MAX_PATH_LEN, "%s/%s_%s-stencil.bmp", PATH_TMP, argv[1], argv[2]);
res=SDL_SaveBMP(stencil, filepath);
if (res!=0) {
fprintf(stderr, "Cannot SaveBMP\n");
exit(4);
}
closeLog(NULL);
return res;
}
|