Horizontal bitmap scrolling technique

More
3 weeks 4 days ago #186 by ludojoey
Thank you the tip!

Yes, some frames are missing.
I will try to optimize, but as I want that everything move (!!) I am afraid that the time to make moving all the elements is much more than one frame !

Thanks again, I learn a lot of things with micro-8 !
The following user(s) said Thank You: Franck

Please Log in or Create an account to join the conversation.

More
3 weeks 4 days ago - 3 weeks 4 days ago #187 by Franck
Remember that the Lofi compiler is a simple single pass compiler that does not perform optimizations on its own, it compiles source code as-is.

So a few things to keep in mind:

Minimize computations, pre-compute if possible. Ex: a=9; is faster than a=4+5;
Calling functions requires arguments to be pushed to the stack during call, than pop from the stack in the function execution. Sometimes it's better to just inline stuff (performance wise), even if it is less 'pretty'.
Custom types are particularly heavy to pass around. If a function just uses a single member, it is better to just pass the member beforehand for instance. Being able to pass custom types as references would be better but it is what it is at the moment.

Back to the scrolling topic, time dilution is a powerful tool that can reduce dramatically the cost of copying the tile buffer. Thanks to the double buffered tile buffer and the hardware scrolling, say you move 2 pixels/frame, you can copy 1/8th of the draw buffer each frame and only swap the buffers once complete, dividing the cost by 8. The slower the scrolling, the more you can divide, making it pretty much costless.


 
Last edit: 3 weeks 4 days ago by Franck.
The following user(s) said Thank You: ludojoey

Please Log in or Create an account to join the conversation.

More
3 weeks 3 days ago #188 by ludojoey
Well, I managed to optimize my code:

For a few functions, I removed parameter passing and used global variables instead.
I made heavy use of "time dilution" by spreading the scrolling work over multiple frames.
Following the advice in the manual, I also implemented double buffering for the display list, since I'm modifying it in real time.

The result isn't too bad. At least, it's good enough for me!



It's funny because, for years, I've been used to writing modular, reusable code and avoiding global variables at all costs (they usually lead to messy code and bugs).

Here, it's pretty much the exact opposite... I'm really forcing myself to code this way!

But it's actually a lot of fun.

(I'd already had a similar experience while writing my Minitel emulator for the MSX1.)
The following user(s) said Thank You: Franck, David, daimos

Please Log in or Create an account to join the conversation.

Time to create page: 0.173 seconds
Powered by Kunena Forum