Jump to content


Photo

25 optimizing techniques for Game Maker.


  • Please log in to reply
63 replies to this topic

#1 cabreak

cabreak

    GMC Member

  • New Member
  • 93 posts

Posted 07 July 2011 - 10:26 AM

25 Optimizing techniques for Game Maker.

I have collected some optimization techniques. There are a lot of techniques which are already mentioned in previous topics. But I just want to gather them in one topic. Inclusive my own optimization techniques.

1. "Synchronization to avoid tearing" (Global Game Settings -> Resolution)
Set this off if you don't really need it. It heavenly affects the CPU.


2. Execute_string,draw_Getpixel, variable_local_set() , surface_getpixel() ...
Those are quite heavy functions for GM. That doesn't mean you can't use them at all. Use them wisely, for example in loading screens or at the end of a game.


3.Instance destroying/deactivating
Destroy instances if you don't need them anymore (instance_destroy()). Deactivate instances if you don't need them now. (instance_deactivate())

This piece of code will first deactiviate everything outside the view 0 and then it activates everything inside the view.
instance_deactivate_region(view_xview[0], view_wview[0], view_hview[0], false, true);

instance_activate_region(view_xview[0], view_yview[0], view_wview[0], view_hview[0], true);



4. Precise collision checking (Sprites)
If you don't need precise pixel collision for a particular sprite, just turn it off.


5.Divisions and trig calculations.

Divisions need a lot more CPY cycles then multiplications or subtractions.
And trig calculations need even more CPU cyles. So avoid using them where possible.
You can try to find faster or other algorithms.

Example "unoptimized code"

player.x += variableA* (1/4) + sin(VariableB)/cos(VariableB)

You can easily optimize it into this:

player.x += 0.25*variableA + tan(VariableB) ;


6. Background Color
Like the Game Maker manual says: "If you have a covering background, make sure you switch off the use of a background color."


7. With construction
Don't underestimate this construction. You can use "with" when you are changing different variables or executing different functions from the same object.

Example "unoptimized code" (From a debug screen in draw event)
draw_text(view_xview[0]+10,view_yview[0]+10,"Speed: "+ string(obj_Player.Speed)) ;
draw_text(view_xview[0]+10,view_yview[0]+27,"direction:"+ string(obj_Player.direction)) ;
draw_text(view_xview[0]+10,view_yview[0]+44,"angle:"+ string(obj_Player.angle)) ;

You can optimize it into this:
with (obj_Player)
{
draw_text(view_xview[0]+10,view_yview[0]+10,"Speed: "+ string(Speed)) ;
draw_text(view_xview[0]+10,view_yview[0]+27,"direction: "+ string(direction)) ;
draw_text(view_xview[0]+10,view_yview[0]+44,"angle: "+ string(angle)) ;
}




9. Switch statement
A common mistake when beginners are programming something is this:

if (a = 5) 
{
//Do something
}
else
{
  if (a = 6)
  {
	//Do something
  }
  else
  {
 	if (a = 7)
	{
	//Do something
	} ...
  }
}

Change this into a switch statement (which is faster):

switch (a)
{
case 5: /*do something*/ break ;

case 6: /*do something else*/ break ;

case 7: /*do something else */ break ;

...
}


10. Crop sprites
Game Maker manual:
First of all, look carefully at the sprites and backgrounds you use. Animated sprites take a lot of memory and drawing lots of sprites takes a lot of time. So make your sprites as small as possible. Remove any invisible area around it (the command crop in the sprite editor does that automatically). The same applies to background images.


11. Avoid memory leaks.
It's a pain the ass if someone notices a memory leak in your software/game.

In Game maker they often occur when you keep creating new variables or when you forget to free memory.

Don't forget these functions: file_find_close(),surface_free(id),sprite_delete(ind), font_delete(ind).

Example of "Not really good code"

fileID = file_text_open_read("data.txt") ;

