Scrolling Map Demo
Moderator: Stef
Scrolling Map Demo
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.
-
- Very interested
- Posts: 710
- Joined: Sat Feb 18, 2012 2:44 am
Re: Scrolling Map Demo
Looks good! The code is very clean
Re: Scrolling Map Demo
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.
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.
Re: Scrolling Map Demo
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: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.
Sorry, I'm not sure I understand what you mean. Can you clarify?Miquel wrote: ¿Have you thought that you can jump horizontal scroll line without being in consecutive positions? I can't see it anywhere.
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.
-
- Very interested
- Posts: 710
- Joined: Sat Feb 18, 2012 2:44 am
Re: Scrolling Map Demo
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.
Re: Scrolling Map Demo
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.
Re: Scrolling Map Demo
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: 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.
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.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.
HELP. Spanish TVs are brain washing people to be hostile to me.
Re: Scrolling Map Demo
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.
Re: Scrolling Map Demo
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.
Re: Scrolling Map Demo
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!
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!
Re: Scrolling Map Demo
I get an error when I compile this ;
Could be a verstion difference? It works fine to compile my code.
Could be a verstion difference? It works fine to compile my code.
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: Scrolling Map Demo
_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.
Re: Scrolling Map Demo
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 and works good now thanks for sharing, kcowolf
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: Scrolling Map Demo
Looks like your sega.s file was corrupted thenHik 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
Re: Scrolling Map Demo
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!
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!