From 9ac742d56bec171a0d252e7ef33b501466448f2b Mon Sep 17 00:00:00 2001 From: Tom Schumm Date: Mon, 2 Jul 2018 14:26:02 -0700 Subject: [PATCH 1/3] Fix copypasta in getMansionPos() --- finders.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/finders.c b/finders.c index 4ea06da..7bc2afd 100644 --- a/finders.c +++ b/finders.c @@ -809,7 +809,7 @@ Pos getMansionPos(long seed, const long area80X, const long area80Z) pos.z += (seed >> 17) % 60; pos.x = area80X*80 + (pos.x >> 1); - pos.z = area80X*80 + (pos.z >> 1); + pos.z = area80Z*80 + (pos.z >> 1); pos.x = pos.x*16 + 8; pos.z = pos.z*16 + 8; return pos; From 6558f5b7a6112f17837fa535652926dfcc6eca7f Mon Sep 17 00:00:00 2001 From: Tom Schumm Date: Mon, 2 Jul 2018 14:30:12 -0700 Subject: [PATCH 2/3] Add comments noting some not-thread-safe functions. --- finders.c | 2 ++ finders.h | 1 + layers.c | 1 + layers.h | 1 + 4 files changed, 5 insertions(+) diff --git a/finders.c b/finders.c index 7bc2afd..81beca0 100644 --- a/finders.c +++ b/finders.c @@ -660,6 +660,8 @@ void baseQuadTempleSearch(const char *fnam, const int threads, const int quality /* getBiomeAtPos * ---------------- * Returns the biome for the specified block position. + * (Alternatives should be considered in performance critical code.) + * This function is not threadsafe. */ int getBiomeAtPos(const LayerStack g, const Pos pos) { diff --git a/finders.h b/finders.h index 6254e12..1ad6407 100644 --- a/finders.h +++ b/finders.h @@ -126,6 +126,7 @@ void baseQuadTempleSearch(const char *fnam, int threads, int quality); * ---------------- * Returns the biome for the specified block position. * (Alternatives should be considered in performance critical code.) + * This function is not threadsafe. */ int getBiomeAtPos(const LayerStack g, const Pos pos); diff --git a/layers.c b/layers.c index 3c6d648..7d37557 100644 --- a/layers.c +++ b/layers.c @@ -861,6 +861,7 @@ void mapBiomeEdge(Layer *l, int * __restrict out, int areaX, int areaZ, int area } +/* This function is not threadsafe. */ void mapHills(Layer *l, int * __restrict out, int areaX, int areaZ, int areaWidth, int areaHeight) { int pX = areaX - 1; diff --git a/layers.h b/layers.h index 9dfefcf..f707efc 100644 --- a/layers.h +++ b/layers.h @@ -376,6 +376,7 @@ void mapDeepOcean(Layer *l, int * __restrict out, int x, int z, int w, int h); void mapBiome(Layer *l, int * __restrict out, int x, int z, int w, int h); void mapRiverInit(Layer *l, int * __restrict out, int x, int z, int w, int h); void mapBiomeEdge(Layer *l, int * __restrict out, int x, int z, int w, int h); +/* This function is not threadsafe. */ void mapHills(Layer *l, int * __restrict out, int x, int z, int w, int h); void mapRiver(Layer *l, int * __restrict out, int x, int z, int w, int h); void mapSmooth(Layer *l, int * __restrict out, int x, int z, int w, int h); From 9ead1a03d6da9944a834a625d9f1e16dd1adef50 Mon Sep 17 00:00:00 2001 From: Tom Schumm Date: Mon, 2 Jul 2018 14:34:01 -0700 Subject: [PATCH 3/3] Exit gracefully when seed files can't be open for writing. --- finders.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/finders.c b/finders.c index 81beca0..0f7da93 100644 --- a/finders.c +++ b/finders.c @@ -531,6 +531,10 @@ static void *baseQuadTempleSearchThread(void *data) sprintf(fnam, "%s.part%d", info.fnam, info.threadID); FILE *fp = fopen(fnam, "a+"); + if (fp == NULL) { + fprintf(stderr, "Could not open \"%s\" for writing.\n", fnam); + exit(-1); + } seed = start; @@ -617,6 +621,10 @@ void baseQuadTempleSearch(const char *fnam, const int threads, const int quality char fnamThread[256]; char buffer[4097]; FILE *fp = fopen(fnam, "w"); + if (fp == NULL) { + fprintf(stderr, "Could not open \"%s\" for writing.\n", fnam); + exit(-1); + } FILE *fpart; int n;