English Amiga Board Starfield in Blitz Basic - helpful critique sought
 Register Amiga FAQ Rules & Help Members List  /  Moderators List Today's Posts Mark Forums Read

 19 December 2008, 12:26 #1 Anding Registered User   Join Date: Nov 2008 Location: Hong Kong Posts: 56 Starfield in Blitz Basic - helpful critique sought This probably seems totally basic and in the age of the dinosaurs to most of you, but I'm refreshing my Amiga coding by trying to rework some classic algorithms from scratch in Blitz Basic 2. The idea of the exercise, of course, is to learn rather than produce something objectively useful This routine is for a starfield, except that it is rather slow! I'm sure I'm missing some tricks. I'd be very grateful for any helpful critique or suggestions. Many thanks indeed Anding ; Starfield research DEFTYPE .w ; the default variable type will be 16 bit integers ; to speed up calculations ; Establish the initial starfield on a ; 3D coordinate system with the centre of the screen at (0,0,0) ; and project these stars onto the screen Dim x(50), y(50), z(50), h(50) ; 3D coordinate and colour of each star Dim sx(50), sy(50) ; screen position of each star For i = 1 To 50 h(i) = Rnd*7+1 ; colour x(i) = Rnd*320-160: y(i) = Rnd*256-128: z(i) = Rnd*512 ; 3D position ; simple projection that scales the star's 3D x and y positions onto ; screen x and y positions according to its depth behind the screen sx(i) = (x(i) * 512/z(i)) + 160: sy(i) = (y(i) * 512/z(i)) + 128 Next ; Establish the display in lo-res with 3 colours BLITZ ; BLITZ mode direct access to the hardware BitMap 0,320,256,3 ; Allocate memory for the bitmap Slice 0,44,3 ; Set-up the copper list Use Slice 0 ; Attach the bitmap Show 0,0,0 ; to the slice main ; Plot the stars For i = 1 To 50 ;Clear the last position occupied by the star Plot sx(i),sy(i),0 ;Move the stars towards the screen (to simulate forward velocity) z(i) = z(i) -10 If z(i) <1 ;If the star passes behind the screen, renew it x(i) = Rnd*320-160: y(i) = Rnd*256-128: z(i) = 512 EndIf ; calculate screen positions using the simple projection as before sx(i) = (x(i) * 512/z(i)) +160: sy(i) = (y(i) * 512/z(i)) +128 Plot sx(i),sy(i),h(i) Next ; wait for a mouse button to exit and continue in a loop until then If Joyb(0)>0 Then End Goto main
 19 December 2008, 13:02 #2 Codetapper 2 contact me: email only!   Join Date: May 2001 Location: Auckland / New Zealand Posts: 3,138 I don't know how well Blitz optimises things, but I see a few things straight away: 1. You are calculating 512/z(i) twice in the main loop. Best to calculate that once and buffer the result for the second time, as div is a very expensive operation. 2. If the x co-ordinate is not on the screen, there is no need to calculate the y co-ordinate (or call the Plot() function). Ditto if the y co-ordinate is not on the screen, the call to Plot() might be wasting some CPU cycles. (Then again, Plot() might check the co-ordinates are on-screen and do nothing itself, I have never really used blitz basic so have no idea sorry!) 3. You might see some star flickering as you are not clearing all (old) stars before plotting all the new ones. If a new star position ends up being where an old one was (and a lower position in the array), the new position may well get erased. Good luck!
 26 December 2008, 13:12 #3 ChrisH Registered User   Join Date: Jun 2008 Location: England Posts: 18 To follow-on from Codetapper's post... "Rnd" is likely quite expensive, and is being called twice per loop. With a few tricks you could reduce that to one. And with a LUT (look up table) you could get rid of it entirely. Not sure about 68k, but multiplications may be slightly expensive (nothing like division though), so if you can make them part of the LUT then so much the better. It's hard to read the code without indentation, but why do you do "x(i) * 512" & "y(i) * 512" every loop? Why not just do the multiplication once, before entering the loop?
 26 December 2008, 16:02 #4 AlfaRomeo A1200 040 SAM440EP 667   Join Date: Jan 2008 Location: Lisbon / Portugal Posts: 776 Why do you don´t change BlitzBasic2 by AmiBlitz3??.. I read somewhere that it is a great compiler Someone knows where to find some code to learn BlitzBasic like foruns? Last edited by AlfaRomeo; 26 December 2008 at 16:27.
27 December 2008, 21:26   #5
prowler
Global Moderator

Join Date: Aug 2008
Location: Sidcup, England
Posts: 10,284
Quote:
 Originally Posted by AlfaRomeo Someone knows where to find some code to learn BlitzBasic like foruns?
Hi AlfaRomeo,

I've had a look in my Amiga archives and found the following files which may help you in your quest to learn Blitz Basic:

