Legacy GM Performance Question

I

Ian

Guest
Simple question, adding in some tiny particles manually and right now im doing bullet shells:



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 by a moderator:

obscene

Member
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.
 
I

Ian

Guest
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.
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.
 
J

Jaqueta

Guest
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?
 
I

Ian

Guest
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?
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

It can always be optimized more!
TRUE, even with all 4 players shooting (has local coop 1-4) still good with me.


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 by a moderator:

Nehemek

Member
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.
 
  • Like
Reactions: Ian
I

Ian

Guest
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.
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
 
J

Jaqueta

Guest
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.
 
I

Ian

Guest
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.
Thanks man, Was using own physics for more control but ill check it out :)
 
Top