FAQ  •  Register  •  Login

Faster Draw

<<

britlion

Posts: 720

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Mon Aug 17, 2009 5:39 pm

Faster Draw

  Code:
DIM a as uinteger   

    FOR a=0 to 175
    PLOT 0,0
    DRAW 255,a
    NEXT a


My timings on this code suggest it's possible to make the DRAW command quite a lot faster. It takes about 9.2 seconds after ZX Basic compiles it and run on a 48K spectrum.

Running exactly the same code on a spectrum 128 with Beta Basic 4.0 added (find at: http://www.worldofspectrum.org/infoseekid.cgi?id=0007956 ) completes in 5.9 seconds. (56% faster execution) Remember, this is running in an extended variant of basic. In the beta basic newsletter 12 he describes a method of queuing up plot and draw commands into a string variable (as if it was an array), and using a very fast draw method to draw the whole array. I haven't tried that yet, but I get the impression it will be far faster (for anything we'd need to draw on screen more than once, anyway - creating the 'array' is still quite slow)

I think Andrew wright's draw code must be pretty staggeringly fast to make that much difference in an interpreted language, though beta basic is generally faster. He has stated in material that his draw code is 2.5 to 3 times as fast as the Sinclair ROM code.

Boriel, your circle routine is incredibly fast (beta basic has, I think, something very similar) - and you've said that the draw routine is faster than basic. I'm not sure I can see the difference in speed with yours over sinclair. Here's a source you might want to look at for a much faster algorithm.

Just something you might want to look at some time!
<<

britlion

Posts: 720

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Mon Aug 17, 2009 6:16 pm

Re: Faster Draw

<<

boriel

Site Admin

Posts: 1239

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Mon Aug 17, 2009 10:26 pm

Re: Faster Draw


Thanks britlion, again.

Effectively, ZX Basic DRAW is faster than BETA BASIC 3.1 one, but slower than 4.x. I will try to improve it. ZX BASIC Draw uses Bresenham's algorithm (the same as circle) wich is quite fast. I will try to examine BETA BASIC 4.x Draw to see what changes.

Regarding to the "STRING" method, this is just a "Polyline Draw", and it will be faster than normal coordinate one, and take less memory: You store each (x, y) pair coordinate in two bytes, and draw from one to another. You can use a string for that (generate cords x, y appending CHR$(x) + CHR$(y) to the string), and later creating an asm routine which traverses the string and call draw subsequently.

I'll see what can I do.
<<

boriel

Site Admin

Posts: 1239

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sat Mar 19, 2011 12:58 am

Re: Faster Draw

Update: As of 1.2.7 the DRAW routine was speed up (somewhat). If you're still interested, you can make a new benchmark (and tell us, please!)
<<

britlion

Posts: 720

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Sat Mar 19, 2011 1:20 pm

Re: Faster Draw

How about this? Seems to test all aspects of drawing..

Sinclair Basic version:
  Code:
10 FOR i=1 TO 127
20 DRAW i,160
30 PLOT i,0
40 NEXT i

50 OVER 1

60 FOR i=0 TO 80
70 PLOT 0,i
80 DRAW 250,i
90 NEXT i

100 REM OVER 2

110 FOR i=1 TO 80
120 CIRCLE 127,87,i
130 NEXT i

140 REM OVER 3

150 FOR i=10 TO 18
160 PLOT 127,87
170 DRAW i,i,i
180 NEXT i


I realised I can't test over 2,3 in sinclair basic...but still:

  Code:
start:
for i=1 to 127
draw i,160
plot i,0
next i

OVER 1

for i=0 to 80
plot 0,i
draw 250,i
next i

OVER 2

for i = 1 to 80
circle 127,87,i
next i

OVER 3

for i = 10 to 18
plot 127,87
draw i,i,i
next i
<<

boriel

Site Admin

Posts: 1239

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sat Mar 19, 2011 7:07 pm

Re: Faster Draw

I think they're Ok. Also check agains HiSoft. I was very surprised for they very-fast drawing routine.

Return to Wishlist

Who is online

Users browsing this forum: No registered users and 0 guests

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO