GML collision checking using binary?

GM_novice

Member
Hi

Fledgeling developer here! I'm just starting to learn Gamemaker studio 2 but I am interested in learning how to optimize my games from the getgo! I have been reading the basic stuff in the manual about binary operations and bitwise operations (bitwise and, or, not and EOR).

As the manual pointed out. Don't use an if statement if you don't have to! This got me thinking, is it possible to use the binary bitwise operators to do collision checking instead of using if statements?

If you could point me to the right direction it would be much appreciated! Which sections in the manual should I read? Are there any good YouTube (or similar) channels that cover code optimization for beginners? Any books you would recommend for beginners?

Sincerely
Daniel
 

Simon Gust

Member
My tips
1. optimize somewhere else. In gm you have more or less one datatype and that is floating point, doing bitwise will have to convert your values each time making your code slower.
2. you just stared to learn using a new language, don't optimize what you don't understand? It's a waste of time.
3. The best way to learn optimizing is to first write bad code. I haven't seen any code of yours.
 

DukeSoft

Member
The collision engine in GMS is already very optimized - I wouldn't start there. Most of the (common) performance issues in GM come from texture swaps, buffer batches, and using draw functions like lines, colour switching, rectangles and text (the last ones create batches). Then there's a lot of possibly useless CPU cycles in checking / calculating values (per step) which only have to be calculated once.

Easiest way is to just check your profiler and see what parts are slowing everything down. Also; Don't optimize early :)

PS: @Simon Gust I'm not sure if point 2 was a pun, but +1 for "its a waste of time" :p
 
Ya you really won't squeeze anything out of trying to re-optimize gm collisions (remember gm has already optimized them substantial in gms1.4+) so the best thing you can do is try and learn how to use them efficiently.

Now, bitwise operations are a lot faster in general and they can be super efficient, but sometimes clarity is more important. When you look back at something in 6 mo will it still make sense? My suggestion if you want to use bitwise create wrapper scripts that handle the calculations internally so when you are reviewing code it is easy to digest, especially if you are working with others.
 
Top