Author Topic: Column Spinner  (Read 6568 times)

0 Members and 1 Guest are viewing this topic.

Offline Xalthorn

  • Amiga 1200
  • ****
  • Posts: 331
  • Karma: 100
    • View Profile
Column Spinner
« on: July 12, 2008 »
This one has gone through so many compiled variations and compression attempts, it's scary.  However, I'm quite proud of the result.

I originally had the thing compiled into a single exe.  Unfortunately, that exe was 1.4 Meg because of the rather large images.  Even compressing with upx only brought it down to about 500k so I opted for a split version with an image loader.  The benefit of this is that you can easily change the images used in the demo to those of your own choice.  All you need are four 180x480 BMP images to replace mine.

Hehe, maybe we can have a little bit of fun to find images that work better than mine (you'll know what I mean when you watch the demo).

This one has needed a heck of a lot of optimisations, doing precalculations where possible.  Eventually I even had to change the UINTEGER declarations to INTEGER declarations (where appropriate) to squeeze the last ounce of speed out of the thing.  Adding music added a little delay but I think it's acceptable for the benefit of having something to listen to.

I welcome any comments or improvements to the code to point out where I missed the obvious optimisations.

Anyway, the source is included as well and is commented (maybe a little over commented in places as I got carried away).  I've also included the ufmod includes and a batch file that will compile the thing for you (it won't compile from within the IDE because of the music includes).

(remainder of files in replies)
« Last Edit: July 12, 2008 by Xalthorn »
Challenge Trophies Won:

Offline Xalthorn

  • Amiga 1200
  • ****
  • Posts: 331
  • Karma: 100
    • View Profile
Re: Column Spinner
« Reply #1 on: July 12, 2008 »
Two more of the images....
Challenge Trophies Won:

Offline Xalthorn

  • Amiga 1200
  • ****
  • Posts: 331
  • Karma: 100
    • View Profile
Re: Column Spinner
« Reply #2 on: July 12, 2008 »
Final image, sorry for the bloaty files :(
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Column Spinner
« Reply #3 on: July 12, 2008 »
Interesting fx!  Thanks for posting the source :)
Quote
    ' In a vain effort to squeeze some speed out of the routine, the variables
    ' have been shortened to single characters as much as possible.
You don't need to do that.  Since freebasic is compiled the length of the variable names is irrelevant.

Jim
PS. The music is awful!
Challenge Trophies Won:

Offline Xalthorn

  • Amiga 1200
  • ****
  • Posts: 331
  • Karma: 100
    • View Profile
Re: Column Spinner
« Reply #4 on: July 12, 2008 »
Okay, I'm going crazy.  I figured that the variable names would be converted to tokens on compilation (probably the wrong term but you know what I mean) and shouldn't make a blind bit of difference.  However, as I went through the code and started shortening the variable names I was sure things sped up.

Knowing me, I probably did a mixture of UINTEGER to INTEGER and variable name shortening at the same time which masked what was speeding things up.

The UINTEGER to INTEGER definitely made a difference though (I just tested it by changing the declaration in SUB COLUMN() again (except for X which needs to stay as a signed integer).

And yes, the music is awful
Challenge Trophies Won:

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Column Spinner
« Reply #5 on: July 12, 2008 »
Xalthorn,
That my friend - is fantastic - thanks for the source code!
Really really impressive - love it!

the music is not awful - just not very good! lol!

DrewPee
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline Xalthorn

  • Amiga 1200
  • ****
  • Posts: 331
  • Karma: 100
    • View Profile
Re: Column Spinner
« Reply #6 on: July 12, 2008 »
Xalthorn,
That my friend - is fantastic - thanks for the source code!
Really really impressive - love it!

the music is not awful - just not very good! lol!

DrewPee

Thanks, I'm really proud of what this achieves, but not quite so proud of the eventual file size ;)

I was tempted to simply texture the column with code to keep the exe size small but then figured it would defeat the point of what I was trying to achieve.

As to the music, I usually have my speakers turned down quite low (if not turned off) and it's not bad at that volume.  When I turned them up, the notes were quite piercing.

I'm taking the view that unless I'm releasing something I expect to sell, or have some other reason to keep the source secret, I'll always release source code.  That means I'll probably always release the source :)
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Column Spinner
« Reply #7 on: July 12, 2008 »
Very interesting FX. Nicely done.

Music: no comment ;-)
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Xalthorn

  • Amiga 1200
  • ****
  • Posts: 331
  • Karma: 100
    • View Profile
Re: Column Spinner
« Reply #8 on: July 12, 2008 »
Hehe, I can see the music is going to be a sore subject on this one.  Although I'm tempted to change it and re-upload I think I'll leave it as a discussion topic :D

Next time I'll have to compose something in a tracker.  That'll *really* give your ears something to worry about.
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Column Spinner
« Reply #9 on: July 12, 2008 »
Welldone dude :)

Cheers,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Column Spinner
« Reply #10 on: July 12, 2008 »
Nice spinny textures :)

It's nice that you put music into this, the sine scroll intro you made was very nice but would have benefitted from a tune.

I am wondering now what you'll do next :)

By the way, I really like the pictures too, they are 24 bit bmps which is the reason you have a large exe, there are png loading libs around for Freebasic if you can't stand to lose any quality, but another option would be to reduce the colours to 8 bitplanes and use the tools rbz made "bin2bas" and "bmp2raw", you'll find them in the tools section of the forum :)

K+ for the neat source too.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Xalthorn

  • Amiga 1200
  • ****
  • Posts: 331
  • Karma: 100
    • View Profile
Re: Column Spinner
« Reply #11 on: July 12, 2008 »
Nice spinny textures :)

It's nice that you put music into this, the sine scroll intro you made was very nice but would have benefitted from a tune.

I am wondering now what you'll do next :)

By the way, I really like the pictures too, they are 24 bit bmps which is the reason you have a large exe, there are png loading libs around for Freebasic if you can't stand to lose any quality, but another option would be to reduce the colours to 8 bitplanes and use the tools rbz made "bin2bas" and "bmp2raw", you'll find them in the tools section of the forum :)

K+ for the neat source too.

Thanks, I'm really proud of this one, and unless I'm doing something silly, that one really stretched the power of my laptop even though it looks like such a simple effect :(

My problem with including music is trying to find small tunes in a huge pile of random stuff, and also trying to find something that sounds halfway decent in the same pile of stuff.  Most of the nice tunes I find use huge samples and even zipped are over a meg.

I considered dropping the quality of the images, but I wanted it to really shine.  I suppose I should really see how many unique colours are actually in them, but what the heck :)

Ahh, I didn't read this one before my other reply.. I didn't notice bmp2raw... I'll go have a hunt :)

Thanks, I tried to tidy it up and comment it for anyone wanting to read it.

As to what I'll do next... not sure yet.  There is a large game project I'm keen to do, but I need to build up some libraries first so I expect there will be lots of library test samples before I get under way with that properly.
« Last Edit: July 12, 2008 by Xalthorn »
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Column Spinner
« Reply #12 on: July 12, 2008 »
If you use winrar then you can get much better compression by following these simple steps -
Code: [Select]
1] selecting all the bmps then right click -> select add to archive
2] in the box that comes up select compression = best
3] go to advanced tab
4] click compression a new box will appear
5] in this box set text compression to disable,
6] set audio compression to disable,
7] set true colour compression to force
8] make sure that the dictionary size for true colour compression is maxed out at 4096 KB
using these settings I have made them all fit into 369 KB archive

Great idea to have the spinning column wish I thought of that and its great that you are sharing the source for this effect. Its an unusual thing to see

Challenge Trophies Won:

