Scrolling Map Demo

SGDK only sub forum

Moderator: Stef

Post Reply
kcowolf
Newbie
Posts: 4
Joined: Tue Jul 15, 2014 11:38 am

Scrolling Map Demo

Post by kcowolf » Thu Dec 22, 2016 3:48 am

I've been working on a small demo of a two-layer scrolling map using SGDK. I've posted the source code on GitHub: https://github.com/kcowolf/GenScrollingMapDemo. All it currently does is the two scrolling layers -- no sprite handling, collisions, etc., but hopefully it'll be useful for someone to learn from or build on. Any comments or criticism would be appreciated.

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Re: Scrolling Map Demo

Post by djcouchycouch » Thu Dec 22, 2016 2:17 pm

Looks good! The code is very clean :)

Miquel
Very interested
Posts: 514
Joined: Sat Jul 30, 2016 12:33 am

Re: Scrolling Map Demo

Post by Miquel » Wed Dec 28, 2016 3:09 pm

Nice! In this case what I would do is rewrite these functions:

void redrawForegroundRow(u16 rowToUpdate);
void redrawBackgroundRow(u16 rowToUpdate);
void redrawForegroundColumn(u16 columnToUpdate);
void redrawBackgroundColumn(u16 columnToUpdate);

into a single one, with a parameter specifying what to do, then make it inline for speed proposes. Usually these type of functions are a lot harder to maintain that to write.

¿Have you thought that you can jump horizontal scroll line without being in consecutive positions? I can't see it anywhere.
HELP. Spanish TVs are brain washing people to be hostile to me.

kcowolf
Newbie
Posts: 4
Joined: Tue Jul 15, 2014 11:38 am

Re: Scrolling Map Demo

Post by kcowolf » Sat Dec 31, 2016 5:08 am

Miquel wrote:Nice! In this case what I would do is rewrite these functions:

void redrawForegroundRow(u16 rowToUpdate);
void redrawBackgroundRow(u16 rowToUpdate);
void redrawForegroundColumn(u16 columnToUpdate);
void redrawBackgroundColumn(u16 columnToUpdate);

into a single one, with a parameter specifying what to do, then make it inline for speed proposes. Usually these type of functions are a lot harder to maintain that to write.
So would the parameter be something an enum value like FG_ROW, BG_ROW, etc? I can give it a try to see if it makes things cleaner. I definitely need to try making it inline; I learned about inline one day in college years ago and never got in the habit of using it.
Miquel wrote: ¿Have you thought that you can jump horizontal scroll line without being in consecutive positions? I can't see it anywhere.
Sorry, I'm not sure I understand what you mean. Can you clarify?

If you mean that you can write past the end of a line on the plane and it'll start showing up on the next line, that gets handled because the buffer is the width of the plane and is always copied to the beginning of the line, then I mod the buffer index by 64 when I write data to it.

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Re: Scrolling Map Demo

Post by djcouchycouch » Sat Dec 31, 2016 12:39 pm

I think he meant the case where the scroll increment in a frame would be greater than 8 pixels, making it skip a row and leaving a hole.

kcowolf
Newbie
Posts: 4
Joined: Tue Jul 15, 2014 11:38 am

Re: Scrolling Map Demo

Post by kcowolf » Sat Dec 31, 2016 6:30 pm

Yeah, 8 pixels per frame is the maximum speed it can handle for the reason you mentioned. That's fast enough for my project, but anyone needing something faster would have to add support for it.

Miquel
Very interested
Posts: 514
Joined: Sat Jul 30, 2016 12:33 am

Re: Scrolling Map Demo

Post by Miquel » Sat Dec 31, 2016 8:54 pm

kcowolf wrote: Sorry, I'm not sure I understand what you mean. Can you clarify?

