God I need a repeat until...

  • While a good idea, in my case, a recursion would likely cause an even bigger delay in completion. Each cycle through the loop I'm looking at an element in the array. I'm then looking at the 9 elements surrounding it (x-1, y-1 to x+1, y+1) and basing changes off the results of that.

    Oh right! In that case Yeah, a simple recursion would iterate unnecessarily.

    Your project looks very exciting.. must be fun programming it! Would love to see it in action :)

    Basically, it's purpose was doing some 'cellular automata' to check and see if a land tile had at least 3 neighboring tiles that were terrain and if not, set it back to a water tile (-1)

    Just wondering if the loops are causing any delay? or they're instantaneous?

    For a larger (or denser) map, I was just wondering, how interesting would be to use a Quadtree algorithm for locating the islands? That's a recursive occupancy-detecting method that takes minimal iterations to find the objects in a 2D map (and hence its nearby objects).

    If you're not familiar with it, here are a couple of videos that have good examples:

    youtube.com/watch

    youtube.com/watch (from 2:08 to 3:03 only)

    But if your algorithm if fast enough, then you don't need anything else.

  • You shouldn't need to use a 'Stop loop' action like that. Just add the "Is flag not set" condition after the "While" condition, and it will only repeat the loop so long that is true.

  • Ah yeah that algorithm, I've actually looked at that in the past. I did a fair bit of reading on procedural terrain generation at one point and that was recommended for smoothing out caves.

    http://www.roguebasin.com/index.php?title=Cellular_Automata_Method_for_Generating_Random_Cave-Like_Levels

    https://gamedevelopment.tutsplus.com/tutorials/generate-random-cave-levels-using-cellular-automata--gamedev-9664

    https://gamedev.stackexchange.com/questions/154540/messy-results-from-simple-cellular-automata-algorithm

    I haven't done much cellular automata work in the past but I've tended to use 2 arrays; one to read from and another to write to. This prevents you from breaking your existing data. Then after processing all of them you swap the arrays. In C3 I did this by using a 3D array with a depth of 2, then alternating the read/write z index between 0 and 1.

    I think you could probably just perform a finite number of passes of your "smoothing" automata without trying to decided if it's "done"

  • Your project looks very exciting.. must be fun programming it! Would love to see it in action :)

    As soon as I get something solid, I'll update this post to a working example.

    Just wondering if the loops are causing any delay? or they're instantaneous?

    So far, it's not too horrible. A second or two. But, I'm far from being done. Nepeo pretty much figured out what I'm doing. I'm using a technique similar to what he linked to:

    roguebasin.com/index.php

    So far, these are the steps I'm taking but, I need at least one more routine and your Quadtree may just fit the bill. I'll study that today.

    * On function 'Startup'
    -> Functions: Call BuildArrayRandom
    -> Functions: Call AverageTheArray
    -> System: Set ArrayTotal to round((ArrayTotal÷ArrayCount))×MapFilter
    -> Functions: Call SetTerrainIslandorWater
    -> System: Set ArrayCount to 0
    -> Functions: Call FillInPonds
    -> Functions: Call EliminateOrphans
    -> Functions: Call PlaceBeaches
    -> Functions: Call CopyToTilemap
    

    First, it builds an array of random numbers.

    Then, it iterates through the array, looking at each cell. It looks at the 8 surrounding cells and replaces the one it's looking at with an average of the other 8.

    The ArrayTotal is the average of all cells in the entire array. By adding the MapFilter (say 0.9 to 1.1) I can easily generate more or less land mass.

    Then, it loops again through the array. If the cell is above that ArrayTotal average, it sets it to the value for the land tile, otherwise, it sets the value to the WaterTile.

    Next, it attempts to look at water tiles that have a lot of land around them and fills them with land tiles.

    The EliminateOrphans is the smoothing I posted above.

    And this next part I'm still working on. It loops again through the array, looks at surrounding tiles and attempts to create a beaches on the island borders from one of 12 possible tiles (N,S,E,W outside curved tiles NW,NE,SW,SE and inside curved tiles NW,NE,SW,SE).

    Finally, it copies the array over to the tilemap and shows it.

    But if your algorithm if fast enough, then you don't need anything else.

    So far, it's pretty quick. That may change as there are still trees, bushes, etc to place. I'm liberally stealing the idea from a game jam project and his would take a full minute or two to generate a map. I'm hoping to be a lot faster than that.

    This is a 200x200 array which it does in about 5 seconds.

    And to show how the map filter works, the above example was at 1.075. The one below was created just by changing that filter to 0.95.

  • Ah yeah that algorithm, I've actually looked at that in the past. I did a fair bit of reading on procedural terrain generation at one point and that was recommended for smoothing out caves.

    http://www.roguebasin.com/index.php?title=Cellular_Automata_Method_for_Generating_Random_Cave-Like_Levels

    You, sir, must be a mind reader. I'll study these links further today. Thanks for pointing them out!

  • Haha well perhaps not a mind reader, I just happen to remember that technique! Not that I ever actually implemented it, my experiments used Perlin noise with a few transforms on top. I had a dig around in my bookmarks to see if I had anything else you might find interesting in there:

    Simulating fluid movement with cellular automata

    Visualising Poisson disc sampling, Fisher Yates shuffle, Sorting and Maze generation algorithms ( Poisson and maze generation might be of interest )

    Maze/Dungeon generation

    Caves and terrain with noise

    Book of shader Interactive book where you can modify the examples

    Youtuber Sebastian Lague does some interesting game dev/procedural generation tutorials.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Would love to see it in action :)

    construct.net/en/forum/construct-3/your-construct-creations-9/procedural-archipelago-every-146271

    Your wish is my command. Unfortunately, since I do all the laboring in an array, there's no real output till it's all done. But it's the beginnings of procedural islands. Now, for rocks, trees and all the interaction fun.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)