while (!file_text_eof(fileID)) do
{
execute_string(file_text_read_string(fileID)) ;
file_text_readln(fileID) ; 
}

If you keep executing this code, in the end it will result in a memory leak.
You always have to close the file (free memory). So adding file_find_close() should fix this leak.



12. Avoid allocation of variables.

In GM there are 3 different types of declaring a variable:

Type 1:
globalvar variableA
You can use the variableA wherever you want in the game. This needs some memory.


Type 2:
variableA = 10  ; //(10 can be any number)
You can use variableA in any code inside the instance. So don't expect to find it when dealing with another object (or another instance of the same object).
This needs less memory then type1.

Type 3:
var variableA ;
You can only use variableA in the current piece of code/script. This declaration of a variable is needs even less memory then type 2.

So don't use a variable of Type 1 if you can also use it as type 3.


13. Use surfaces

Regarding functions like draw_circle, draw_rectangle and draw_line first draw the primitive to a surface, then draw the surface to the screen. It's much faster that way but it also needs more memory.
Note (ramses12): The primitives must only be drawn once, when the surface is created.


14. Sample down sound/music.

Sound can take up a lot of memory and space, especially wavs and mp3s, so sample them down if you can. Ask yourself if the higher bitrate or extra channel is worth the hit!


15. Use tiles instead of objects.

Tiles are much, much faster than objects, so you should use them in place of objects whenever you can. You can actually do a lot of things with tiles, like create and destroy them, set their depth, get their position, etc. They're not completely static.
Background details that you don't actually interact with are perfect tile material.

16. Use DLL's

GML is a interpreted language. And interpreted languages are most of the time slower than a compiled language.
So use DLL's for performance critical code. They can be a lot faster.


17. Use constants
They are faster than dynamic variables. Use them where possible!



18. Use Arrays

Memory which is allocated for an array is linear. That means it's faster to get data from an array then using X different variables.

But keep an array as small as possible, so that you don't waste memory.



19. Use grids

Theoretically they have the same performance as a 2d array. But the region functions (like ds_grid_set_region, ds_grid_add_region, …) are a lot faster. So use grids instead of arrays if you need things like regions.



20. Use lists.

Game Maker manual:
They are implemented using simple arrays but, as this is done in compiled code it is a lot faster than using an array yourself.



21. Game priority (Global game settings --> Other)

Game Maker Manual:
You can set the priority of the game process. This priority indicates how much processor time is allotted to the game. In normal mode the operating system tries to give processor time to each process that needs it in some reasonable way. The higher you put the priority the more time is allotted to the game, making it run more smoothly and faster. But other processes get less time (also Windows processes so even the mouse might not move anymore). Use this with care.

22. Use texture_set_priority(texid,prio)

Game Maker Manual:
When there is too little video memory some will be removed temporarily to make room for others that are needed. The ones with lowest priority are removed first. Default, all have priority 0 but you can change the priority here. (Use positive values!)



23. Use texture_set_interpolation(linear)

Game Maker Manual:
Indicates whether to use linear interpolation (true) or pick the nearest pixel (false). Linear interpolation gives smoother textures but can also be a bit blurry and sometimes costs extra time. This setting also influence the drawing of sprites and background. Default is false. (This can also be changed in the global game settings.)



24. Use display_set_colordepth(coldepth)

Coldepth can be 16 or 32 (16 bit or 32 bit). All modern GPU's support 32-bit. But changing it to 16-bit will gain extra performance. A disadvantage is that the colors are quite ugly. So it's only useful when you're creating a non-game application.


25. Use your brain

Edited by cabreak, 07 July 2011 - 06:54 PM.

  • 7

#2 ramses12

ramses12

    6

  • GMC Member
  • 5769 posts
  • Version:GM8.1

Posted 07 July 2011 - 10:59 AM

Nice collection you've got in there.

1. "Synchronization to avoid tearing" (Global Game Settings -> Resolution)
Set this off if you don't really need it. It heavenly affects the CPU.

