• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Procedural Generation

Hey,

I'm coding my own procedural generation and trying to make it get shaped depening on the width of the room. So, if I ever change the room_width, that won't affect the code.

Here is the code I use for creating ground objects;

Create Event of a Persistent Object called "oGame"
Code:
addX = -16; // So it puts the first ground object where it needs to be. ( 0,0 sprite origin )

if (GroundisReady = 0) //This gets set to 1 if any of the ground objects get out of the room.
 {
  repeat(99999) // How can I make it repeat until GroundisReady variable is not equal to 1?
   {
    addX += 16;
    instance_create(addX,160,oGroundTile);
   }
 }
Do you think that type of generation would cause problems?
 
Last edited:

NightFrost

Member
Do you think that type of generation would cause problems?
Well, it will lock up the game until the loop is done. I think it is fine to do procgen in discrete steps. A project of mine displayed a progress bar while a new dungeon was generated.
How can I make it repeat until GroundisReady variable is not equal to 1?
But if you want one big loop you can use either a while loop or a do ... until loop. Both examples run until variable is set to value that is not one (here, set to zero).
Code:
GroundisReady = 1;
// WHILE
while(GroundisReady == 1){
   ...
   if(something something) GroundisReady = 0;
}

// DO UNTIL
do {
    ...
    if(something or other) GroundisReady = 0;
} until (GroundisReady != 1);
 
Well, it will lock up the game until the loop is done. I think it is fine to do procgen in discrete steps. A project of mine displayed a progress bar while a new dungeon was generated.

But if you want one big loop you can use either a while loop or a do ... until loop. Both examples run until variable is set to value that is not one (here, set to zero).
Code:
GroundisReady = 1;
// WHILE
while(GroundisReady == 1){
   ...
   if(something something) GroundisReady = 0;
}

// DO UNTIL
do {
    ...
    if(something or other) GroundisReady = 0;
} until (GroundisReady != 1);
Thanks for your reply!

I was planning to lock the game with a "Loading Screen" saying its loading and create the player after everything is created. How did you do your loading screen/bar? And these codes you've typed are meant to be in the Step Event right? I was in need the ground objects to be created at the same time because of the animations but I'll just set their image_index to = 0 when the game starts :)
 

NightFrost

Member
The progress bar itself was a bog-standard one, drawing a rectangle of certain width inside a box. I had a certain number of steps in the dungeon generation, like dungeon done, enemies places, treasure placed, light sources placed. Each would bump a step counter which was used to widen the drawn progress bar rectangle. And since I knew the dungeon procgen would take a certain amount of steps, I could bump the step counter by one after procgen had ran through a quarter of them, half, etc. I made my life simpler by running the procgen in a dedicated room as all I needed out of it was a grid array with the dungeon walls and locations of monsters, treasure and lights.

The code would go into step event if you want to run it a bit at a time, but if you run one huge loop it doesn't really matter where it is, as it runs only once. My procgen code was a modified drunkard walk in step event. Each corridor digger would run through its logic once per step - that is, it would carve out a single grid cell of the dungeon. Thus, if I wanted for them to dig 200 times, it would take 200 steps to complete the dungeon. (And the progress bar would bump up every 50 steps since it was coded to progress on each quarter done.)
 

nicognito

Member
Well, it will lock up the game until the loop is done. I think it is fine to do procgen in discrete steps. A project of mine displayed a progress bar while a new dungeon was generated.
Hi, @NightFrost!
Can I ask you how long your dungeon initizalization would take if you generated everything in one giant loop, on the game platform you're targeting?

I posted a similar question as Turkish Coffee here: https://forum.yoyogames.com/index.p...game-initialization-taking-a-long-time.33825/

It seems you're confirming loading your game by chunks in steps is the way to go with GMS, since there's no easy way to do multi threading with GML. My game initialization takes about 500ms on my iPhone in YYC mode (could take more time, (1) if the generated data is "bad" and I need to regenerate the data, or (2) if I want to generate more data).

Thanks.
 
Last edited:
W

Wraithious

Guest
Thanks for your reply!

I was planning to lock the game with a "Loading Screen" saying its loading and create the player after everything is created. How did you do your loading screen/bar? And these codes you've typed are meant to be in the Step Event right? I was in need the ground objects to be created at the same time because of the animations but I'll just set their image_index to = 0 when the game starts :)
Hi, I found a solution I posted on another thread to implement a loading screen, maybe this will help you out with that:

yea, I don't think you could do anything about gameplay while loading, but here's an example of how you could make a loading bar, but also note you don't have to make a loading bar you can draw anything you want while it's loading, if you did mod 100,000 you could go visual novel style and have 10 different backgrounds with text show up one at a time, or if you did mod 10,000 you could have 10 different backgrounds with 10 separate sub scenes in each one.
create event:
Code:
global.test=1000000;
global.testdraw=1;
done=0;
a=2;
b=0;
step event:
Code:
///test
for(b=done; b < global.test;b+=1)
{
if(global.testdraw=0)
{done+=1;
if (done mod 10000 == 0) global.testdraw=1;
}
}
if(global.testdraw=1)
{if a>0 a-=1;
if(a=0)
{
global.testdraw=0;
a=2;
}
}
Draw event:
Code:
///test
if(done<global.test)
{draw_set_color(c_yellow);
draw_roundrect(199,199,301,226,1);
draw_set_color(c_red);
draw_roundrect(200,200,300,225,0);
draw_set_color(c_green);
draw_roundrect(199,200,199+((100/(global.test/done)*1.01)),225,0);
draw_set_color(c_black);
draw_text(200,206,done);
}
 

NightFrost

Member
Hi, @NightFrost!
Can I ask you how long your dungeon initizalization would take if you generated everything in one giant loop, on the game platform you're targeting?
I never tested it that way, but at the very least it would have ben a significant hiccup. The number of diggers it ran also grew randomly over time, and those hitting dead end were discarded, so it had some variation. It was targeted on windows, so CPU power (and laptop vs desktop) would also have been a factor.
 
Top