PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Is 3000+ sprites normal? :)

SpritesUnlimited displays more than 3000 animated sprites. Doesn't anyone wonder how I did that? :) I can bumb up this figure to 30.000 if you wish, the app can easily handle that without dropping below the 50fps mark. :)
i already know :)
The demo is quite nice and I encourage all to try it out.  

I'll make a wild guess and say 'compiled sprites?'
Nope. Sorry.
Moose or Chuck · 08 Sep 2001, 14:01 UTC
I want to know, tell me? Did you reinvent GAPI?
I know how you did it! Floating point math and 64 bit integer operations, using BitBlt to output to a regular window. ;D

Dan East
Darn, dan answered right before I was going to!
~
Just looked @ some of your tutorials Jacco and I knew I had to write a personal thank you. Some very good info there. Can't wait for tutorial 6. Perhaps sometime in the near future you can cover alpha-blending in detail? It's the mystery that I've been trying to find an answer to (in form of understandable code ;) on this board for quite some time.

BTW, let me take a guess @ the 3000 sprite puzzle: sprite routines w/ ARM asm?
Nope, wrong again. :) I'll try to write the tutorial on Monday. Apparently no one is going to guess how this works. :) You'll hate me so much once I tell you how it's done.
You're Jimmy and you have invented an app that overclocks the processor to 500 mhz - or makes it work like a geforce
Hi,

OK, I'll put you guys out of your misery. :)
Here's the trick: Basically, you're watching a flipbook with eight pages. Each page is initially empty, but I use the first 8 frames to draw one sprite on each of them, each time on a slightly different position. Flipping these 8 pages makes the 'sprite' move, without the need to actually draw the thing. When I run out of my 8 pages, I return to page one. This page contains already one sprite, at it's initial position. Now I draw a second sprite. During frame 10 - 16 I add a sprite to page 2 - 8, so that each page contains two srpites, and flipping these pages makes it look like I'm now moving two sprites.

I hope you get the idea by now. In sprites unlimited, sprites are drawn along a fixed trajectory (wave spiral (circle with slowly decreasing radius, radius is multiplied by a sine to get the waves)) and a second plain spiral path. That's all.

So, sorry Carp, you can't use this in Argentum. It's just a trick.

Anyway. I'll try to explain it better in tutorial six. :)

Have a nice weekend,

- Jacco.
Ah trickery!  The man is a witch!  Grab the torches!  Who's with me??? :)

I managed to get a bit over 1500 alpha blended sprites per frame at 50hz using C code on my iPaq.  My test sprite was a anti-aliased filled circle that fit inside an 8x8 pixel rectangle (r = 4 pixels).  I think your demo used something similar but it was hard to tell since I couldn't stop the animation in your demo.  This number also includes having to copy a 240x320 backbuffer to the front buffer each frame, but there's nothing else going on (no positioning logic) - just blits and flips.

Still, 1500 per frame is pretty good for a handheld device and would make a nice particle animation demo.  If you don't need alpha blending the number jumps to 3800 at 50hz.  Now THAT is sassy.

I also made an attempt at hand-coding a compiled sprite, but since the majority of pixels are opaque within the 8x8 rect, there wasn't a perf win.

BTW, the Playstation 2 claims 18.75 million 8x8 pixel sprites per second.  That's 100 times what I'm getting on my iPaq.



wait a minute, you're saying the playstation can only show 100x the number of 8x8 sprites an ipaq can?! hahaha
1500 alpha blended sprites at 50 fps is very good! Could you post a demo? It might be cool to model a milkyway spiral with that. :)

BTW, now that every PPC will have an ARM in the near future, it's time we dive in some serious ASM people... :) I'm going to do GBA coding for my boss, so I'll build some ARM knowledge while I'm at the office. Lucky me.
Heh, this sucks. We just started covering MIPS assembley in one of the courses in my University. Why couldn't it be ARM, dammit? ;)
I don't have a lot of free time to cook up demos, but I'll see if I can't get you an .exe that moves some alpha-blended sprites around over a background image on an iPaq.  I suppose I'll have to add an FPS counter and some way to specify the number of sprites on the screen.

Give me your e-mail address and I'll send to anyone that is interested.


Jacco.Bikker@Davilex.nl :)
Check out EasyCE for an easy way to calculate fps: Use resettimer() and msecs() to determine the number of milliseconds it took to render the previous frame. FPS can be derived easily from that number.
I'm already doing the FPS calculation (how do you think I obtained the previously posted framerates?) but I'm displaying it with a string posted to the debugger every 4 seconds.  What I was referring to earlier was that I probably need an FPS counter that displays on-screen, rather than in the debugger.  I have done this before with my D3D apps, I just find it to be a bit tedious.

Get EasyCE. It has a build-in font and print routines. Not fast code, but for a short string, it's perfect. Saves you lots of stupid work.
I've sent the sprite sample to your Hotmail e-mail address, Jacco.  Let me know if you didn't receive it or if you have problems running it.

Since the demo bounces a bunch of these 8x8 alpha-blended sprites around the screen it must do collision detection with the edges of the display and invert one of the components of a direction vector.  This eats up some time and drops the sprite throughput to 750 @ 50 FPS.

Witch! Witch!

I say we throw him in the lake and see if he floats!!!

Still pretty slick...but I feel like I just watched another show on the Loc Ness Monster only to see no conclusive proof again...
Moose or Chuck · 13 Sep 2001, 15:07 UTC
That's a good analogy.
hey, is Really ARM the only processor that will be used in the future? Would be ql, cause programming for 3 different processors suxx bigtimes, no asm really possible, but with just arm using asm could give us all a BIG speed boost.YUPIEE!!!
haha, you engrish people crack me up!
Moose or Chuck · 13 Sep 2001, 17:00 UTC
That's not engrish. That's ghetto english mixed in with some 'ql nu aig' spelling techniques. Someone needs to go back to kindergarten.
nah, he probably just used an american dictionary...
nah, sorry for my bad english, never spent the time to learn proper gramma:/ And ql is cool often used by quake ppl (nah ppl you play pocket quake, don't you?!?:)
yes we play pocketquake, but we also know the difference between being cool and being kewl. the latter stinks like oj simpson.
Have you smelled him before?
He smells like Amish. <grin>
Aah, he may be familiar with the groundhog then.
Digby, I tried your demo. Pretty awesome performance you got there. :) If I can find the time, I'll give you another demo to think about later this week. :) More sprite stuff.
Jacco,

Thanks for checking out the demo.  I don't have a lot of free cycles these days, but I'd be interested in hearing any ideas you have.

Hey let me ask you something.  If you were going to write a sprite library which of these features would you support and which would you consider to be higher priority?

- Alpha blending
- Color key transparency
- Rotation by any arbitrary angle
- Scaling
- Clipping to edge of screen (viewport?)
- Mirror, flip vertically/horizontally
- Z sorting (sprite has a single depth value)
- Image loading (bmp, jpg, png?  which formats?)


Of course this question is open to all, but I would be most interested to hear from people who have at least used, if not developed,  sprite libraries and what sort of things are absolutely necessary and what sort of things aren't.  Or maybe things you would have liked to have that weren't available in the library you used for your game.  Thanks.

As a graphic artist I say:
Support Alpha blending and PNG, BMP and TGA. Also Z-sorting and rotating the sprite.
The other ones are not that high priority, but implementing them would be neat.
Is that your secret project? Is it??
No secret projects here.  I have more than enough to keep me busy.  I'm just trying to get a conversation going that has something to do with actual development rather than muffins.

Thanks for the feedback.  As an artist, why do want the loader to support more than one image format?  Don't your tools support multiple formats?



ok I'm currently developing my own sprite library for PPC which is partially ready and that's what I would go for:
1.Image loader (first tga, then jpg/png or own format)
2.Clipping to the edge of screen(this one is very important)
3.Color key transparency
4.Alpha-blending
5.Mirror/flip (might save you a lot of space used to store sprites
6.Z-sorting, if you need that
7.Scaling, if you need that
I wouldn't even think about creating an arbitary angle rotation procedure, cause it's quite slow and creates POOR results most of the time.(Partially true about the scaling procedure as well...)
Digby wrote:

> Alpha blending
> Color key transparency
> Rotation by any arbitrary angle
> Scaling
> Clipping to edge of screen (viewport?)
> Mirror, flip vertically/horizontally
> Z sorting (sprite has a single depth value)
> Image loading (bmp, jpg, png?  which formats?)

Here's what I did in the Nutcracker: I wrote a really simple sprite class that does the most basic stuff that a sprite should do: Draw itself, nicely clipped to the screen area. That's all. I did use alpha blending, but that trick could easily be done in the simple sprite class I just described. I also needed 'white sprites', like when the player gets hit (for that authentic flashing effect). Added that too.

My point is: You don't want a bulky full featured sprite library. You want some code that is reusable, fast at it's core, and extendible. I would never release a sprite library with my white flash effect (since probably no one will ever use it), but still I needed it. While on the other hand, I did not need rotation and scaling. If that would have been in my sprite library, it would have made the sprite code much more complex (especially the clipping), and my executable would have been larger.

One question: Are you creating this library for yourself, or for the general public?

And one last remark: Loading PNG/GIF/Whatever is not the core business of a sprite library. The sprite library should retrieve it's data from an arbitrary buffer. A PNG/GIF/Whatever library should take care of the image loading. That way, your paralax scrolling library can benefit from the same code.

Just some ideas.

- Jacco.
Paul Johnson · 18 Sep 2001, 06:55 UTC
My guess would be a span sorting algorithm whereby you bucketsort spans of sprites for each line of the screen and deal with overlaps.

No overdraw whatsoever!
Great comments.  Thanks and keep it coming!

MirekCz,
The rotation will be fast and it will look good. It's the same algorithm used in texture mapping, however it's nowhere near as fast as pre-rotating the image and displaying a strip of the images.  You could still use the rotation routine to save space though.  You load the single sprite image from disk, then generate the strip of multiple, rotated images using the sprite rotation function.  Imagine a game that allowed the player to choose from 25 different vehicles, all of which would need 32 frames of rotation.  If you did this on the fly when the game loaded you won't have to store all of those images on the user's device.

Jacco,
I don't think I need a sprite library for what I'm doing, so to answer your question I suppose this would be for public consumption.  I'm not signing up to do it though, I'm just gathering ideas.  You've made some good points.  Image loading is pretty simple to write and could be used in a number of other places in a game.  It probably shouldn't be part of the sprite library.
No one should have to pay the price for a code path that goes through things like clipping or rotation when the app doesn't need it.

Paul Johnson,
What about sprites that must be alpha blended with what is already drawn into the frame buffer?  I see 2 ways to handle this, either defer the rendering until an EndDraw marker is found in the display list, then draw the sprites back-to-front, or use a depth buffer and draw the sprites as they are submitted.  You would have to force the app to draw all of it's opaque sprites first, then draw any translucent sprites in back to front order.


Digby:well, you have got it wrong in few places:
1.assuming a 32x32x16bpp car each picture takes 2kb of ram, so we get 8 pictures into 16kb... so 25 cars aren't a problem at all.. and why only 8 pictures? because we can use a routine that will rotate a sprite by 90/180/270 degrees on the fly - while drawing... it's almost as fast as normal drawing and allows to keep you only 8 pictures to give you a total of 32pictures for a full rotation. And you don't lose quality!
2.About the rotating engine.. it will really bring poor results comparing to pre-drawing it
Thanks for the feedback.  As an artist, why do want the loader to support more than one image format?  Don't your tools support multiple formats?

I use different formats for different graphics. Jpeg is good for photos and stuff. PNG is the perfect format for design stuff, and bitmaps to make it look complete.
MikeCz,

My point was that a single image will use less than multiples of that image.  However, the fact remains that unless you are only rotating in 90 degree increments, you're going to need more images on disk for the intermediate positions.

The quality issue would depend on the image.  If the rotation code is the same as what is in a paint program, then the result would be the same (inverse texture mapper w/ bilinear filtering).  It will produce the same result as if you loaded the sprite image on a texture-mapped 3D quad and then rotated it about the Z axis with your 3D display card.  On my system, that looks pretty good and seems to be comparable to the result I get rotating images by an arbitrary angle with paint programs.
If however you are using 3D modelling software and rendering rotated views, then the lighting and shadows are recalculated with each new image.  That is something that an affine transformation couldn't produce.  If that's what you're doing then your lighting effects are going to be incorrect when you flip/mirror to produce the images in the 3 other quadrants.

I think the rotation function has a place in a sprite library, although from thinking about your comments it's moving lower on the list.  Good comments Mike - thanks.  

Anyone else with ideas?

I have a cool tech demo that I want to tweak just a tiny bit more before I release it. It's currently drawing 100 bouncing balls, all 80x80 pixels, nicely clipped to the screen, at 50fps (iPaq). That's 640.000 pixels per frame, or 32 million pixels a second. I hope to boost the code to 60fps tonight. I'll post a demo tomorrow, and sources a couple of days after that.
digby:who in the hell would use a standard rotation function to create pre-rendered rotated sprites?:)
and the quality issue is quite big I believe, hand done or rendered graphic is much better, althrought you're right about the lighting problem, i use a top-down view so it's not an issue to me, thru.

Phantom:WOW, I would like to see source for that, I manage to put 1000 100x100 bitmaps into backbuffer per sec on an ipaq....(16bpp)
MikeCz,
Either the game wants to reduce download time, disk requirements and has a lot of these types of images, or the game allows arbitrary artwork to be used as a sprite, and it can generate the rotated images via the library routines.  Is this something that a lot of people will do?  Beats me.  I'm just throwing out ideas for comment.

Jacco,
That's cool.  I'd like to see it.  Are they alpha blended?
No, no alpha blending this time. I got the frame rate up a bit (can't try it on the iPaq though, left the craddle at the office), I hope it's something like 60fps now.

MirekCZ: Of course you can have a look at the sources in a day or two, as usual. :)
Digby:beat me, but I would never allow myself to do that! - quality is most important
Phantom:hehehe, well I will be first one to download that.. btw have you got some alpha-blending demos too?:) (my alpha-blending routines are like 50% slower then transparent image drawing)
MirekCz: Register dude. :)
Anyway, you'll probably be a bit disappointed when you see the sources. It's not as simple as the sprites unlimited demo this time. :)
I haven't seen sprite unlimited demo source actually, let me guess thru, you're going for run-lenght encoding? Would seem like a right step to take for a fast sprite engine and I can't see anything else that could make such a big gap in speed. I have did one with 80x86/MMX asm, it really rocks:) I haven't go for one with PPC cause I'm creating a very little game atm and it won't need that much speed I guess... it's very hard to develop anything anyway, cause I don't own an PPC:/ Ok, I'm away to register now...;)

PS.Maybe it's not the best place/time to do, but I remember your Phantom engine, Jacco.. from the good old software rasterization time.. it was really cool, you could actually create one for PPC, would roxx I guess:)
So how do you like me now?:) My first message, hah:)
Jacco,

Are you up to more trickery? :)

I won't allow myself to fall into a Monty Python rehash...

'witch, witch' ... 'burn her, burn her'
Mirek, where you referring to the 'Phantom cyberspace' demo? I already did a voxel engine on the iPaq. :) The cuberspace thing was basically a double voxel engine, one voxel map coming from the floor and one from the ceiling, allowing for indoor scenes. Pretty cool on a 386, back then. :)
Jacco:hmm, might be, it's quite a long time;) I do remember that I wanted to be as smart as you back then... well actually I still do;) And yes, you did make the old machines "fly":)
Anyway you didn't answer my question, Is your new sprite demo using a run-lenght encoding to get such high numbers? With my functions I wouldn't been able to get more then like 25fps with that many 80x80sprites...

PS.run-lenght encoding, not sure if it's the correct name for it, but it's what I have heard once, basically it's about calculating how many transparent pixels are between non-transparent pixels and then just jump over them everytime you encounter them instead checking every pixel if it's transparent or not.
PS2.wrong again, the run-lenght is an approach where you check for pixels with the same color rather, I have just changed it to transparent/non-transparent cause that's what gives a big boost in sprite drawing...(is there a name for that?!? I used to name them FTIF with a friend long time ago.. and i still do (FTIF-fast transparent image format)
Let's say it's one of the tricks I used. :) The most important 'trick' is an algorithm that allows me to draw this many sprites with zero overdraw. I believe you mentioned such an algorithm also a couple of messages back.
Ohh, you mean the span sorting algo mentioned by Paul Johnson? Yep, it should work great for big ball sprites... still not really usefull in real-life algorythms I believe (ie try to draw transparent trees with it and the number of spans that you will have to insert will be huge;)
Ok, I will shut up because noone likes me by now anyway;)
/me went to stole Phantom's backbuffer->frontbuffer copying routine couse his is damn slow (takes 1/60 of sec;)
You have a better way of rotating a 240x320 buffer to the internal 320x240 iPaq buffer? :) FYI: I bypassed this in the bouncer demo. That demo draws to a 240x320 buffer on the Casio's, and to a 320x240 buffer on the iPaq. That's why the balls are tilted 90 degrees on the iPaq (you can only tell by looking at the texture).
well, as for now I was using a function which reads xpitch/ypitch values and saves to the buffer according to them - works very slow - I was trying to write a function which would work on 32bit values, it would be probably much faster, but I haven't got a possibility to test it anywhere and after crashing my friends IPAQ 2 times I gave up. (the idea is to read two long values from backbuffer, make some shifts/adds/ands and save two long values to IPAQ video buffer - from what I have noticed, working on 32bit values makes the memcpy routines 100% faster then working with 16bit values, so a big speed boost here might be possible (the and/add/shift function doesn't make big difference here from what I have noticed... no PPC to test anything thru:/
I thought of that, but I didn't try it because I think the cache will perform poor this way: To plot two pixels at once you have to read from the source buffer two pixels on different scanlines. I should really try it to see if it's really faster or not. It's the core of EasyCE.
Yes, try it. I guess it will be MUCH faster... cache doesn't seem to do anything here - my function that rotates a bitmap while drawing works with pretty much the same speed and you read different scanlines with different order...
(it actually works few-several % slower but i would guess that's because the additional calculation it has to perform instead just increasing bitmap/screen pointer by 1 every pixel)
btw why should cache perform poor? We're reading a big block of bytes and I don't see why cache should help us with that (there isn't any prefetching implemented I guess) Anyway what's the size of cache on those processors? I wouldn't give it more then 16kb or so... I really don't see your point here
Well I don't know how this works on the PocketPC, but on the PC a cacheline is 32 bytes, so if you read one of these bytes, the other 31 bytes are cached. So, reading or writing continous chunks of memory is more efficient.
well, yes, but what we do is we read one line of cache and then another one which is somewhere else, and from this place we move forward by reading following pixels from both places (so we use the other loaded bytes, assuming a PPC cache can hold two cache lines)
Perhaps someone else can shed some light on the cache issue? Anyway, I'll at least time the performance of both approaches. It's a piece of cake to add the 32bit rotate code.
Guys the way to deal with the iPaq's native landscape oriented display is to treat it as a 320x240 contiguous buffer, and pre-rotate all of your images that you will be copying to the display.  This allows you to copy spans of pixels at a time instead of that goofy "swap the x and y" method.  If you're concerned about performance, you look at the hardware config, then work backwards through the API, your app, and eventually your data.  You store your data in a format that the hardware can deal with so that there is minimal munging going on to get it to screen.

Digby, I absolutely agree that this is the way to get the best possible performance. However, if you own just an iPaq, it's not an option to write a game this way that also works on the Casio. The overhead of the rotation code is quite small btw, especially for a game that runs at about 30fps. And if we can get it twice as fast, like Mirek suggested, I believe this is a better option than having separate sprite routines / print routines / everything routines for Casio and iPaq and every other PocketPC that doesn't conform to Casio's or Compaq's 'standard'. I know it's slower, but it saves a lot of work, and generally makes it possible to write software for one device and run it on all. An (as small as possible) speed penalty is acceptable, in my opinion.

BTW, the bouncers demo uses the approach you suggested, to get maximum performance. I would never do that for The Nutcracker though. I can't test on all devices, sadly.
Jacco:hey, what's up? Didn't hear anything from you latelly.. Did you make it? I guess it should be like 1h of work max with an IPAQ around... I'm quite busy with map editor so didn't have any time to do any optimizations...
I look after the kids on Thursdays, so no PM for me then... I'm back now. :)
Jacco, dont you know!? Kids love PocketMatrix:)
Well, if you could setup a Dutch forum... :) My daughter is pretty smart, but English at the age of 3 is a bit too much.
Well, I guess it's time to teach her programming;)
If she's going to be a programmer she won't need english. Unless of course she is going to document Jacco's code so the rest of us mortals can understand it :)


She's definitely going to be a programmer. :) I'm teaching her maths and reading now. Like I said, she's kinda bright. :)
wow, looks like she's very bright
ohh well, just don't show her quake or she'll be lost for the coders community for a year or two;)