Syncronization doesn't affect the CPU slowing it down that way. It rather does not allow the process to refresh itself at a rate that would be faster than the screen buffer. Otherwise, the drawing area would only partially be copied into the buffer, resulting in a part of the previous frame still visible on the screen.

2. Execute_string and draw_Getpixel.
Those are quite heavy functions for GM. That doesn't mean you can't use them at all. Use them wisely, for example in loading screens or at the end of a game.

And of course, here are included all the similar functions, like execute_file(), variable_local_set() and similar, or surface_getpixel().

7. With construction
Don't underestimate this construction. You can use "with" when you are changing different variables or executing different functions from the same object.

Example "unoptimized code" (From a debug screen in draw event)

draw_text(view_xview[0]+10,view_yview[0]+10,"Speed: "+ string(obj_Player.Speed)) ;
draw_text(view_xview[0]+10,view_yview[0]+27,"direction:"+ string(obj_Player.direction)) ;
draw_text(view_xview[0]+10,view_yview[0]+44,"angle:"+ string(obj_Player.angle)) ;

You can optimize it into this:
with (obj_Player)
{
draw_text(view_xview[0]+10,view_yview[0]+10,"Speed: "+ string(Speed)) ;
draw_text(view_xview[0]+10,view_yview[0]+27,"direction: "+ string(direction)) ;
draw_text(view_xview[0]+10,view_yview[0]+44,"angle: "+ string(angle)) ;
}

You should be aware that those two codes do something different. One draws the info just once, and the other repeats for every instance of obj_Player. Also, if there's no instance of objPlayer in the room, the first code would probably throw an error.

It's a pain in the ass if someone notices a memory leak in your software/game.

This sentence made me smile :)

12. Avoid allocation of variables.

In GM there are 3 different types of declaring a variable:

Type 1:

globalvar variableA
You can use the variableA wherever you want in the game. This needs some memory.


Type 2:
variableA = 10  ; //(10 can be any number)
You can use variableA in any code inside the instance. So don't expect to find it when dealing with another object (or another instance of the same object).
This needs less memory then type1.

Type 3:
var variableA ;
You can only use variableA in the current piece of code/script. This declaration of a variable is needs even less memory then type 2.

So don't use a variable of Type 1 if you can also use it as type 3.

Now this is something I hardly consider as a real fact. Where did you find that global variables need more memory than local ones?
Plus, variables don't slow the game down at all, it has nothing to do with CPU.

13. Use surfaces

Regarding functions like draw_circle, draw_rectangle and draw_line first draw the primitive to a surface, then draw the surface to the screen. It's much faster that way.

That's true, but you must mention that the primitives must only be drawn once, when the surface is created. Otherwise, if the program executes the drawing every step it would be far worse.


- Ramses
  • 0

#3 cabreak

cabreak

    GMC Member

  • New Member
  • 93 posts

Posted 07 July 2011 - 11:09 AM

1. Everything goes first to the CPU. And the CPU has to wait for the synchronization to end. So it actually really affect the CPU :).

2. Yes ofcourse, there are more expensive functions than these two. I will add those. Thank you.

7. Indeed, it's a small difference. But for this case it does the same and it's faster. It's just the concept (example) of using the with construction.

12. Well, using local variables are faster for the CPU, that's for sure. Globalvars are working slower than local. But about the memory, I was also doubting about that, but the Game Maker Manual has convinced me.

Sometimes you want variables only within the current piece of code or script. In this way you avoid wasting memory and you are sure there is no naming conflict. It is also faster than using global variables.


13.You're right about that! I will edit it soon.

Edited by cabreak, 07 July 2011 - 11:14 AM.

  • 0

#4 cabreak

cabreak

    GMC Member

  • New Member
  • 93 posts

Posted 07 July 2011 - 11:15 AM

Nice collection you've got in there.


Thank you. There are a lot techniques written by myself.

Edited by cabreak, 07 July 2011 - 11:15 AM.

  • 0

