# Mapmaking Discussion & Philosophy (WIP/Critique) > Dungeon/Subterranean Mapping >  cavern generator

## drow

i thought i'd post a first look at what i'm currently working on,
adding caverns to my random dungeon generator.

i'm using the cellular automata algorithm from roguebasin for the rough layout,
and making repeated passes at increasingly finer resolution to achieve the final cavern.

the next step is improving performance.  13 seconds for a small dungeon at screen
resolution is a bit much, and generating a print resolution map is crazy.
after that, parsing the rough layout for rooms.

----------


## Marken4

Looks like a seahorse on the second pic... ^^ I think it looks nice, whats the white border around the edges tho? Sometimes the boxpattern(?) disseapears..

----------


## drow

> whats the white border around the edges tho? Sometimes the boxpattern(?) disseapears..


that's just the difference between the rough layout and the final cavern outline.
at some point, i'll have to update the imaging code.

----------


## Redrobes

Looks good. I could wait 13 seconds for it tho - thats no biggie. I think quality is more important than a few seconds wait.

----------


## RobA

And another great input to my smp script! (scaled up 3 times)



-Rob A>

----------


## drow

found a way to improve performance, and i've updated or created all the style routines.
(although the style routines pretty well wipe out my performance gains)

----------


## drow

my algorithm for identifying chambers within the caverns mostly works,
though it's pretty complicated and could probably be improved.

the second map is a desert caverns scaled for print.
about 3.5 minutes to generate, the majority of which is creating and dealing with image masks.

----------


## drow

i'm down to about 4 seconds for a standard medium size cavern map,
10 seconds with style, and 2 minutes with style at print scale.

i think i'm done with optimization, unless anyone knows some deep magic
for dealing with cellular automata across 9 million cell arrays.

----------


## drow

my brain won't stop working on this.
now down to 2 seconds, 5 seconds, and 1 minute.

a colossal cavern only takes 15 seconds, 26 seconds with style.
at print resolution should take about 8 minutes, but the process
consumes all the memory on my machine and grinds to a halt.   :Smile:

----------


## mathuwm

I dont know what you are talking about but I like the results ; )

----------


## drow

http://donjon.bin.sh/dungeon/?dungeon_layout=Cavernous

----------


## Talroth

Have you mapped out your memory usage in your algorithm? What exactly are you doing with your system memory? Do you have anyway to cut a map into chunks for fine detail processing and then automatically stitch it back together after the fact?

----------


## drow

> Have you mapped out your memory usage in your algorithm?
> What exactly are you doing with your system memory?


that's been this morning's work, aside from a quick trip to ikea.   :Smile: 

the generator is written in perl, so i'm at perl's mercy regarding memory allocation and usage.
and perl is rather notorious for sacrificing ridiculous piles of memory for performance.

i've converted the cell map from an array of arrays of integers (lazy)
to an array of strings, using vec() to manipulate it.

$map->[$r][$c]   # uses a lot of memory
vec($map->[$r],$c,1)   # a lot less memory, and isn't any slower
much better!  a colossal cavern, standard style and print scale, now takes 3.5 minutes to generate,
and the process consumes just over 500 MB of memory, instead of the 3+ GB it was sucking down before.

the parchment style is the most computationally expensive, and pushes that to 7.5 minutes.
the resulting image is an 8051 x 8051 pixel jpeg, 13 MB in size.

----------


## Sharpe

Man, you're awesome! Very talented.

I've noticed that there are no entrances to your caverns, though. Will you make it so that there's a cave opening running off the map?

----------


## Big Mac

> Man, you're awesome! Very talented.
> 
> I've noticed that there are no entrances to your caverns, though. Will you make it so that there's a cave opening running off the map?


I was about to say both of those things too. The maps do look great.

If this is going to be automated, could you perhaps give the user a choice to the number of entrances (when you eventually get to that stage)?

One entrance would give people a cave, but two (or a few) would give them the option to pass through the cave system to get somewhere else. That might be useful.

----------


## Sharpe

Man, Drow, you really rock.

Ever think about a random forest generator?

----------


## Jaxilon

wow, I just saw all the stuff you have on there. What a great resource. I can see using it to help build stuff for my RPG group when I'm in a hurry and so on. Thanks for all your hard work on this stuff.

----------


## industrygothica

Indeed, great resource.  Thanks a bunch!

----------


## MadCatUSA

Awesome! Love it! I'll be using this a lot!

----------


## Sharpe

Drow, as a suggestion for your random dungeon generator, would you consider making an option for all plain doors? Thanks!

----------


## Vorhees

This is Awesome i Use this Site ALOT , nice to meet ya Drow and keep up the Good Work

----------


## drow

> I've noticed that there are no entrances to your caverns, though. Will you make it so that there's a cave opening running off the map?





> Drow, as a suggestion for your random dungeon generator, would you consider making an option for all plain doors? Thanks!


ack, november already.  i'll get back to looking at these.  i'd also like to avoid too much option bloat, though.   :Smile:

----------


## drow

finally got a break...




> Drow, as a suggestion for your random dungeon generator, would you consider making an option for all plain doors? Thanks!


Doors: [ Basic ]
this will limit the generator to using archways (no door) and plain doors only.
there are a few other options available, as well.




> I've noticed that there are no entrances to your caverns, though. Will you make it so that there's a cave opening running off the map?


Peripheral Egress? [ Yes ]
applies to both hewn dungeons and caverns.
setting this to [ Multiple ] adds 2-4 outside tunnels.

----------


## drow



----------


## industrygothica

Very nice.

----------


## Thomian

Awesome stuff you have going there.

----------


## bloodymage

I'm trying to use this as I need some caverns for my game, but when it asks for levels, it only generates the highest level. I input eight and it gave me Level 8. How do I get the other levels?

I see now. It queries which level to draw.

OK, now all I need is to figure out how to print them out. I'm only getting a piece of the map when I try to print it out.

----------


## bloodymage

I got it figured out. Great site, by the way.

----------

