[SOLVED]Game running horribly slow

LIke the subject says, my game is running horribly slow. I don't have any loops in my game so it can't be that. I think it might be some memory leaks...IDK. Could someone give me some help in narrowing down why everything is slow. Its mainky the animations...they just run slow.


Thanks


Ted
 

obscene

Member
Use show_debug_overlay(true) somewhere and post a screenshot.

Also use the debugger, turn on the profiler and sort that so the most cpu intensive parts float to the top.
 
D

deem93

Guest
One issue that I had to face in my game was that some objects would be created infinite amount of times when standing on a trigger. Maybe something worth checking. The solution was that if there were more than 1 instance, it would destroy all other instances.
 
That's not a solution deem93...A solution would be to have a trigger_activated variable set to false, only spawn an instance if the trigger_activated variable is false and after the instance is spawned the trigger_activated variable gets set to true. Your 'solution' eats up needless CPU cycles, creating and destroying instances every step.

Learn to use the debugger Ted, that's the solution to this problem.
 
@RefresherTowel Ok. I'm game. It's about time I learned to use the debugger thoroughly. You know you sound like my professor for comp sci 101 twenty years ago. LOL. So I don't waste my time going through misapplied youtube videos, where do you suggest I start?
 
T

Taddio

Guest
Then it's most likely the draw event. Do you draw lots of text and primitives directly on screen? If so, try to draw them to surfaces, instead.
Fire up the profiler in the debugger, and you'll see exactly what eats up your processing power.
Also might be worth organizing your texture pages cleanly to avoid unnecessary swaps. You can preview them to see how they look, very useful.
 
@Taddio I don't know what you mean by drawing them to surfaces. I ran the profiler in the debugger and it came back with my achievement splash screens taking up around 158 for five achievements. I'm sure that's what
is slowing things down, I just don't know where in the achievement code its doing that.

Also, what do you mean by organizing my texture pages? That's something else I don't know about.
 
T

Taddio

Guest
For texture pages, you can refer to this.
The basics are: try to have as little texture swaps as possible, i.e. use the same texture pages for things that will be drawn together (e.g. you could have a texture will all your GUI stuff, and a couple texture page with all your different levels tilesets and sprites).
https://docs2.yoyogames.com/source/_build/2_interface/3_settings/textures.html


For surfaces, you will have to look into them. surface_create(), surface_set_target(), surface_reset_target() and draw_surface() are the basics functions you will need!

And when you mean 158 in the profiler, you mean in milliseconds? That's indeed a lot. Are you constantly opening/closing files, or something likke that?
 
Yeah its 158 milliseconds. I'm not constantly opening/closing files. There are a couple step events in a couple objects that keep on running.Those objects are taking up 158 milliseconds.
 
@Taddio

For surfaces, you will have to look into them. surface_create(), surface_set_target(), surface_reset_target() and draw_surface() are the basics functions you will need!
Ok. I'm looking at the surfaces and I'm not sure if I quite understand them. Follow me.
Instead of drawing to the screen, I create a surface, draw to the surface and then reset. Then later on when I want to draw the surface, I use draw_surface and it will draw the surface a t whatever coordinates I supply?
 
T

Taddio

Guest
Exactly! The neat thing is you also set how big the surface is when you create it, so it only draws what needs to be drawn (efficient).
Everything draw_** between surface set/reset will be drawn onto that surface.

Also, you can see them in the debugger, so you can visually check the size, what's on it, and how many surfaces are drawn at every given time (tho it updates only when the game is paused, I think, and you may have to use the circle-arrow to refresh them!

Edit/add: an example of where it could save processing is if you wanted to have blood that stays on screen even if your enemy is dead. Simply drawing the blood on a surface would allow you to safely destroy the enemy and still draw the blood. You would not have to import a new spr_blood in the game to draw every time, that would become unbeareable if there were 1000s of blood splats everywhere
 
Last edited by a moderator:
@Taddio Ok. Now what I don't understand is this. Say I want to have my SentryBatObject which is normally drawn with draw_self drawn on a surface. Do I go to my draw event and create a surface, do draw_self, and then reset. Then what do I do? Do I just call the draw_surface right afterwards?
 
T

Taddio