#5 ramses12

ramses12

    6

  • GMC Member
  • 5769 posts
  • Version:GM8.1

Posted 07 July 2011 - 11:40 AM

1. Everything goes first to the CPU. And the CPU has to wait for the synchronization to end. So it actually really affect the CPU public/style_emoticons/default/smile.gif.

Actually, this should be the the job of the graphics card.

But for this case it does the same and it's faster. It's just the concept (example) of using the with construction.

I'm curious about why would it be faster to call the statements in another instance. Posted Image I think that you mean that it is faster to with(obj)draw_something() than using draw_something() in the draw event of obj.

In this way you avoid wasting memory

That doesn't mean that code variables are smaller in size, but that they are freed after a short time. A local variable remains there as long as the instance whom it belongs to remains alive. But they are the same. It's only a matter of freeing it.
Anyway, as an integer variable uses only four bytes, it is less likely that anyone will ever consume with variables more space than say 2k :P
  • 0

#6 cabreak

cabreak

    GMC Member

  • New Member
  • 93 posts

Posted 07 July 2011 - 11:44 AM

1. Everything goes first to the CPU. And the CPU has to wait for the synchronization to end. So it actually really affect the CPU public/style_emoticons/default/smile.gif.

Actually, this should be the the job of the graphics card.

But for this case it does the same and it's faster. It's just the concept (example) of using the with construction.

I'm curious about why would it be faster to call the statements in another instance. Posted Image I think that you mean that it is faster to with(obj)draw_something() than using draw_something() in the draw event of obj.

In this way you avoid wasting memory

That doesn't mean that code variables are smaller in size, but that they are freed after a short time. A local variable remains there as long as the instance whom it belongs to remains alive. But they are the same. It's only a matter of freeing it.
Anyway, as an integer variable uses only four bytes, it is less likely that anyone will ever consume with variables more space than say 2k :P


1. That's true. But it also affects the CPU. http://en.wikipedia..../Screen_tearing

2. It's about the variables (obj_Player.angle) . I've benchmarked it, it's faster.

3. Well, I'm sure it's faster. But like I said, I doubt if it uses more memory.
  • 0

#7 paul23

paul23

    GMC Member

  • Global Moderators
  • 3366 posts
  • Version:GM8

Posted 07 July 2011 - 12:51 PM

Good list, though I question quite a few things you covered. (Not saying they're bad, but speedwise they seem to hardly give any advantage). First thing you should notice is that memory has little effect on the speed of a program. (Well reading & writing on the stack is much faster, but you can't control that with gamemaker). But generally memory consumption has no effect on the speed of a program.


7. With construction

Speed difference is mostly neglectable when using a with statement

9. Switch statement

Did you test this? In gamemaker I doubt there's any real gain (each case has to be evaluated anyways). (Though switch often makes more sense for readability).

18. Use Arrays

Memory which is allocated for an array is linear. That means it's faster to get data from an array then using X different variables.

But keep an array as small as possible, so that you don't waste memory.

Uhm what? Where does it say the memory is linear? And how does this make accessing them faster?



19. Use grids

Theoretically they have the same performance as a 2d array. But the region functions (like ds_grid_set_region, ds_grid_add_region, …) are a lot faster. So use grids instead of arrays if you need things like regions.

On the other hand getting/writing variables to a specific position is much more slowly than using arrays.



20. Use lists.

Game Maker manual:
They are implemented using simple arrays but, as this is done in compiled code it is a lot faster than using an array yourself.

Well apart for algorithms this isn't true, like with grid accessing data inside the list is slow in GM.
  • 0

#8 Tepi

Tepi

    GMC Member

  • Global Moderators
  • 4201 posts
  • Version:GM8.1

Posted 07 July 2011 - 12:57 PM

Yeah now you need to point out a source to #5 (and tell us why it applies to Game Maker). Preferably some kind of a benchmark program that would support your claims.

