Basically (dont want to get into too much detail because its a few thousand lines for the whole thing)
I generate the terrain on one array, this array is 1024x1024. It is this large because the detail of the terrain is quite noticeable.
Now, after generating the terrain i start generating the rivers, the rivers use the Best Path (A*) pathfinding algorithm, but instead of the H value being distance from the target, its the height of the terrain (gravity affect).
Now, if i was doing pathfinding of a 1024x1024 area, it takes too long. Like i left it running for 5mins, it hadnt done it, i cant expect a loading screen to take that long.
So i made it so the pathfinding was done on a smaller area, eg.
Then if i ever needed to get information from the terrain i would just do something like:
H = HeightOfTerrain[CurrentX*Optimization][Y*Optimization]
Then when i had done it all and it go round to drawing the river (because this means theres gaps in the river because im not calculating the area between say 1*Optimization and 2*Optimization (which is 5)) I had to do a forloop like:
for (int i = 0; i < Optimization; i++)
HeightOfTerrain[CurrentX*Optimization+i][CurrentY*Optimzation+i] -= 100;
And that would say make the riverbed deeper by 100, which is how u see the riverbed in the heightmap.
The total code comes to just over 2000 lines over 5 files.
As you can see from above, it ment the rivers went from taking a few minuets to generate each, to a matter of seconds.. and thats generating 3.