1. Hey! Guest! The 33rd GMC Jam will take place between May 23rd, 12:00 UTC (Friday noon) and May 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

"Infinite Terrain" memory problems

Discussion in 'Programming' started by Logan Bevans, Mar 13, 2019.

  1. Logan Bevans

    Logan Bevans Member

    Joined:
    May 17, 2018
    Posts:
    39
    Hi, iv has been working on a game with near infinite terrain in which I deactivate all of the objects except for the once in my view I'm having issues with my memory increasing whenever I explore from the main loading part it starts dropping fps. Iv thought it could have something to do with the activating and deactivation of the objects possible some being left activated though i doubt it any help would be greatly appreciated

    [scr_render
    instance_deactivate_object(obj_block);
    instance_deactivate_object(obj_break);
    instance_deactivate_object(obj_enemy2);
    instance_deactivate_object(obj_item);
    instance_deactivate_object(obj_solidblock);
    instance_deactivate_object(obj_ghostblock);

    instance_activate_object(obj_logspawn_oak);
    instance_activate_object(obj_logspawn_birch);
    instance_activate_region((view_xview[0])-64, (view_yview[0])-64, (view_wview[0])+96, (view_hview[0])+96, true);]

    If needed I can provide the code of my terrain generation if that's the issue
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,514
    So can the player move backwards? Do you really need everything to stay in the game?
     
  3. Warspite2

    Warspite2 Member

    Joined:
    Jun 23, 2016
    Posts:
    92
    Can you provide more code? I'm wondering if your problem is not related to this.
     
  4. Logan Bevans

    Logan Bevans Member

    Joined:
    May 17, 2018
    Posts:
    39
    Yeah its a terraria esk terrain generation
    ////scr_worldgen---------------------------------------------------------------------------
    var sh,ah,dirt_level,stone_level,water_level,adl,starting_room,ending_room, tree, biome,hill;
    sh = 1920;
    randomize();
    //Starting Height
    ah = sh;


    starting_room = argument0;
    ending_room = argument0 + 1728;

    tree = choose(1);
    biome = 2; //choose(1,2,3,4);
    hill = choose(true,false,false);
    cacti = 0;

    for(xx = starting_room; xx < ending_room; xx += 32) {

    if biome = 1{

    //Biomes
    //------PLAINS------//
    instance_create(xx,ah,obj_grass);
    // p = choose(1,1,2,0,0,);
    // if p = 1 {
    // if !place_meeting(x,y,obj_cactus) {
    // instance_create(xx,ah-32,obj_grassplants);
    // }
    // }
    dirt_level = ah + 32*choose(2,3,3,3);
    stone_level = 4192; //room_height poss inf down
    water_level = 1920;

    //Dirt Level
    for(yy = ah; yy < dirt_level; yy += 32){
    instance_create(xx, yy + 32, obj_dirt);
    adl = yy
    }
    //Stone Level
    for(yy = adl; yy < adl + 64; yy += 32){
    u = round(random(choose(3)));
    if u = 1{
    instance_create(xx, yy + 64, obj_stone);
    }else {
    instance_create(xx, yy + 64, obj_dirt);
    }
    }
    for(yy = adl + 64; yy < stone_level; yy += 32){
    instance_create(xx, yy + 64, obj_stone);
    }
    //Height Variation In Biome
    if (hill){
    amp = 7;
    } else {
    amp = 5 + random(4);
    }
    ah += amp*sin((2*pi)/1728*(xx-864))+((8+random(8))*sin((2*pi)/choose(54,108,240)*xx))+((15+random(2))*sin((2*pi/240)*xx));
    }

    if biome = 2{
    ///-----PLAINSwTrees--///

    instance_create(xx,ah,obj_grass);
    // p = choose(1,1,2,0,0,);
    // if p = 1 {
    // if !place_meeting(x,y,obj_cactus) {
    // instance_create(xx,ah-32,obj_grassplants);
    // }
    // }
    //global.th = choose(5,6,6,6,6,6,7,7,7);
    global.th = choose(5);
    dirt_level = ah + 32*choose(2,3,3,3);
    stone_level = 4192; //room_height poss inf down
    water_level = 1920;
    if (ah <= water_level){
    tree += 1;
    }

    // //Trees
    // if (tree = 9) && (ah <= water_level){
    /// c = choose(1,1,2);
    // if c = 1{
    // with(instance_create(xx,ah - 32,choose(obj_logspawn_oak,obj_logspawn_birch))){
    // canGrow = true;
    // }
    // }
    tree = choose(1,2,2,3,3,4,4,5);
    }
    //Dirt Level
    for(yy = ah; yy < dirt_level; yy += 32){
    instance_create(xx, yy + 32, obj_dirt);
    adl = yy
    }
    //Stone Level
    for(yy = adl; yy < adl + 64; yy += 32){
    u = round(random(choose(3)));
    if u = 1{
    instance_create(xx, yy + 64, obj_stone);
    }else {
    instance_create(xx, yy + 64, obj_dirt);
    }
    }
    for(yy = adl + 64; yy < stone_level; yy += 32){
    instance_create(xx, yy + 64, obj_stone);
    }
    //Height Variation In Biome
    if (hill) {
    amp = 16;
    } else {
    amp = 10 + random(4);
    }
    ah += amp*sin((2*pi)/1728*(xx-864))+((8+random(8))*sin((2*pi)/choose(54,108,240)*xx))+((15+random(2))*sin((2*pi/240)*xx));
    }

    if biome = 3{
    /// ----FOREST----/////
    instance_create(xx,ah,obj_grass);
    // p = choose(1,1,2,0,0,);
    // if p = 1 {
    // if !place_meeting(x,y,obj_cactus) {
    // instance_create(xx,ah-32,obj_grassplants);
    // }
    // }
    global.th = choose(5,6,6,6,6,6,7,7,7);
    dirt_level = ah + 32*choose(2,3,3,3);
    stone_level = 4192; //room_height poss inf down
    water_level = 1920;
    if (ah <= water_level){
    tree += 1;
    }
    //Trees
    if (tree = 9) && (ah <= water_level){
    c = choose(1,1,2);
    if c = 1{
    with(instance_create(xx,ah - 32,choose(obj_logspawn_oak,obj_logspawn_birch))){
    canGrow = true;
    }
    }
    tree = choose(2,3,3,4);
    }
    //Dirt Level
    for(yy = ah; yy < dirt_level; yy += 32){
    instance_create(xx, yy + 32, obj_dirt);
    adl = yy
    }
    //Stone Level
    for(yy = adl; yy < adl + 64; yy += 32){
    u = round(random(choose(3)));
    if u = 1{
    instance_create(xx, yy + 64, obj_stone);
    }else {
    instance_create(xx, yy + 64, obj_dirt);
    }
    }
    for(yy = adl + 64; yy < stone_level; yy += 32){
    instance_create(xx, yy + 64, obj_stone);
    }
    //Height Variation In Biome
    if (hill) {
    amp = 16;
    } else {
    amp = 10 + random(4);
    }
    ah += amp*sin((2*pi)/1728*(xx-864))+((8+random(8))*sin((2*pi)/choose(54,108,240)*xx))+((15+random(2))*sin((2*pi/240)*xx));
    }
    /*
    if biome = 4{
    //------Desert----\\\

    instance_create(xx,ah,obj_sand);

    //Cactus and other Plants
    // c = choose(1,1,2,0,0,0,0,0,0);
    // if c = 1 {
    // if !place_meeting(x,y,obj_desertplants) {
    // instance_create(xx,ah-32,obj_cactus);
    // }
    // }
    // p = choose(1,1,2,0,0,);
    // if p = 1 {
    // if !place_meeting(x,y-32,obj_cactus) {
    // instance_create(xx,ah-32,obj_desertplants);
    // }
    // }

    sand_level = ah + 32*choose(2,3,3,3);
    stone_level = 4192;
    water_level = 1920;

    //Sand Level
    for(yy = ah; yy < sand_level; yy += 32){
    instance_create(xx, yy + 32, obj_sand);
    adl = yy
    }
    sandstone_level = adl + 32*choose(1,2,2,2,3);

    //Sandstone Level
    for(yy = adl; yy < sandstone_level; yy += 32){
    instance_create(xx, yy + 64, obj_sandstone);
    }
    for(yy = sandstone_level; yy < stone_level; yy += 32){
    instance_create(xx, yy + 64, obj_stone);
    }
    //Height Variation In Biome
    if (hill) {
    amp = 16;
    } else {
    amp = 10 + random(4);
    }
    ah += amp*sin((2*pi)/1728*(xx-864))+((8+random(8))*sin((2*pi)/choose(54,108,240)*xx))+((15+random(2))*sin((2*pi/240)*xx));
    }
    */




    return ending_room;

    thats the main code for creating the blocks than in my players step event i have

    if global.facing = -1 {
    if (x >= (global.chunk/2) && render){
    render = false;
    global.chunk = scr_worldgen(global.chunk);
    render = true;
    }
    }else {
    if global.facing = 1 {
    if (x <= (global.chunk2/2) && render){
    render = false;
    global.chunk2 = scr_worldgen(global.chunk2 - 3456);
    render = true;
    }


    }
    }

    this calls the scr when im facing each way to generate the world

    Yeah The player can move back
     
    Last edited by a moderator: Mar 15, 2019
  5. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,514
    There is something I want to test later tonight, but in the meantime, is there anyway you can convert it from relying on objects for the terrain and instead generate tiles for the terrain? the tiles are going to stay in your memory, but then again so are all of those instances. The difference is the tiles won't need to be deactivated and reactivated over and over. That would be predictably one huge bane removed from the CPU's workload.
     
  6. Logan Bevans

    Logan Bevans Member

    Joined:
    May 17, 2018
    Posts:
    39
    Yeah I thought of that I'm not quite sure on how to do that I'm still new to coding iv learned the basics but not quite good enough :) iv read up on someone else in a similar situation I don't quite remember but I don't think it fixed the issue but I'm definitely willing to try anything out
     
  7. Logan Bevans

    Logan Bevans Member

    Joined:
    May 17, 2018
    Posts:
    39
    or if theres a way to limit the amount of chunks created a limit to how far i can go
     

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