Most of the list seemed to be just made up so that the list would be longer. Some of those aren't even optimization techniques. Some are utterly insignificant, and your list is also missing some important techniques such as using repeat loops instead of others when it's possible.

Although obvious, one really important technique is mathematical simplification. However, many people can't seem to recognize how lengthdir_x(point_distance(x1,y1,x2,y2), point_direction(x1,y1,x2,y2)+90) simplifies.
  • 0

#9 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9260 posts
  • Version:Unknown

Posted 07 July 2011 - 01:08 PM

For #13, you should mention that although this will save processing power, it uses up more memory (the surface requires memory), so it's a trade-off between processing speed and memory usage.

-IMP ;) :)
  • 0

#10 cabreak

cabreak

    GMC Member

  • New Member
  • 93 posts

Posted 07 July 2011 - 01:20 PM

Good list, though I question quite a few things you covered. (Not saying they're bad, but speedwise they seem to hardly give any advantage). First thing you should notice is that memory has little effect on the speed of a program. (Well reading & writing on the stack is much faster, but you can't control that with gamemaker). But generally memory consumption has no effect on the speed of a program.


7. With construction

Speed difference is mostly neglectable when using a with statement

9. Switch statement

Did you test this? In gamemaker I doubt there's any real gain (each case has to be evaluated anyways). (Though switch often makes more sense for readability).

18. Use Arrays

Memory which is allocated for an array is linear. That means it's faster to get data from an array then using X different variables.

But keep an array as small as possible, so that you don't waste memory.

Uhm what? Where does it say the memory is linear? And how does this make accessing them faster?



19. Use grids

Theoretically they have the same performance as a 2d array. But the region functions (like ds_grid_set_region, ds_grid_add_region, …) are a lot faster. So use grids instead of arrays if you need things like regions.

On the other hand getting/writing variables to a specific position is much more slowly than using arrays.



20. Use lists.

Game Maker manual:
They are implemented using simple arrays but, as this is done in compiled code it is a lot faster than using an array yourself.

Well apart for algorithms this isn't true, like with grid accessing data inside the list is slow in GM.


7. Like I said, don't underestimate it. There is clearly a speed difference. Even if it's small.
9. To be honest, I didn't test this. But I think it really has a performance gain (In C# it has for example).
18. They are for example faster in using loops. That's basic knowledge of computer science. Also, a one dimensional array uses linear memory.
19. Don't know about that, but I wrote: "Use grids instead of arrays if you need things like regions"
20. That's nonsense.
  • 0

#11 cabreak

cabreak

    GMC Member

  • New Member
  • 93 posts

Posted 07 July 2011 - 01:28 PM

Yeah now you need to point out a source to #5 (and tell us why it applies to Game Maker). Preferably some kind of a benchmark program that would support your claims.

Most of the list seemed to be just made up so that the list would be longer. Some of those aren't even optimization techniques. Some are utterly insignificant, and your list is also missing some important techniques such as using repeat loops instead of others when it's possible.

Although obvious, one really important technique is mathematical simplification. However, many people can't seem to recognize how lengthdir_x(point_distance(x1,y1,x2,y2), point_direction(x1,y1,x2,y2)+90) simplifies.


About the benchmark: I will.

And it's not about "so that the list would be longer.". Every small thing will help.
It's not only about optimization (title is kinda misleading), but also about gaining extra performance where needed.
Ofcourse, there are plenty of other optimizations.

The mathematical simplification is indeed a optimization. But like you said, many people can't simplify algorithms. It's all about algebra.

Edited by cabreak, 07 July 2011 - 01:28 PM.

  • 0

#12 cabreak

cabreak

    GMC Member

  • New Member
  • 93 posts

Posted 07 July 2011 - 01:31 PM

For #13, you should mention that although this will save processing power, it uses up more memory (the surface requires memory), so it's a trade-off between processing speed and memory usage.

-IMP ;) :)


