summaryrefslogtreecommitdiff
path: root/src/test/testfunc_004_buildterrain.c
blob: 6be0015cce66fc7c7658f6de0def6b7d07bbf895 (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
#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

int main(int argc, char **argv) {
	int res;
	char filepath[MAX_PATH_LEN];
	gameIni_t gIni;
	gameRess_t gRess;
	gameGraphics_t gGraph;

	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]);
	res=loadIni(&gIni, filepath);
	if (res!=0) exit(res);

	// Loading lvl ini file
	snprintf(filepath, MAX_PATH_LEN, "%s/%s/%s", PATH_LEVEL, argv[1], argv[2]);
	res=loadIni(&gIni, filepath);
	if (res!=0) exit(res);

	// 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);
	res=loadIni(&gIni, filepath);
	if (res!=0) exit(res);

	
	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, &gGraph);
	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(gGraph.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(gGraph.stencil, filepath);
	if (res!=0) {
		fprintf(stderr, "Cannot SaveBMP\n");
		exit(4);
	}

	closeLog(NULL);

	return res;
}