Skip to content

Commit

Permalink
Add oceanic elevation variation to the new archipelago mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Rideout committed Nov 8, 2015
1 parent 6de1dc5 commit 37666c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
22 changes: 18 additions & 4 deletions src/generate.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ heman_image* heman_generate_archipelago_political_2(int width, int height,
}

heman_image* heman_generate_archipelago_political_3(int width, int height,
const heman_color* colors, int ncolors, int seed, heman_image* political)
const heman_color* colors, int ncolors, heman_color ocean, int seed,
heman_image* political)
{
heman_image** elevations = malloc(sizeof(heman_image*) * ncolors);
for (int cindex = 0; cindex < ncolors; cindex++) {
Expand All @@ -350,7 +351,6 @@ heman_image* heman_generate_archipelago_political_3(int width, int height,
heman_image* elevation = heman_image_create(width, height, 1);
heman_image_clear(elevation, 0);
for (int cindex = 0; cindex < ncolors; cindex++) {

#pragma omp parallel for
for (int y = 0; y < height; ++y) {
HEMAN_FLOAT* dst = elevation->data + y * width;
Expand All @@ -359,10 +359,24 @@ heman_image* heman_generate_archipelago_political_3(int width, int height,
*dst = MAX(*src, *dst);
}
}

heman_image_destroy(elevations[cindex]);
}
free(elevations);

heman_image* ocean_elevation = heman_generate_archipelago_political_2(
width, height, ocean, seed, political, 0);
#pragma omp parallel for
for (int y = 0; y < height; ++y) {
HEMAN_FLOAT* dst = elevation->data + y * width;
HEMAN_FLOAT* src = ocean_elevation->data + y * width;
for (int x = 0; x < width; ++x, ++dst, ++src) {
if (*src < 0) {
*dst = *src;
}
}
}
heman_image_destroy(ocean_elevation);

return elevation;
}

Expand All @@ -378,6 +392,6 @@ void heman_generate_archipelago_political(int width, int height,
} else {
int ncolors = points->width;
*elevation = heman_generate_archipelago_political_3(
width, height, colors, ncolors, seed, *political);
width, height, colors, ncolors, ocean, seed, *political);
}
}
4 changes: 2 additions & 2 deletions test/test_heman.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "hut.h"

#ifdef __APPLE__
double omp_get_wtime() { return 0; }
double omp_get_wtime() { return 1; }
int omp_get_max_threads() { return 1; }
#else
#include <omp.h>
Expand Down Expand Up @@ -338,7 +338,7 @@ void test_political()
heman_image* elev;
heman_image* poli;
heman_generate_archipelago_political(
imgres, imgres, pts, colors, ocean, seed, &elev, &poli, 0);
imgres, imgres, pts, colors, ocean, seed, &elev, &poli, 1);
heman_image* oceanimg = heman_color_apply_gradient(elev, -0.5, 0.5, grad);
elev = heman_ops_stairstep(elev, 2, 4, 1);
poli = heman_ops_sobel(poli, beach);
Expand Down

0 comments on commit 37666c6

Please sign in to comment.