Hello I am trying to create a procedurally generated world to my game.I have already figured out how to do it but the problem is that it's taking too much time. I am trying to generate a world size of 8400x2500 and It takes 70 minutes to finish the process. Any thoughts how to improve speed of generating this world? Here are some code that I wrote to generate my world and an image to show how does it look:
#include <iostream>
#include "anl.h"
int main()
{
anl::CMWC4096 rnd;
rnd.setSeedTime();
anl::CImplicitGradient ground_gradient;
ground_gradient.setGradient(0, 0, -1, 1);
std::cout << "Generating Lowlands..." << std::endl;
//LOWLANDS
anl::CImplicitFractal lowland_shape_fractal(anl::BILLOW, anl::GRADIENT, anl::QUINTIC);
lowland_shape_fractal.setNumOctaves(2);
lowland_shape_fractal.setFrequency(1);
//lowland_shape_fractal.setSeed(rnd.get());
anl::CImplicitAutoCorrect lowland_autocorrect(-1, 1);
lowland_autocorrect.setSource(&lowland_shape_fractal);
anl::CImplicitScaleOffset lowland_scale(0.125, -0.10);
lowland_scale.setSource(&lowland_autocorrect);
anl::CImplicitScaleDomain lowland_y_scale;
lowland_y_scale.setSource(&lowland_scale);
lowland_y_scale.setYScale(-1);
anl::CImplicitTranslateDomain lowland_terrain;
lowland_terrain.setSource(&ground_gradient);
lowland_terrain.setYAxisSource(&lowland_y_scale);
//LOWLANDS//
std::cout << "Generating Highlands..." << std::endl;
//HIGHLANDS
anl::CImplicitFractal highland_shape_fractal(anl::FBM, anl::GRADIENT, anl::QUINTIC);
highland_shape_fractal.setNumOctaves(4);
highland_shape_fractal.setFrequency(2);
//highland_shape_fractal.setSeed(rnd.get());
anl::CImplicitAutoCorrect highland_autocorrect(-1, 1);
highland_autocorrect.setSource(&highland_shape_fractal);
anl::CImplicitScaleOffset highland_scale(0.25, 0.0);
highland_scale.setSource(&highland_autocorrect);
anl::CImplicitScaleDomain highland_y_scale;
highland_y_scale.setSource(&highland_scale);
highland_y_scale.setYScale(-1);
anl::CImplicitTranslateDomain highland_terrain;
highland_terrain.setSource(&ground_gradient);
highland_terrain.setYAxisSource(&highland_y_scale);
//HIGHLANDS//
std::cout << "Generating Mountains..." << std::endl;
//MOUNTAINS
anl::CImplicitFractal mountain_shape_fractal(anl::RIDGEDMULTI, anl::GRADIENT, anl::QUINTIC);
mountain_shape_fractal.setNumOctaves(8);
mountain_shape_fractal.setFrequency(1);
//mountain_shape_fractal.setSeed(rnd.get());
anl::CImplicitAutoCorrect mountain_autocorrect(-1, 1);
mountain_autocorrect.setSource(&mountain_shape_fractal);
anl::CImplicitScaleOffset mountain_scale(0.53, 0.10);
mountain_scale.setSource(&mountain_autocorrect);
anl::CImplicitScaleDomain mountain_y_scale;
mountain_y_scale.setSource(&mountain_scale);
mountain_y_scale.setYScale(-0.5);
anl::CImplicitTranslateDomain mountain_terrain;
mountain_terrain.setSource(&ground_gradient);
mountain_terrain.setYAxisSource(&mountain_y_scale);
//MOUNTAINS//
std::cout << "Mixing Terrains..." << std::endl;
//TERRAIN
anl::CImplicitFractal terrain_type_fractal(anl::FBM, anl::GRADIENT, anl::QUINTIC);
terrain_type_fractal.setNumOctaves(3);
terrain_type_fractal.setFrequency(0.2);
//terrain_type_fractal.setSeed(rnd.get());
anl::CImplicitAutoCorrect terrain_autocorrect(0, 1);
terrain_autocorrect.setSource(&terrain_type_fractal);
anl::CImplicitScaleDomain terrain_type_y_scale;
terrain_type_y_scale.setSource(&terrain_autocorrect);
terrain_type_y_scale.setYScale(-1);
anl::CImplicitCache terrain_type_cache;
terrain_type_cache.setSource(&terrain_type_y_scale);
//TERRAIN//
anl::CImplicitSelect highland_mountain_select;
highland_mountain_select.setLowSource(&highland_terrain);
highland_mountain_select.setHighSource(&mountain_terrain);
highland_mountain_select.setControlSource(&terrain_type_cache);
highland_mountain_select.setThreshold(0.55);
highland_mountain_select.setFalloff(0.2);
anl::CImplicitSelect highland_lowland_select;
highland_lowland_select.setLowSource(&lowland_terrain);
highland_lowland_select.setHighSource(&highland_mountain_select);
highland_lowland_select.setControlSource(&terrain_type_cache);
highland_lowland_select.setThreshold(0.25);
highland_lowland_select.setFalloff(0.15);
anl::CImplicitCache highland_lowland_select_cache;
highland_lowland_select_cache.setSource(&highland_lowland_select);
anl::CImplicitSelect ground_select;
ground_select.setLowSource(0.0);
ground_select.setHighSource(1);
ground_select.setThreshold(0.5);
ground_select.setFalloff(0.0);
ground_select.setControlSource(&highland_lowland_select_cache);
std::cout << "Generating Caves..." << std::endl;
//CAVES
//CAVES ORYGINAL
anl::CImplicitFractal cave_shape(anl::RIDGEDMULTI, anl::GRADIENT, anl::QUINTIC);
cave_shape.setNumOctaves(1);
cave_shape.setFrequency(5);
//cave_shape.setSeed(rnd.get());
anl::CImplicitBias cave_attenuate_bias(0.91);
cave_attenuate_bias.setSource(&highland_lowland_select_cache);
anl::CImplicitCombiner cave_shape_attenuate(anl::MULT);
cave_shape_attenuate.setSource(0, &cave_shape);
cave_shape_attenuate.setSource(1, &cave_attenuate_bias);
anl::CImplicitFractal cave_perturb_fractal(anl::FBM, anl::GRADIENT, anl::QUINTIC);
cave_perturb_fractal.setNumOctaves(6);
cave_perturb_fractal.setFrequency(5);
//cave_perturb_fractal.setSeed(rnd.get());
anl::CImplicitScaleOffset cave_perturb_scale(1.0, 0.0);
cave_perturb_scale.setSource(&cave_perturb_fractal);
anl::CImplicitTranslateDomain cave_perturb;
cave_perturb.setSource(&cave_shape_attenuate);
cave_perturb.setXAxisSource(&cave_perturb_scale);
anl::CImplicitSelect cave_select;
cave_select.setLowSource(1.0);
cave_select.setHighSource(0.0);
cave_select.setControlSource(&cave_perturb);
cave_select.setThreshold(0.9);
cave_select.setFalloff(0.0);
//CAVES ORYGINAL//
//CAVES MINE
anl::CImplicitFractal cave_perturb_fractal_deep(anl::RIDGEDMULTI, anl::GRADIENT, anl::QUINTIC);
cave_perturb_fractal_deep.setNumOctaves(1);
cave_perturb_fractal_deep.setFrequency(100);
//cave_perturb_fractal_deep.setSeed(rnd.get());
anl::CImplicitSelect cave_select_deep;
cave_select_deep.setLowSource(1.0);
cave_select_deep.setHighSource(0.0);
cave_select_deep.setControlSource(&cave_perturb_fractal_deep);
cave_select_deep.setThreshold(0.98);
cave_select_deep.setFalloff(0.0);
anl::CImplicitScaleDomain scaledomain;
scaledomain.setSource(&cave_select_deep);
scaledomain.setYScale(0.0);
/////->>>>>>>>>>>>>>>>>>>>
anl::CImplicitFractal cave_perturb_fractal_deep1(anl::RIDGEDMULTI, anl::GRADIENT, anl::QUINTIC);
cave_perturb_fractal_deep1.setNumOctaves(1);
cave_perturb_fractal_deep1.setFrequency(50);
//cave_perturb_fractal_deep1.setSeed(rnd.get());
anl::CImplicitSelect cave_select_deep1;
cave_select_deep1.setLowSource(0.0);
cave_select_deep1.setHighSource(1.0);
cave_select_deep1.setControlSource(&cave_perturb_fractal_deep1);
cave_select_deep1.setThreshold(0.8);
cave_select_deep1.setFalloff(0.0);
anl::CImplicitScaleDomain scaledomain1;
scaledomain1.setSource(&cave_select_deep1);
scaledomain1.setYScale(0.0);
/////<<<<<<<<<<<<<<<<<<<<<<<<<-
////->>>>>>>>>>>>>>>>>>>>>>>>>>
anl::CImplicitFractal cave_perturb_fractal_deep2(anl::RIDGEDMULTI, anl::GRADIENT, anl::QUINTIC);
cave_perturb_fractal_deep2.setNumOctaves(1);
cave_perturb_fractal_deep2.setFrequency(25);
//cave_perturb_fractal_deep2.setSeed(rnd.get());
anl::CImplicitSelect cave_select_deep2;
cave_select_deep2.setLowSource(0.0);
cave_select_deep2.setHighSource(1.0);
cave_select_deep2.setControlSource(&cave_perturb_fractal_deep2);
cave_select_deep2.setThreshold(0.85);
cave_select_deep2.setFalloff(0.0);
anl::CImplicitScaleDomain scaledomain2;
scaledomain2.setSource(&cave_select_deep2);
scaledomain2.setYScale(0.0);
////<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<-
////->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
anl::CImplicitFractal cave_perturb_fractal_deep3(anl::RIDGEDMULTI, anl::GRADIENT, anl::QUINTIC);
cave_perturb_fractal_deep3.setNumOctaves(1);
cave_perturb_fractal_deep3.setFrequency(7);
//cave_perturb_fractal_deep3.setSeed(rnd.get());
anl::CImplicitSelect cave_select_deep3;
cave_select_deep3.setLowSource(0.0);
cave_select_deep3.setHighSource(1.0);
cave_select_deep3.setControlSource(&cave_perturb_fractal_deep3);
cave_select_deep3.setThreshold(0.85);
cave_select_deep3.setFalloff(0.0);
anl::CImplicitScaleDomain scaledomain3;
scaledomain3.setSource(&cave_select_deep3);
scaledomain3.setYScale(0.0);
/////<<<<<<<<<<<<<<<<<<<<<<<<<<<-
anl::CImplicitCombiner combiner0(anl::MAX);
combiner0.setSource(0, &scaledomain1);
combiner0.setSource(1, &scaledomain2);
anl::CImplicitCombiner combiner1(anl::MAX);
combiner1.setSource(0, &combiner0);
combiner1.setSource(1, &scaledomain3);
anl::CImplicitCombiner combiner2(anl::MAX);
combiner2.setSource(0, &scaledomain);
combiner2.setSource(1, &combiner1);
anl::CImplicitFractal fractal(anl::FBM, anl::GRADIENT, anl::QUINTIC);
fractal.setNumOctaves(6);
fractal.setFrequency(0.25);
//fractal.setSeed(rnd.get());
anl::CImplicitScaleOffset scaleoff(0.5, 0.0);
scaleoff.setSource(&fractal);
anl::CImplicitTranslateDomain translate;
translate.setSource(&combiner2);
translate.setXAxisSource(&scaleoff);
anl::CImplicitFractal fractal1(anl::FBM, anl::GRADIENT, anl::QUINTIC);
fractal1.setNumOctaves(4);
fractal1.setFrequency(1);
//fractal1.setSeed(rnd.get());
anl::CImplicitScaleOffset scaleoff1(0.5, 0.0);
scaleoff1.setSource(&fractal1);
anl::CImplicitTranslateDomain end;
end.setSource(&translate);
end.setXAxisSource(&scaleoff1);
//CAVES MINE//
anl::CImplicitCombiner all_caves_combine(anl::MIN);
all_caves_combine.setSource(0, &cave_select);
all_caves_combine.setSource(1, &end);
anl::CImplicitCombiner ground_cave_multiply(anl::MULT);
ground_cave_multiply.setSource(0, &all_caves_combine);
ground_cave_multiply.setSource(1, &ground_select);
//CAVES
std::cout << "World Generated..." << std::endl;
std::cout << "Adding to compose..." << std::endl;
anl::CRGBACompositeChannels compose1(anl::RGB);
compose1.setBlueSource(&ground_cave_multiply);
compose1.setGreenSource(&ground_cave_multiply);
compose1.setRedSource(&ground_cave_multiply);
compose1.setAlphaSource(1.0);
std::cout << "End compose-ing" << std::endl;
anl::TArray2D<anl::SRGBA> img(8400 /1, 2400 /1);
anl::SMappingRanges ranges;
anl::mapRGBA2D(anl::SEAMLESS_NONE, img, compose1, ranges, 0);
anl::saveRGBAArray((char*)"img/a.tga", &img);