-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
123 lines (105 loc) · 2.72 KB
/
main.c
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
120
121
122
123
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <zlib.h>
#include <dirent.h>
#include <string.h>
#include <locale.h>
#include <math.h>
#include "main.h"
#include "config.h"
#include "nbt.h"
#include "level.h"
#include "chunk.h"
#include "colors.h"
#include "colors/hardcoded.h"
#include "renderer.h"
#include "renderers/flat.h"
int main (int argc, char **argv)
{
configuration config;
level *l = NULL;
color_map *map = NULL;
renderer *r = NULL;
int errcode = 0, i, tile_x, tile_z, tile_x_start, tile_x_end, tile_z_start, tile_z_end;
char filename_buffer[256];
if (!setlocale(LC_CTYPE, ""))
{
fprintf(stderr, "Can't set the specified local! Check LANG, LC_CTYPE, LC_ALL\n");
return 1;
}
if ((errcode = parse_commandline_options(argc, argv, &config)) != 0)
{
printf("Error parsing configuration: %s\n", config_error_message(errcode));
goto main_cleanup;
}
map = color_map_hardcoded_new(256, 4);
if (map == NULL)
{
printf("Error loading color map\n");
goto main_cleanup;
}
l = level_load(config.input_path);
if (l == NULL)
{
printf("Error loading level\n");
goto main_cleanup;
}
/*
level_get_dimensions(l);
tile_x_start = (int)floor(l->smallest_x / 16) - 1;
tile_x_end = (int)floor(l->largest_x / 16);
tile_z_start = (int)floor(l->smallest_z / 16) - 1;
tile_z_end = (int)floor(l->largest_z / 16);
*/
r = renderer_flat_new(l, map);
if (r == NULL)
{
printf("Unable to initialize a new flat renderer\n");
goto main_cleanup;
}
if (errcode = renderer_perform(r, config.tile_x, config.tile_z, config.output_filename))
{
printf("Rendering failed: %i\n", errcode);
}
/*
for (tile_x = tile_x_start; tile_x <= tile_x_end; tile_x++)
for (tile_z = tile_z_start; tile_z <= tile_z_end; tile_z++)
{
memset(filename_buffer, 0, 256);
snprintf(filename_buffer, 256, "%s/tile_%i_%i.png", config.output_filename, tile_x, tile_z);
if (errcode = renderer_perform(r, tile_x, tile_z, filename_buffer))
{
printf("Rendering failed: %i\n", errcode);
}
}
*/
main_cleanup:
if (r != NULL)
renderer_free(r);
else
{
if (l != NULL)
level_free(l);
if (map != NULL)
color_map_free(map);
}
free_config(&config);
}
void free_string(void *str)
{
free(str);
}
void hex_print(void *hex, int len)
{
int i;
unsigned char c;
for (i = 0; i < len; i++)
{
c = (unsigned char)*((unsigned char*)hex + i);
printf("%.2X", c, i);
}
}
void print_help(void)
{
}