Guest
@Taddio Ok. Now what I don't understand is this. Say I want to have my SentryBatObject which is normally drawn with draw_self drawn on a surface. Do I go to my draw event and create a surface, do draw_self, and then reset. Then what do I do? Do I just call the draw_surface right afterwards?
Yep, don't use surface functions outside of the draw event. I sometimes create them in the create event, but that's not recommended for a couple reasons I know, and probably a bunch of other reasons I don't know of.
You should set up a simple and light test project to try to mess around with them if your project takes a while to compile, the coordinates are kind of easy to mess up in the beginning (a surface (0,0) is it's top left)
 
Also, if you're -just- using draw_self() no need to create a surface. A surface is useful for when you are using a bunch of draw commands all in a row.

So let's say you have a info pop up that has a draw_text for the title, a draw_text for the info, perhaps a draw_text for something else as well, you're also using draw_rectangle twice to have an inner background and an outer border and maybe a few draw_set_alphas and draw_set_colours going on throughout. Instead of drawing all of this every step, you'd draw it all to a surface once, and then simply draw the surface. That reduces the amount of draw calls you're making from however many are making the info pop, to simply one draw call.

But all of this optimisation stuff depends -heavily- on your specific project and how you've coded it up. Just using some surfaces won't necessarily free a bunch of cpu cycles UNLESS you're overusing draw commands. Each piece of optimisation you do needs to take into consideration how your project is structured and what the best way to reduce the amount of code/heaviness of the code that you have coded is. There's no magic bullet, one fix trip to getting good optimisation. It all depends on what you are doing in your project.
 
OK so I have isolated a group of Objects That are taking up the most CPU cycles but I don’t understand why they are showing up that way, they are just supposed to be a line or two of Code that gets called (an if statement) but It’s taking up 150 ms of cpu cycles
 
T

Taddio

Guest
Try to expand the lines in the profiler with the "+"
If, for example, you see something like
Code:
obj_player(draw)//call_count//lots of ms// big %
Try to post the revelant code (in this example, the obj_player draw event).
Between the bunch of us, we might find an optimization solution, or a loophole in the code that was overseen

Edit;
Like so:

This is an example from my current project. You can see how intensive it is to just draw simple ****. This is from one of my main menu page, and no surfaces are used. This is a perfect case example of good use of surfaces to reduce processing, tho I just didn't bothered messing with them yet.

Edit_2:
End result is this, this is a simple object that loops 7 times with a couple character sprites, a button sprite, and some text. Yet, when currently drawing on screen every step, I dont even reach fps = room speed. Im sure all will be good when drawn to surfaces, tho.
 
Last edited by a moderator:
T

Taddio

Guest
And that runs slow? I'm surprised, there doesn't seem to be anything wrong in the profiler. It's taking 0.159 ms, not 159 ms. A step at 60 fps is around 16.6ms.
I don't see what it could be...do you have something else running in the background? Tried to clear cache, save and restart GM? Restart computer.

Edit: whoa, just saw you have 400mb+ of memory usage, how big is that game, exactly? There may be a leak somewhere...
 
What are the 3 *Splash objects at the top of your profiler list doing?

Because according to the profiler, you appear have 255 instances of each object running at the same time. At least I assume that from the fact you have step events are being called 255 times each per frame.
 
T

Taddio

Guest
Yeah, @IndianaBones is right, put the instance list whete the ressource tree is in the debugger, so we can see what ot looks like.
And if obj_splash are simple graphical effects and you do need 250+ of each, (I'm guessing by the object name, I make no assumptions), you could use particles instead of objects, way less overhead that way
 
And that runs slow? I'm surprised, there doesn't seem to be anything wrong in the profiler. It's taking 0.159 ms, not 159 ms. A step at 60 fps is around 16.6ms.
I don't see what it could be...do you have something else running in the background? Tried to clear cache, save and restart GM? Restart computer.

Edit: whoa, just saw you have 400mb+ of memory usage, how big is that game, exactly? There may be a leak somewhere...
The game has big graphics. Its big in general as well.
 
Relevant code for the splashes:
Agapite Splash
Code:
    alpha -= alpha_step // decrease alpha



    image_alpha = alpha;


if (alpha <= 0)
{
  global.achievement_agapite_spkash = false;
  instance_destroy();
 
}
Crystal Copper Splash

Code:
    alpha -= alpha_step // decrease alpha



    image_alpha = alpha;


if (alpha <= 0)
{
  global.achievement_crystal_copper_splash = false;
  instance_destroy();
 
}
Adamantium Splash

Code:
    alpha -= alpha_step // decrease alpha



    image_alpha = alpha;


if (alpha <= 0)
{
  global.achievement_adamantium_splash = false;
  instance_destroy();
 
}
Out of all the splashes coming up 255, it seems to be these three that always show up.
 
T

Taddio

Guest
Not sure, honestly. Your fps shows 500+, so that doesn't look like it's too hard on the processing.
One thibg I noticed tho, is your instances numbers are quite high, you may be creating a bunch of things you're not even aware you're creating.
Check the instance_number(obj) function, and use a couple of show_debug_message to make sure you don't have a (potentially very big) bunch of useless objects.
Every object instance has a overhead to it, even an empty object, so creating 1000s of them will slow things down.
 
T

Taddio

Guest
Yes. These numbers will go up for every instance created in the gane, never reusing the same, so I cant say if you have 10000 of them at the same time, but the function instance_number I gave you in the link will tell how many there are AT ANY GIVEN TIME, which is what you want to know.
Either way, you are creating a lot of instances, at least 12000 from the moment you started your game to the moment you took your screenshot
 

TheouAegis

Member
Also make sure your sound files are 352kbps or lower. Had to help a guy earlier who was using 2Mbps sound files and lagging horribly.
 
Well Taddio, TheouAegis, and RefresherTowel I think its the Agapite Achievement Object. Within the first ten seconds of gameplay there were 250 instances of it. There is supposed to be 1.

Edit: That did the trick. There was a typo in three of the achievements causing them to create and create over and over again. I guess the debugger is pretty useful.
 
Last edited by a moderator:
T

Taddio

Guest
Looks like that woukd be the problem (part of it, at least).
Look at how/when/what is creating these, it's most likely creating an instance every step.
 
Wow...who dug this thread up. ;) I killed a bunch of artwork and my music I dead. I'm still working on the sizing issue. It is 1.6 GB as of right now. The speed issue
sort of happens when you get towards the last level. It starts the first level and slowly get slowly as you get to the last level.
 
Top