English Amiga Board Help with smooth 3D Cube in C on A500 using Draw() and Move()
 Register Amiga FAQ Rules & Help Members List  /  Moderators List Today's Posts Mark Forums Read

 18 October 2020, 00:46 #1 a1k3k Registered User   Join Date: Apr 2020 Location: Kernelville Posts: 13 Help with smooth 3D Cube in C on A500 using Draw() and Move() As a challenge, I've taken it upon myself to delve into Amiga coding in C and attempt to make a few 3D routines. Is it possible to create a decently smooth wireframe rotating cube using C that runs on a stock A500? I ask because I've seen [ Show youtube player ] and it seems he's managed to do it using pure C, but I haven't managed to do so yet. In my own attempt, I've tried double buffering (swapping out two bitmaps every frame). The flicker is reduced, but the frame rate is still abysmally slow, something like 1-2 frames per second. Even when I turn off rotation and just have basic horizontal movement, it's slow. On a souped-up UAE config it's smooth though. So I reckon it's nothing to do with the transformation parts, which are integer and use lookup tables for trig functions. I'm using a 320x200 screen with 2 bitplanes. My cube is pretty much self-explanatory: `struct node cubeNodes[8] = {{-1, -1, -1},{-1, -1, 1},{-1, 1, -1},{-1, 1, 1},{1, -1, -1},{1, -1, 1},{1, 1, -1},{1, 1, 1}};` `struct edge cubeEdges[12] = {{0, 1},{1, 3},{3, 2},{2, 0},{4, 5},{5, 7},{7, 6},{6, 4},{0, 4},{1, 5},{2, 6},{3, 7}};` My bitmap swapper: ```void swapBitmap(){ static int bitmap = 0; if (bitmap==0) { rp.BitMap = &b2; ri.BitMap = &b2; SetRast(&rp,0); bitmap=1; } else { rp.BitMap = &b; ri.BitMap = &b; SetRast(&rp,0); bitmap=0; } }``` where rp is the RastPort and ri is RastInfo. My copper list updater: ```void updateCopperLists() { MakeVPort (&v, &vp); MrgCop (&v); LoadView (&v); WaitTOF(); WaitBlit(); }``` and finally, my draw routine which basically iterates through the object edges and does a Move() on the first vertex and a Draw() on the second vertex. On entry it swaps in the bitmap on which it'll draw on, and prior to exit updates the copper list so the bitmap is shown: ``` swapBitmap(); for (i = 0; i < obj->edgeSize; i++) { /* Draw line using screen coordinates */ Move (&rp, obj->nodes[obj->edges[i].nodeA].x + WIDTH / 2 + obj->centerAt.x, -obj->nodes[obj->edges[i].nodeA].y + HEIGHT / 2 + obj->centerAt.y); Draw (&rp, obj->nodes[obj->edges[i].nodeB].x + WIDTH / 2 + obj->centerAt.x, -obj->nodes[obj->edges[i].nodeB].y + HEIGHT / 2 + obj->centerAt.y); } } updateCopperLists();``` FWIW I've also tried starting the main code with Forbid() and Disable() but it doesn't help speed up in any measurable sense. Anyone has any tips? Maybe it's something I'm overlooking? I'm pretty new to coding for the Amiga but I'd love to keep at it and get better as I've always wanted to code my own demo routines that can run on a bog standard A500. I'd like to move on to assembler later on, but first I'd like to be able to hash it out in C.
 18 October 2020, 09:32 #2 Ernst Blofeld Registered User   Join Date: Sep 2020 Location: France Posts: 9 I think your updateCopperLists function may be doing more than it needs to. I don't think you should be calling MrgCop on every buffer flip. This example http://amigadev.elowar.com/read/ADCD.../node05B3.html certainly looks like it does less. I have used the second method described here http://amigadev.elowar.com/read/ADCD.../node0346.html with success before, but can't find my code at the moment to demonstrate. Last edited by Ernst Blofeld; 18 October 2020 at 09:46.
 18 October 2020, 16:57 #3 Samurai_Crow Total Chaos forever!   Join Date: Aug 2007 Location: Waterville, MN, USA Age: 46 Posts: 1,555 The OS routines are abysmally slow. Interface directly with the hardware for a massive speed boost.
18 October 2020, 22:52   #4
a1k3k
Registered User

Join Date: Apr 2020
Location: Kernelville
Posts: 13
Quote:
 Originally Posted by Ernst Blofeld I think your updateCopperLists function may be doing more than it needs to. I don't think you should be calling MrgCop on every buffer flip. This example http://amigadev.elowar.com/read/ADCD.../node05B3.html certainly looks like it does less.
The example uses Intuition's RethinkDisplay() which apparently does MrgCop() and LoadView(). Since I'm not using Intuition screens and bypassing it altogether, I just thought I'd do the same. Though you may be right that it probably shouldn't be called on every flip as they indicate in the RKM "WARNING: This routine can take several milliseconds to run, so do not use it lightly." but the example provided does not heed that.

Quote:
 Originally Posted by Ernst Blofeld I have used the second method described here http://amigadev.elowar.com/read/ADCD.../node0346.html with success before, but can't find my code at the moment to demonstrate.
I've now tried this second method and it's still slow. Maybe a bit faster, but nothing usable.

18 October 2020, 22:55   #5
a1k3k
Registered User

Join Date: Apr 2020
Location: Kernelville
Posts: 13
Quote:
 Originally Posted by Samurai_Crow The OS routines are abysmally slow. Interface directly with the hardware for a massive speed boost.
Any pointers on how to do that in C? I'm fairly new to Amiga coding (although an old hand with coding in general).

18 October 2020, 23:13   #6
Ernst Blofeld
Registered User

Join Date: Sep 2020
Location: France
Posts: 9
Quote:
 Originally Posted by a1k3k The example uses Intuition's RethinkDisplay() which apparently does MrgCop() and LoadView(). Since I'm not using Intuition screens and bypassing it altogether, I just thought I'd do the same. Though you may be right that it probably shouldn't be called on every flip as they indicate in the RKM "WARNING: This routine can take several milliseconds to run, so do not use it lightly." but the example provided does not heed that. I've now tried this second method and it's still slow. Maybe a bit faster, but nothing usable.
How fast is it if you remove everything except for the buffer swapping? ie leaving very little apart from LoadView swapping buffers? And, conversely, how fast is it if you just use single buffering? It would be useful to know where the overhead really is.

 19 October 2020, 02:44 #7 Samurai_Crow Total Chaos forever!   Join Date: Aug 2007 Location: Waterville, MN, USA Age: 46 Posts: 1,555 If you're using more than 2 bits per pixel, reduce the palette depth. This will speed up the blitter by freeing up bandwidth used by the display DMA. You should only need 3 foreground colors to draw a cube.
 19 October 2020, 10:05 #8 Ernst Blofeld Registered User   Join Date: Sep 2020 Location: France Posts: 9 Looking at the youtube clip, he's not doing half the work you are. He's drawing into a single bitplane, probably clearing only the bits he's touched, and probably not using double buffering as he can probably sync with the display as he's drawing so little. I'm sure you can get your stuff to be smoother once you've worked out where the time is going, but I wouldn't compare to his. You may want to check out the bartman gcc vs-code stuff that will allow you to profile in a modernish way. Last edited by Ernst Blofeld; 19 October 2020 at 19:01.
 19 October 2020, 16:48 #9 Samurai_Crow Total Chaos forever!   Join Date: Aug 2007 Location: Waterville, MN, USA Age: 46 Posts: 1,555 Looking at the YouTube clip there are 2 playfields at 1 bitplane each. The Copper work is best done only once. A double-buffered one bitplane screen is easy when there are only 2 copper lists. The copper does all the bitplane changes too.
19 October 2020, 23:52   #10
a1k3k
Registered User

Join Date: Apr 2020
Location: Kernelville
Posts: 13
Quote:
 Originally Posted by Ernst Blofeld How fast is it if you remove everything except for the buffer swapping? ie leaving very little apart from LoadView swapping buffers? And, conversely, how fast is it if you just use single buffering? It would be useful to know where the overhead really is.
So I included a little fps timer in the code and I get on my A1k 5-6 fps with absolutely nothing on, except buffer swap. With single buffer, I get a solid 6. OTOH on my 25MHz A3k I went from 25 to 43 fps.

Quote:
 Originally Posted by Ernst Blofeld Looking at the youtube clip, he's not doing half the work you are. He's drawing into a single bitplane, probably clearing only the bits he's touched, and probably not using double buffering as he can probably sync with the display as he's drawing so little. I'm sure you can get your stuff to be smoother once you've worked out where the time is going, but I wouldn't compare to his. You may want to check out the bartman gcc vs-code stuff that will allow you to profile in a modernish way.

