David Olofson wrote:
How about this, do it as one file and write routines to hide how you
actually read, and blit the images.
Just what I did in “sprite.[ch]” in Kobo Deluxe.
[skip…]
The function will grab 16x16 tiles starting in the top-left corner of
the specified image, working on to the right, wrapping to the next
row when it hits the edge. Number of tiles is determined by the size
of the image and the tile size only. Each tile will be stored as a
separate SDL_Surface. Every frame is automatically passed through a
configurable image processing plugin chain, where necessary
conversions and transformations are performed.
But if they’re are all of uniform size, why not put them all in a
vertical strip?
Why?
Or you prefer editing whole bank at once in, say, Gimp,
and have them all laid out in a grid and then loading the bank straight
from the file?
That’s the way the files are arranged currently - but you could give
the engine a vertical or horizontal strip is well; it doesn’t matter. The
engine extracts the tiles and stores them in the way it sees fit anyway.
The reasons why I decided to use one surface per frame:
* It's easy for rendering code to ask the "container" for a
specific frame without knowning about the internals of
the container.
* The plugin system becomes nice and clean, as I can just
pass the bank to each plugin, and have it loop over the
frames without worrying about any other per-frame
boundaries than the natural boundaries of each surface.
(Correct clamping during interpolation is messy enough
as it is without that...)
* No source rects need to be filled in and passed to
SDL_BlitSurface().
* SDL doesn't have to do RLE clipping all the time.
Even that way, I would’ve written a loader to convert multiple files,
say, each containing related images into one single bank than to
withness sheer inefficiency of skipping lots of data to the start of
each line of sprite.
Well, of course… What’s your point?
You can load multiple files into the same bank with my engine if you
like. You can also load a whole image as a single frame, and you can
"load" a rectangle from a frame of one bank as a fram of another bank.
(You can even load an SFont as a bank - although that’s currently a bit
of a kludge internally. I’ll ditch SoFont and hack a more carefully
integrated font system some time…)
The only restriction is that all frames of a bank must be of the same
size. Why? Well, the sprite engine must know the size of every sprite in
the system to do wrapping (for wrapping worlds like that in Kobo Deluxe)
and off-screen culling correctly, and it simply asks sprite.[ch] about
it. As I don’t want to mix up graphics coordinates and control system
coordinates (which are incompatible in scaled modes!), I can’t check the
surfaces directly. And as a matter of fact, there may not always be a
surface to check at all! The engine is supposed to work even if the
graphics isn’t loaded, to be usable in dedicated game servers and the
like. (Obviously, if you’re constructing collision detection masks from
the graphics, you’ll have to load at least the sprites anyway.)
Sure, I could allow mixed surface sizes in banks, or eliminate one
dimension of addressing entirely, but the current system is nice and
clean, and more than sufficient for what I’ve done so far. Might change
eventually, but I doubt it. (In native OpenGL mode, that would complicate
things a great deal, as the idea is to keep all frames of a bank in a
minimal number of OpenGL textures, rather than one texture per frame.)
//David Olofson — Programmer, Reologica Instruments AB
.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |
-------------------------------------> http://olofson.net -'On Wednesday 23 January 2002 18:10, Alexander Sabourenkov wrote:
On Tuesday 22 January 2002 20:12, Bob Pendleton wrote: