mirror of
https://github.com/Cubitect/cubiomes.git
synced 2025-09-22 11:04:57 -04:00
Removed POSIX dependence.
This commit is contained in:
parent
5127be24a4
commit
f3243ca3fc
@ -8,6 +8,7 @@
|
||||
#include "finders.h"
|
||||
#include "generator.h"
|
||||
|
||||
|
||||
#define SEED_BUF_LEN 0x10000
|
||||
|
||||
|
||||
@ -16,7 +17,12 @@ struct compactinfo_t
|
||||
int64_t seedStart, seedEnd;
|
||||
};
|
||||
|
||||
void *searchCompactBiomesThread(void *data)
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
static void *searchCompactBiomesThread(void *data)
|
||||
#else
|
||||
static DWORD WINAPI searchCompactBiomesThread(LPVOID data)
|
||||
#endif
|
||||
{
|
||||
struct compactinfo_t info = *(struct compactinfo_t *)data;
|
||||
|
||||
@ -53,7 +59,10 @@ void *searchCompactBiomesThread(void *data)
|
||||
|
||||
free(seeds);
|
||||
|
||||
return NULL;
|
||||
#ifdef USE_PTHREAD
|
||||
pthread_exit(NULL);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -70,7 +79,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
printf("Starting search through seeds %"PRId64 " to %"PRId64", using %u threads.\n", seedStart, seedEnd, threads);
|
||||
|
||||
pthread_t threadID[threads];
|
||||
thread_id_t threadID[threads];
|
||||
struct compactinfo_t info[threads];
|
||||
|
||||
for (t = 0; t < threads; t++)
|
||||
@ -81,6 +90,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
info[threads-1].seedEnd = seedEnd;
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
|
||||
for (t = 0; t < threads; t++)
|
||||
{
|
||||
pthread_create(&threadID[t], NULL, searchCompactBiomesThread, (void*)&info[t]);
|
||||
@ -91,6 +102,17 @@ int main(int argc, char *argv[])
|
||||
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;
|
||||
}
|
||||
|
||||
|
29
finders.c
29
finders.c
@ -2,7 +2,6 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
@ -488,8 +487,11 @@ int countBlocksInSpawnRange(Pos p[4], const int ax, const int ay, const int az)
|
||||
return best;
|
||||
}
|
||||
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
static void *search4QuadBasesThread(void *data)
|
||||
#else
|
||||
static DWORD WINAPI search4QuadBasesThread(LPVOID data)
|
||||
#endif
|
||||
{
|
||||
quad_threadinfo_t info = *(quad_threadinfo_t*)data;
|
||||
|
||||
@ -595,14 +597,17 @@ static void *search4QuadBasesThread(void *data)
|
||||
fclose(fp);
|
||||
free(lowerBits);
|
||||
|
||||
return NULL;
|
||||
#ifdef USE_PTHREAD
|
||||
pthread_exit(NULL);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void search4QuadBases(const char *fnam, const int threads,
|
||||
const StructureConfig structureConfig, const int quality)
|
||||
{
|
||||
pthread_t threadID[threads];
|
||||
thread_id_t threadID[threads];
|
||||
quad_threadinfo_t info[threads];
|
||||
int64_t t;
|
||||
|
||||
@ -616,6 +621,9 @@ void search4QuadBases(const char *fnam, const int threads,
|
||||
info[t].sconf = structureConfig;
|
||||
}
|
||||
|
||||
|
||||
#ifdef USE_PTHREAD
|
||||
|
||||
for (t = 0; t < threads; t++)
|
||||
{
|
||||
pthread_create(&threadID[t], NULL, search4QuadBasesThread, (void*)&info[t]);
|
||||
@ -626,6 +634,19 @@ void search4QuadBases(const char *fnam, const int threads,
|
||||
pthread_join(threadID[t], NULL);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
for (t = 0; t < threads; t++)
|
||||
{
|
||||
threadID[t] = CreateThread(NULL, 0, search4QuadBasesThread, (LPVOID)&info[t], 0, NULL);
|
||||
}
|
||||
|
||||
WaitForMultipleObjects(threads, threadID, TRUE, INFINITE);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// merge thread parts
|
||||
|
||||
char fnamThread[256];
|
||||
|
14
finders.h
14
finders.h
@ -4,9 +4,21 @@
|
||||
#include "generator.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
|
||||
typedef HANDLE thread_id_t;
|
||||
|
||||
#else
|
||||
#define USE_PTHREAD
|
||||
#include <pthread.h>
|
||||
|
||||
typedef pthread_t thread_id_t;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#define SEED_BASE_MAX (1LL << 48)
|
||||
#define PI 3.141592653589793
|
||||
|
2
layers.h
2
layers.h
@ -46,7 +46,7 @@ enum BiomeType
|
||||
|
||||
enum BiomeTempCategory
|
||||
{
|
||||
Oceanic, Warm, Lush, Cold, Freezing, Unknown
|
||||
Oceanic, Warm, Lush, Cold, Freezing, UnknownTemp
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user