BBC BASIC for Windows
« 'Bouncy Balls' (BB4W/BBCSDL) »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:59pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 hotthread  Author  Topic: 'Bouncy Balls' (BB4W/BBCSDL)  (Read 562 times)
David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: 'Bouncy Balls' (BB4W/BBCSDL)
« Reply #3 on: Feb 13th, 2017, 8:41pm »

My final offering:

"Vector Balls" - BB4W regulars will have seen this all before, but I've been experimenting a lot with BBCSDL Android (ARM). This animation works very nicely on my Moto G4.

http://pastebin.com/usZSyDb8

Scroll down the page to the 'RAW Paste Data' section, then be sure to select ALL of the program, copy and paste into the BB4W/BBCSDL IDE.


David.
--
« Last Edit: Feb 13th, 2017, 8:42pm by David Williams » User IP Logged

michael
Senior Member
ImageImageImageImage


member is offline

Avatar




PM


Posts: 335
xx Re: 'Bouncy Balls' (BB4W/BBCSDL)
« Reply #4 on: Feb 14th, 2017, 02:28am »

Very cool. I installed the arm version of bbcsdl on my samsung Galaxy, but when bbc starts it shows a light screen then stops. Perhaps my samsung is too old. :(
User IP Logged

I like making program generators and like reinventing the wheel
meneer
New Member
Image


member is offline

Avatar




PM


Posts: 5
xx Re: 'Bouncy Balls' (BB4W/BBCSDL)
« Reply #5 on: Feb 17th, 2017, 12:32pm »

This was fun and running fast enough to make some sort of scrolling game.
Through my work phone ( Moto G4 play ) is a bit slow.


David,
Do you have something to make readable bitmap files?
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: 'Bouncy Balls' (BB4W/BBCSDL)
« Reply #6 on: Feb 21st, 2017, 1:11pm »

on Feb 13th, 2017, 8:41pm, David Williams wrote:
My final offering:


For a game project, I needed a fast-ish filled circle plotter, so I wrote one in x86 and ARM assembly language. Still a lot of room for improvement as far as code efficiency is concerned, but this will have to do for now. Here's a demo of it (it performs pretty well on my Moto G4)...

EDIT (1): Oops. Code didn't work when copied & pasted. Will attempt to re-post it here again later. Sorry for any inconvenience caused.

EDIT (2): Pastebin link (scroll to bottom of page to the 'RAW Paste Data' section then select ALL of the code in the box, then copy and paste it into the BB4W/BBCSDL IDE:

http://pastebin.com/39TeLRbP (link dies after 1 month)


Meener asked: "Do you have something to make readable bitmap files?"

All I have is a bit of code for loading a 32bpp BMP image and converting it to the 16bpp RGB565 (or, oddly, 32bpp ARGB8565) format required by my sprite plotters.


David.
--
« Last Edit: Feb 21st, 2017, 2:01pm by David Williams » User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: 'Bouncy Balls' (BB4W/BBCSDL)
« Reply #7 on: Feb 21st, 2017, 3:14pm »

Speed comparison between "CIRCLE FILL" and my filled circle plotting routine. Same sets of random positions, radii and colours. I have tried to keep the test(s) as fair as possible.

Laptop PC (Intel Celeron) Windows 10

BASIC's "CIRCLE FILL" command:
Constant colour : 2189 circles/sec.
Random colour: 1973 circles/sec.

Custom routine:
Constant colour : 5592 circles/sec.
Random colour: 5517 circles/sec.




Motorola Moto G4 (Android)

BASIC's "CIRCLE FILL" command:
Constant colour : 266 circles/sec.
Random colour: 10 circles/sec. (!)

Custom routine:
Constant colour : 4258 circles/sec.
Random colour: 4324 circles/sec. (slightly weird result, but it varies somewhat)


The reason for the miserable figures on Android for "CIRCLE FILL" is that rendering of large circles is VERY slow. In this test, the radii vary randomly from 1 to 500 pixels.

On Intel/Windows, the custom routine is about twice as fast, whereas on Android (ARM), it is many times faster.

Hence the need for my own filled circle plotting routine!



Here's a link to the speed test program for those interested:

http://pastebin.com/a2VQuq17


David.
--
« Last Edit: Feb 21st, 2017, 3:14pm by David Williams » User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: 'Bouncy Balls' (BB4W/BBCSDL)
« Reply #8 on: Feb 21st, 2017, 7:11pm »

With a constant radius for all circles (48 pixels), and the circles constrained such that they all fit inside the 360x640 program window, I get the following timings:

Laptop PC (Intel Celeron) Windows 10

BASIC's "CIRCLE FILL" command:
Constant colour : 7685 circles/sec.
Random colour: 7170 circles/sec.

Custom routine:
Constant colour : 38919 circles/sec.
Random colour: 37765 circles/sec.


Motorola Moto G4 (Android)

BASIC's "CIRCLE FILL" command:
Constant colour : 321 circles/sec.
Random colour: 41 circles/sec. (!)

Custom routine:
Constant colour : 20299 circles/sec.
Random colour: 19573 circles/sec.


With better programming, including a vastly improved horizontal line filler (the current one is hugely suboptimal on both x86 & ARM architectures), one could perhaps double (at least) the throughput of the custom routine.

User IP Logged

meneer
New Member
Image


member is offline

Avatar




PM


Posts: 5
xx Re: 'Bouncy Balls' (BB4W/BBCSDL)
« Reply #9 on: Feb 22nd, 2017, 07:25am »

David,

The G4 values are quite different than my Moto G4 play variant.
(whis is logical as the G4 play is based on the G3 hardware)

CIRCLE FILL command
Constant Colour : 262 circles/sec
Random colour : 1 circles/sec

Custom filled-circle route
Constant Colour : 3295 circles/sec
Random color : 3314 circles/sec


My Sony Xperia does it slighty better.

CIRCLE FILL command
Constant Colour : 283 circles/sec
Random colour : 23 circles/sec

Custom filled-circle route
Constant Colour : 4905 circles/sec
Random color : 4855 circles/sec

I have tried to load an 32bpp BMP file including the alpha channel using the FNloaddata included in the examples but it doesn't display correctly.



Jeroen
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: 'Bouncy Balls' (BB4W/BBCSDL)
« Reply #10 on: Feb 22nd, 2017, 12:22pm »

on Feb 22nd, 2017, 07:25am, meneer wrote:
The G4 values are quite different than my Moto G4 play variant.
(whis is logical as the G4 play is based on the G3 hardware)

[...]

My Sony Xperia does it slighty better.

[...]


Thanks for running the test program on your mobile devices.

I should explain that the main purpose of making the filled circle plotter, and the triangle plotter that I will be coding tonight at work, is so that my programs can generate their own simple graphics more efficiently. Although my circle plotter seems faster than BASIC/SDL on Android, it is actually intrinsically very slow for large and partially clipped circles! This is mostly because of the simplistic clipping that it performs; it calculates all the points along the circle edge, even if those points lie outside the viewport. This is very wasteful for large circles. For a circle of 500 pixels radius, it calculates and individually clip-tests all 2*PI*r (3142) points around the circle's edge, whereas a more sophisticated algorithm just 'processes' the visible points of the circle. My triangle/quad plotter will suffer from a similar problem.


Quote:
I have tried to load an 32bpp BMP file including the alpha channel using the FNloaddata included in the examples but it doesn't display correctly.


Most of those sprite/bitmap plotters of mine (which are only experimental), only handle RGB565 bitmaps, so you would load in your 32bpp BMP image using (for example) FNLoadData, and then convert it to the required RGB565 format (which ignores your alpha mask!), or to 32bpp ARGB8565 (8 bits alpha, 5 bits red, 6 green, 5 blue) which can be plotted using PlotAlphaBlend (which I haven't yet released). I will post some example code in a few hours.

I should point out that my little graphics library, aimed primarily at Android, is an absolute pig to use, and I really don't recommend it unless you have masochistic tendencies. I couldn't figure out how to pass parameters to my ARM machine code routines using BASIC's CALL command, as in:

CALL PlotSprite, bufVars%, bmAddr%, bmW%, bmH%, x%, y%

I know it must be possible, because that's how the ARM binary version of SORTLIB works.

I'm not having much luck with SYS either!

I know it's early days, and perhaps documentation will come our way at some point, although some of the signals coming from Richard recently in regard to the future development of the Android edition of BBCSDL makes me wonder if it's worth continuing my own explorations with it.

I'll post some code shortly.


David.
--
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: 'Bouncy Balls' (BB4W/BBCSDL)
« Reply #11 on: Feb 22nd, 2017, 1:51pm »

Jeroen,

Here is some example code for loading in a BMP32 bitmap image (with alpha mask), and plotting it using 'PlotAlphaBlend':

http://pastebin.com/uukx85QJ

You will need the 72x72 BMP32 test image:

http://www.proggies.uk/temp/ball72x72.zip

The Zip folder also contains the example program and the original PNG image that I converted to BMP32. The PNG image came from openclipart.org .

As you can see, quite a bit of faffing around is needed just to plot some sprites. Sorry about that!


BTW, I should have mentioned in the program somewhere, that the width and height of a BMP image can be obtained by reading the 32-bit values at offsets 18 and 22 in the BMP header. In the case of the example program:

ballW% = ball%!18
ballH% = ball%!22


EDIT: Here's a slightly modified version of the example program which plays around with the BMP's alpha mask to produce a 'fuzzy' effect:

http://pastebin.com/c8Z7tJLH



David.
--


« Last Edit: Feb 22nd, 2017, 2:22pm by David Williams » User IP Logged

meneer
New Member
Image


member is offline

Avatar




PM


Posts: 5
xx Re: 'Bouncy Balls' (BB4W/BBCSDL)
« Reply #12 on: Feb 23rd, 2017, 12:38pm »

David,

I have succesfully managed to read 32bit BMP files with Alpha values.
Thanks.

I will make some demo to see if I can make a scrolling gaming field filled with tiles.

Cheers,
Jeroen
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: 'Bouncy Balls' (BB4W/BBCSDL)
« Reply #13 on: Feb 23rd, 2017, 8:26pm »

Demo of filled triangle plotting routine, intended for BBCSDL (Android), but works with BB4W:

http://pastebin.com/h2m70R9Q

Compare performance (especially on Android) with this version which uses BASIC's PLOT 85 to draw the triangles:

http://pastebin.com/xp89yEgs

In the case of BBCSDL (Android), my plotter seems hundreds of times faster (at least on my Moto G4), even though it's actually very inefficient.


David.
--
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: 'Bouncy Balls' (BB4W/BBCSDL)
« Reply #14 on: Feb 24th, 2017, 4:44pm »

Semi-transparent triangles (random opacities):

http://pastebin.com/JMCjPtUZ


To do: quad poly plotter, thick line plotter, bitmap supersampling code, image blur, and lots of other bits and pieces.

Hopefully Richard will at some point implement SYS for the ARM variant of BBCSDL for calling machine code routines, so that parameters can be pulled off the stack as with the x86 version of BB4W. In ARM BBC BASIC V (etc.), the SYS statement loads parameters directly into selected registers, which is usually very convenient.


David.
--
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: 'Bouncy Balls' (BB4W/BBCSDL)
« Reply #15 on: Feb 24th, 2017, 8:37pm »

Semi-transparent triangles & circles over a colourful background. Works nicely on my Android phone (Motorola Moto G4).

http://pastebin.com/cK3GMipJ
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: 'Bouncy Balls' (BB4W/BBCSDL)
« Reply #16 on: Feb 25th, 2017, 12:53am »

Same program as previous, but now with an FPS indicator.

http://pastebin.com/ZKnKBjaR

I get 32 fps (average) on my Moto G4, which isn't bad considering that all the graphics is software-rendered (no hardware acceleration) on a relatively slow processor. More efficient colour-blending code (for both x86 and ARM architectures) ought to at least double the speed of the rendering.


David.
--


User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: 'Bouncy Balls' (BB4W/BBCSDL)
« Reply #17 on: Feb 28th, 2017, 1:26pm »

Thick lines with round endpoints:

http://pastebin.com/zvUAwMG8
User IP Logged

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

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls