BBC BASIC
« Snow Scene animation »

Welcome Guest. Please Login or Register.
Jan 23rd, 2018, 4:48pm


Cross-platform BBC BASIC (Win32, Linux x86, Android, Mac OS-X, Raspberry Pi)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Snow Scene animation  (Read 394 times)
treehouse
New Member
Image


member is offline

Avatar




PM


Posts: 13
xx Re: Snow Scene animation
« Reply #2 on: Jan 8th, 2018, 8:47pm »

Great stuff. At first I thought I'd got the measure of this program in the first few seconds. Tree, snow. It was only by studying the program I realised the wind is drifting the snowflakes about, and they're settling on the ground and tree.

Quote:
The code is optimised for BBCSDL but will run (rather slowly) in BB4W
There's a WAIT 4 in there, which it seems it can do without. A bit faster.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 692
xx Re: Snow Scene animation
« Reply #3 on: Jan 8th, 2018, 9:24pm »

on Jan 8th, 2018, 8:47pm, treehouse wrote:
There's a WAIT 4 in there, which it seems it can do without.

Without a WAIT, the program will consume 100% CPU (100% of one core anyway) which isn't generally acceptable. In the old days (for example on the BBC Micro) it was quite normal to run the CPU 'flat out', and indeed doing so would probably have little effect either on power consumption or temperature.

But modern CPUs aren't like that: running a core at 100% will cause the battery in a laptop to run down much faster than is desirable, and is also likely to result in so much heat production that the cooling fan(s) ramp up.

So a WAIT of some kind is desirable, and a WAIT 4 will cause the animation to max out at about 25 frames a second which is fast enough to be fairly smooth. In a more sophisticated program it may well be necessary to take steps to ensure that the frame rate is constant irrespective of the CPU speed.

Many graphics programs rely on *REFRESH (snowscene is an exception) and then you must take special care. In BB4W it simply sets a flag telling Windows to redraw the window when it next gets an opportunity, whereas in BBCSDL it actively synchronises with the display's refresh rate by waiting until the next vertical sync.

Therefore you can often end up wanting to use code similar to the following to match the program's performance on the two platforms:

Code:
      IF INKEY$(-256) = "W" THEN WAIT 2
      *REFRESH 

Richard.

P.S. I should perhaps add that, these days, I generally develop programs under BBCSDL and their performance when running under BB4W (if they work at all) is not something I pay much attention to.
« Last Edit: Jan 8th, 2018, 10:05pm by Richard Russell » User IP Logged

treehouse
New Member
Image


member is offline

Avatar




PM


Posts: 13
xx Re: Snow Scene animation
« Reply #4 on: Jan 9th, 2018, 12:28am »

Ah yes, I remember now! I looked up a fair few things in the help as I went through the code, but I didn't bother to look up WAIT.

That issue of constant frame rate is just what I've come across in my biggest BB4W project, a game that I suddenly realised ran crazy fast on a different machine. As usual, not sure I'll ever finish it anyway!

And I probably need to introduce at least a WAIT 0 into a few others.
Thanks
John
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls