Swords and Software

About Minesweeper 3

Multithreading

A few problems from Minesweeper 1 had persisted in Minesweeper 2. Most notably I might mention the timer, that used 100% CPU in Minesweeper 1, and that worked only when the mouse was moved in Minesweeper 2 to prevent this load. But I am also referring to the issue of maintainability. Although the code was very much improved between Minesweeper 1 and 2, there still were a lot of reduntant dependencies between classes and it was difficult to add any features.

Such problems meant that a revisit to the Minesweeper Legacy was inevitable. On 4th February 2007 I began Minesweeper 3 and, within the span of the same day, had reproduced the original functionality of Minesweeper 2. Minesweeper 3 had some substantial improvements over its predecessor: these included simplified class dependencies, faster grid-redrawing times, and a single, small tileset instead of several fonts floating around. Dependencies were further reduced by abandoning the SDL_image extension that Minesweeper 2 had adopted.

However, the main problem remained: I could not possibly get the timer working without some sort of multithreading. While SDL has capabilities for multithreading, I could not find a way, due to the structure of my classes, to both implement separate threads and keep the object oriented paradigm consistent. In the end I had to resort to using global variables to successfully implement threads.

Multithreading not only allowed me to implement a flawless timer, but also allowed me to try out some new graphical effects that would have blocked the interface in a single-threaded environment. This can be seen in the rollover fading tiles in Minesweeper 3.

Other, less important features that were planned or implemented in Minesweeper 2 were dropped in the sequel. Menus were never planned for Minesweeper 3, and graphics that respond to half-clicks (holding down the left mouse button but not releasing it) were designed but not used. This was because adding them would have added unnecessary complication to the source code without adding anything to the user experience.

© Daniel D'Agostino 2006 - 2025
dandago [at] gmail [dot] com