Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fast Integer Square Roots
#1
A few of you have wondered why I've been obsessing over speeding up math functions, cos the compiler is for games! :-)

Well, here's a concrete example of Fast square roots in action. Part of the football algorithm is "Who do I move, and where?" on the field. I'm hoping for better graphics, but this was a mock up to look at the math of that problem. If a player is moving with the ball, who is nearest to their path to intercept them?

With players all over the place, you have to work out distances to vectors. I finally got this working correctly (it sometimes broke, the last time I looked at this - and it turned out I was crossing the 16 bit number barrier. With a newer, longer sqrt function I can go back and make the algorithm work) and here it is in two versions - one using the ROM sqr() function, and the other using isqrt.bas from http://www.boriel.com/wiki/en/index.php/...:ISqrt.bas - this is a concrete example of why the slow ROM routines can become a problem for certain aspects of certain games. The speed difference is startling. The ONLY difference in the source code is changing the square root used from ROM to library. A matter of a couple of characters and an include.

It picks a point for a ball, and draws the pass line to another player. Then every other player has a line drawn to the nearest point on that line, or the nearest end if that IS the nearest point on the line. But look at the speed difference!

Note: press ENTER for a new screen.

ROM - http://sites.google.com/site/britlion/Passing-sqr.tzx

isqrt - http://sites.google.com/site/britlion/Pa...sqrtLF.tzx
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)