



(function |procedure )(.*?)(;(\n|.)*?begin)((\n|(begin(\n|(begin(\n|(begin(\n|(begin(\n|.)*?end)|.)*?end)|.)*?end)|.)*?end)|.)*?)(\n end;)This is then replaced using the following replace text. The $1 values are the groups that are matched in the regular expression. This enables me to place the procedure name, parameters and return type in the traced output ($2). It also ensures that all of the code from the program is output in the right spot.
$1$2$3This regular expression converts the following code...
{$IFDEF TRACE}
TraceEnter('sgCamera', '$2', '');
{$ENDIF}
$5
{$IFDEF TRACE}
TraceExit('sgCamera', '$2', '');
{$ENDIF}
$15
function VectorFrom(x, y: Single): Vector; overload;into this code which now has the tracing details added.
begin
result := VectorFrom(x, y, false);
end;
function VectorFrom(x, y: Single): Vector; overload;This should save me some time... though a real parser trace injector would be great!
begin
{$IFDEF TRACE}
TraceEnter('sgCamera', 'VectorFrom(x, y: Single): Vector', '');
{$ENDIF}
result := VectorFrom(x, y, false);
{$IFDEF TRACE}
TraceExit('sgCamera', 'VectorFrom(x, y: Single): Vector', '');
{$ENDIF}
end;
Another small feature of MacOS that I use often is the help search feature. This searches for the text you type in the program's menu options. The image here shows searching for "Picture" in Word. Selecting one of the found options opens the menu and a pointer indicates where the option is. You can then either click the menu or just execute it directly from the help itself.
A few people I know have recently switched to using Macs, so I thought I would try to put up Mac related tips for them here on my blog. I'll try to do one each week, but... we'll see :).tell application "A"
set title of (current slide of first slideshow) to "Hello World"
end tell
tell application "B"
activate
set theIndex to slide index of slide of view of active window
set selectedSlide to slide theIndex of active presentation
set content of text range of text frame of shape 1 of selectedSlide to "Hello World"
end tell


I upgraded my primary work machine from Leopard to Snow Leopard (see image of the real animal taken in Afghanistan). 