Quote:
 Originally Posted by Samurai_Crow Looking at the YouTube clip there are 2 playfields at 1 bitplane each. The Copper work is best done only once. A double-buffered one bitplane screen is easy when there are only 2 copper lists. The copper does all the bitplane changes too.
You're right guys, I absolutely missed the point that he's using a different approach. To start with, I'll probably try to cut down from 2 bitplanes to 1.

Thanks for all the insight, I appreciate it a lot!

20 October 2020, 04:27   #11
Ernst Blofeld
Registered User

Join Date: Sep 2020
Location: France
Posts: 9
Quote:
 Originally Posted by a1k3k 5-6 fps with absolutely nothing on, except buffer swap
This is surprising to me, I would have expected even OS friendly code to do around 15 fps to do nothing.

Yesterday, 15:04   #12
a1k3k
Registered User

Join Date: Apr 2020
Location: Kernelville
Posts: 13
Quote:
 Originally Posted by Ernst Blofeld This is surprising to me, I would have expected even OS friendly code to do around 15 fps to do nothing.
So I screwed up big time in my earlier posts and FPS checks. I forget to comment out a call to a critical non-draw function: the rotation function. Yes, I know. I thought I had it commented out, but didn't.

Anyway, that function was the culprit. I was doing some math with doubles and that killed the speed. I changed it over to integer math and everything is way, way faster now and smooth as butter.

Here are some stats:
Screen is 320x256, 1 bitplane, 1 cube scaling, rotating and moving across the screen.

(A) Single buffer, no WaitTOF(): 30-31 with flicker
(B) Single buffer, 1 WaitTOF(): 25 fps solid with flicker
(C) Single buffer, 2 WaitTOF(): 16-17 fps with flicker

(D) Double buffer, no WaitTOF(): 30-31 without flicker
(E) Double buffer, 1 WaitTOF(): 25 fps solid without flicker
(F) Double buffer, 2 WaitTOF(): 16-17 fps without flicker

So out of the lot, D seems great. I guess B and E are at a constant 25 fps due to the WaitTOF() limiting refreshes.

Using 2 WaitTOF()'s decreases performance and is not required since I'm not using interlaced modes.

And without any work (no cube drawing and transformations):

(G) Single buffer, no WaitTOF(): 357 fps
(H) Single buffer, 1 WaitTOF(): 50 fps
(I) Single buffer, 2 WaitTOF(): 25 fps

(J) Double buffer, no WaitTOF(): 336 fps
(K) Double buffer, 1 WaitTOF(): 50 fps
(L) Double buffer, 2 WaitTOF(): 25 fps

For the double buffer swapper, all I do is set the LOFCprList, SHFCprList, RastInfo and RastPort bitmaps and then do a LoadView() (no MakeVPort() and MrgCop()).

 Yesterday, 15:32 #13 Samurai_Crow Total Chaos forever!   Join Date: Aug 2007 Location: Waterville, MN, USA Age: 46 Posts: 1,555 Beam sync with WaitTOF can free up some processor time for other functions because, unlike PC, vertical blank triggers an interrupt on Amiga.
Yesterday, 17:07   #14
Ernst Blofeld
Registered User

Join Date: Sep 2020
Location: France
Posts: 9
Quote:
 Originally Posted by a1k3k (D) Double buffer, no WaitTOF(): 30-31 without flicker
Maybe you want to move to triple buffering.

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

 Similar Threads Thread Thread Starter Forum Replies Last Post arti support.Games 41 03 December 2019 17:53 Knocker Coders. Asm / Hardware 2 07 September 2016 09:13 fondpondforever Amiga scene 3 25 June 2015 09:40 Gilloo Coders. Asm / Hardware 19 04 December 2011 18:36 daznic Retrogaming General Discussion 1 03 June 2009 20:44

 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         project.AmigaLive     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.Amiga 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     Kinky Amiga Stuff     Collections     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     Coders. Contest         Coders. Entries Creation     Graphics         Graphics. Work In Progress         Graphics. Finished Work         Graphics. Tutorials     Music         Music. Work In Progress         Music. Finished Work         Music. Tutorials Off Topic     OT - General     OT - Entertainment     OT - Sports     OT - Technical     OT - Gaming

All times are GMT +2. The time now is 01:53.

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