Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Ikkerens on June 21, 2010, 05:20:32 am

Title: Smooth Scrolling Tilemapper
Post by: Ikkerens on June 21, 2010, 05:20:32 am
Well, so I have been trying some things with axe now (RAM clear every 2 minutes ftw  ;D)
And I came up with a scrolling tilemapper, which speed I think is fair.

I think it can be optimized in some ways, but I can't find any more ways.

P.S. I wanted to make a GIF for demonstration, but after loading the ROM with wabbitemu, nothing happens.

Edit: Uploaded the optimized version
Title: Re: Scrolling Tilemapper
Post by: Quigibo on June 21, 2010, 05:48:25 am
Awesome!  The code seems fairly simple.  As far as optimizations, one thing that stuck out at me was that you were using X-(X/8*8) to do what is more simply just X^8.  Same for Y.  Also, you store the pointer to the sprite in P but only use it once.  You can just put that whole expression where P is so that way you don't have to store and load to it.  Its more convenient for the programmer too when you use less variables.  Nice job again!
Title: Re: Scrolling Tilemapper
Post by: Ikkerens on June 21, 2010, 06:41:43 am
I don't see why you're doing X^8
Code: [Select]
X/8->N
X-(N*8)->I    <-- The N given here is already rounded since axe doesn't support floating numbers, which im using in my advantage.
My guess is that X^8 would give all the wrong calculations,
N is my offset where to start drawing, where I would position it.

Could you please explain why you'd do that?
Title: Re: Scrolling Tilemapper
Post by: Magic Banana on June 21, 2010, 08:33:04 am
Both X^8 and X-(N*8 ) come up with the same answer. X^8 is an optimization of what you have already. It's not changing the answer in any way.
If you didn't know already, Axe uses ^ as modulus instead of the normal 'to the power of...'
If you don't quite understand modulus, maybe this will help:

Say X is 25
(25)/8=3.125  (the decimal/remainder is dropped. No floating numbers here.)
(25)-[(3)*8]=1
Now using modulus
(25)^8=1 (25/8 is 3r1. Division takes the whole number while modulus takes the remainder.)

Lets try again with 39.
(39)/8=4r7(remember to drop the remainder for division)
(39)-[(4)*8]=7
Back to modulus
(39)^8=7 (4r7, whole number is dropped.)

Hope this explains to you what he's talking about.
Title: Re: Smooth Scrolling Tilemapper
Post by: Ikkerens on June 21, 2010, 08:36:35 am
Well, I don't really understand it, but il just use it.
Title: Re: Smooth Scrolling Tilemapper
Post by: Magic Banana on June 21, 2010, 09:01:44 am
Oh, I totally forgot to actually look at the program.  :P

...

Ok, I'm back. Looks nice. I'm sure this will help somebody out.

I think that this:
Code: [Select]
:If X≠64 and getKey(3)
:X+1→X
:End
:If X≠0 and getKey(2)
:X-1→X
:End

can be shortened to this:
Code: [Select]
:If X and (X≠64
:X+getkey(3)-Getkey(2)→X

Oh, another tiny optimization you can use is remove the Return at the bottom. Once it hits the bottom of your code, there is an implied Return.
Title: Re: Smooth Scrolling Tilemapper
Post by: Ikkerens on June 21, 2010, 09:06:55 am
Those getkey things won't work, I need seperate checks.

And the bottom return, its part of a subroutine, u sure its safe to remove?
Title: Re: Smooth Scrolling Tilemapper
Post by: calc84maniac on June 21, 2010, 09:22:38 am
Already got this in my own calc version:
Code: [Select]
:If X≠64 and X
:X+getkey(3)-Getkey(2)→X
:End
But can't get it to work.

And the bottom return, its part of a subroutine, u sure its safe to remove?
This is because the "and" is bitwise, not logical. This is why I wanted Quigibo to support logical and,or,xor statements...
Title: Re: Smooth Scrolling Tilemapper
Post by: Magic Banana on June 21, 2010, 09:30:16 am
Oh, and here I was thinking it was already supported.  :P
Guess I'll have to wait until he implements that.

From the Axe documentation:
'If the last line of your program is Return, then remove it. Even if it was part of a
subroutine, the return is automatically added at the end for you so there's no need to
have 2 returns at the end. Saves 1 byte.'

EDIT:100th post. Wee!  ;D
Title: Re: Smooth Scrolling Tilemapper
Post by: Ikkerens on June 21, 2010, 09:41:47 am
Instead, I did this:
Code: [Select]
X-(X≠0 and getKey(2))+(X≠64 and getKey(3))→X

Which works.
Title: Re: Smooth Scrolling Tilemapper
Post by: Magic Banana on June 21, 2010, 09:57:14 am
Awesome! Good to see that you worked it through. :)
Title: Re: Smooth Scrolling Tilemapper
Post by: FinaleTI on June 21, 2010, 09:57:42 am
Here's a gif, for anyone who wants to see it.
Title: Re: Smooth Scrolling Tilemapper
Post by: SirCmpwn on June 21, 2010, 09:58:30 am
Nice, Ikkerens!
Title: Re: Smooth Scrolling Tilemapper
Post by: Ikkerens on June 21, 2010, 10:00:24 am
Here's a gif, for anyone who wants to see it.

Alot more fluid on calc tho.
Title: Re: Smooth Scrolling Tilemapper
Post by: ztrumpet on June 21, 2010, 11:45:35 am
Nice, Ikkerens!  Excellent job! ;D
Title: Re: Smooth Scrolling Tilemapper
Post by: DJ Omnimaga on June 21, 2010, 11:55:59 am
wow nice! I am surprised at how small the code is, too. Do you mind if I ever use parts of it in one of my program if I ever make a game again?
Title: Re: Smooth Scrolling Tilemapper
Post by: Ikkerens on June 21, 2010, 01:16:19 pm
wow nice! I am surprised at how small the code is, too. Do you mind if I ever use parts of it in one of my program if I ever make a game again?

Go ahead, thats the main reason why I shared it.
But under 1 condition: Author credits :)
Title: Re: Smooth Scrolling Tilemapper
Post by: DJ Omnimaga on June 21, 2010, 01:17:42 pm
yeah don't worry if I use it ^^

Also I noticed a bug: when you scroll up/down from each edges of the map, it scrolls twice faster than in the middle
Title: Re: Smooth Scrolling Tilemapper
Post by: Ikkerens on June 21, 2010, 01:21:12 pm
yeah don't worry if I use it ^^

Also I noticed a bug: when you scroll up/down from each edges of the map, it scrolls twice faster than in the middle

Yeh, I noticed that, dunno what's going wrong tho.
Thought it was optic trickery.
Title: Re: Smooth Scrolling Tilemapper
Post by: Quigibo on June 21, 2010, 02:27:34 pm
My guess would be that the number of sprites it has to draw is more/less causing the speed to change slightly.
Title: Re: Smooth Scrolling Tilemapper
Post by: DJ Omnimaga on June 21, 2010, 02:28:55 pm
mhmm I am confused... since he draws everything each frame regardless of their position on screen. Could it be that when trying to store them on certain screen sides, they aren't drawn at all?
Title: Re: Smooth Scrolling Tilemapper
Post by: Ikkerens on June 21, 2010, 02:32:32 pm
I'd doubt that, my code only draws whats visible on-screen plus a right-side and bottom row.
Title: Re: Smooth Scrolling Tilemapper
Post by: DJ Omnimaga on June 21, 2010, 02:39:50 pm
really? Mhmm I didn't notice any checks x.x
Title: Re: Smooth Scrolling Tilemapper
Post by: Ikkerens on June 21, 2010, 02:43:15 pm
really? Mhmm I didn't notice any checks x.x

In the drawing sub, change the fors to this:
Code: [Select]
For(T,0,7)
For(S,0,11)

You'll see the difference.
Title: Re: Smooth Scrolling Tilemapper
Post by: DJ Omnimaga on June 21, 2010, 02:43:58 pm
ok I'll check this after work
Title: Re: Smooth Scrolling Tilemapper
Post by: FinaleTI on June 27, 2010, 12:31:35 pm
I was playing with this program yesterday and I modified it so that it masks a sprite over the map, then masks a forground over the entire screen.

Screenie and source (Credit for the original engine goes to Ikkerens of course :)) attached:
Title: Re: Smooth Scrolling Tilemapper
Post by: Madskillz on June 27, 2010, 01:11:09 pm
Wow, that is really awesome. Does it remind anyone else of George's old game that he was working on? I cant remember what it was called, but it had similar aspects with parts of the map placed on the top of the sprite. For example when he walked under an archway.
Title: Re: Smooth Scrolling Tilemapper
Post by: Galandros on June 27, 2010, 01:25:27 pm
Looks really cool and a nice speed.

I did not see the Axe Parser source code to understand the method but in assembly horizontal scrolling is much slower too because shifting bits by rotating them is much more time expensive than moving entire bytes around in the graphics buffer.
Title: Re: Smooth Scrolling Tilemapper
Post by: DJ Omnimaga on June 27, 2010, 02:16:52 pm
Wow this is awesome. Look pretty great too. You should make it scroll 2 pixels so it moves a bit faster, though. Also, I discovered why it runs faster on edges and some other portions of the map, when scrolling vertically: it's because when sprites are aligned horizontally on the screen (displayed at multiple of 8 pixels), it takes twice less time to happen. Displaying them at different locations horizontally apparently requires more processing power because of how the memory works (each byte contains 8 pixels. Imagine when you need to display parts of a byte in another for 96 sprites).

Wow, that is really awesome. Does it remind anyone else of George's old game that he was working on? I cant remember what it was called, but it had similar aspects with parts of the map placed on the top of the sprite. For example when he walked under an archway.
Probably not a lot of people around here, since they all joined long after Dys left, but I remember the project quite well. It was amazing (It used Star Ocean 1 tiles, rigth?)

(http://www.omnimaga.org/images/screenshots/auraanim.gif)
Title: Re: Smooth Scrolling Tilemapper
Post by: Madskillz on June 28, 2010, 01:19:24 am
Yep that would be the one. Brings back memories of how impressive/awesome it was.
Title: Re: Smooth Scrolling Tilemapper
Post by: Builderboy on June 28, 2010, 01:20:34 am
Is there still a copy/demo of it around anywhere?  I would like to just play around with it ^^
Title: Re: Smooth Scrolling Tilemapper
Post by: DJ Omnimaga on June 28, 2010, 03:59:00 am
Unfortunately, nope :(

No demo were ever released
Title: Re: Smooth Scrolling Tilemapper
Post by: Ikkerens on June 28, 2010, 05:07:07 pm
I was playing with this program yesterday and I modified it so that it masks a sprite over the map, then masks a forground over the entire screen.

Screenie and source (Credit for the original engine goes to Ikkerens of course :)) attached:

Well done, kinda like that effect.
Could always be nice when creating cinematics or sumthing.
Title: Re: Smooth Scrolling Tilemapper
Post by: FinaleTI on June 28, 2010, 05:19:26 pm
Or for mapping Chrono Trigger style... *cough*
Actually Chrono Trigger is what inspired my mod of your engine.
Title: Re: Smooth Scrolling Tilemapper
Post by: DJ Omnimaga on June 28, 2010, 10:55:41 pm
I was playing with this program yesterday and I modified it so that it masks a sprite over the map, then masks a forground over the entire screen.

Screenie and source (Credit for the original engine goes to Ikkerens of course :)) attached:

Well done, kinda like that effect.
Could always be nice when creating cinematics or sumthing.
One idea I had using his trick would be to have a second tilemap displayed on top of the first that is smaller, but scrolls 2x faster. Example: when you are in a forest, leafs could scroll faster. That tilemap could just loop. Another use could be in a side scrolling game where you are in a cavern and you see stalagmites/stalacites in front of the game map, scrolling 2x faster when you move around. You could even add a background that scrolls much slower. Keep in mind this would become rather slow, though, especially if you had to use sprite masking.
Title: Re: Smooth Scrolling Tilemapper
Post by: Ikkerens on June 29, 2010, 03:45:31 am
I was playing with this program yesterday and I modified it so that it masks a sprite over the map, then masks a forground over the entire screen.

Screenie and source (Credit for the original engine goes to Ikkerens of course :)) attached:

Well done, kinda like that effect.
Could always be nice when creating cinematics or sumthing.
One idea I had using his trick would be to have a second tilemap displayed on top of the first that is smaller, but scrolls 2x faster. Example: when you are in a forest, leafs could scroll faster. That tilemap could just loop. Another use could be in a side scrolling game where you are in a cavern and you see stalagmites/stalacites in front of the game map, scrolling 2x faster when you move around. You could even add a background that scrolls much slower. Keep in mind this would become rather slow, though, especially if you had to use sprite masking.

