Skip to content

dev-collision-multithreading

Pre-release
Pre-release

Choose a tag to compare

@khuiqel khuiqel released this 24 Apr 03:11
· 115 commits to dev since this release

PowerTanks Battle | pre-release Version post-0.2.5.1: Collision Multithreading
I added multithreaded collision!... And performance is nearly identical. :(

Changelog (main things only):

  • multithreaded collision (though performance is nearly identical to single-threaded)
  • switched to GLFW from FreeGLUT
  • cross-platform compilation

Developer Notes

I tried investigating the lack of performance gain from going multithreaded, and I think the limitation is memory bandwidth. Each thread does part of the collision, then the list of collision pairs is merged. From my simple and unscientific tests with 4 threads, the merging takes about as long as the broad phase algorithm. There is a rather obvious solution to this: don't merge the results, instead letting each thread handle the rest of the collision (narrow phase and resolve). In order to do that, the entire collision system would have to be rewritten, which I'm not as against as I used to be, but that's a lot of work I don't plan on doing anytime soon.

How to run:

(Set the number of threads in the INI (ThreadCount). 1 is single-threaded, 0 is every core on your system.)

Windows

To play, simply download the zip file and unzip it, then run the .exe. If you have an Intel/AMD CPU made after 2016, your CPU should have the AVX2 instruction set, so try running the -avx2 executable for free extra performance.

Alternatively, you can build from source using Visual Studio. Just download the source code and compile it.

Linux

You have to compile from source.

  1. install GLFW and GLEW: sudo apt install libglfw3-dev libglew-dev
    • non-Debian systems currently untested
  2. mkdir build && cd build
  3. cmake .. -DCMAKE_BUILD_TYPE=Release (optional and recommended: -DCMAKE_CXX_FLAGS=-march=native -DCMAKE_C_FLAGS=-march=native)
  4. make -j$(nproc)
  5. Copy res/ and tanks.ini to the build directory
  6. Note: On Ubuntu, going fullscreen seems to force the window to the largest monitor, unless "Auto-hide the Dock" is enabled. It appears that Ubuntu forces windows that are too large for the current screen (which means full height is too much due to the dock) to the largest screen.