Wednesday, June 19, 2024

Revisit 坦克大战编程

In 2021 I posted two blog regarding building Tank natively with Visual Studio Build tools:

When I trying to redo the build from scratch, I noticed some is missing in my post, for example, there is no 'Build' folder by default. No need of Cygwin. Also, I'm planning to add network support, so player can play the game over internet. So I decide to make another blog to explore this. So here is a complete step by step for creating the build:

  1. Download Visual Studio Build Tools. Go to https://visualstudio.microsoft.com/downloads/?q=build+tools, scroll down and looking for something like Build Tools for Visual Studio 2022. When install, only need select "Desktop Develoment with C++", and for optional modules, the build environment such as MSVC v143 and C++ CMake tools for Windows are needed. All other can be deselected to save some space.
  2. Run "git clone https://github.com/quyq/Tanks.git" in working directory to pull the source code
  3. Install SDL2 header file and lib. SDL2 binary can be download from:
  4. Start a Visual Studio Build Tools environment, and do:
    • create 'build' folder (such as 'mkdir build') under project root
    • change working directory to 'build' (i.e. run 'cd build'), then run:
      • cmake -G "NMake Makefiles" ..
      • Note: the two dots is a must which set the source folder as one level up, and this will create Makefile, out folder and several other files/folder under 'build'
    • Run 'NMake' which should create 'tank.exe' under 'build/out' folder. Resource files would be copied to there too.

For using "NMake Makefiles" generator, update settings.json as:

{
    "terminal.integrated.defaultProfile.windows": "Command Prompt",
    "cmake.generator": "NMake Makefiles",
}

The first line will change default terminal from "Power Shell" to "Command Prompt". The next line select the generator. By default, it will use Visual Studio 16 2019 generator.

Build under WSL might be much easier, just install make/g++ and SDL2 develop package, then run make. If using Win11+WSL2, then no other extra work needed. If running WSL2 on Win10, may need update to latest WSL which has systemd support for GUI. And for audio, may follow instruction from https://x410.dev/cookbook/wsl/enabling-sound-in-wsl-ubuntu-let-it-sing/ which has clear step by step instruction and does not open unnecessary permission for utilizing PulseAudio.

 

0 Comments:

Post a Comment