Offline Xalthorn

  • Amiga 1200
  • ****
  • Posts: 331
  • Karma: 100
    • View Profile
Re: Column Spinner
« Reply #13 on: July 12, 2008 »
That's amazingly tidy, but would still exceed the post limit.  It's good to know for next time though, thanks :)

I was actually toying with the idea of doing a square twister and then wondered how I'd do a round one... this is the result.
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Column Spinner
« Reply #14 on: July 13, 2008 »
I checked out the asm code with UINTEGER and INTEGER swapped over in the COLUMNS subroutine.  The uinteger code is about 10 instructions longer than the integer one.  The main reason for this is the I blending variable being a DOUBLE, which causes a slew of floating point calculations which you don't need.  You can fix it with a bit of fixed point math:
Code: [Select]
DIM AS UINTEGER T
DIM AS DOUBLE I
...
                    I=BRIGHTNESS(X+127)

T=I*256

                    R=((P SHR 16)AND 255)*T
                    G=((P SHR 8) AND 255)*T
                    B=(P AND 255)*T

R=R SHR 8
G=G SHR 8
B=B SHR 8

                    BUFFER(YO+XCENT+X)=((R SHL 16) OR (G SHL 8) OR B)

And, if you work a bit harder you can make the BRIGHTNESS array be a UINTEGER in the first place and remove some of the extra shifts by building them in to the colour calculations.  That's about 1/2 the code size, and should stop your laptop melting ;)

In general, either do the whole calculation in float/double or do it all in integer.  It's the conversions between the two that kill the performance.

Jim
Challenge Trophies Won:

Offline Xalthorn

  • Amiga 1200
  • ****
  • Posts: 331
  • Karma: 100
    • View Profile
Re: Column Spinner
« Reply #15 on: July 13, 2008 »
Ahh that explains why it went nuts, thanks Jim I'll go and have a play :)
Challenge Trophies Won:

Offline Xalthorn

  • Amiga 1200
  • ****
  • Posts: 331
  • Karma: 100
    • View Profile
Re: Column Spinner
« Reply #16 on: July 13, 2008 »
Doh! of course, do the calculations at increased values to hide the fractions and then divide them again to bring back to a normal range.  I used to do this in asm to fake floating points.

In case anyone is reading this and doesn't know what I'm waffling on about, I'll try to explain.

In this case, I want to multiply a whole number with a number that has decimal places, 389 x 0.5 for example.

Normally, we would take a calculator and type the numbers in, but what if the calculator didn't have a decimal point?  We couldn't do the calculation as it stands.

So what we can do is multiply the 0.5 by a whole number to make it a whole number (please don't get pedantic and wonder why the calculator can suddenly do this multiplication, I've just woken up and analogies are tricky at the moment).

Computers really like numbers that are factors of 2, so let's multiply the number by 256.  This means that our calculation is now:

389 x (0.5 x 256) or 389 x 128

Much easier, we just have to remember to divide the final result by 256 at the end, to bring the total back into our expected range.  Also, there is a nice trick we can do to divide a whole number by a factor of 2.  We simply shift the BITs to the right as many times as we need.

If we were to double a number, we could shift the BITs left by one, to halve it, we shift right by one.
Shifting left by two places would be x4, right by two would be /4
Shifting left by three places would be x8, right by three would be /8
and so on
Shifting left by eight places would be x256, right by eight places would be /256

It's a really useful and fast method of multiplication as the computer doesn't actually do any multiplication, it just moves BITs around.
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Column Spinner
« Reply #17 on: July 13, 2008 »
Thats a neat trick alright to take that one step further you can even merge a multiply and a division into a single shift but its more useful on older systems. If you take advantage of the deep pipelines of modern CPUs you can reduce a division to a single clock cycle if the division was a floating point operation and you fill in the gaps between where the division begins and ends with operations that do not rely on the result of the division. Shifts are much slower on Pentium CPUs than you might think.

Challenge Trophies Won: