This and other 15-466 base code is built around a collection of useful libraries and functions which we will collectively call "nest". This name captures the goal of having the various parts and functions relatively easy to reconfigure (and remove), while still forming a good support for your game.
Here is a quick overview of what is included. For further information, ☺read the code☺ !
- Base code (files you will certainly edit):
main.cpp
creates the game window and contains the main loop. Set your window title, size, and initial Mode here.MenuMode.*pp
declaration+definition for a sprite-based menu. New: text drawing included. New: menu movement sounds.StoryMode.*pp
declaration+definition for demo story mode. You'll probably adapt this to do something else entirely. New: background music loading and playing.- New:
Sound.*pp
a basic game audio system. You may wish to add extra parameters (like looping) to sounds. Jamfile
responsible for telling FTJam how to build the project. Change this when you add additional .cpp files and to change your runtime executable's name..gitignore
ignores generated files. You will need to change it if your executable name changes. (If you find yourself changing it to ignore, e.g., your editor's swap files you should probably, instead be investigating making this change in the global git configuration.)
- Useful code (files you should investigate, but probably won't change):
- New:
load_wav.*pp
load audio data from wav files. - New:
load_opus.*pp
load audio data from opus files. Load.*pp
deferred resource loading.data_path.*pp
get paths relative to the game's directory.read_write_chunk.hpp
simple helper to load/save data arrays.Sprite.*pp
runtime component of a sprite asset pipeline.DrawSprites.*pp
helper for drawingSprite
s from the sameSpriteAtlas
. New:draw_text
included. New: pixel-perfect alignment mode included.Mode.hpp
base class for modes (things that recieve events and draw).ColorTextureProgram.hpp
example OpenGL shader program, wrapped in a helper class.gl_compile_program.hpp
helper function to compiles OpenGL shader programs.load_save_png.hpp
helper functions to load and save PNG images.GL.hpp
includes OpenGL 3.3 prototypes without the namespace pollution of (e.g.) SDL's OpenGL header; on Windows, deals with some function pointer wrangling.gl_errors.hpp
provides aGL_ERRORS()
macro.pack-sprites.cpp
,sprites/extract-sprites.py
utilities used in the sprite asset pipeline. See the README.
- New:
- Here be dragons (files you probably don't need to look at):
make-GL.py
does what it says on the tin. Included in case you are curious. You won't need to run it.glcorearb.h
used bymake-GL.py
to produceGL.*pp
This code is set up to build across Linux, Windows, and MacOS.
Building will be done from the command prompt, using FTJam, the freetype project's fork of Perforce's excellent "Jam" build tool (Documentation page at Perforce, for the curious).
To add or remove files from the build, read and edit the Jamfile.
Setup for your development environment should be relatively simple:
- (Optional) Make sure your system is set up to make it easy to use your favorite code editor and git from the command prompt. So much nicer than using a GUI.
- Install one of our target C++ compilers:
- Linux: g++
- MacOS: clang++ (from XCode)
- Windows: Visual Studio Community 2019
- Install ftjam from your OS's package manager:
- Linux: e.g.
sudo apt-get install ftjam
- MacOS: e.g.
brew install ftjam
- Windows: (skip this step; jam for windows is included in the nest-libs package)
- Linux: e.g.
- Extract an appropriate release of nest-libs to a sibling of this folder:
Once you are finished, your directory tree should looks something like this:
game-programming/ #can be called anything
nest-libs/ #nest-libs from that repository's releases page
windows/ #subdirectory name varies depending on platform
...
my-game/ #fork of this code; can be called anything
...
... #eventually, you will have further subdirectories for other games
Once you have your development environment set up, building is as simple as opening a command prompt (see Windows Note below), changing to the game directory, and running jam
.
Here are a few worthwhile variations:
# Note: Always build from the game's root folder:
$ cd game-programming
$ cd my-game
# Simplest build command:
$ jam
# Variation: multiple (six, in this case) build jobs in parallel:
$ jam -j6
# Variation: quit if any build job fails:
$ jam -q
# Variation: run game if build succeeds:
$ jam && dist/pong
# Variation: show commands being run (useful for debugging the Jamfile):
$ jam -dx
# Useful: show summary of jam flags:
$ jam -h
# Variation: this is what I generally use:
$ jam -q -j6 && dist/pong
# Useful: delete all built files:
$ jam clean
Windows Note: a pre-compiled jam.exe
and a .bat file + .lnk to launch a VS2019 command prompt with jam in the %PATH%
are included in the nest-libs/windows/tools/
directory. The README.md in that folder explains how to use them.