Wednesday, July 28, 2004

GLOP

A language written in Perl to help make game programming easy,

#!/usr/bin/perl
use site;
use Glop;

GLOP::Draw->circle();

In GLOP Glop::Draw->Circle() means the same as Glop::Draw::Circle->draw(), used in many subsystems due to the small module quanta. But thats too easy, lets do something good,

#!/usr/bin/perl
use site;
use Glop;

Glop::Actor->Menu(
[ Start => sub { ... } ], [ Quit => sub { ... } ] );

Going a bit further, Actors are things that stay on the screen and the kernel keeps track of them (they are fire and forget) , four methods: new, make, step and draw. The step and draw are called every frame with step being called before draw.

#!/usr/bin/perl
use site;
use Glop;

view( -16, -12, 16, 12 );
Circle->make();

package Circle;

use Glop;
use Glop::AutoGL;
use base 'Glop::Actor';

sub new { ... }
sub make{ ... }
sub step { ... }
sub draw { ... }

Similar to Actors, Transients are things that are continued actions that eventually ends, and are placed in TransientQueues.

All input is via $KERNEL->input(), e.g. $KERNEL->input->Keyboard, and is registered in the make() method (a "kind of" constructor).

What about speed? Perl is interpreted, not good. But there are ways to fix it, there are always places to optimise your program, you'll always run into speed problems no matter what language you're writing in. You'll be able to write your game in 1/100 th of the time, even if it runs at 1/2 the speed.

But what do you do if you do run into speed problems? Try to move things into display lists (rendered directly by the graphics card). For instance to move the rendering of our circle into a display list, we'd use invar { Glop::Draw->Circle() }, but don't do anything that changes inside it as it won't happen. This works suprisingly well!

Available at SourceForge CVS glop.sf.net, but not yet on CPAN.