Scotland Yard
Scotland Yard is an experiment into multi threading I undertook during my time at University. The game is based on an old board game I played when I was younger that pitted a team of players against an individual.
Multi Threading:
The three threads used in the game each have a unique role as outlined below:
- Game Engine: Handles simulation of the game and control input.
- Graphics Engine: Handles all the drawing to the scene.
- Entry Thread: Sets up the other threads and is responsible for responding to Windows messages.
Information about the game world that is used by more than one thread is stored in a lock protected singleton class. The lock system allows multiple threads to read from the data, but will only allow one thread to alter the data at any time. The threads are designed to work with read-only data for as long as possible before requesting a write lock to update the data. A write lock is only granted when the other threads are not reading the data structure.
Scene based design
The program is based around the abstract class of a "scene". These scenes can be loaded in the background by a dedicated thread while the user is doing something else and switched with the active scene as soon as the loading thread exits. The scene approach allows me to implement any new menus (such as a "settings for a new game page") without changing the existing code in the program.