Game Optimization

Smacktard

Member
I've always heard to not worry about optimization until it becomes a problem. Well now, it's become a problem. My game is very small and light on assets, so I'm surprised it's suddenly starting to lag. Problem is, I'm not sure why.

I've been doing a lot of work on my menu system, specifically the "Controls" section. The control section draws and animates boxes, sprites that represent the actions, and keys that are attached to each action, which can be modified. There's an "if" shader applied to each of the boxes that makes them appear white (off and on) when selected.

See video:

The menu system has switch states that make it so that most of the code in the Draw GUI event (1000 lines of it) are not even activated if the menu is unpaused. The "Control" section has its own state.

Problem is, since implementing the "Control" section of my menu, my game has started to lag a LOT. When I enter the first room, the frame rate drops to like 10 fps. What's strange is that when I open the menu and select "Controls" and exit out of the menu, the lag is gone. What could be causing this? How do I get rid of it?
 

drandula

Member
I think you need to elobarate more.
But my first assumption is that it isn't actually optimization issue, but more of miswritten code, which causes code being looped / executed unnecessarily many times.
From the video I cannot say what is wrong.
 

kraifpatrik

(edited)
GameMaker Dev.
You can easily find out what's the biggest issue by running the game in debug mode, going to the profiler (I think it's under "Other" tab or something like that) and hitting "start profiling" button. You can then see how much time individual events and functions take etc.
 

Smacktard

Member
I think you need to elobarate more.
But my first assumption is that it isn't actually optimization issue, but more of miswritten code, which causes code being looped / executed unnecessarily many times.
From the video I cannot say what is wrong.
I don't understand why code looping would cause the problem though if the problem only started occuring for the code I wrote in the switch state, which isn't even active when the stutter is occurring. And like I said, when this state IS activated, the stutter goes away entirely until I enter a new room.

More details, see pic:


Top image draws sprites for all of the accepted key presses for each action in the game, but only when THAT section of the menu is open.

Bottom image applies shader that changes the color of the selected window, which there can only be one of at a time.

However, these are within a state that isn't even ACTIVE when the stutter occurs. What's for real weird is that as soon as I open the "Control" section of the menu (thus activating the state), the lag disappears until I enter a new room and it starts again.
 

Attachments

Smacktard

Member
You can easily find out what's the biggest issue by running the game in debug mode, going to the profiler (I think it's under "Other" tab or something like that) and hitting "start profiling" button. You can then see how much time individual events and functions take etc.
This sounds like a great tool I never knew existed. Unfortunately, I think that means I must updated my GM to the latest version, which was causing me some problems :(
 

kraifpatrik

(edited)
GameMaker Dev.
This sounds like a great tool I never knew existed. Unfortunately, I think that means I must updated my GM to the latest version, which was causing me some problems :(
I'm pretty sure that it has always been there and so you should have it too, even if you're not on the latest version 🤔
 

Smacktard

Member
I'm pretty sure that it has always been there and so you should have it too, even if you're not on the latest version 🤔
I get this when I try to run it.

EDIT: I've commented everything in the switch state, and the lag still occurs, so it must be coming from somewhere else. Looks like I'll have to download the newest version, run debug, and check where it's coming from.

EDIT 2: What I still don't understand is WHY the lag disappears as soon as I run the "Control" switch state.
 

Attachments

Last edited:

TsukaYuriko

☄️
Forum Staff
Moderator
I get this when I try to run it.
Ensure you're using a compatible runtime (File -> Preferences -> Runtime Feeds -> Master) for the IDE version you're using. The one listed in the release notes is a safe bet.


What I still don't understand is WHY the lag disappears as soon as I run the "Control" switch state.
Because whatever code runs when you do this makes the code that causes the lag cease to run.
 

Smacktard

Member
Because whatever code runs when you do this makes the code that causes the lag cease to run.
This helped me to solve the issue. I had some leftover "shader_set" code in the create event that had been left there for a while. I only noticed it when I tried actually playing the game rather than just screwing with menus. Issue solved, thanks!

Also, I feel like an idiot. Hooray!
 
Top