1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 Procedural World Generation [GM:S 1.4]

Discussion in 'Programming' started by Turkish Coffee, Mar 2, 2019.

  1. Turkish Coffee

    Turkish Coffee Member

    Joined:
    Nov 25, 2016
    Posts:
    559
    Hey,

    I'm creating a world with these codes and I ask for optimization tips as its my first time creating & handling a huge procedural room. And I'd like to know how I should approach "creating parallax moving backgrounds using oBiomeObjects"
    Step event of oGame (deleted some unneeded codes)
    Code:
    ///Build The Game World
    iother = instance_number(oBiomeObject);
    // WHILE
    if (GroundisReady == 0) {
       instance_create(addX,160+worldmover,oGroundTile);
       addX += 48;
    }
    if (GrassisReady == 0)
    {
       instance_create(addXg,167+60,oGrass1);
       addXg += 32;
    }
    if (GroundisReady == 1)
     {
      if (BiomesAreReady == 0)
      {
       var inst = instance_create(addXBiome,166+60,oBiomeObject);
       inst.i = iother+15;
       iother++;
       addXBiome += 256;
      }
      if (TownisReady == 0)
       {
         instance_create(room_width/2,166+worldmover,oTownCenter);
         instance_create(room_width/2,166+worldmover,oCampfire);
         TownisReady = 1;
       }
     }
    if (TownisReady == 1 && StartingPeopleReady == 0 && GrassisReady == 1)
     {
     //Creating people here
      StartingPeopleReady = 1;
     } else if (view_yview[0] != 60)
      {
       view_yview[0] = 60;
      } else if (view_yview[0] == 60 && whiten == false)
       {
        global.game = "running";
       }
    
    and in the oBiomeObject Draw Event
    Code:
     if (backgroundID != noone) //backgroundID determined in step event thats randomly chosen from the Create Event
      {
        if !(tile_exists(backgroundID))
        {
         if (backgroundID == sStoneBoulder2)
          {
           draw_sprite(backgroundID,0,x,y );
          }
         if (backgroundID == sRocks1)
          {    
           draw_sprite(backgroundID,0,x,y );  //I've been drawing them with tile_add(); before    
          }
        }
      }
    
     
  2. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,149
    This code isn't in any way consequential to performance as there are only like 50 lines of code. I see no loops, I don't see why you need variables like "GroundIsRead", they are never changed, what is their purpose?

    Why don't you add this
    Code:
    var t = current_time;
    
    above your code.

    and this
    Code:
    var t = current_time - t;
    show_debug_message("generation time: " + string(t) + " ms");
    
    below your code
     
  3. Turkish Coffee

    Turkish Coffee Member

    Joined:
    Nov 25, 2016
    Posts:
    559
    First, such variables as "GroundIsReady" are getting set to 1 from different objects. For example, "GroundIsReady" is set to 1 when a ground object gets out of the room. Either way, that can be done with the instance amount in the future.
    Other than that, I was expecting someone saying If I should or not use grids and if creating static ground -snow and such effects differ though- with objects is bad or not.

    Thanks for the answer, I'm getting 0-1ms from the output.
     
  4. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,149
    Sure a grid would be more performant, but I really rather want you to make the decision of what you want. Realize what each party has and how difficult it is to use them.
    Right now, you're getting 0 to 1 ms for this code. How do you determine when a piece of generation is done though, can you test the time from the start to the finish or the limit of generation?
     
  5. Turkish Coffee

    Turkish Coffee Member

    Joined:
    Nov 25, 2016
    Posts:
    559
    I've changed the generation code a bit and heres the full version of it without deleting some parts. Also I did what I must've done before at the last parts.
    Code:
    ///Build The Game World
    iother = instance_number(oBiomeObject);
    
    YOFVIEW = view_yview[0];
    // WHILE
    
    if (GroundisReady == 0) {
       instance_create(addX,160+worldmover,oGroundTile);
       addX += 48;
    }
    if (GrassisReady == 0)
    {
       instance_create(addXg,167+60,oGrass1);
       addXg += 32;
    }
    if (GroundisReady == 1)
     {
      if (BiomesAreReady == 0)
      {
       var inst = instance_create(addXBiome,166+60,oBiomeObject);
       inst.i = iother+15;
       iother++;
       addXBiome += 256;
      }
      if (TownisReady == 0)
       {
         instance_create(room_width/2,166+worldmover,oTownCenter);
         instance_create(room_width/2,166+worldmover,oCampfire);
         view_yview[0] = (0+(view_hview[0]/4)+15+worldmover);
         TownisReady = 1;
         instance_create(x-500,y-500,oTechTree);
       }
     }
    if (TownisReady == 1 && StartingPeopleReady == 0 && GrassisReady == 1)
     {
        with (instance_create(room_width/2-(32*7),y,oKing))
        {
         spd = 0.25;
         state = "move";
         other.alarm[10] = room_speed*3.25;
         sprite_index = sKingMoveRight;
         image_speed = 0.15;
        }
      with (instance_create(oKing.x-11,y,oHuman))
       {
        type = "javeliner";
        moveDir = "right";
        alarm_set(1,room_speed*3)
        state = "wander";
       }
      with (instance_create(oKing.x-19,y,oHuman))
       {
        type = "javeliner";
        moveDir = "right";
        alarm_set(1,room_speed*3)
        state = "wander";
       }
      with (instance_create(oKing.x-27,y,oHuman))
       {
        type = "lumberman";
        moveDir = "right";
        alarm_set(1,room_speed*3)
        state = "wander";
       }
      with (instance_create(oKing.x-35,y,oHuman))
       {
        type = "villager";
        moveDir = "right";
        alarm_set(1,room_speed*3)
        state = "wander";
       }
      StartingPeopleReady = 1;
      instance_create(x,y,oEnemyBase);
    
     
      view_object[0] = oTestCamera;
     } else if (view_yview[0] != 60)
      {
       view_yview[0] = 60;
      } else if (view_yview[0] == 60 && whiten == false && StartingPeopleReady == 1 && GroundisReady == 1 && TownisReady == 1)
       {
        instance_create(room_width/2+32,y,oTestCamera);
        instance_create(mouse_x,mouse_y,oCursor);
        global.game = "running";
        whiten = true;
        oBackgroundController.BlackScreenAlpha = 0.9;
        global.t = current_time - global.t;
        show_message("Game Gen Time: " + string(global.t) + " ms");
       }
    
    How the generation parts gets set to true
    Ground objects get generated depending on the width of the room so for this instance, a room with 3008 width, gets filled with ground objects around 3200 ms. And when a ground objects gets out of the room, it sets the GroundIsReady to 1.

    The last part of the generation gets triggered around 9200 ms
    Code:
    else if (view_yview[0] != 60)
      {
       view_yview[0] = 60;
      } else if (view_yview[0] == 60 && whiten == false)
       {
       global.game = "running";
       }
    
     
  6. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    1,188
    Just out of curiosity, how many instances are you generating? Might be best to use a data structure rather than a bunch of objects, much less overhead that way. But if you're only generating a few, probably not worth swapping over.
     
  7. Turkish Coffee

    Turkish Coffee Member

    Joined:
    Nov 25, 2016
    Posts:
    559
    I'm generating a few right now but I'll increase the world width so there will be so much more instances.
    267-275 instances in a 3003 room_width though depends on the random outputs which can create more objects such as vegetation.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice