sandbox games - how???

Blitz3D Forums/Blitz3D Beginners Area/sandbox games - how???

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

it seems that the amount of types in the scene is what's bogging it down.

I'm not sure what the code you posted is supposed to prove. Of course the more type instances you have [to iterate through] the longer it's going to take, but a writepixelfast() operation for each instance is only going to slow things even further. It's an expensive operation:

Graphics 800,600,0,2
SetBuffer BackBuffer()

Type dot
	Field xPos%
	Field yPos%
	Field col%
End Type
Global currentDot.dot=Null


For i%=1 To 1000000
	currentDot=New dot
	currentDot\xPos=Rand(0,GraphicsWidth()-1)
	currentDot\yPos=Rand(0,GraphicsHeight()-1)
	currentDot\col=0 Shl 24 Or Rand(100,255) Shl 16 Or Rand(100,255) Shl 8 Or Rand(100,255) Shl 0
Next

Text 10,10,"Short initialisation delay..."
Flip
Cls
Delay 5000

Text 10,10,"Test 1..."
Flip
Cls
startTime%=MilliSecs()
For currentDot=Each dot

Next
result1%=MilliSecs()-startTime


Text 10,10,"Test 2..."
Flip

startTime=MilliSecs()
LockBuffer BackBuffer()
	For currentDot=Each dot
		WritePixelFast currentDot\xPos,currentDot\yPos,currentDot\col
	Next
UnlockBuffer BackBuffer()
result2%=MilliSecs()-startTime

Cls
Text 10,10,"Iterating through list:                               "+result1+" millisecs."
Text 10,20,"Iterating through list with writepixelfast operation: "+result2+" millisecs."
Flip
WaitKey


Notice there that I'm passing WritePixelFast a set of integers rather than floats (which is what rnd produces) also -- it's a good habit to minimise type conversion for speed critical operations.