[SOLVED]Game running horribly slow

Discussion in 'Programming' started by Ted Gress, Mar 12, 2019.

  1. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    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
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,572
    Not a lot to go on so:

    https://forum.yoyogames.com/index.php?threads/lag-problem.59692/#post-360096



     
  3. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    Thanks @samspade. I don't have a lot to go on myself - i'll check out the links.
     
  4. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,321
    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.
     
  5. deem93

    deem93 Member

    Joined:
    Nov 14, 2017
    Posts:
    91
    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.
     
  6. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    985
    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.
     
  7. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    @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?
     
  8. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    So it runs smooth at 1700 fps and drags at 100 fps. Sometimes it locks up at 100 fps.
     
  9. Taddio

    Taddio Member

    Joined:
    Nov 16, 2018
    Posts:
    289
    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.
     
  10. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    @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.
     
  11. Taddio

    Taddio Member

    Joined:
    Nov 16, 2018
    Posts:
    289
    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?
     
  12. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    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.
     
  13. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    @Taddio

    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?
     
  14. Taddio

    Taddio Member

    Joined:
    Nov 16, 2018
    Posts:
    289
    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: Mar 14, 2019 at 10:48 PM
  15. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    @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?
     
  16. Taddio

    Taddio Member

    Joined:
    Nov 16, 2018
    Posts:
    289
    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)
     
  17. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    985
    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.
     
  18. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    What should I be using in the texture groups ?

    Similar to surfaces?
     
  19. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    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
     
  20. Taddio

    Taddio Member

    Joined:
    Nov 16, 2018
    Posts:
    289
    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:
    [​IMG]
    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.
    [​IMG]
     
    Last edited: Mar 15, 2019 at 11:58 PM
  21. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    Ok this is me running the profiler on a spot where the animation "sticks"

    upload_2019-3-15_23-42-12.png
     
  22. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
  23. Taddio

    Taddio Member

    Joined:
    Nov 16, 2018
    Posts:
    289
    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...
     
  24. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    1,930
    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.
     
  25. Taddio

    Taddio Member

    Joined:
    Nov 16, 2018
    Posts:
    289
    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
     
  26. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    The game has big graphics. Its big in general as well.
     
  27. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
  28. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
  29. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
  30. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    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.
     
  31. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    Seems to be tooo many instances for one splash screen:

    upload_2019-3-16_13-24-35.png
     
  32. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    upload_2019-3-16_13-25-29.png
     

    Attached Files:

  33. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
  34. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
  35. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    Does anybody have any ideas from looking at these screenshots?
     
  36. Taddio

    Taddio Member

    Joined:
    Nov 16, 2018
    Posts:
    289
    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.
     
  37. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    Where do you seee the number of instances?
     
  38. Taddio

    Taddio Member

    Joined:
    Nov 16, 2018
    Posts:
    289
    Click the green link in my previous post.
    In your screenshots, Im looking at the numbers just beside the +/- in the all instance tab
     
  39. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    What? the 112005 1112006, etc..?
     
  40. Taddio

    Taddio Member

    Joined:
    Nov 16, 2018
    Posts:
    289
    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
     
  41. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,236
    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.
     
  42. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    501
    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: Mar 18, 2019 at 3:12 AM
    Taddio and RefresherTowel like this.
  43. Taddio

    Taddio Member

    Joined:
    Nov 16, 2018
    Posts:
    289
    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.
     

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