Spike:Pascal Drawing, Sound, and input
From SwinBrain
Name: Pascal Drawing, Sound, and Input
CVS Module: PascalDSnI
Contents |
Overview
Experiment with the drawing, sound, and input API available under Windows and accessible from Pascal.
Background
The Escape from Swinburne requires a means to interact with the user interface for drawing, playing sound, and collecting input. As the project will be using Pascal this spike aims to determine how to perform these tasks using Pascal, or how to enable these tasks to be performed.
Goals and Risks
This spike aims to overcome the following risks:
- The Team lacks experience developing graphical applications using Pascal
- There is no simple Pascal API for playing sounds
This spike aims to achieve the following goals:
- Determine how to draw using WinGraph
- Determine how to handle user input with WinCRT
- Determine how to play sounds using the Win32 API from Pascal
Deliverables
At the conclusion of this spike the following deliverables will be available:
- Pascal Drawing, Sound, and Input article, a short tutorial covering the points mentioned above
- Source code available for download from the article, and in CVS
- A 5 minute presentation on the core concepts and a short demo of the code
Resources
Timeline
- Start Date: 28th November 2006
- Deadline: 30th November 2006
Current Status
- In progress
Analysis, Planning, and Design notes
I need to look at sample code for the use of WinGraph/Mouse/CRT (this should also help brush up my Pascal syntax skills). Also, I need to look at the WinGraph documentation for method reference.
For sound, I need to find a Win32 API for playing sound. If it is inadequate I will need to look into calling DirectSound APIs from Pascal.
To test all this I will need to make a small program that allows the user to use the mouse and keyboard to paint bitmaps and pixels to the screen and play sounds.
Spike Outcomes
- Spike Source Code
- Pascal Drawing, Sound, and Input HowTo Article
Tasks Undertaken
All the below tasks were combined in the construction of a small sample program that demonstrates ability in each point below.
- Revising Pascal Syntax
- Learning WinGraph (Screen painting)
- Learning WinMouse (Mouse input)
- Learning WinCRT (Keyboard input)
- Learning the Win32 API PlaySound()
- Learning to use DirectSound from Pascal
- Learning to use OpenAL
What we found out
- The WinGraph unit is suitable for painting. Keep in mind that you should not repaint something over and over and over or you will get flickering. Repaint only when there are changes.
- The WinMouse unit is acceptable for reading mouse input.
- The WinCRT unit is mostly acceptable for reading keyboard input. However, it does not report "Key Up"/"Key Down"/etc events which would be very useful in a game where holding keys down is how the game is played, rather than individual key presses (which are currently reported as fast successive keypresses).
- Refer to the WinGraph List of Routines for function documentation for WinGraph/Mouse/CRT.
- The Win32 API PlaySound() is unacceptable for game use since it will only play one sound at a time. If a second is played at the same time as the first it will either cut the first off or not play the second sound.
- You cannot use DirectSound from Pascal because the function for loading Wave files into a buffer for a DirectSound secondary buffer are not actually part of the DirectSound API and are only available in C. This means that, although you can use DirectSound via a unit, you cannot load a Wave file without manually written code or compiling the functions into a DLL for use in Pascal. This was undesirablely complex and was dropped.
- The OpenAL unit is acceptable for sound use since it supports mixing. It leaked memory and had to be fixed manually. There are good tutorials for its use here.
Open Issues and Risks
- When the HeapTrc unit is loaded to track memory leaks in the application, it reports errors in memory. When the unit is removed the program runs fine. This may be a problem in the future, but for now it seems to be a harmless issue with the HeapTrc unit and the OpenAL unit.
Recommendations
- WinGraph/Mouse/CRT are acceptable for use in games. Some helper functions for more easily performing keyboard reads and typical painting functions might be of use in larger applications.
- For sound, use the OpenAL unit and DLL.