Re: Learning how to code free movement and panning in a game like Swamp.

Okay. So, here is an informative Python repl session.

>>> import timeit
>>> timeit.timeit(lambda: pan_value((5, 0), 90, (2, 0)), number=10000)/10000.0
1.0377488363072835e-05
>>> timeit.timeit(lambda: pan_value((5, 0), 90, (2, 0)), number=10000)
0.10387503569908141
>>>

So you can basically run 2 or 3 thousand calls to it a frame without it even being that big a deal.
Your version may be faster, but mine is extensible.  The magnitude, normalize  and dot functions I am utilizing will work with any number of dimensions, up to and including vectors that are so long they break your ram.  Unfortunately, the pan_value function only works in 2-the 3-dimensional version absolutely requires transformation matrices, because otherwise you have to do a projection onto a plane.  Obviously panning stops mattering once we get into 4, as do most games.
But seriously, don't optimize until and unless it proves to be too slow.  This can be microoptimized even further by not using tuples at all and getting rid of the dot and normalize functions and technically you can compute cosine with a division.  But it simply does not matter.  Code for clarity, not for speed.
Make your game.&n bsp; When your game proves to be too slow, profile it.  Then fix whichever functions are at the top of the list of total time taken.  Any other optimization in Python is simply not worth it-if you are actually doing something that might actually have a performance issue of this sort at all then you're using C/C++.
And I could care less about Python 3-a huge number of libraries remain unported, enough that most people who use the language still use 2.  This is changing and I'll start caring when Twisted and Gevent port as, if you're going to try networked games in Python, you really really want one or the other of those.  3 has some very nice features, but a lot of the useful stuff is available as backports and it's just not worth it without all the stuff you can get in 2 (hint: gameobjects, possibly the ODE bindings, not sure if lxml ported yet or not...).  3 is nice in theory, but it's going to stay theory until we actually see a concerted effort by all the major libraries-in practice, braking backward compatibility in an established programming language as they did means they're lucky that Python is still popular.



_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : Aprone via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : frastlin via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : Aprone via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : frastlin via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : frastlin via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : frastlin via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : frastlin via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : frastlin via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : frastlin via Audiogames-reflector
  • ... AudioGames . net Forum — Off-topic room : camlorn via Audiogames-reflector

Reply via email to