Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Hayleia on February 05, 2012, 04:00:16 pm

Title: PixelMapping ?
Post by: Hayleia on February 05, 2012, 04:00:16 pm
PixelMapping ?

So, with Kindermoumoute, we are trying to get a smooth-scrolling and pixel-based mapping, so the map can be modified anywhere.
The Bitmap function would work but is too slow :(
Basic tilemapping with sprites is fast but is not pixel based so wouldn't make it

Kindermoumoute came up with that code (spoilered) but we would like to know: is there a faster way to do it ?

Spoiler For Spoiler:

:.A
:0->X->Y
:1->S
:Tangent(0,0,GDB1TMAP)
:
:Repeat getKey(15)
:For(S)
:If X<159
:If getKey(3)
:X++
:Horizontal -
:F5(0,63,95,)
:End
:End
:
:If X>0
:If getKey(2)
:X--
:Horizontal +
:F5(0,63,0,)
:End
:End
:
:If Y<127
:If getKey(4)
:Y++
:Vertical -
:F5(0,,,95)
:End
:End
:
:If Y>0
:If getKey(1)
:Y--
:Vertical +
:F5(63,,0,95)
:End
:End
:End
:DispGraph
:End
:Return
:
:.refresh the erased column or line
:Lbl  F5
:For(I,r1,r2)
:For(J,r3,r4)
:If I+Y*192+X+J->r5/8+GDB4MAP+2er5^8
:Pxl-On(J,I)
:Else
:Pxl-Off(J,I)
:End
:End
:End
:Return
:
:
:.stupid map, just for the test
:[FFC0]->GDB1TMAP
:[5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C]->GDB4MAP
:[C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5]
:[5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C]
:[C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5]
:[5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C]
:[C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5]
:[5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C]
:[C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5]
:[5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C5C]
:.with 60 more lines like this :P
Title: Re: PixelMapping ?
Post by: Runer112 on February 06, 2012, 07:00:05 pm
we would like to know: is there a faster way to do it ?
/me arrives on the scene. >:D

After hours of work and many methods tested, I have developed code for what I believe is about as fast as bitmap scrolling can get in pure Axe! For comparison, here's a table of the time the routine you posted takes (with minor fixes, because it didn't work) versus my crazy new code. :hyper:

   Old routine   New routine
Horizontal scroll cycles15550048500
Vertical scroll cycles18400022500


Horizontal scrolling is twice as slow as vertical scrolling in my version, but that's still more than three times faster than the old horizontal scrolling! ;D

Source and eye candy is attached. I'll also put the SourceCoder-ized source here, look at it if you dare:
Spoiler For Axe source code (SourceCoder format):
:.ISCROLL Image scrolling test
:
:DeltaList(256,192)[vIMG]→ºIMG
:
:DiagnosticOff
:FnOff
:ClrDraw
:Tangent({-}80→X,{-}64→Y,ºIMG)
:
:While 1
: DispGraph
: If getKey(1)
:  !If Y-1<{-}128
:   Y--
:   Vertical -
:   63:DrawY()
:  End
: End
: If getKey(2)
:  If X
:   +1→X
:   Horizontal +
:   DrawL()
:  End
: End
: If getKey(3)
:  !If X-1<{-}160
:   X--
:   Horizontal -
:   DrawR()
:  End
: End
: If getKey(4)
:  If Y
:   +1→Y
:   Vertical +
:   0:DrawY()
:  End
: End
:EndIf getKey(15)
:Return
:
:Lbl DrawY
: conj(→{r1}-Y*32+ºIMG+2,{L1}+2,32)
: Fill({r1}*12+{L6},12,{E}0100→{{L1}}{^r})
: Tangent(X,{r1},{L1})
:Return
:
:Lbl DrawR
: 11+{L6}→{r3}
: {E}01→{r4}
: 95
: Goto Draw0
:Lbl DrawL
: {L6}→{r3}
: {E}80→{r4}
:  and 0
: Lbl Draw0
: Select(-X,{^8+ºMasks}→{r2})
: *32/256-(Y*32)+ºIMG+2
: For(64)
:  not({→{r1}} and {r2}-1/256) and {r4} or {{r3}}→{{r3}}+12→{r3}
:  {r1}+32
: End
:Return
:
:[8040201008040201]→ºMasks

Title: Re: PixelMapping ?
Post by: TIfanx1999 on February 07, 2012, 08:17:58 am
Wow! Impressive work as always Runer! =)
Title: Re: PixelMapping ?
Post by: parserp on February 07, 2012, 09:25:06 am
Once again, we see the awesomeness of Runer112. :D
Title: Re: PixelMapping ?
Post by: kindermoumoute on February 07, 2012, 12:49:25 pm
Amazing ! O_O
I don't understand Draw0 routine, but I suppose DrawC was a test routine ? ^^


EDIT : I wonder if it could workd with 2 more features :
Title: Re: PixelMapping ?
Post by: Runer112 on February 07, 2012, 04:17:42 pm
Draw0 isn't a routine you should be calling, I just have that label there as an optimized way to combine the routines that redraw the left and right edges. DrawC was my old method for redrawing the left and right edges that I got rid of because it was less optimized than DrawR and DrawL. I guess I forgot to remove the references to it.

Regarding shifting more than one pixel per frame: is this really necessary? It shifts very quickly already, I think it's something like 72 vertical pixels per second and 55 horizontal pixels per second with only one pixel shifted per DispGraph. But if you really wanted to shift more than one pixel per frame, you may as well just perform the 1-pixel shift in a loop, because there isn't a method for shifting multiple pixels at once that's much more optimized.

I could make it work with a map larger than 256*256, I think you'd only have to tweak a few numbers. But do you really want an image larger than 256*256? A 256*256 image is already 8KB, if you go larger than that you may not even be able to fit the images in RAM.
Title: Re: PixelMapping ?
Post by: kindermoumoute on February 07, 2012, 04:25:55 pm
In fact.. I thought probably we would need a map 512*128 or 256*256 or 1024*64. But always with X>=256 and Y<=256.
But that's already really impressive and usefull. :)
Title: Re: PixelMapping ?
Post by: LincolnB on February 07, 2012, 04:53:13 pm
For comparison, here's a table of the time the routine you posted takes (with minor fixes, because it didn't work) versus my crazy new code. :hyper:

   Old routine   New routine
Horizontal scroll cycles15550048500
Vertical scroll cycles18400022500

How did you measure this?
Title: Re: PixelMapping ?
Post by: kindermoumoute on March 08, 2012, 09:46:07 am
In DrawY subroutine, why are you filled with zeros line to replace?
Fill(r1*12+L6,12,0
Vertical + or Vertical - commands are not supposed to do it ?

(I already try without this line, I know it's needed to make it work, but I don't understand why) :banghead:

EDIT : ok I see, only horizontal +/- resets bits.  D:

EDIT2 : after 4 hours, I understand all.. except that end of line : {r3}+12->r3
I think it's supposed to do r3+12->r3 but how it is it possible it works ? :w00t:
Title: Re: PixelMapping ?
Post by: Runer112 on March 08, 2012, 04:48:56 pm
That's only the end of the line, the whole line is:

not({→r1} and r2-1/256) and r4 or {r3}→{r3}+12→r3

What this is really doing, just in an optimized manner, is this:

not({→r1} and r2-1/256) and r4 or {r3}→{r3}
r3+12→r3