GM:S 1.4 Performance Question

Discussion in 'Programming' started by Ian, Jun 28, 2016.

  1. Ian

    Ian Member

    Joined:
    Jun 20, 2016
    Posts:
    143
    Simple question, adding in some tiny particles manually and right now im doing bullet shells:

    [​IMG]

    Create:
    Code:
    alarm[0] = 3*room_speed; //Timer for destroying
    var shell_hsp = random_range(3,5);
    var shell_vsp = random_range(-2,-5);
    scr_throwable_ini(shell_hsp,shell_vsp,.5,.5,.13,false,obj_solid);//Just initializes the vars for hroizantal/vertical speed as well as a fric/bounce vars
    Step:
    Code:
    Basically just collision/gravity/friction code, nothing important
    So just wanted to know if there is any good practices out there for something like this, looking for efficiency, thanks.
     
    Last edited: Jun 28, 2016
  2. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,400
    Well what you have in your create event is fine and even if it weren't it's the create event so it can't have much impact anyway. If there's anything that can be optimized it would be the step event.
     
    41nd and Ian like this.
  3. Ian

    Ian Member

    Joined:
    Jun 20, 2016
    Posts:
    143
    Yeah i found a game crashing memory leak due to a loop i had but took it out, was due to a reused collision check that had a while loop in it that throwables do not need. Step event only holds collision+movement/fric+bounce/gravity, cant really optimize anymore.
     
  4. Jaqueta

    Jaqueta Member

    Joined:
    Jun 23, 2016
    Posts:
    338
    After the bullet shell stop, you can turn it into a DECAL and then destroy the object, a Decal is a sprite that don't do anything, don't move, animate... this is pretty useful because you can have only ONE object, and have a ton of decals at it.

    But if the performance issue it DURING the shell step, it's probably something with your collision or some code that could be optimized

    Why don't you send us the whole code for us to take a look?
     
  5. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,400
    It can always be optimized more!
     
  6. Ian

    Ian Member

    Joined:
    Jun 20, 2016
    Posts:
    143
    Oh no, no performance issues at all. Was just wondering any built in GM functions since im from Unity that might help even more. For the decal thing, i changed the alarm to 1.5 so they destroy a lot quicker

    Code:
    ///scr_throwable()
    
    //Gravity
    if(!place_meeting(x,y+1,collision))
    {
        vsp += grav;
    }
    
    
    //Friction
    
    if(hsp != 0)
    {
        if(abs(hsp) - fric > 0)
        {
            if(throwable) hsp -= fric*image_xscale; else hsp -= (fric*image_xscale)*-1;
        }
        else
        {
            hsp = 0;
        }
    }
    
    //X Check
    if(place_meeting(x+hsp,y,collision))
    {
        hsp = (-hsp*bounce)*1.5;
        image_xscale *= -1;
    }
    x += hsp;
    
    //Y Check
    if(place_meeting(x,y+vsp,collision))
    {
        vsp = -vsp*bounce;
        if(abs(vsp)<1) vsp = 0;
    }
    y += vsp;
    Theres the throwable script, should change the name to bounce because it doesnt apply to just throwables (like grenades or swords). I have a boolean argument "throwable" that will decide on fric dir

    TRUE, even with all 4 players shooting (has local coop 1-4) still good with me.
    [​IMG]

    The flashlights pos/fire rates/bullets havent been adjusted yet, just use it for testing atm. Only 2 different kind of bullets but you get the point
     
    Last edited: Jun 28, 2016
  7. Nehemek

    Nehemek Member

    Joined:
    Jun 20, 2016
    Posts:
    42
    I can propose various solutions.

    1) Surface for unused things
    -Create a surface
    -When a bullet shell stops moving draw it's sprite to said surface and then destroy the bullet shell.
    -Draw that surface on a controller draw event.

    Cons: Surfaces can be volatile on memory and you might need to recreate them and when you do they wont have the bullets that you previously placed (this happens when the game loses focus).

    2) What was proposed above but explained:
    -Have an object called "shells display".
    -This object has an array that stores the x and y of shells.
    -When a shell stops moving you add a new shell to the array.
    -The object loops through the arrays and draws a shell on each position.

    Cons: Slower as you will send more sprites to be drawn rather than all in a single run. But hey theres no way to lose the data unless you wipe out the array.
     
    Ian likes this.
  8. Ian

    Ian Member

    Joined:
    Jun 20, 2016
    Posts:
    143
    Thanks for the tips, think ill stick to this because i use enough surfaces as is so dont want to use more memory and since this is not a big impact on performance I will just stick to this instead of second opt
     
  9. Jaqueta

    Jaqueta Member

    Joined:
    Jun 23, 2016
    Posts:
    338
    Well, the bounce script is very good, but for a Gameplay core mechanic.
    If it's just a visual thing like shells, there's no need for all that code, you could just use a simple code, like this.
     
  10. Ian

    Ian Member

    Joined:
    Jun 20, 2016
    Posts:
    143
    Thanks man, Was using own physics for more control but ill check it out :)
     

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