improved thread-safety of hills

This commit is contained in:
Cubitect 2018-07-04 10:53:35 +01:00
parent d9c2c8ae07
commit 1c313238d0
2 changed files with 10 additions and 12 deletions

View File

@ -861,7 +861,6 @@ 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) void mapHills(Layer *l, int * __restrict out, int areaX, int areaZ, int areaWidth, int areaHeight)
{ {
int pX = areaX - 1; int pX = areaX - 1;
@ -878,13 +877,7 @@ void mapHills(Layer *l, int * __restrict out, int areaX, int areaZ, int areaWidt
exit(1); exit(1);
} }
if(bufsize < pWidth*pHeight) buf = (int *) malloc(pWidth*pHeight*sizeof(int));
{
if(buf != NULL) free(buf);
bufsize = pWidth*pHeight;
buf = (int*)malloc(bufsize*sizeof(int));
}
l->p->getMap(l->p, out, pX, pZ, pWidth, pHeight); l->p->getMap(l->p, out, pX, pZ, pWidth, pHeight);
memcpy(buf, out, pWidth*pHeight*sizeof(int)); memcpy(buf, out, pWidth*pHeight*sizeof(int));
@ -982,6 +975,8 @@ void mapHills(Layer *l, int * __restrict out, int areaX, int areaZ, int areaWidt
} }
} }
} }
free(buf);
} }
@ -1202,7 +1197,8 @@ void mapShore(Layer *l, int * __restrict out, int areaX, int areaZ, int areaWidt
void mapRiverMix(Layer *l, int * __restrict out, int areaX, int areaZ, int areaWidth, int areaHeight) void mapRiverMix(Layer *l, int * __restrict out, int areaX, int areaZ, int areaWidth, int areaHeight)
{ {
int idx; int idx;
int *buf = (int*)malloc(areaWidth*areaHeight*sizeof(int)); int len;
int *buf;
if(l->p2 == NULL) if(l->p2 == NULL)
{ {
@ -1210,12 +1206,15 @@ void mapRiverMix(Layer *l, int * __restrict out, int areaX, int areaZ, int areaW
exit(1); exit(1);
} }
len = areaWidth*areaHeight;
buf = (int *) malloc(len*sizeof(int));
l->p->getMap(l->p, out, areaX, areaZ, areaWidth, areaHeight); // biome chain l->p->getMap(l->p, out, areaX, areaZ, areaWidth, areaHeight); // biome chain
memcpy(buf, out, areaWidth*areaHeight*sizeof(int)); memcpy(buf, out, len*sizeof(int));
l->p2->getMap(l->p2, out, areaX, areaZ, areaWidth, areaHeight); // rivers l->p2->getMap(l->p2, out, areaX, areaZ, areaWidth, areaHeight); // rivers
for(idx = 0; idx < areaHeight*areaWidth; idx++) for(idx = 0; idx < len; idx++)
{ {
if(isOceanic(buf[idx])) if(isOceanic(buf[idx]))
{ {

View File

@ -376,7 +376,6 @@ 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 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 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); 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 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 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); void mapSmooth(Layer *l, int * __restrict out, int x, int z, int w, int h);