Hmm, that's indeed right. Thank you!
Let me fix this.
  • 0

#13 Medusar

Medusar

    GMC Member

  • GMC Member
  • 1228 posts
  • Version:GM:Studio

Posted 07 July 2011 - 03:07 PM

For #16: yes, but not always... there is an overhead for calling DLL functions you know.

#25 is probably the most important one; why did you put it last on the list?
  • 0

#14 cabreak

cabreak

    GMC Member

  • New Member
  • 93 posts

Posted 07 July 2011 - 03:30 PM

For #16: yes, but not always... there is an overhead for calling DLL functions you know.

#25 is probably the most important one; why did you put it last on the list?


Yeh, that's true. But it's not that much.

And about 25: Do you think anybody is interesting in that tip ? Don't take me wrong, but it's indeed the most important one. Happy that someone mentions it.
  • 0

#15 PurpleFuzzy

PurpleFuzzy

    Punk Rock Princess

  • New Member
  • 1587 posts
  • Version:GM7

Posted 07 July 2011 - 04:46 PM

Number 25 is more important than any of the preceding 24.

8. Fewer collision checks
Objects that have collision events are much slower than objects that don't. So place those events in the objects which will have the fewest instances. A good example is the player versus the 100 bullets. You obviously have to do a collision check between the two objects. Make sure that event goes in the player object instead of the 100 bullets.


Or better yet, use a parent object for all the bullets, and define the damage in the collision with the player object. 101 bullet objects, only a single collision event.

Nice list.

-PF
  • 0

#16 Medusar

Medusar

    GMC Member

  • GMC Member
  • 1228 posts
  • Version:GM:Studio

Posted 07 July 2011 - 06:02 PM

Oh I forgot about this one for #8: if collision checks are necessary, don't use precise collisions.
  • 0

#17 Erik Leppen

Erik Leppen

    GMC Member

  • GMC Member
  • 2038 posts
  • Version:GM:Studio

Posted 07 July 2011 - 06:17 PM

8. Fewer collision checks
Objects that have collision events are much slower than objects that don't. So place those events in the objects which will have the fewest instances. A good example is the player versus the 100 bullets. You obviously have to do a collision check between the two objects. Make sure that event goes in the player object instead of the 100 bullets.

Nonsense.

I read this every now and then, although much more often in the GM6 era than nowadays, but I tested it back then and it didn't hold. I tested it now again, and it doesn't hold. At least, not on my computer. Have you actually tested this?

I did the following test: I created two objects having the same sprite, and then did this from a third object:
repeat 5000 {
  instance_create(random(room_width), random(room_height), objectA)
}
repeat 50 {
  instance_create(random(room_width), random(room_height), objectB)
}

I put a Collision event in A doing something simple. Then I ran the game and wrote down the FPS. Then, I switched the 50 and 5000 in the code above so there were 5000 B and 50 A. I re-ran the game and wrote down the FPS.

Here are the results.
5000x A and 50x B, precise checking ON (which means 5000 instances having a collision event): 20 fps.
50x A and 5000x B, precise checking ON (which means 50 instance having a collision event): 18 fps.
5000x A and 50x B, precise checking OFF (which means 5000 instances having a collision event): 22 fps.
50x A and 5000x B, precise checking OFF (which means 50 instance having a collision event): 20 fps.
For the fun of it, I removed the collision event out of A: 85 fps.

As you can see, there's no real difference, and if you do count the 2 fps difference, then it's the other way around! Also as you can see the precise checking option doesn't really matter that much either.

And if you think about it, (using tip 25) it's actually pretty logical. Having 50 instance check for collisions against 5000 others, would cost about the same amount of time as having 5000 instances check for collision against 50 others. Namely, 50 x 5000 times the time it costs for checking for one collision between two instances. By the way, given that that are 250000 pairs that need to be checked, this is actually pretty fast.


Game Maker manual:
[Lists] are implemented using simple arrays but, as this is done in compiled code it is a lot faster than using an array yourself.

