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

instance_create_layer makes game slow

Discussion in 'Programming' started by nick13579, Aug 9, 2018.

  1. nick13579

    nick13579 Member

    Joined:
    Jul 20, 2016
    Posts:
    43
    So I want to make an instance at the mouse position whenever the player presses the mouse. So I have the object and the only code running is :

    if(mouse_check_button_pressed(mb_left)) instance_create_layer(mouse_x, mouse_y, "Building_Layer1", obj_house);

    However, the problem comes when I only make around 7 of the objects and the game starts jittering. I'm not that familiar with the debugger, but it says its still running at like 700 fps. So, to my knowledge, it shouldn't look like it's lagging. Also, when I just place a ton of those same objects in the room and then run the game, it doesn't lag at all.

    Let me know if you need any more information,
    Thanks!
     
  2. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    758
    Let the profiler run for a bit while the game is "lagging" - does this give you any insight? Please also share the results with us.
     
  3. nick13579

    nick13579 Member

    Joined:
    Jul 20, 2016
    Posts:
    43
    Okay ya I just left but I will be back tonight. Could you tell me what the profiler is I’m not familiar with that

    Thanks!
     
  4. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    758
    My previous post contains a link to the manual page which explains the debugger, including its profiler module, in great detail. Please refer to the manual page for further information.
     
  5. nick13579

    nick13579 Member

    Joined:
    Jul 20, 2016
    Posts:
    43
    Oh okay I didn’t see that. Thanks a lot I will definitely look at that later
     
  6. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    3,274
    Bentley and IndianaBones like this.
  7. nick13579

    nick13579 Member

    Joined:
    Jul 20, 2016
    Posts:
    43
    Okay so I ran the profiler and this is what I got

    When I used code to create two more instances:
    housespawned.PNG

    When I used code to create a lot more instances (second image):
    housespawnedlots.PNG

    When I placed a lot of the objects in the room before running and had no lag:
    houseprespawned.PNG
     
  8. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    1,609
    It's hard to see the reason for slowdown. Need to dig for some more info.

    It seems like keyboard_check_pressed() is taking up all of your frame time for all 3 examples.

    How many instances are running in each of the tests above?

    Is the profiler data above cumulative or average values?

    The profiler has an option to show frametime OR number of times per step the function is called. Can you post the info for number of executions per step for the examples above.

    Post the code where you are using keyboard_check_pressed().

    Also, if you aren't aware of this already, can you turn on the debug overlay ( put the command show_debug_overlay(true) in your game start event or similar location ). It will draw some info at the top of your game window. Read the manual entry for show_debug_overlay() to see what the info means. It basically shows you frame rate, batches, and amount of CPU/GPU used per frame.

    Take a screenshot of the output of the debug info for each of the examples you showed above and post it here
     
  9. nick13579

    nick13579 Member

    Joined:
    Jul 20, 2016
    Posts:
    43
    The only code running on the object is
    if(keyboard_check_pressed(vk_backspace)) instance_create_layer(mouse_x, mouse_y, "Building_Layer1", obj_house);
    in the step event

    The profiler was on average values

    Not sure how many instances of the object are running, but I probably made around 10 when placing them with the backspace button, but like 20 when I placed them in the room before running the game.

     
  10. nick13579

    nick13579 Member

    Joined:
    Jul 20, 2016
    Posts:
    43
    Also, I have had the debug overlay showing for a while even though I’m not that sure how to read it. But that bar on the top seems to increase in size exponentially for every object I place in the game while playing it
     
  11. IndianaBones

    IndianaBones Member

    Joined:
    Jul 5, 2016
    Posts:
    1,609
    The main ones are the yellow bar is the time taken for the Draw Event, the red bar is Step Event.

    The first number in parentheses is texture swaps, the second is vertex batches.

    What are the sizes of the bars / which one is significantly larger, and what numbers are you getting in the parentheses?
     
  12. nick13579

    nick13579 Member

    Joined:
    Jul 20, 2016
    Posts:
    43
    When I place 12 of the objects the parentheses look like this (23)(27)

    The yellow bar seems to always be a little in front of the red one and both of them don't extend past the first little line.

    Also, now that I look, the debug window was showing a different fps or something, because the fps on the debug overlay says it's around 13 fps when I have 12 placed

    When I place 12 of the objects in the room and then run the game, the parentheses show (23)(24) and the fps is well over 100
     
  13. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    4,966
    Isn't 100 kinda low? Debugger fps should be over 1000, shouldn't it?
     
  14. Sinaz20

    Sinaz20 Member GMC Elder

    Joined:
    Aug 22, 2016
    Posts:
    131
    Is that code you showed us in the obj_house, per chance?

    If it is, then after 7 presses of Backspace, you'd have 128x the starting amount of houses in the scene.

    Stab in the dark that you might have done this instead of putting the house spawning check and code in a controller object of some sort.

    During debug, I beleive somewhere in the profiler or one of the watching tabs you can see how many instances of each object are in the room. That would be helpful info... unless you can tell us definitively that this code is NOT in the obj_house step event.
     
    nick13579 likes this.
  15. nick13579

    nick13579 Member

    Joined:
    Jul 20, 2016
    Posts:
    43
    Ohhhhh ya. It is in the obj_house event so it’s creating a ton of them on top of each other. This should not be a problem with how the game will work in the future. That line of code will run in a separate object I just had it in the obj_house for test purposes. Explains a lot

    Thanks guys
     
    Sinaz20 likes this.

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