Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

e6quisitory/wolf3d-reimpl-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deprecation Notice

This repo contains my first-implementation in C++ of the Wolfenstein 3D re-implementation project that I have now moved over to being implemented in Rust here. I will no longer work on this C++ version of the project; the project continues to get worked on and will get finished in Rust. I leave all the text below from the original README (with some slight modifications) for this project repo for those curious/interested.


Wolfenstein 3D Re-implementation in C++

  1. Introduction & Demo
  2. Build Instructions
  3. Controls & Map Loading
  4. Immediate Goals
  5. Later Goals
  6. Credits
  7. Resources Used

I'm attempting to re-implement, from scratch, the classic 1992 id Software game, Wolfenstein 3D. Re-implementing most of the functionality in the game is the goal, including rendering the game world, enemies, weapons, sound system, etc. So far, I've implemented the following functionality:

  • Raycasting
  • Selectively textured walls with lighting
  • Sprites
  • GPU accelerated texture mapping
  • Doors w/ automatic closing
  • Map loading from a csv file
  • Smooth movement using VSYNC
  • Mouse to look around
  • Minimap (dev tool)

Here's a couple short videos of what the engine is currently capable of:

Engine_Demo.mp4

Minimap_Demo.mp4

The only dependacy of the project thus far is SDL2, used to open a window and render pixels into it, hardware-based texture scaling, reading keyboard and mouse inputs, and VSYNC.

The comments in the commits are full of detailed explanations on the implementation of parts of the engine, how I encountered and fixed bugs, etc. Worth looking at if you're building something like this yourself.

The following instructions assume you're running on an x86-64 Windows machine.

  1. Install MSYS2 from here.

  2. When the install wizard is finished, it'll launch a terminal for the UCRT64 environment. We do not want this; instead we'd like to work in a terminal for the CLANG64 environment. So, in the Windows start menu search, type MSYS2 CLANG64 and a program of that name should pop up. Click it and another terminal will pop up.

  3. Inside this terminal for the CLANG64 environment, we first update all pre-installed packages by running the command below. Enter Y (for yes) when prompted to allow installation. The terminal might close, and if it does, reopen from the start menu as before.

    pacman -Suy
    
  4. Now we install the packages we need to clone this repo and compile it.

    pacman -S mingw-w64-clang-x86_64-clang
    pacman -S mingw-w64-clang-x86_64-cmake
    pacman -S mingw-w64-clang-x86_64-ninja
    pacman -S mingw-w64-clang-x86_64-SDL2
    pacman -S git
    
  5. Clone this repo and cd into it.

    git clone https://github.com/e6quisitory/wolf3d-clone.git
    cd wolf3d-clone
    
  6. Run the following to build the project into a .exe executable:

    mkdir build
    cd build
    cmake -G "Ninja" ..
    ninja
    
  7. Finally, run the executable like so:

    ./wolf3d-clone.exe
    
  1. Ensure CMake and Ninja are installed on your Mac through Homebrew:

    brew install cmake
    brew install ninja
    
  2. Head on over to the SDL releases page and download the latest SDL release for macOS (with a .dmg extension).

    • After download, mount the .dmg archive (open it)
    • Inside you'll see a macOS framework bundle named SDL2.framework. Copy it.
    • Open a Finder window, hit Command+Shift+G and type in /Library/Frameworks
    • Now paste the copied SDL2.framework into this folder
  3. Clone this repo and cd into it:

    git clone https://github.com/e6quisitory/wolf3d-clone.git
    cd wolf3d-clone
    
  4. Run the following to build:

    mkdir build
    cd build
    cmake -G "Ninja" ..
    ninja
    
  5. Now a clickable .app executable should be present in this build directory. You can run it from the terminal with the command below, and you can also navigate to it and simply double-click it as well to launch.

    open -n ./wolf3d-clone.app
    

Note that the below instructions have been tested on Ubuntu, and should work on other Debian-based distros as well (ex. Linux Mint, etc.). I cannot ensure that they'll work on non-Debian based distros, like Arch, CentOS, etc.

  1. Update your package lists

    sudo apt update
    
  2. Install the following packages

    sudo apt install build-essentials
    sudo apt install cmake
    sudo apt install ninja-build
    sudo apt install libsdl2-dev
    sudo apt install git
    
  3. Clone this repo and cd into it:

    git clone https://github.com/e6quisitory/wolf3d-clone.git
    cd wolf3d-clone
    
  4. Run the following to build:

    mkdir build
    cd build
    cmake -G "Ninja" ..
    ninja
    
  5. Now run the compiled executable like so:

    ./wolf3d-clone
    

Game controls

  • W, A, S, D to move
  • Mouse to look around
  • spacebar for opening doors
  • Esc to exit game

Minimap controls

  • ~ (tilde) key to unlock/relock the mouse from the main window
  • Left click on tiles in the minimap to spawn to them (if possible)
  • Right click anywhere on minimap to change player view direction

Map loading

The map file is map.csv, located in the assets folder. It is ASCII encoded, not UTF-8 encoded. I find that editing the file is easiest in Excel. As for how to construct the map, i.e. what the values in the map.csv file mean, I have yet to type up a new guide; I will get to that soon. In the mean time, you can read this old guide and look at the values in the included map.csv and try to piece things together.

  • Enemy AI & character animation
  • Weapons
  • Multithreaded raycasting
    • Thread pool
    • Mutexes/locks for shared data access b/w threads
  • Linux pre-compiled binary
  • Write a more sophisticated CMake script that:
    • In Debug config simply compiles into executable
    • In Release config makes a proper, signed, pre-compiled binary package for the platform (Windows, macOS, Linux) using CPack
      • Downloads a copy of SDL2, puts it inside the package, and links executable to that local copy (changes RPATH)
      • Puts assets folder inside binary package as well
  • Darken distant walls (shadow/depth effect)
  • Textured ceiling & floor
  • Add joystick support
  • Port to browser using Webassembly
  • Networked multiplayer (aspirational)
  • Proper map editor (aspirational)
  • Port to iOS?

All wall and sprite textures + the logo at the top of this README are from the official Wolfenstein 3D artwork that shipped in the game back in 1992. I found them here.