forked from Cubitect/cubiomes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_compactbiomes.c
167 lines (136 loc) · 4.57 KB
/
find_compactbiomes.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "finders.h"
#include "generator.h"
struct compactinfo_t
{
int64_t seedStart, seedEnd;
unsigned int range;
BiomeFilter filter;
int withHut, withMonument;
int minscale;
};
#ifdef USE_PTHREAD
static void *searchCompactBiomesThread(void *data)
#else
static DWORD WINAPI searchCompactBiomesThread(LPVOID data)
#endif
{
struct compactinfo_t info = *(struct compactinfo_t *)data;
int ax = -info.range, az = -info.range;
int w = 2*info.range, h = 2*info.range;
int64_t s;
LayerStack g = setupGenerator(MC_1_14);
int *cache = allocCache(&g.layers[L_VORONOI_ZOOM_1], w, h);
for (s = info.seedStart; s != info.seedEnd; s++)
{
if (checkForBiomes(&g, cache, s, ax, az, w, h, info.filter, info.minscale))
{
int x, z;
if (info.withHut)
{
int r = info.range / SWAMP_HUT_CONFIG.regionSize;
for (z = -r; z < r; z++)
{
for (x = -r; x < r; x++)
{
Pos p;
p = getStructurePos(SWAMP_HUT_CONFIG, s, x, z);
if (isViableFeaturePos(Swamp_Hut, g, cache, p.x, p.z))
goto L_hut_found;
}
}
continue;
L_hut_found:;
}
if (info.withMonument)
{
int r = info.range / MONUMENT_CONFIG.regionSize;
for (z = -r; z < r; z++)
{
for (x = -r; x < r; x++)
{
Pos p;
p = getLargeStructurePos(MONUMENT_CONFIG, s, x, z);
if (isViableOceanMonumentPos(g, cache, p.x, p.z))
goto L_monument_found;
}
}
continue;
L_monument_found:;
}
printf("%ld\n", s);
fflush(stdout);
}
}
freeGenerator(g);
free(cache);
#ifdef USE_PTHREAD
pthread_exit(NULL);
#endif
return 0;
}
int main(int argc, char *argv[])
{
initBiomes();
int64_t seedStart, seedEnd;
unsigned int threads, t, range;
BiomeFilter filter;
int withHut, withMonument;
int minscale;
// arguments
if (argc <= 1)
{
printf( "find_compactbiomes [seed_start] [seed_end] [threads] [range]\n"
"\n"
" seed_start starting seed for search [long, default=0]\n"
" end_start end seed for search [long, default=-1]\n"
" threads number of threads to use [uint, default=1]\n"
" range search range (in blocks) [uint, default=1024]\n");
exit(1);
}
if (argc <= 1 || sscanf(argv[1], "%" PRId64, &seedStart) != 1) seedStart = 0;
if (argc <= 2 || sscanf(argv[2], "%" PRId64, &seedEnd) != 1) seedEnd = -1;
if (argc <= 3 || sscanf(argv[3], "%u", &threads) != 1) threads = 1;
if (argc <= 4 || sscanf(argv[4], "%u", &range) != 1) range = 1024;
// TODO: set up a customisable biome filter
filter = setupBiomeFilter(BIOMES_L13_OCEAN_MIX_4,
sizeof(BIOMES_L13_OCEAN_MIX_4)/sizeof(int));
minscale = 1; // terminate search at this layer scale
// TODO: simple structure filter
withHut = 0;
withMonument = 0;
printf("Starting search through seeds %" PRId64 " to %" PRId64", using %u threads.\n"
"Search radius = %u.\n", seedStart, seedEnd, threads, range);
thread_id_t threadID[threads];
struct compactinfo_t info[threads];
// store thread information
uint64_t seedCnt = ((uint64_t)seedEnd - (uint64_t)seedStart) / threads;
for (t = 0; t < threads; t++)
{
info[t].seedStart = (int64_t)(seedStart + seedCnt * t);
info[t].seedEnd = (int64_t)(seedStart + seedCnt * (t+1));
info[t].range = range;
info[t].filter = filter;
info[t].withHut = withHut;
info[t].withMonument = withMonument;
info[t].minscale = minscale;
}
info[threads-1].seedEnd = seedEnd;
// start threads
#ifdef USE_PTHREAD
for (t = 0; t < threads; t++)
{
pthread_create(&threadID[t], NULL, searchCompactBiomesThread, (void*)&info[t]);
}
for (t = 0; t < threads; t++)
{
pthread_join(threadID[t], NULL);
}
#else
for (t = 0; t < threads; t++)
{
threadID[t] = CreateThread(NULL, 0, searchCompactBiomesThread, (LPVOID)&info[t], 0, NULL);
}
WaitForMultipleObjects(threads, threadID, TRUE, INFINITE);
#endif
return 0;
}