Im doubting that, doesn't sound too difficult in my head.
Might try it out once, if no one else does.
Title: Re: Smooth Scrolling Tilemapper
Post by: DJ Omnimaga on June 29, 2010, 03:49:14 am
well, the thing that could slow things down is the fact you would have to draw like 5 13x9 maps every frame (first, the background, scrolling every two frame, secondly, the middleground (where your character walks) mask, third, the middleground tilemap itself, fourth the foreground mask, scrolling 2 pixel by 2 pixel and finally the foreground tilemap. If all your tiles are sqares, then you don't need masks, though.
Title: Re: Smooth Scrolling Tilemapper
Post by: Ikkerens on June 29, 2010, 03:53:04 am
I'd say, 2 extra lines in my for loop, optimized not more than 100 bytes extra. (excl. Graphics)
Title: Re: Smooth Scrolling Tilemapper
Post by: DJ Omnimaga on June 29, 2010, 03:57:47 am
I guess you should prbly try it, then, since you seems to find the idea pretty easy (I have a clue how, but I am not too sure how I would manage over 16 fps on a regular 83+ with it. I mean, it's between 351 and 585 tiles per frame you need to draw, after all)
Title: Re: Smooth Scrolling Tilemapper
Post by: Ikkerens on June 29, 2010, 04:21:39 am
I guess you should prbly try it, then, since you seems to find the idea pretty easy (I have a clue how, but I am not too sure how I would manage over 16 fps on a regular 83+ with it. I mean, it's between 351 and 585 tiles per frame you need to draw, after all)

Well, the main slowdown is DispGraph, not the Pt- functions.
But DispGraph still has to draw 768 bytes, no matter how many tiles.
Title: Re: Smooth Scrolling Tilemapper
Post by: DJ Omnimaga on June 29, 2010, 04:25:03 am
I know, but drawing an incredible amount of tiles eventually adds a slow down. Trust me, I tried it myself. I got an engine right now that draws 14 sprites+tiles per frame. It's blazing fast! If I add a background of 96 tiles, regardless of their content, the speed drops by almost half.

Please show me proof that you can achieve similar speed between a tilemapper where 96 tiles are displayed every frame (unaligned horizontally) and one with 300-500.
Title: Re: Smooth Scrolling Tilemapper
Post by: Quigibo on June 29, 2010, 04:25:45 am
Well, the foreground layer would be sparse, so it wouldn't be that many tiles.  Its 117 tiles for the background.  I'll give a conservative estimate of 20 tiles in the foreground and lets say for sake of argument that all 20 tiles are masked.  Plus maybe a 4 tile character, that's 161 tiles per frame, which should be around 16 fps in 15MHz mode, but probably laggy at normal speeds.
Title: Re: Smooth Scrolling Tilemapper
Post by: DJ Omnimaga on July 02, 2010, 03:10:52 am
I found a trick to make parralax scrolling much faster for when you use a background filled with the same 8x8 tile:

Instead of doing
Code: [Select]
X^16->Q/2->Q
Y^16->R/2->R
For(Z,0,12)
For(O,0,8)
Pt-On(Z*8-Q,O*8-R,Pic1)
End
End

I did
Code: [Select]
X^16->Q/2->Q
Y^16->R/2->R
For(Z,0,12)
For(O,0,1)
Pt-On(Z*8-Q,O*8-R,Pic1)
End
End
For(Z,1,7)
Copy(L6,Z*96+L6,96)
End

It's 77 bytes larger, but see the huge speed difference below! (the later code doesn't need as much processing power because only 24 tiles needs to be displayed unaligned). Note that due to the nature of the engine I am using in my game, the speed increase is much higher than it would be with a regular tilemapper. If your tilemapper is very complex, it's up to you to decide if the speed increase vs size increase is worth it
Title: Re: Smooth Scrolling Tilemapper
Post by: Builderboy on July 02, 2010, 03:23:28 am
Thats ingenious :D I wonder if any Tilemapper Axioms will be written, because i hear there are mucho optimizations that are involved with displaying smooth tilemaps instead of just looping a sprite routine.
Title: Re: Smooth Scrolling Tilemapper
Post by: DJ Omnimaga on July 02, 2010, 03:32:46 am
yeah same here. I would kinda prefer if it was implemented in Axe, though, so it can be used in the contest. I assume this is not a priority, though. Also I wonder how he would handle smooth scrolling?

I got the idea of Copying the buffer top content when working with unaligned tiles. I saw it was 2x slower and thought: hey, if I just draw enough tiles to fill the top 8 rows, why wouldn't I just copy the rest below afterward? It would need to draw 4x less tiles unaligned.
Title: Re: Smooth Scrolling Tilemapper
Post by: Galandros on July 02, 2010, 04:20:40 am
Looks nice DJ.
And makes me remember Sonic bonus levels. ^^
Title: Re: Smooth Scrolling Tilemapper
Post by: DJ Omnimaga on July 02, 2010, 04:59:08 am
thanks ^^
Title: Re: Smooth Scrolling Tilemapper
Post by: Quigibo on July 02, 2010, 06:35:05 am
Awesome job!

By the way:
Code: [Select]
For(Z,1,7)
Copy(L6,Z*96+L6,96)
End
can be
Code: [Select]
Copy(L6,L6+96,96*7)Since once the first 8 rows are copied to the second 8 rows, the pointer is now on the 2nd row, so its now copying the second row to the third row, etc.
Title: Re: Smooth Scrolling Tilemapper
Post by: DJ Omnimaga on July 02, 2010, 09:20:37 am
Nice, I didn't know it would repeat like this in this case. I'll give this a try. Thanks for the tip!

EDIT: Tried it and it works pretty well. I wonder if the speed increases? I am sure I am noticing something slightly faster
Title: Re: Smooth Scrolling Tilemapper
Post by: ztrumpet on July 03, 2010, 11:15:24 am
Nice!  That's a really cool idea.  Great job! ;D