Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Any TopTips for easy speedups?

A topic by stevebaines created Jun 14, 2017 Views: 571 Replies: 5
Viewing posts 1 to 6
Submitted

So, thanks to the extra day, I will get to submit my almost-finished entry, yay!

But, it's painfully slow.   I know that there's only so much that can be done about it - it is interpreted BASIC on a slow machine, after all!

Anyone have any top-tips for 'easy win' speedups that are still within the 'BASIC-only' rules?

E.g. fast ways of reading the keyboard, or ways of replacing slow conditionals with gotos and calculations,  clever use of arrays, etc.

I'm extremely rusty with ZX BASIC - this is the first time I've used it in 30 years, and it shows! :-)

Submitted(+1)

So, I don't know much about what is fast and what is slow in ZX BASIC, but here are a couple of small items to get this thread started.  Hopefully some much more knowledgeable people will join in (I know you are out there, from browsing the entries - impressive stuff in there)!

1.  Spectrum BASIC stores variables in the order you declare them, and when it needs to access one it searches linearly through them in memory. This means that variables that are going to be accessed most often should be declared first.

2. Shorter variable names also speed up the look-up, so use single character variables where possible.

Submitted(+1)

Hi! An idea could be pre-calculating values that will be used often or making "conversion tables" accessed instead of calculating values every time, but it depends on what your game has to do...

You can also use redundant data structures (48K is a LOT of memory ;) ) to access data more quickly. For my snake, I used a single dimension array acting as circular buffer to update the tail position at each step and added a bidimensional array matrix to check for collisions with the snake itself (besides walls of mongoose).

HostSubmitted

I didn't have the time to cleanup my own code...but will after the Jam is complete.

Executing FOR : NEXT loops on the same line where possible can help remove need for processing line numbers.

Limit GOTO  and GOSUB  jumping in main Game Loop - do most of your setups and jumping before you move into your Game Loop.

Submitted(+1)

I went with simple turn-based games to avoid running into performance issues, but one thing people mention a lot is that Sinclair Basic keeps lines of code in a linked list, which it rescans from the start every time you do a goto or gosub. So often-used jump destinations should be near the top of the code. Of course, that means kissing code organization bye-bye...

Submitted

Thanks for the tips!   Unfortunately for the current challenge, I ran out of time to try to speed it up much, but this will be useful in the future.

I wasted a lot of time experimenting and getting some modest speedups, and then had a mad panic to add all the missing stuff to make my entry into an actual game. Hey ho.