If you mean that you can write past the end of a line on the plane and it'll start showing up on the next line, that gets handled because the buffer is the width of the plane and is always copied to the beginning of the line, then I mod the buffer index by 64 when I write data to it.
This is right: you always send a full row/column to the vdp. If case you don't want to send the full line then you have to handle in some cases two DMAs (or two pieces of data).
kcowolf wrote:So would the parameter be something an enum value like FG_ROW, BG_ROW, etc? I can give it a try to see if it makes things cleaner. I definitely need to try making it inline; I learned about inline one day in college years ago and never got in the habit of using it.
It's done to avoid repetition of code. It's a nest for bugs: When you are reviewing a large project mind skips on reading the same code over and over, you correct the bug on one repetition but not on others,... Usually you can suspect how bad a code is by searching repetition.
HELP. Spanish TVs are brain washing people to be hostile to me.

Natsumi
Very interested
Posts: 82
Joined: Mon Oct 05, 2015 3:00 pm
Location: 0x0
Contact:

Re: Scrolling Map Demo

Post by Natsumi » Sun Jan 01, 2017 1:50 am

Then you try to optimize and find that unrolling loops is an effective method for doing that. But hey, one good tip I can give you is... Use macros if possible. You can have a piece of code a million times, and still one change affects all of it, Really quite useful for gaining both speed, and yet easy way to fix issues and whatnot. The problem with 68000 is, that branching is really slow. Trying to optimize your code to avoid branching is almost always beneficial. Ever changed a bcc to scc? Because I have, many times.

Miquel
Very interested
Posts: 514
Joined: Sat Jul 30, 2016 12:33 am

Re: Scrolling Map Demo

Post by Miquel » Mon Jan 02, 2017 5:43 pm

Still you can use inline or macros on unrolling (as you said). Also compilers can do unrolling for themselves if you favour speed instead of size. Anyway is a general good advise to not optimize code until you are finished with you project, and then keep and maintain both branches. Instead is much more rewarding to optimize structures (classes, database, whatever), do pc programmers don't know so much about it, and this don't affect readness of code.
HELP. Spanish TVs are brain washing people to be hostile to me.

themrcul
Very interested
Posts: 116
Joined: Fri Apr 15, 2016 2:21 pm

Re: Scrolling Map Demo

Post by themrcul » Wed Jan 11, 2017 3:48 am

This is just a note to thank kcowolf for releasing his scrolling code.

I worked for days to get my version working, and in the end it only worked 4-ways. If I scrolled in both horizontal and vertical directions, after a few frames some rows/columns would mess up.

Anyway after implementing kcowolf's code into my project, scrolling works perfectly and smoothly! I can't thank you enough! :)

Hik
Very interested
Posts: 68
Joined: Thu Jul 30, 2015 11:39 pm
Location: Iceland

Re: Scrolling Map Demo

Post by Hik » Wed Jan 11, 2017 1:05 pm

I get an error when I compile this ;

Image

Could be a verstion difference? It works fine to compile my code.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Scrolling Map Demo

Post by Stef » Wed Jan 11, 2017 3:52 pm

_hard_reset should be contained in the sega.s file, if you use a custom sega.s file for your project or if the compilation fails that may be the problem.

Hik
Very interested
Posts: 68
Joined: Thu Jul 30, 2015 11:39 pm
Location: Iceland

Re: Scrolling Map Demo

Post by Hik » Wed Jan 11, 2017 5:45 pm

I took the sega.s out of the scrolling-map-demo/src/boot folder and then it worked to compile

Looks and works good now thanks for sharing, kcowolf

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Scrolling Map Demo

Post by Stef » Thu Jan 12, 2017 12:32 am

Hik wrote:I took the sega.s out of the scrolling-map-demo/src/boot folder and then it worked to compile

Looks and works good now thanks for sharing, kcowolf
Looks like your sega.s file was corrupted then ;)

kcowolf
Newbie
Posts: 4
Joined: Tue Jul 15, 2014 11:38 am

Re: Scrolling Map Demo

Post by kcowolf » Mon Jan 16, 2017 8:26 am

Apologies for not replying sooner. I should be subscribed now so I'll get email notifications.

Hik, glad you were able to solve the compiling issue. Stef, thanks for your help with this.

themrcul, you're welcome. Good luck on your project!

Post Reply