Is there a way to speed up the game?

I

izark

Guest
I don´t know if I understand correctly so please help me.

Each step of the game Gamemaker loops through all the objects in the room and read their code.
Imagine I use a room speed of 9999.
The game is not going to run at that speed. Maybe 1000 at much, but, if I keep adding objects to a room that number is going to decrease.
I have found that deactivating objects have the contrary effect.
I am building a puzzle game and there is a speed-up option that increases the room speed.
I deactivate every object that is not neccessary when this happens.
How can I get the maximum possible speed, or room speed. What other things can I do? I am also using tiles when objects are not necessary.

Thank you!
 
J

joakimFF

Guest
I wouldn't raise the room speed to make things go faster, say you double the room speed but the players computer only can handle the game running at say 45 fps then you wouldn't get the desired effect.
instead I would have a variable keeping track if the game should go faster and apply the necessary speed to everything that needs to go faster.
like

if speed_up {
speed = 8;
alarm[0] = 4;
}
else {
speed = 4;
alarm[0] = 8;

}

its more work but he end result will probably be more stable. just my two cents...
 
I

izark

Guest
I wouldn't raise the room speed to make things go faster, say you double the room speed but the players computer only can handle the game running at say 45 fps then you wouldn't get the desired effect.
instead I would have a variable keeping track if the game should go faster and apply the necessary speed to everything that needs to go faster.
like

if speed_up {
speed = 8;
alarm[0] = 4;
}
else {
speed = 4;
alarm[0] = 8;

}

its more work but he end result will probably be more stable. just my two cents...
Thanks ! But everything that needs to go faster is already running the fastest they can go.
It is about blocks that move 48 units in a certain direction (up,down,left or right)
and perform certains actions in a synchronized way
in a grid with units with a size of 48.
The code can´t be changed to make it faster. So, I am looking for something else.
I mean, it is already really fast. But I want more. I am also keeping graphics to a minimum. :)
 
T

tserek

Guest
C++ or Assembly language way to go, GM includes all the basic gfx and sfx libraries to the compiled exe need or not (just a guess, a raw GM8 executable stands for 2332kb with just one room and object) which may in theory slow down your game 0.00001 sec.
 
Last edited by a moderator:
S

Shihaisha

Guest
The code can´t be changed to make it faster. So, I am looking for something else.
I mean, it is already really fast. But I want more. I am also keeping graphics to a minimum.
A block changing its speed and direction 60 times per second is a lot more than a human mind can track or control in a puzzle game, so what for do you want more? Perhaps you should provide more details on what kind of effect you are trying to achieve.
 
I

izark

Guest
Well, C++ or Assembly language way to go, GM includes all the basic gfx and sfx libraries to the compiled exe need or not (just a guess, a raw GM8 executable stands for 2332kb with just one room and object) which may in theory slow down your game 0.00001 sec
Ok, so I guess there is a limit and it has to do with the way Gamemaker works.

A block changing its speed and direction 60 times per second is a lot more than a human mind can track or control in a puzzle game, so what for do you want more? Perhaps you should provide more details on what kind of effect you are trying to achieve.
In this puzzle you just activate icons and change their values in a grid. Then you press the run button and many operations are made. When I say many, I mean A LOT.
So, if your program is working, and you think that everything is correct, you speed up the process until all the conditions to win the game are met.
 
T

tserek

Guest
At all using other language to exclude the stuff you won't need won't make the game run faster. For my research GM graphics creating progress won't be any faster after room speed 60. Best option is to optimize the code and minimize the stuff you're about to include, to make it also more memory friendly. I cannot even play all the brand new games on my computer because require too much CPU and RAM.
 
Last edited by a moderator:

Micah_DS

Member
You never want to run your game at 9999. It's an incredible waste of CPU power. The higher you set the room speed number, the more priority the game requires from the CPU (you can see this by looking at 'fps_real').
Also, if you go with 9999 and don't have any frame skipping code, you'll royally screw yourself over, as the game will also needlessly try to execute the draw event 9999 times a second.

Are you using an array for all your blocks/icons as opposed to objects?
If your'e not using an array, you could very likely make your code much more efficient, only it would require a substantial rewrite of code, which I'm not sure you're open to.

