English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 13 June 2018, 14:39   #81
Master484
Registered User
Master484's Avatar
 
Join Date: Nov 2015
Location: Vaasa, Finland
Posts: 330
More about the Dual Playfield effects on CPU speed, the Amiga hardware manual says this:

" ...if there are more than four bit-planes, bit-plane DMA will begin to steal cycles from the 68000 during the display...bla bla bla...for a six-bit-plane display bit-plane DMA steals 50 percent of the open slots that the processor might have used if there were only four bitplanes displayed. "

So I think that means that the CPU has 50 % less memory access time during dual playfield (which has 6 bit planes). But the internal operations of the CPU will still run at full speed.

But by reducing the screen size we get large areas where there is no bit-plane DMA active at all, and this gets some of the lost speed back.

Also a smaller screen size means smaller bitmaps for background and double buffering, which saves RAM.

And also you have less tiles to blit when scrolling, and also bullets and other stuff exit the visible screen area faster, which means that you can generate new bullets and enemies slightly faster.

So making the display smaller gives many benefits at the same time.

---

Also about the Blitz capability to do shmups, here is a video of the Blitz game Insectoids 2:

[ Show youtube player ]

It uses a 2+3 dual playfield instead of of the normal 3+3 dual PF, and runs at full 50 FPS and draws lots of aliens at once. The game is written by Mark Sibly himself and the source code is available on the Ultimate Blitz CD, the folder was named "PD disk 2" or something.

And the way how the 2+3 is made is simple: there is normal dual PF Slice creation command, but it only defines 5 bitplanes instead of 6. And the back PF bitmap has depth of 2, and the front PF has depth of 3. And that's it.

I think that with this method you could make a 1+3 dual PF too, so only 2 colors for the starfield...but if the stars scroll, then with copper effects you can make that look good.

And 1+3 would be only 4 planes...I wonder if this way it would be as fast DMA wise as normal 16 color mode? Would be awesome to get the full CPU speed and still be able to draw everything with QBlits without the need of background repair, although 2 colors for background is good for space games only.

And also another trick of how Insectoids 2 gets so many aliens on screen, is that once the aliens reach formation, they are no longer normal enemies, but are blitted just once to the double buffer bitmaps, and then it scrolls the entire alien rows with the Scroll command.

This way it can get a maximum of 40 aliens to screen at 50 FPS. (the Youtube video runs at 30 FPS, but on real machine this is 50 FPS)

And the aliens are BOBs, and the game uses PColl, ShapeSpriteHit and ShapesHit for collisions. But the 4 IF method is faster than ShapesHit, so Insectoids 2 could be still be made faster.
Master484 is offline  
Old 13 June 2018, 15:20   #82
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 3,679
Quote:
Originally Posted by Master484 View Post
Here is one more idea:

Add four more variables for the bullets: bulletLeftSide, bulletRightSide, bulletUpSide, bulletDownSide.
I would rather treat shots as a single point (or a one-dimensional object if needed). It saves you three (two) collision checks and should still have the precision needed for a convincing game.
idrougge is offline  
Old 13 June 2018, 16:23   #83
Cobe
Registered User

 
Join Date: Jan 2014
Location: Belgrade / Serbia
Age: 35
Posts: 607
Nice info Master484! Thanks!
But how can we create 2+3 or 1+3 dualplayfield with displaylibrary?
Cobe is offline  
Old 13 June 2018, 16:50   #84
E-Penguin
Banana

 
Join Date: Jul 2016
Location: Darmstadt
Posts: 678
I don't think you can have 1+3. You can have 1+2 or 2+3.

http://amigadev.elowar.com/read/ADCD.../node0092.html
Quote:
Bits 14, 13, 12 - BPU2, BPU1, BPU0
Number of bitplanes used.

000 = only a background color
001 = 1 bitplane, PLANE 1
010 = 2 bitplanes, PLANES 1 and 2
011 = 3 bitplanes, PLANES 1 - 3
100 = 4 bitplanes, PLANES 1 - 4
101 = 5 bitplanes, PLANES 1 - 5
110 = 6 bitplanes, PLANES 1 - 6
111 not used
If you set it for four bitplanes, you'll have two odd and two even, so will end up with a 2+2.

You could do a 2+3 and use BitPlaneBitMap to get a virtual single-plane bitmap for fast blitting, but it wouldn't save on DMA time.
E-Penguin is offline  
Old 13 June 2018, 18:56   #85
Cobe
Registered User

 
Join Date: Jan 2014
Location: Belgrade / Serbia
Age: 35
Posts: 607
Looking at this how bitplanes are assigned http://amigadev.elowar.com/read/ADCD.../node0079.html I think you're right. But 2+3 would still be a gain. And 2 bitplanes for bkg with few copper changes of colors would be sufficient in many cases.

And to answer my own question, it seems to me that simply setting dualplayfield and 5 bitplanes in coplist does the job... I always thought dualplayfield is more "magical" so I never tried lowering the number of bitplanes
Cobe is offline  
Old 13 June 2018, 19:43   #86
Shatterhand
Warhasneverbeensomuchfun

Shatterhand's Avatar
 
Join Date: Jun 2001
Location: Rio de Janeiro / Brazil
Age: 35
Posts: 2,977
Quote:
Also about the Blitz capability to do shmups, here is a video of the Blitz game Insectoids 2:
Considering when the aliens are on top of the screen its just the bitmap scrolling, this is actually moving less stuff on screen than my own Quasarius. Quasarius could have up to 12 aliens + 3 enemy bullets + 3 missiles at bottom screen without slowdown (I think I could come with even a little more, but I didn't want to risk it )

THOUGH now I remember the Aliens actually move at 25 hz at the start, going to 50hz when you've destroyed 1/3 of them. But this wasn't for speed, I remember I was getting the same amount of stuff being drawn at 50 fps.

Insectoids 2 is, at most, moving 16 aliens on screen. To be quite honest, depending upon what kind of shmup you are doing, 16 isn't a lot.
Shatterhand is online now  
Old 13 June 2018, 20:11   #87
Retro1234
Bo Bo

Retro1234's Avatar
 
Join Date: Jun 2006
Location: 5150
Posts: 3,988
How did you do collision in Quasarius?

Can someone have a look at how the collision is done in Insectoids 2 - Nice game.

I'm not having a go but theres not a single High Quality Shoot em up, Scrolling platformer etc made with Blitz 2 yet it had this reputation as Super Powerful.
Retro1234 is offline  
Old 13 June 2018, 22:18   #88
Master484
Registered User
Master484's Avatar
 
Join Date: Nov 2015
Location: Vaasa, Finland
Posts: 330
Quote:
I don't think you can have 1+3. You can have 1+2 or 2+3.
I just tested this and indeed trying to create a 1+3 dual PF resulted in an error.

But 2+3 worked fine, and in comparison to 3+3 drawing speed increased by some 10 %.

---

Also I quickly tested the effects of screen size reductions, and on an A500 config and dual PF it seemed that reducing Height brought more speed than reducing Width.

Also reducing Width on a A500 system that had Fast RAM didn't seem to have that much effect. But on a config without Fast RAM it did have a small effect. And on my AGA shmup demo reducing width also has effect, even with Fast RAM turned on. So when reducing screen size test both Width and Height to see which brings the best results on the target machine.

Quote:
And to answer my own question, it seems to me that simply setting dualplayfield and 5 bitplanes in coplist does the job... I always thought dualplayfield is more "magical" so I never tried lowering the number of bitplanes
Yes that's the way, 6 bitplanes for a normal dual PF, and 5 bitplanes for the 2+3 dual PF concept.

And if you're making an AGA 16+16 color dual PF, then set 8 bitplanes.

And also for AGA dual PF to work properly, you should set Display Controls as follows:

DisplayControls CoplistNumber,0,$1c00,$23

$1c00 allows a full 16+16 dual playfield where the back PF colors actually start at the right place (pen number 16 instead of the default 8).

And $23 moves the sprite colors to 32-47. This allows a nice palette arrangement of 16+16+16 for AGA dual playfield games.

Although I'm not 100% sure that $23 is the right value, but for me it worked at least.

Quote:
Can someone have a look at how the collision is done in Insectoids 2 - Nice game.
It uses the standard Blitz collision commands: PColl, SpriteShapesHit and ShapesHit. The "4 IF statements method" discussed in this thread beats both ShapesHit and RectsHit in speed. But Insectoids 2 is fast enough so the basic commands were enough for it.

Quote:
I'm not having a go but theres not a single High Quality Shoot em up, Scrolling platformer etc made with Blitz 2 yet it had this reputation as Super Powerful.
True, there are Skidmarks and Worms, and some good PD games like Defender and Zombie Apocalypse, but not any shooters that would absolutely fill the screen with bullets and action.

But what about AMOS? Does anyone know which AMOS game has the most stuff moving on screen?
Master484 is offline  
Old 13 June 2018, 22:39   #89
Cobe
Registered User

 
Join Date: Jan 2014
Location: Belgrade / Serbia
Age: 35
Posts: 607
Thanks for the tests!

Quote:
Originally Posted by Master484 View Post
And if you're making an AGA 16+16 color dual PF, then set 8 bitplanes.

And also for AGA dual PF to work properly, you should set Display Controls as follows:

DisplayControls CoplistNumber,0,$1c00,$23

$1c00 allows a full 16+16 dual playfield where the back PF colors actually start at the right place (pen number 16 instead of the default 8).

And $23 moves the sprite colors to 32-47. This allows a nice palette arrangement of 16+16+16 for AGA dual playfield games.

Although I'm not 100% sure that $23 is the right value, but for me it worked at least.
Yeah, I banged my head one night a while ago with that http://eab.abime.net/showpost.php?p=...&postcount=129

and now when I look at code I had then it reads
Code:
DisplayControls 0,0,$1c00,$13  ;dpf2 colours 16-31,sprite colors 32-48
But I remember that I was poking around to find a number for sprite colors and I think that maybe it even worked with some other numbers or I changed something and then had to change those numbers too...
Cobe is offline  
Old 13 June 2018, 22:45   #90
Shatterhand
Warhasneverbeensomuchfun

Shatterhand's Avatar
 
Join Date: Jun 2001
Location: Rio de Janeiro / Brazil
Age: 35
Posts: 2,977
Quote:
How did you do collision in Quasarius?
I was still learning stuff on Quasarius (heh, I still am today ), so I did some really dumb stuff.

The game has 3 collisions to check.

First is enemy bullet/missiles vs player. The player is a sprite, I use the playfield collision test, I check if the sprite channel of the player colided with the yellow color. If it does, paleyr dies. (it doesn't matter which bullet hit it)

Second is player bullet against enemy. Player has just 1 bullet on screen (which is also a sprite).. I first test that sprite channel against playfield... if it has a hit, I check if the player bullet is at the UFO height at the top. If it is, UFO is destroyed, move on. If not, I check each enemy with the "4 ifs" technique up until I find it. It's one bullet against 12 enemies, so it's not that bad to do it.... still if I remember correctly, I test against half enemies on one frame and half enemies on another enemies because sometimes the game did a little hiccup when doing this test.

Then third is Player vs Green Tokens. They are all sprites, but the green tokens use shared channels ( 4 and 5, 6 and 7 you can't tell if a sprite collided with either channel 4 OR 5, it just consider it collided with both. This happens with each pair of sprite channels and seems to be a hardware feature, not a problem with blitz). I really don't remember, but I think I just do the 4 ifs with them too.

Quote:
I'm not having a go but theres not a single High Quality Shoot em up, Scrolling platformer etc made with Blitz 2 yet it had this reputation as Super Powerful.
Honestly, how many "High Quality Shoot em up" are made on Amiga? Most of them are kinda lousy with low framerates, etc. Then you have stuff made by *very* skilfull programmers like Andreas Tadic (I think Project-X is a very lousy shoot'em up, but its technically amazing), Ron Pieket or Martin Pedersen.

And then even Pedersen... Hybris could be redone on Blitz 2 and Battle Squadron... he had do some really magical stuff with the blitter coding in ASM from what I read on his interview about the game and STILL enemies move just at 25 fps. Swiv runs at 25 fps and still slowdowns from time to time (and, come on, Ron Pieket was an amazing coder).

Mega Typhoon looks like black magic on the hardware and yet the coder had to use a shitload of tricks on it and the game looks like puke and has no music.

ST Dragon slowdowns a lot, Dragon Breed runs at 25 fps, R-Type 2 slowdowns a lot, R-Type has lots of stuff missing from the arcade (including the backdrop for level 1, tsc) so it has to move less stuff on screen, Disposable Hero doesn't move a lot of stuff on screen (and when it has to move big stuff, it's only moving it and nothing else), Uridium 2 has very small bobs/sprites....

Honestly, the machine is not geared for arcade shoot'em ups. Blitz Basic or not, it doesn't look like people did it much better using ASM. I honestly think you can do a GOOD shoot'em up on Blitz 2, but you really need to plan it properly to work.

Quote:
Skidmarks and Worms,
There's one thing I believe they have in common with both games which always made me feel this is what Blitz would do better:

I really don't think they are updating the bitmap with tiles or anything like that. They just use a big bitmap and scroll them around. That's why Skidmarks tracks are kinda limited in size (but works well for the game)... and worms screens aren't all that big either, considering the games doesn't have a lot more of graphics to store (and probably doesn't even need a Double Buffer),there's enough memory to handle it.

Last edited by Shatterhand; 13 June 2018 at 22:50.
Shatterhand is online now  
Old 15 June 2018, 11:02   #91
Retro1234
Bo Bo

Retro1234's Avatar
 
Join Date: Jun 2006
Location: 5150
Posts: 3,988
Earok uses Blitz 2 so maybe he can say what the best way for this collision is.
Retro1234 is offline  
Old 15 June 2018, 16:08   #92
Master484
Registered User
Master484's Avatar
 
Join Date: Nov 2015
Location: Vaasa, Finland
Posts: 330


I made a small collision test program. ADF with source is in the attachment of this post.

The instructions are printed to the screen, just press the numbers to create objects and change stuff.

There is no other code than Blitting, collisions, and moving objects that bounce around the screen, and change directions when they hit the walls.

Test results on standard 512K A500 with cycle exact ON:

DRAWING SPEED at 50 FPS:
16*16 enemies: 28
8*8 bullets: 41

DRAWING SPEED at 25 FPS:
16*16 enemies: 58
8*8 bullets: 84

COLLISION SPEED at 50 FPS:
1 enemy and 36 bullets
10 enemies and 13 bullets
16 enemies and 5 bullets

COLLISION SPEED at 25 FPS:
1 enemy and 76 bullets
10 enemies and 30 bullets
16 enemies and 24 bullets

Note: The drawing speeds mean either enemies or bullets, not both at same time.

Bullets are divided into two groups and the groups are checked at alternate frames, and the 4 IF method is used. Only collision type checked is bullets vs aliens. Dual playfield is of the 2+3 type, and screen is a 288*200 Slice + 288*32 status panel under it. The aliens are drawn in 8 colors, and the bullets in 4 colors.

The "HIT" sign is a Block, and it is drawn every frame, either as visible or as a solid block of black. This maybe costs about 1 or 2 bullets.

---

So, if we analyse the 50 FPS cases, then we can see that:

Drawing a bullet is 30 % faster than drawing an alien. And 28 aliens can be drawn with no collisions.

But when collisions are happening, it can draw the following combinations:

1 alien and 36 bullets. 36 bullets equal some 25 aliens. And 25 + 1 = 26.
10 enemies and 13 bullets. 13 bullets equal some 9 aliens. And 10+9 = 19.
16 enemies and 5 bullets. 5 bullets equal some 3 aliens. And 16+3 = 19.

And 19 / 28 = 68. So the collisions eat some 32 % of the drawing capacity.

So in a 50 FPS game where there is 16 aliens the player could fire maybe 3 bullets, if collisions are checked this way.

But in 25 FPS we get 16 enemies and 24 bullets, which is a lot better. And player could be a sprite, allowing 50 FPS player movement if sprite commands are put to the VBlank Interrupt.

---

But so yeah, this is slow, and some faster solution would be nice...I have a few ideas but I need to experiment on them first before posting them...thinking about lookup tables for the grid idea and stuff like that. If it works, I'll then post an updated version of this demo.

---

Also one thing that I noticed is that "Repeat...Untils" are a lot faster than "For...Nexts", even when variable counters were used for loop control.

And also I realized that the "variable change" method actually needs 4 effected variables before it brings more speed, because when you put the variables back, that adds an extra variable change event, and this is why you need 4 list variables before you gain more speed.

And also in all likelyhood you already know this, but adding a DEFTYPE .w to the beginning of the code makes all new variables "words" instead of "Quicks", which is the default (and slow) Blitz variable type.
Attached Thumbnails
Click image for larger version

Name:	CollisionTest_001.png
Views:	120
Size:	10.8 KB
ID:	58584  
Attached Files
File Type: zip CollisionTest.zip (32.2 KB, 20 views)
Master484 is offline  
Old 15 June 2018, 17:40   #93
Retro1234
Bo Bo

Retro1234's Avatar
 
Join Date: Jun 2006
Location: 5150
Posts: 3,988
Might seem silly but does it make a difference doing it like this with Gosubs

Main loop
For I to Blah
Stuff
Gosub DrawBobs
Gosub Collision
Next I

Collision:
For C=
If do bounding checks etc
Next C
Return

Etc
Retro1234 is offline  
Old 15 June 2018, 17:52   #94
Shatterhand
Warhasneverbeensomuchfun

Shatterhand's Avatar
 
Join Date: Jun 2001
Location: Rio de Janeiro / Brazil
Age: 35
Posts: 2,977
Hey Master484, very nice prototype!

Yeah, I know about the Deftype thing.. but I never use a Variable before declaring it . Old habits don't die easily
Shatterhand is online now  
Old 16 June 2018, 09:06   #95
E-Penguin
Banana

 
Join Date: Jul 2016
Location: Darmstadt
Posts: 678
Master484 thank you for sharing the code! I see a few potential optimisations; I'll have a go and repost it here if they make any difference.
E-Penguin is offline  
Old 16 June 2018, 13:35   #96
Master484
Registered User
Master484's Avatar
 
Join Date: Nov 2015
Location: Vaasa, Finland
Posts: 330
Quote:
Might seem silly but does it make a difference doing it like this with Gosubs

Main loop
For I to Blah
Stuff
Gosub DrawBobs
Gosub Collision
Next I

Collision:
For C=
If do bounding checks etc
Next C
Return
Not much, except that Gosubs add some extra slowdown, especially when they are inside the loop that goes through all objects. Each Gosub adds two operations: "jump to address" + "Return". And if you have 100 objects in the "For...Next" loop that means 100 jumps and 100 Returns.

Therefore one good way to optimize code is "loop unrolling"; replace all gosubs with directly copy pasted sub routines. And then make the executable and release the program...but always keep a source code version which still has the Gosubs, because unrolling the Gosubs can make the code a totally unreadable long list of spaghetti.

Quote:
Master484 thank you for sharing the code! I see a few potential optimisations; I'll have a go and repost it here if they make any difference.
There are indeed a few things that could still be optimized; such as the loop end conditions checks, where a simple "Until NextItem = 0" would have been enough. I tested it and making this change boosted speed some 10 scanlines; which is good, but not enough.

I'll post an updated demo version soon, if my new ideas bring more speed.

---
---


Also yesterday I thought on how Mega Typhoon can calculate all those collisions for some 100+ objects on screen at 50 FPS.

And then I realised that the game mostly only needs sprite vs BOB collisions. The Player is a sprite, and enemy bullets are bobs. And player bullets are sprites, and enemies are bobs. Only the player power-up rockets are bobs, so only they need bob vs bob collisions. And also the power-up icons are bobs I think.

So most likely it uses the same method that Blitz Sprite vs Playfield and Sprite vs Color collision commands use. There are a lot of collisions to check, but actual bounding box checks are only done when a "Sprite vs Color" or "Sprite vs Playfield" event has been triggered. And the sprite collision commands are fast even in Blitz.

This has to be only logical explanation on why Mega Typhoon is so fast in comparison to every other Amiga shmup. Although one other game also exists, the PD shooter Blaster, which runs on 2+2 dual PF, and can draw about as much as Mega Typhoon...and also in this game all collisions are Sprites vs Bobs only.
Master484 is offline  
Old 16 June 2018, 14:05   #97
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 3,505
Quote:
Originally Posted by Master484 View Post
Therefore one good way to optimize code is "loop unrolling"; replace all gosubs with directly copy pasted sub routines. And then make the executable and release the program...but always keep a source code version which still has the Gosubs, because unrolling the Gosubs can make the code a totally unreadable long list of spaghetti.
This sounds like a good use case for macros - effectively automated loop unrolling, where you can leave your code referencing the macro, and the compiler will insert the subroutine at compile time for you.
Daedalus is online now  
Old 16 June 2018, 14:49   #98
E-Penguin
Banana

 
Join Date: Jul 2016
Location: Darmstadt
Posts: 678
I need to check the syntax but you should be able to replace the direction change "multiplication by - 1" with a negation and an addition (dir = (~dir) + 1). Assuming two's complement.
E-Penguin is offline  
Old 16 June 2018, 15:10   #99
Retro1234
Bo Bo

Retro1234's Avatar
 
Join Date: Jun 2006
Location: 5150
Posts: 3,988
I only ask because some times I know it seems strange but seems to be quicker sometimes than spaghetti, especially when you have loops in loops.

Last edited by Retro1234; 16 June 2018 at 15:15.
Retro1234 is offline  
Old 16 June 2018, 16:17   #100
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 3,679
Quote:
Originally Posted by Master484 View Post
The "4 IF statements method" discussed in this thread beats both ShapesHit and RectsHit in speed.
That's just absurd. Are there any edge cases RectsHit must handle? Otherwise I can't understand how Acid Software could come up with a library routine that is slower than basic.
idrougge is offline  
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
SetCol/DoColl-How to test collisions with different sprites against different colors? Shatterhand Coders. Blitz Basic 1 12 January 2017 19:51
Quickest code.... Galahad/FLT Coders. Asm / Hardware 10 01 January 2017 18:23
[REQ:ASM] Sprite collisions basics jman Coders. Tutorials 5 03 September 2011 01:07
What is the quickest way Doc Mindie support.WinUAE 6 17 October 2007 22:15
Disable Sprite Collisions DeAdLy_cOoKiE Retrogaming General Discussion 4 24 March 2006 18:56

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 Jump


All times are GMT +2. The time now is 18:24.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.
Page generated in 0.13699 seconds with 16 queries