This sample work is a multi-threaded simulation of a Galton Box using metal, wooden and rubber balls. The simulation can be run as a single box or as two boxes distributed across a network using Winsock networking over port 2001, in this mode balls are transferred across the network to the other box when they pass the centre of the box.
The multithreaded physics code uses a scalable design that treats each physics object that needs to be updated as a job. The jobs are completed by a number of multithreaded workers that take multiple jobs out of the job queue. In the event that no jobs are available workers will take unprocessed jobs from other workers to load balance.
This is a piece of work that I'm really proud of and am still adding to. Recently the job queue was reimplemented using the STL queue container which allows jobs to once again be processed in a FIFO context. My own simple queue system originally processed in FIFO but this had to be changed when the networking element was implemented.
|
‘s’ |
Pause Simulation |
|
‘x’ |
Close Simulation |
|
‘n’ |
Toggle Cloth |
|
Space Bar |
Switch between real-time & 1/10th speed |
|
‘1’ |
Make all balls metal |
|
‘2’ |
Make all balls wooden |
|
‘3’ |
Make all balls rubber |
|
‘4’ |
Randomise ball types |
|
‘r’ |
Reset camera |
|
‘+’ / ‘b’ |
Add balls |
|
‘-‘ / ‘p’ |
Remove balls |
|
‘<’ |
Zoom out |
|
‘>’ |
Zoom in |
|
Left mouse button & mouse left/right |
Rotate camera about y-axis |
|
Right mouse button & mouse up/down |
Rotate camera about x-axis |
|
Middle mouse button & mouse left/right |
Rotate camera about z-axis |
The source code for this project is provided
here
and includes an executable. To compile, the GXBase libraries developed at the