Assuming you don't want to rewrite all your code, my tips are:
  • look for ways to lower the object count
  • remove any precise collisions you can (if you have any)
  • if you have v-sync on, turn it off
  • if you're using blend modes or alpha, limit their use or remove them
  • nest your ifs where applicable (if you're using GML)
  • you can find some of these tips and more on this YYG blog post.
 
S

Shihaisha

Guest
In this puzzle you just activate icons and change their values in a grid. Then you press the run button and many operations are made. When I say many, I mean A LOT.
So, if your program is working, and you think that everything is correct, you speed up the process until all the conditions to win the game are met.
I think the correct solution would be not to speed up the game, but change your code (as suggested above already), even if you think it can't be changed. You'll need a script with all those "many operations" in it, and then in step or alarm event you can repeat that script as many times as you want to speed up your gameplay accordingly. Of course, this may require rewriting some (or all) logic in your game. Instead of letting physcal block objects to move or bump into each other in each step, you'll have to store x/y positions and states of blocks in variables, perform all actions on blocks in your script (repeating n times to get required speed-up), and then output on screen final positions and states of blocks for each step.

So basically your game will be played not in the room directly 9,999 times per second, but in the script, which will be repeated 9,999 times per second, with results of those actions visible on screen 60 times per second.
 
I

izark

Guest
I want to thank you all for answering to this thread, I will take everything into consideration but I have to say that you were right about changing my code, specially this:

As an alternative you can use the "repeat(num){ }" statement in order to execute the same code several times per step, this way you can speed it up without having extra steps of the room speed: https://docs.yoyogames.com/source/dadiospice/002_reference/001_gml language overview/401_08_repeat.html
For example if you use "repeat(10){ //some code}" at room speed "60" your code inside the repeat statement will execute 10x60 = 600 times per second.
Once the program is running, only two objects are executing code: A Controller and Blocks.
I have used the function -repeat- in the controller to loop through all the blocks and execute their code.

And the result are REALLY GOOD.

I have made a very unefficient program and this is what it takes to complete without the -repeat- function and using normal speed : 4 min, 1 sec.
Now, using the -repeat- function at normal speed: 41 secs
which means that the execution is 587% faster now than before, and this is just what I wanted. I will use this code only when the speed-up option is active.

Thank you all!! :)

PD: I have used this with the speed up option ON and this happens:
Before: 19 secs
Now: 3 secs lol.
 
Last edited by a moderator:

acidemic

Member
Try experimenting with repeat values, use different numbers like repeat(100) or repeat(1000) or anything else to see if this improves the execution of your code.
 

Freddy Jones

Your Main Detective
I'm writing this from my phone, so this could potentially be erroneous, but here's my suggestion.

If you're trying to get step by step precision, and speed up the code, you could just perform the steps yourself.

Say if you want the game to process the state twice a step, have an object run every (necessary) instance's step event one more time at the end of the step.

For example:
Code:
//this is a controller object's end step event

repeat( processSpeed ){
  With( important object ) {
     event_perform( ev_step,0);
  }
}
Of course, you'll need to run that "with" block over every important object.

Note: this is the simplest way to approach your problem without changing your games structure, but if the processing involved in your step events over a large number of instances is high, then you will need to optimize your code, or at the very worst, look into interpolating your logic.

If my answer was pretty much the same as someone else's, then by all means sorry. Either way I hope I helped somehow.
 
I

izark

Guest
I'm writing this from my phone, so this could potentially be erroneous, but here's my suggestion.

If you're trying to get step by step precision, and speed up the code, you could just perform the steps yourself.

Say if you want the game to process the state twice a step, have an object run every (necessary) instance's step event one more time at the end of the step.

For example:
Code:
//this is a controller object's end step event

repeat( processSpeed ){
  With( important object ) {
     event_perform( ev_step,0);
  }
}
Of course, you'll need to run that "with" block over every important object.

Note: this is the simplest way to approach your problem without changing your games structure, but if the processing involved in your step events over a large number of instances is high, then you will need to optimize your code, or at the very worst, look into interpolating your logic.

If my answer was pretty much the same as someone else's, then by all means sorry. Either way I hope I helped somehow.
That is exactly what I am doing now, with a break statement.

repeat( processSpeed ){
With( important object ) {
event_perform( ev_step,0);
}
}

I didn´t know before this thread this was possible. And by the way I wrote the code, this implementation was very easy to archieve.
 
D

DevNorway

Guest
Code:
event_perform()
Will also slow down your game more than a script would.
 
I

izark

Guest
Code:
event_perform()
Will also slow down your game more than a script would.
I am performing event perform inside envent perform in with statements inside a with statement and everything is going really great :) But everything has to go inside a repeat loop.
 
Top