Blitz Support Suite ADFs (3) - RAR archive [1.13MB]
Blitz Basic 2.1 ADFs (3) - RAR archive [1.41MB]
Ultimate Blitz Basic 2.1 CD ISO image - RAR archive [8.61MB]
Blitz Basic 2 Examples ADFs (4) - ZIP archive [1.13MB]

Let me know if you would find any or all of these files useful and I'll upload them for you.

prowler

 31 December 2008, 16:02 #6 Anding Registered User   Join Date: Nov 2008 Location: Hong Kong Posts: 56 These are great suggestions and have moved me on quite a bit. Thanks a lot everyone for the helpful ideas. Merry Christmas and Happy New Year to all Amiga Coders!
 12 January 2009, 23:47 #7 syphus Registered User   Join Date: Jan 2009 Location: Newcastle, UK Posts: 18 Thanks for posting your source, Anding! I've not been having much luck finding good snippets to learn from, but this sort of thing is great for people like me, who are just starting out. It helped me to get stuff displayed on screen for the first time
 13 January 2009, 01:09 #8 KevG Banned   Join Date: Jan 2009 Location: U.K. Posts: 93 You can get rid of the 3d calculation completely inside the loop and things would speed up really good! To do this, simply create an array of x & y values for each star. Calculate all the valid x & y values from 3D space and put them in their own list before entering the main loop. Now all you have to do now is read the lists for each star and plot the x & y values. This is an ultra fast way of doing it because you are just reading from a list and not performing any calculations at all! Hope that helps :-) Kev G.
13 January 2009, 03:40   #9
AlfaRomeo
A1200 040 SAM440EP 667

Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 776
Quote:
 Originally Posted by prowler Let me know if you would find any or all of these files useful and I'll upload them for you.
Hi prowler,
Thanks for your help and sorry for the delay in my answer but I was out during christmas/new year and so I only saw your message today
I think the BB2 examples ADFs may be useful to me if you could upload to the zone

13 January 2009, 12:53   #10
prowler
Global Moderator

Join Date: Aug 2008
Location: Sidcup, England
Posts: 10,284
Quote:
 Originally Posted by AlfaRomeo I think the BB2 examples ADFs may be useful to me if you could upload to the zone
Hi Alfa,

They're in the Zone for you.

Have fun!

prowler

 13 January 2009, 22:46 #11 AlfaRomeo A1200 040 SAM440EP 667   Join Date: Jan 2008 Location: Lisbon / Portugal Posts: 776 Thanks prowler, you´re the best

 Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 Similar Threads Thread Thread Starter Forum Replies Last Post Havie Coders. Blitz Basic 30 08 September 2013 10:15 twiggy Coders. General 14 21 February 2009 16:29 petza request.Apps 11 08 April 2007 02:49 jobro request.Apps 12 28 November 2005 19:15 LaundroMat Retrogaming General Discussion 5 24 July 2001 09:10

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home News Main     Amiga scene     Retrogaming General Discussion     Nostalgia & memories Support     New to Emulation or Amiga scene         Member Introductions     support.WinUAE     support.WinFellow     support.OtherUAE     support.FS-UAE     support.Hardware         Hardware mods         Hardware pics     support.Games     support.Demos     support.Apps     support.Amiga Forever     support.Amix     support.Other Requests     request.UAE Wishlist     request.Old Rare Games     request.Demos     request.Apps     request.Modules     request.Music     request.Other     Looking for a game name ?     Games images which need to be WHDified abime.net - Hall Of Light     HOL news     HOL suggestions and feedback     HOL data problems     HOL contributions abime.net - Amiga Magazine Rack     AMR news     AMR suggestions and feedback     AMR data problems     AMR contributions abime.net - Home Projects     project.Amiga Lore     project.EAB     project.IRC     project.Mods Jukebox     project.Wiki abime.net - Hosted Projects     project.aGTW     project.APoV     project.ClassicWB     project.Jambo!     project.Green Amiga Alien GUIDES     project.Maptapper     project.Sprites     project.WinUAE - Kaillera Other Projects     project.Amiga Demo DVD     project.Amiga Game Factory     project.CARE     project.EAB File Server     project.CD32 Conversion     project.Game Cover Art         GCA.Feedback and Suggestions         GCA.Work in Progress         GCA.Cover Requests         GCA.Usefull Programs         GCA.Helpdesk     project.KGLoad     project.MAGE     project.Missing Full Shareware Games     project.SPS (was CAPS)     project.TOSEC (amiga only)     project.WHDLoad         project.Killergorilla's WHD packs Misc     Amiga websites reviews     MarketPlace         Swapshop     EAB's competition Coders     Coders. General         Coders. Releases         Coders. Tutorials     Coders. Asm / Hardware     Coders. System         Coders. Scripting         Coders. Nextgen     Coders. Language         Coders. C/C++         Coders. AMOS         Coders. Blitz Basic Off Topic     OT - General     OT - Technical     OT - Entertainment     OT - Sports     OT - Adult     OT - Gaming

All times are GMT +2. The time now is 07:38.

 -- EAB3 skin ---- EAB2 skin ---- Mobile skin Archive - Top