However, for somethings you do need Windows... Visual Studio for example. I use Parallels Desktop for Mac. Its a virtual machine, and allows you to run Windows, or other operating systems, under Mac OS. I have found this has worked really well for me. If you are moving from an existing PC, you can also make use of Parallels Transporter. It can be used to create a Virtual Machine image of your existing PC. You can then use this as a full backup, ensuring you don't lose any of those important settings or data from your PC.
An alternative to Parallels is Virtual Box. I know a few people who have used this, but I haven't tried it myself. The benefit of this is that it is free...
If you use any form of chat, you'll want to get Adium, a free chat client that can be used to chat with MSN, Yahoo, Google, Facebook, and others... There are heaps of extras that really make it an impressive application. The duck image is really cute, and the many replacement dock images are worth looking at.
Office for Mac is likely to be another program that you need. It is mostly compatible with the Windows version, though the 2008 edition is missing VBA support. I have both the 2008 and the 2004 version installed.
Back in February 2007 I developed some Automator actions to manipulate Postscript files. I used these actions in the past to convert my presentation slides into multi-page PDFs. By creating these as scripts it became easy to quickly convert a large number of presentations into "lecture notes" that I could upload for the students.
I share an office with Clinton who has lately become somewhat of a Python convert. Today I started to play with Python for the first time. Unlike "normal" people I didn't start with Python in Python... I started by embedding it within a Pascal program. Embedding Python within Pascal was really simple - I am totally amazed! With less than 20 lines of Pascal code you can embed a Python interpreter and have it load and run python modules.
The Summer Semester Project this year is working on extending the SwinGame API that was started last year. This is a really exciting project with some great outcomes already, and we're less than half way through...
Ok installing Leopard was a little more complicated that I thought!
Today I have been asked a few threading questions from students studying at Swinburne. Usually these were about the "How to" do something with threads, when I think the real question was should threads be used at all?
Here is an image of the first initial database that we designed. It's a bit messy, but most of what we needed was one there. We made some alternations the more we worked on it, but this version worked fairly well.
My project, Escape From Swinburne (EFS), has shed some features including multiple AIs and more complex animations such as skidding-to-a-halt. However, all is not lost. In fact, over the last three weeks great progress was made (remembering that a "week" is three days plus some voluntary time at home, for this Scholarship).Animated Graphics
EFS has implemented an animation system that allows any world object (an object in the game world such as the player or a floor piece) to have animations for certain actions. A world object, when loaded, can load as many image frames as it likes, then can specify what ranges of frames make a certain animation (eg. frames 10-19 are the left walk animation).
EFS provides the following animation hooks for world objects:
A small "fudge" has to be made with the current animation system because of a limitation in the collision system. The collision system can't deal with world objects that change width as they animate (since they might change width into a wall and get stuck). Hence, when animating, the player's (or any other world object's) width can never change and transparency must be used as padding. However, this means that players can seem to be able to step off an edge without falling (they are being caught on their transparent part). This is gotten around by putting a "shield" around the player at the edges of his bitmaps. It looks poor at the moment, but I hope to improve it.
Collision System
I wrote a complicated collision and movement system that uses vectors to control movement and some basic vector math (unit vectors etc) to detect collisions. Thank god I kept my Specialist Maths notes from school!
A main problem was that world objects could collide with something, but never butt right up to it (since their movement was cancelled because a collision would occur if it continued); there was always a gap. I resolved this by "growing" a movement vector pixel by pixel (using unit vectors) until the object either collided with something, or it was able to move by its whole vector. This meant that objects could "move as close as possible" to other objects, removing that gap.

World Scrolling
EFS lets you load a large wide image as a background to a level and will size the level to that image. It then lets the player move left and right around the level, scrolling the view as necessary.
A problem with this method is that every frame that is rendered has had the entire large background image painted. This is a very inefficient method, since only a fraction of the background is visible at a time, yet all of it is being painted. I have calculated that the painting of the whole background takes around 40-50% of the entire frame's rendering time: a massive inefficiency.
However, I lack the time to rewrite that system, what with the deadline fast approaching. Lucky today's modern computers can handle it.
Sound and Music
This part of EFS was cut back considerably. Originally I wanted each game object to be able to have their own individual sounds, but now there can be only three sounds: the background music, the player's walking sound, and the player's jetpack sound.
I grabbed some free sounds off the Internet and bashed them with a wave editor to make them sound slightly reasonable. However, they aren't the best; if you listen carefully you can hear artefacts and the sound repeating harshly. But they are quite okay.
However, as heavily cut back as this feature is, it still sounds great and does not detract from the experience.
Dynamic Frames-Per-Second Load Balancing
This part of EFS took me a long time (relatively) to do. The game speed in games should be constant and shouldn't be faster on faster computers. Old DOS games often have this problem. EFS has a dynamic load balancer that calculates data updates such as movement and collision every 16 milliseconds (62.5 fps) and the rest of the CPU's time is spent on rendering graphics frames as fast as possible (with a hard-coded max of 125fps to stop flickering). However, when the rendering framerate drops beneath 30fps, EFS will start sacrificing game data fps to speed up the rendering. The result: the game plays slower, but with a higher (but not that high) framerate. Modern computers almost never experience this.
This was achieved by using a "performance counter" from the Win32 API that counts time in microseconds (as opposed to a normal time getting function which get time accurate to around 10ms: not good enough). The game goes into a tight loop (maxing out your CPU) and only runs the data update once 16ms has passed. It will then only run a frame render when:
However, it will skip renders if the framerate is over 125fps (a render was last run in the last 8ms).
My laptop manages around 80fps on one of my testing levels, and my main computer (much more powerful) managed 180fps until I put a cap on that to 125fps to prevent the flickering that occurs at very high framerates.
I created fps meters in the top-left corner of EFS, to show the player their current, highest, and lowest fps for the game data and the graphics rendering.
Loading from a File
EFS will load its levels from map files. This means you can create levels on the fly without changing the source code of EFS just by editing a few text files.
Unfortunately, EFS has become so complicated that creating these text files is time-consuming and difficult. I had to create a template in Excel to help myself since the files get very complicated. A visual level editor is needed, but I don't have time to create one. :(
Jetpacking
The earlier revisions of EFS did jumping by adding an upwards movement vector against the downward vector of gravity. By holding down spacebar, you were able to continue adding that upwards vector against gravity and accelerate upwards at a great rate. I liked the "feature" so much, I decided to dump "jumping" and keep this "jetpacking" functionality instead. However, to limit their usefulness (otherwise the game would be ridiculously easy as you would be able to just fly across the top of the level), I implemented "jetpack fuel" which uses up as you fly and recharges when you don't. An onscreen progress bar is painted to show the jetpack fuel status.

TODO: Real Map(s)
At moment, I've created a simple dodgy testing map with my stellar (read: awful) drawing skills in MS Paint. It looks like a drawing out of a kindergartener's book. Even my dear old mother thinks its poor. Take a look at the screenshots to see what I mean.
The plan is, for the real maps, to take a picture of outside in Swinburne somewhere with a panoramic camera (for the wide angle) and then gaussian blur it in Photoshop to create a nice background for the levels. I have tried this before with Eyal's camera phone and it came up nicely. It is a technique I am pinching for some webcomics that use it for the backgrounds on the panels.
Then I will have to create the levels, which will be a pain because of the file format. Hopefully I can make something good in the time I have left. :|
TODO: AI
The very last feature of EFS I aim to get in before the deadline is a really stupid AI enemy. This AI will move left and right (changing direction when it hits something) and when the player touches it, the player will die.
This will require not only new code for AIs, but also changes in the collision system that will allow something to happen when the player collides with an AI, and allow the AI to detect when it hits a wall so it can move the other way.
I'll probably hack these changes into the code nastily just to get the feature done in time. I have a feeling that to get it done "properly" (ie not completely crap and limited) I will need a serious revamp of a lot of EFS (collisions, the game loop, etc). So we will see whether this feature makes the final version or not.
Wish me luck.

did it.
The Escape from Swinburne project, which I am responsible for, consists of two parts:Recently, I just finished the first step of the project: a spike (learning task) on drawing, input and sound in Pascal. Drawing and input were no problem (besides the inevitable revision of the Pascal syntax that I learned half a year ago (easy)) as they have been handled by the WinGraph, WinCRT and WinMouse units, but sound turned out to be more difficult than it looked.
The first approach I took to sound was to try to play it through the Win32 API. I used the PlaySound() function, only to find that PlaySound() does not play two sounds at once. It either cuts off the first sound and plays the second one, or doesn't play the second one. Pretty useless in a game that needs to be able to have background music and multiple sounds of action happening.
The next approach was the next logical step: use DirectSound. Unfortunately, because all this is written in Pascal and DirectSound is normally used from C or C++ programs, the first hurdle was getting access to the DirectSound APIs. This wasn't so hard, since I found a unit that wrapped up all the external calls nicely for me.
The next problem was figuring out how to use DirectSound. I got three books from Andrew and Clinton, one DirectX 5 (OLD!!) and two DirectX 9 books. Ironically, the DirectX 5 book was the best of the lot. The DirectX 9 books either talked about DirectMusic, a lower level DirectSound type thing that I really didn't want to get involved in, or had missing details such as how to actually load a sound (that was particularly useless).
Eventually, I came to a point where I realised the function that people use to load a wave file into memory for DirectSound isn't actually part of DirectX and is part of something else, which I couldn't access from Pascal because it was written in C++. Net result: DirectSound was a complete failure.
Then Andrew and I hunted around a bit more and found the OpenAL library and a unit for using it in Pascal. I was able to use OpenAL successfully (since it included wave file loading functions).
All these things I learned along the way culminated in a little program that lets you draw stuff (pixels or bitmaps) on its window with the mouse and play two sounds at once by pressing a keyboard key.
I then wrote a HowTo article explaining how to use WinGraph for drawing, WinCRT for keyboard input, WinMouse for mouse input, and OpenAL for sound. That is a long article!
And then, finally, to finish it all off I had to create a short 5 minute presentation showing what I did. I had to create this presentation using the "Beyond Bullet Points" presentation style. Although, during the semester, I've been imitating this style (as I've seen it presented by Andrew) in my own presentations, this time it was different since I had to do it by the book. We were given a template to fill out that details the logical steps that the presentation must take to establish itself, present its information and then conclude cleanly. That was a lot more time consuming than expected and took around half a day to do! Apparently, you get faster at it when you do it more.
You can see what I've done here:

The "Werewolf Project" is produced by the Howlers. The three students that are in this group are Eyal Gross, Allan Jones, and Joost Funke Kupper.