tank movement simulation

Other talk that doesn't fit elsewhere.
This is for General Discussion, not General chat.
elio
Regular
Regular
Posts: 508
Joined: 09 Jun 2007, 22:11

tank movement simulation

Post by elio »

so, here's a 'little' code which drives some tanks around in 2d, it is not related to warzone besides it leant to warzone's own movement code and perhaps if it's mature enough it'll make it in the game.

here are some screenshots for those wo can't compile source code :P
i use codeblocks as ide, so .cbp is the project file.
i suggest to play around with main.c (escpecially where the tanks are initialised) and the constants in simulation.c

i made no cleanup and it has hardly any commentary xD

enjoy ;)
You do not have the required permissions to view the files attached to this post.
elio
Regular
Regular
Posts: 508
Joined: 09 Jun 2007, 22:11

Re: tank movement simulation

Post by elio »

there are several bottlenecks in my code, i never used sqrt but cos / sin a lot.

this is what i found
http://gruntthepeon.free.fr/ssemath/

it is not as exact as the posix version but a lot faster
I chose to write them in pure SSE1+MMX so that they run on the pentium III of your grand mother, and also on my brave athlon-xp, since thoses beast are not SSE2 aware. Intel AMath showed me that the performance gain for using SSE2 for that purpose was not large enough (10%) to consider providing an SSE2 version (but it can be done very quickly).
benching sinf .. -> 3.2 millions of vector evaluations/second -> 142 cycles/value on a 1830MHz computer
benching cosf .. -> 3.2 millions of vector evaluations/second -> 142 cycles/value on a 1830MHz computer
benching sin_ps .. -> 18.1 millions of vector evaluations/second -> 25 cycles/value on a 1830MHz computer
benching cos_ps .. -> 18.2 millions of vector evaluations/second -> 25 cycles/value on a 1830MHz computer
EvilGuru
Regular
Regular
Posts: 615
Joined: 23 Jun 2007, 22:41

Re: tank movement simulation

Post by EvilGuru »

Performance wise there should be no need for a special/dedicated library.

The C standard math functions (-lm) are usually very well optimised and as of GCC 4.3 can be auto-vectorised (-ftree-vectorized) assuming your loops are written well. (GCC will auto-emit SSE/SSE2/SSE3/SSSE3/3dNow/MMX code depending on your compiler switches.) If you find yourself doing a lot of vector math, however, I highly recommend you take a look at Eigen (http://eigen.tuxfamily.org/index.php?title=Main_Page ) which is one of the fastest vector/matrix math libraries going. It is C++, which may or may not be an issue, however, is very well written and performs spectacularly.

Neat application (currently toying around with adding more tanks).
elio
Regular
Regular
Posts: 508
Joined: 09 Jun 2007, 22:11

Re: tank movement simulation

Post by elio »

it's just a header file:
sse_mathfun.h source code for sin_ps, cos_ps, sincos_ps, exp_ps, log_ps, as straight C. http://gruntthepeon.free.fr/ssemath/sse_mathfun.h
oh i just saw this awesome collection of "Steering Behaviors For Autonomous Characters" http://www.red3d.com/cwr/steer/
awesome, i'll take a look if i can implement these concepts. there is a library http://opensteer.sourceforge.net/ but it's c++ and - a library^^
elio
Regular
Regular
Posts: 508
Joined: 09 Jun 2007, 22:11

Re: tank movement simulation

Post by elio »

update!

ok, now it has a tank avoidance algorithm implemented, according to http://www.red3d.com/cwr/steer/Unaligned.html
i wrote it from scratch, because i didn't want to dig around in c++ (OpenSteer)

it works at least with two tanks, hmm but has some bugs, but development goes in the right direction xD
You do not have the required permissions to view the files attached to this post.
qwerty800
Trained
Trained
Posts: 183
Joined: 07 Mar 2008, 21:23

Re: tank movement simulation

Post by qwerty800 »

I would much more refer to this :)
elio
Regular
Regular
Posts: 508
Joined: 09 Jun 2007, 22:11

Re: tank movement simulation

Post by elio »

my algorithm is not pathfindig, it's after pathfinding, tank should avoid other tanks, drive backward etc..