dev-collision-multithreading-v2
Pre-releasePowerTanks Battle | pre-release Version post-0.2.5.1: Collision Multithreading v2
I improved the multithreaded collision implementation, then completely rewrote collision to be single-pass. Now multithreading shows noticeable performance gains. :)
Changelog (new main things only):
- fixed off-by-one thread creation count
- collision rewrite: single-pass, multithreading for broad phase, no copying partial results into a separate list, static list to avoid reallocations
- various performance optimizations
- bumped instruction set to SSE4.2 (though the attached executable was compiled with SSE2)
Developer Notes
I tried rewriting collision to be "single-pass", and it worked. (Previously, different object collisions were calculated in separate "passes"; this meant tank-bullet collision could only happen after bullet-wall collision was finished.) It was a lot more straightforward than I thought, and the performance gains were significant. Note that only the broad phase of collision is multithreaded, as multithreading everything is an extremely difficult problem; even real games made in professional game engines struggle with that, despite multi-core consoles having existed since the 7th generation (PS3 & Xbox 360).
How to run:
(Set the number of threads in the INI (ThreadCount). 1 is single-threaded, 0 is every core on your system. Additionally, you may want to experiment with changing ThreadTaskSize depending on your CPU utilization.)
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.
- install GLFW and GLEW:
sudo apt install libglfw3-dev libglew-dev- non-Debian systems currently untested
mkdir build && cd buildcmake .. -DCMAKE_BUILD_TYPE=Release(optional and recommended:-DCMAKE_CXX_FLAGS=-march=native -DCMAKE_C_FLAGS=-march=native)make -j$(nproc)- Copy
res/andtanks.inito thebuilddirectory - 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.