This is only true if you're actually using the list functions. If all you're doing is just moving around data, then you're better off using arrays. However ds_list_shuffle is a lot faster than if you were to write your own array shuffle function, because ds_list_shuffle is compiled. That's the difference. But if you're not using that difference, than it doesn't matter. Of course, lists have other advantages, but I assume this topic is about execution speed.
  • 0

#18 cabreak

cabreak

    GMC Member

  • New Member
  • 93 posts

Posted 07 July 2011 - 06:33 PM


8. Fewer collision checks
Objects that have collision events are much slower than objects that don't. So place those events in the objects which will have the fewest instances. A good example is the player versus the 100 bullets. You obviously have to do a collision check between the two objects. Make sure that event goes in the player object instead of the 100 bullets.

Nonsense.

I read this every now and then, although much more often in the GM6 era than nowadays, but I tested it back then and it didn't hold. I tested it now again, and it doesn't hold. At least, not on my computer. Have you actually tested this?

I did the following test: I created two objects having the same sprite, and then did this from a third object:
repeat 5000 {
  instance_create(random(room_width), random(room_height), objectA)
}
repeat 50 {
  instance_create(random(room_width), random(room_height), objectB)
}

I put a Collision event in A doing something simple. Then I ran the game and wrote down the FPS. Then, I switched the 50 and 5000 in the code above so there were 5000 B and 50 A. I re-ran the game and wrote down the FPS.

Here are the results.
5000x A and 50x B, precise checking ON (which means 5000 instances having a collision event): 20 fps.
50x A and 5000x B, precise checking ON (which means 50 instance having a collision event): 18 fps.
5000x A and 50x B, precise checking OFF (which means 5000 instances having a collision event): 22 fps.
50x A and 5000x B, precise checking OFF (which means 50 instance having a collision event): 20 fps.
For the fun of it, I removed the collision event out of A: 85 fps.

As you can see, there's no real difference, and if you do count the 2 fps difference, then it's the other way around! Also as you can see the precise checking option doesn't really matter that much either.

And if you think about it, (using tip 25) it's actually pretty logical. Having 50 instance check for collisions against 5000 others, would cost about the same amount of time as having 5000 instances check for collision against 50 others. Namely, 50 x 5000 times the time it costs for checking for one collision between two instances. By the way, given that that are 250000 pairs that need to be checked, this is actually pretty fast.


Game Maker manual:
[Lists] are implemented using simple arrays but, as this is done in compiled code it is a lot faster than using an array yourself.

This is only true if you're actually using the list functions. If all you're doing is just moving around data, then you're better off using arrays. However ds_list_shuffle is a lot faster than if you were to write your own array shuffle function, because ds_list_shuffle is compiled. That's the difference. But if you're not using that difference, than it doesn't matter. Of course, lists have other advantages, but I assume this topic is about execution speed.


About the array: Yeh, I should have mention that. It's a little unclear indeed.

But I'm actually stunned about the "Fewer Collision checks". This is very interesting.
I'm going to set up a benchmark by myself. I didn't wrote this one anyway.
  • 0

#19 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16820 posts
  • Version:GM:Studio

Posted 07 July 2011 - 06:48 PM

Out of curiosity I just did a quick test using the exact system that erik used and got a steady 35 fps no matter what. So (and common sense agrees) it matters not where the collision event goes.

(PS: cabreak, don't double post! Use the >edit< button... Posted Image)
  • 0

#20 cabreak

cabreak

    GMC Member

  • New Member
  • 93 posts

Posted 07 July 2011 - 06:53 PM

Out of curiosity I just did a quick test using the exact system that erik used and got a steady 35 fps no matter what. So (and common sense agrees) it matters not where the collision event goes.

(PS: cabreak, don't double post! Use the >edit< button... Posted Image)


I did another benchmark and yeh I got the same result. Didn't knew it at all!

Sorry about double posting. It's because I'm in an hurry.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users