Skip to content

Instantly share code, notes, and snippets.

@gsquaredxc
Created January 9, 2020 05:46
Show Gist options
  • Save gsquaredxc/3de6431c7f211eaaccace369ed0f97e4 to your computer and use it in GitHub Desktop.
Save gsquaredxc/3de6431c7f211eaaccace369ed0f97e4 to your computer and use it in GitHub Desktop.
#include "finders.h"
#include "generator.h"
#include <vector>
#include <iostream>
#include <thread>
#include <string>
#include <sstream>
struct compactinfo_t
{
int64_t seedStart, seedEnd;
unsigned int range;
BiomeFilter filter;
};
struct biomeCoords {
int xcord, zcord;
unsigned int biomeNum;
};
std::vector<int64_t> storage;
std::vector<biomeCoords> biomeList;
bool safeAdd = true;
static void *searchThread(void *data) {
struct compactinfo_t info = *(struct compactinfo_t *)data;
int64_t s;
LayerStack g = setupGenerator(MC_1_13);
for (s = info.seedStart; s < info.seedEnd; s++){
int i = 0;
applySeed(&g,s);
bool checker = true;
for (unsigned i=0; i<biomeList.size(); i++){
if (checker){
Pos pos;
pos.x = biomeList.at(i).xcord;
pos.z = biomeList.at(i).zcord;
if(getBiomeAtPos(g,pos) == biomeList.at(i).biomeNum){
if(biomeList.size()-1 == i){
storage.push_back(s);
std::cout << s << '/n';
safeAdd = false;
checker = false;
}
} else {
checker = false;
}
}
}
}
freeGenerator(g);
return 0;
}
int main(int argc, char *argv[])
{
initBiomes();
int64_t seedStart, seedEnd;
unsigned int threadNum, t, range;
BiomeFilter filter;
// arguments
if (argc <= 0)
{
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=1e8]\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], "%lli", &seedStart) != 1) seedStart = 0;
if (argc <= 2 || sscanf(argv[2], "%lli", &seedEnd) != 1) seedEnd = 100000000LL;
if (argc <= 3 || sscanf(argv[3], "%u", &threadNum) != 1) threadNum = 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));
bool start = false;
while(!start){
std::string input;
std::cin >> input;
if (input == "start"){
start = true;
} else {
std::stringstream split (input);
std::string x;
std::string z;
std::string biome;
std::getline(split,x,',');
std::getline(split,z,',');
std::getline(split,biome,',');
biomeCoords coords;
coords.xcord = std::stoi(x);
coords.zcord = std::stoi(z);
coords.biomeNum = std::stoi(biome);
biomeList.push_back(coords);
}
}
std::cout << "Starting search through seeds " << seedStart << " to " << seedEnd << ".\n";
std::vector<std::thread> threads;
struct compactinfo_t info[threadNum];
// store thread information
for (t = 0; t < threadNum; t++)
{
int64_t seedCnt = (seedEnd - seedStart) / threadNum;
info[t].seedStart = seedStart + seedCnt * t;
info[t].seedEnd = seedStart + seedCnt * (t+1) + 1;
info[t].filter = filter;
}
info[threadNum-1].seedEnd = seedEnd;
// start threads
#ifdef USE_PTHREAD
for (t = 0; t < threadNum; t++)
{
threads.push_back(std::thread(searchThread,(void*)&info[t]));
}
for (auto& th : threads) th.join();
#else
for (t = 0; t < threadNum; t++)
{
threadID[t] = CreateThread(NULL, 0, searchCompactBiomesThread, (LPVOID)&info[t], 0, NULL);
}
WaitForMultipleObjects(threads, threadID, TRUE, INFINITE);
#endif
/*for (unsigned i=0; i<storage.size(); i++)
std::cout << storage.at(i) << '\n';
return 0;*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment