collision detection speed

Blitz3D Forums/Blitz3D Programming/collision detection speed

I just discovered:
ClearCollisions clears the list of everything that recently collided, which is the same as doing ResetEntity on all the collided entities. It doesn't clear the list of objects that are checked for collisions. it doesn't do what I want here.

I just ran a speed test, and EntityType model,0 (where 0 is not involved in any collisions) does NOT increase the speed of checking.

In fact it seems that the entity is involved in collision checking because it's the same speed!


In fact, UpdateWorld runs the same whether or not I have ANY Collisions statements. The only thing that speeds it up is HideEntity.

UpdateWorld does more than collision detection, maybe collision detection is actually quite fast, and it's the other things that UpdateWorld does that slow things down?

I don't know - i think I see exponential slowdown the more bullets i have on screen, which would seem to me that there's something going on like bullets x enemies collision checking. just drawing a new bullet should be a linear progression. collision detecting will grow faster.

so, if not collision detection i can't figure out why i'm losing so much speed

here's testing code, kinda interesting.

; speed test comparing setting EntityType ent,0 to remove from collisions
; vs HideEntity.  HideEntity of course removes the entity from sight so 
; it doesn't do the same thing.

; verdict - EntityType ent,0 doesn't do anything!
; UpdateWorld still takes the same amount of time. 
; Hell it takes the same amount of time if you don't have any Collisions statement.

 
Graphics3D 640,400,0,0 
toSphere=1:toPoly=2:toBox=3
makeStop=1:fullSlide=2:preventDownSlide=3

Global T_BULLET=1, T_ENEMY=2
Type bullet
	Field model
End Type
 
Global howmany=200
For t = 1 To howmany
	b.bullet=New bullet	
	b\model=CreateSphere(8) 
	EntityType b\model,T_BULLET
	;HideEntity b\model
	ScaleEntity b\model,1,1,1
	PositionEntity b\model,Rnd(100),Rnd(100),Rnd(100)
	EntityRadius b\model,1

	e=CreateCube() 
	EntityType e,T_ENEMY
	ScaleEntity e,1,1,1
	PositionEntity e,Rnd(100),Rnd(100),Rnd(100)
	EntityBox e,1,1,1,1,1,1 
	
Next

Collisions T_BULLET,T_ENEMY,toPoly,fullSlide 
runtest("toPoly, fullslide")
Collisions T_BULLET,T_ENEMY,toBox,fullSlide 
runtest("toBox, fullslide")
Collisions T_BULLET,T_ENEMY,toBox,makeStop 
runtest("toBox, makeStop")
Collisions T_BULLET,T_ENEMY,toSphere,fullSlide 
runtest("toSphere, fullslide")

Function runtest(description$)
	For b.bullet = Each bullet	
		; eventually we either change the entitytype of each entity or we hide them all.
		; the speed increase comes from hiding them.
		; no speed increase by changing the entitytype.
		
		EntityType b\model,0	; -> no speed increase 
		;HideEntity b\model 	; -> speed increase (uncomment this, and comment the line above to compare)

		did=did+1
		s=MilliSecs()
		For x = 1 To 300
			UpdateWorld ; docs claim this is where collision detection happens.
		Next
		e=MilliSecs()-s
		remain=howmany-did
		DebugLog remain+" "+description$+": "+e
	Next
End Function
	
WaitKey