This project is a sandbox for me to learn CMake, SDL and C/C++ better. Also, it will serve as a "minimal working example" of a game that can run as WASM or an executable (at least on a mac/linux/unix based OS, until I can actually understand how to use CMake right). I will then use this as a template so I can work on multiple similar projects without having to recreate this setup each time. It uses Adobe Open Source fonts as a submodule to improve portabililty so fonts can be loaded in with a relative path.
NOTE: Running this initial game on mobile does not run smoothly. There is a long delay between when the screen is pressed and when the "click" is able to be processed by the game. I am thinking it's probably best mainly aim to make games that work well on desktop b/c of this.
There is a playable WASM demo of this game here:
https://wasm.jander.io/SandGame/game.html
- CMake
- Emscripten
- Docs: https://emscripten.org/
- Source Code: https://github.com/emscripten-core/emsdk
- Installation: https://emscripten.org/docs/getting_started/downloads.html
- SDL2
- Docs: https://www.libsdl.org/
- Source Code: https://github.com/libsdl-org/SDL/tree/SDL2
- Installation: https://wiki.libsdl.org/SDL2/Installation
- adobe-fonts/source-code-pro
# Clone repo and submodules:
git clone --recurse-submodules [email protected]:jude253/SandGame.git
To intially setup up Emscripten:
cd include/emsdk
./emsdk install latest
./emsdk activate latest
Next, build the project for WASM one time using the instructions below.
Make a build (doesn't have to be named build/
) directory, run cmake
with relative path to project root from there, then run make
. Somewhat like the unix style build, but with no configure
step yet.
mkdir build
cd build
cmake ..
make
Alternatively, use this command instead of make
:
cmake --build .
Use the same commands as above, but replace cmake ..
with this:
cmake -DUSE_EMSCRIPTEN=ON ..
NOTE: If you are running make
for the first time since installing
the emsdk, make sure the shell you run make
in has not run
source ./emsdk_env.sh
as this makes the caching of emscripten port
libraries fail. Run source ./emsdk_env.sh
after running make
the
first time.
NOTE: If you switch back to normal building, use this command for the first time to disable the cached key:
cmake -DUSE_EMSCRIPTEN=OFF ..
Run once to enable emscripten commands in shell session:
source ./include/emsdk/emsdk_env.sh
From /build
run:
emrun dist/game.html
./build/dist/game
Run from build
directory
cmake .. && make && ./dist/game