www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/24/18:46:15

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp,rec.games.programmer
Subject: Re: How to program compiled sprites?
Date: Fri, 24 Jan 1997 20:36:45 +0000
Organization: None
Lines: 40
Distribution: world
Message-ID: <lfA6gzAd1R6yEwVr@talula.demon.co.uk>
References: <32e54b6d DOT 501326 AT news DOT prestel DOT co DOT uk>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Luke Steele writes:
>I recently obtained the Allegro, the graphics programming library for
>DJGPP.  One of the test programs that comes with it demonstrates
>certain methods of sprite putting, including one called compiled
>sprites.  How does this work?  According to the documentation, the
>routine performs a number of immediate 'mov's, but I am unable to see
>how this could make things faster.  Surely, the time for an immediate
>'mov' is 1 cycle, as is the time for each mov in a 'rep movsd'?  What
>is it that I'm not getting?

You're forgetting that when drawing sprites, Allegro skips over zero
pixels, so you can make some areas of the shape transparent and let the
background show through.

So for every pixel in a regular sprite, it has to test the pixel (1
clock), do a conditional branch (1-3 clocks on a 486, depending whether
the branch is taken or not), and then write it. And because each pixel
needs testing, bytes have to be copied individually rather than in 32
bit groups.

RLE sprites are quite a bit faster, because they store the transparent
areas as runs of solid or absent pixels. This means that 32 bit copies
can be used within a solid run, and testing is only required when the
image changes from solid to masked or vice versa.

With compiled sprites, all the testing is done when the sprite is
created, so zero pixels don't cause any overhead (the sprite compiler
simply doesn't include any instructions for them). If there's only one
solid pixel in a sprite, you only get one move instruction. If there are
10 solid pixels in a row, you get two 32 bit moves followed by a 16 bit
move, and since all this is precalculated, drawing the thing is
extremely fast. Of course it also takes up a ridiculous amount of memory
(which may do bad things to your cache), and the image can't be clipped
if it lies off the edge of the screen, but it's still the fastest way I
know of drawing masked images...

/*
 *  Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
 *  Ghoti: 'gh' as in 'enough', 'o' as in 'women', and 'ti' as in 'nation'.
 */

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019