GML collision checking using binary?

Discussion in 'Programming' started by GM_novice, Jan 13, 2020 at 1:50 PM.

  1. GM_novice

    GM_novice Member

    Joined:
    Monday
    Posts:
    2
    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
     
  2. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,241
    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.
     
  3. DukeSoft

    DukeSoft Member

    Joined:
    Jun 20, 2016
    Posts:
    798
    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
     
  4. GM_novice

    GM_novice Member

    Joined:
    Monday
    Posts:
    2
    Thanks guys! I will keep that in mind! :)
     
  5. robproctor83

    robproctor83 Member

    Joined:
    Sep 30, 2019
    Posts:
    204
    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.
     

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