Author Topic: PixelMapping ?  (Read 8168 times)

0 Members and 1 Guest are viewing this topic.

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
PixelMapping ?
« 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
« Last Edit: February 05, 2012, 04:15:10 pm by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: PixelMapping ?
« Reply #1 on: February 06, 2012, 07:00:05 pm »
we would like to know: is there a faster way to do it ?
* Runer112 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

« Last Edit: August 23, 2012, 05:27:30 pm by Runer112 »

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: PixelMapping ?
« Reply #2 on: February 07, 2012, 08:17:58 am »
Wow! Impressive work as always Runer! =)

Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: PixelMapping ?
« Reply #3 on: February 07, 2012, 09:25:06 am »
Once again, we see the awesomeness of Runer112. :D

Offline kindermoumoute

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 836
  • Rating: +54/-3
    • View Profile
Re: PixelMapping ?
« Reply #4 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 :
  • A variable to determina numbers of pixels to shift each frame (defaut is 1).
  • Does it work with larger map than 256*256 ?
« Last Edit: February 07, 2012, 01:01:18 pm by kindermoumoute »
Projects :

Worms armageddon z80 :
- smoothscrolling Pixelmapping : 100%
- Map editor : 80%
- Game System : 0%

Tutoriel français sur l'Axe Parser
- 1ère partie : en ligne.
- 2ème partie : en ligne.
- 3ème partie : en ligne.
- 4ème partie : 10%
- Annexe : 100%

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: PixelMapping ?
« Reply #5 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.
« Last Edit: February 07, 2012, 04:21:07 pm by Runer112 »

Offline kindermoumoute

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 836
  • Rating: +54/-3
    • View Profile
Re: PixelMapping ?
« Reply #6 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. :)
Projects :

Worms armageddon z80 :
- smoothscrolling Pixelmapping : 100%
- Map editor : 80%
- Game System : 0%

Tutoriel français sur l'Axe Parser
- 1ère partie : en ligne.
- 2ème partie : en ligne.
- 3ème partie : en ligne.
- 4ème partie : 10%
- Annexe : 100%

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
Re: PixelMapping ?
« Reply #7 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?
Completed Projects:
   >> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
   >> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.


Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)



Offline kindermoumoute

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 836
  • Rating: +54/-3
    • View Profile
Re: PixelMapping ?
« Reply #8 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:
« Last Edit: March 08, 2012, 12:25:38 pm by kindermoumoute »
Projects :

Worms armageddon z80 :
- smoothscrolling Pixelmapping : 100%
- Map editor : 80%
- Game System : 0%

Tutoriel français sur l'Axe Parser
- 1ère partie : en ligne.
- 2ème partie : en ligne.
- 3ème partie : en ligne.
- 4ème partie : 10%
- Annexe : 100%

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: PixelMapping ?
« Reply #9 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