Bugbox Multi-Threaded Version Two

Download the BugboxMultiThreaded2 EXE (47KB) in compressed ZIP format.

Download the BugboxMultiThreaded2 project files (52KB) in compressed ZIP format.
   
The second multi-threaded solution
The philosophy behind this second multi-threaded solution was discussed in detail on the page for the previous version. This solution continues to use live objects, where each Bug creates its own thread and timer and calculates its own moves. But now the Box, on the main thread and with its own timer, polls the Bugs for their position and renders them into either a GDI Device Context or an OpenGL Rendering Context depending on user choice.

Placing all rendering work on the main thread allows this version to experiment with double-buffered rendering using OpenGL (use the Options menu to toggle between GDI and OpenGL mode). In addition, the load of waiting for i/o is taken away from the Bug threads. Since the Bugs' properties will now be accessed from more than one thread, the data needs to be synchronised using Critical Section objects. Something I considered was whether the Box should cache the latest reported positions of Bugs. However, copying values into a data structure and then indexing into it seems no less costly than calling a member function on a CBug object to simply return its properties, so I rejected caching.

WinZip® brings the convenience of Windows to the use of Zip files and other compression formats. If you don't have "the most celebrated shareware app in the history of computing" already, use the above link to download it.
   
Conclusion
In GDI mode, the application renders using the GDI function BitBlt. Choosing the OpenGL rendering option causes the OpenGL API glDrawPixels to be used, which draws to the back buffer of an OpenGL Rendering Context, and the front and back buffers are swapped every frame. In normal GDI mode, things are fine with a small number of Bugs, but a jerkiness begins to build up with a large number of Bugs. This is probably due to the fact that the single framebuffer is being written into whilst it is being viewed. Switching into OpenGL mode completely cures the jerkiness because it uses double-buffering. If you'd like to see more OpenGL samples, please look at my Graphics Samples page.

That's as far as I've got with the Bugbox project at present. I will be posting the COM, MTS and COM+ versions in due course. In terms of persormance, this version in OpenGL mode is the best we'll get; the following ones will simply serve to illustrate component technology and database transactions.

 
last updated: 9-oct-01