SLOW imagescollide after writing to imagebuffer

Blitz3D Forums/Blitz3D Beginners Area/SLOW imagescollide after writing to imagebuffer

Paradox7(Posted 2004) [#1]
take below code and run it, I need to draw to a image and then check it for collisions, drawing to it is no problem, if you COMMENT OUT ""totalt = ImagesCollide (mouseIMG, mxnew,mynew,0,playfieldIMG,0,0,0)"" in the program, (use mouse to draw) you will see that drawing is fine, and happens fast, draw to imagebuffer, and display it. Simple, now turn on imagescollide and it slows and interrupts big time. Its not that imagescollide is slow at all, because when you arn't drawing and just moving the mouse around, it collides fast, and detects, ect. it only crawls when you try to Draw to ImageBuffer, and then after check it with imagescollide. like its not releasing it fast enough for imagescollide to do its work or something, Why, even using lockbuffers, doesn't help.

Any way to get this to work right, maybe poke/peek to a bank? i dunno, just need to draw and check for collisions at the same time. (well checking while drawing)

Const xres = 800
Const yres = 600
Graphics xres,yres,16, 1
Global mouseIMG, playfieldIMG, mxold,myold,mxnew,mynew

mouseIMG = CreateImage(16,16)
playfieldIMG = CreateImage(xres,yres)
SetBuffer ImageBuffer(mouseIMG)
Rect 0,0,16,16,1

SetBuffer BackBuffer()

Repeat
mxold = mxnew
myold = mynew
mxnew = MouseX()
mynew = MouseY()

	If MouseDown(1) Then
		LockBuffer ImageBuffer(playfieldIMG)
		WritePixelFast mxnew-16,mynew-16, $05FF05, ImageBuffer(playfieldIMG)
		UnlockBuffer  ImageBuffer(playfieldIMG)

		;SetBuffer ImageBuffer(playfieldIMG)
		;Line mxold-16, myold-16, mxnew-16,mynew-16
		;SetBuffer BackBuffer()
	End If
	
	totalt = ImagesCollide (mouseIMG, mxnew,mynew,0,playfieldIMG,0,0,0)
	
		DrawBlock playfieldIMG,0,0
		DrawImage mouseIMG, MouseX(),MouseY()

		Text 10,10,totalt
	Flip True
	Cls
	
Until KeyHit(1)



MSW(Posted 2004) [#2]
I can see one major problem that would cause it to crash...


WritePixelFast mxnew-16,mynew-16, $05FF05, ImageBuffer(playfieldIMG)
		


That is NOT good if say mxnew = 3 and mynew = 14 as it tries to WritePixelFast offscreen

Another problem is that it does an ImagesCollide every update...even when you arn't drawing...is that your intention...or do you want it to check for collisions when the user draws?


semar(Posted 2004) [#3]
I wonder why you need to draw on the image playfieldIMG.

You are modifing the image always in the same way, that is, colouring with $05FF05, or drawing a line on it.

Wouldn't be better to prepare an animated image for the mouse cursor instead, and use the appropriate frame when needed ? In this way, you have the writepixel stuff out from the main loop, and your prog will be much more smooth.

Finally, you should avoid Flip True, and just use Flip instead; perhaps you can use a timer too, which will ensure your main loop running always at a constant speed; check for CreateTimer and WaitTimer commands.

Hope this helps,
Sergio.


Paradox7(Posted 2004) [#4]
Yes it is intended to check for collisions every update, this is just a test program to test with real quick, my inital test program had timers and logic fps and all that good stuff ;) i just ripped it all out to make this test for you all real quick, plus about it writing out side of screen with +14 ect ect, doesn't matter as its just a test.

Ok, what the true aim is, is have multipule user control lines running around on the screen that leave its trail behind, if you crash into a line then you die. Its like the game snake, except your line doesn't grow, its a line always left behind, i've looked at "snake" game examples, but they all use the TYPE method, of say holding each block of the snake in a type and moving around like that, but here i'm talking about pixels, and a huge screen, plus Many players on the screen at once, that would be alot of stuff to run through, and just seems to be a waste, when it would be so so simple to. Draw on background Image that guys are running all over, and if they collide with crap left on Background Image, then kill player. So Simple, but seems to be a bug in using imagescollide after doing a write to the imagesbuffer.

As you can see when doing imagescollide ever update is not a problem, it is very fast (draw something then move mouse around points you drawed, and see it collides and all that very fast, no stops) so that is not a problem at all, take out the imagescollide and then go and draw, drawing to image if Very Fast also. So why can't you draw to the image and then check for imagescollide


Paradox7(Posted 2004) [#5]
well well well, i'm not the only one, i found this at blitzcoder, this guy had the same problem, i think its a bug of blitzbasic, time to move this to the bugs forum.

http://www.blitzcoder.com/cgi-bin/ubb-cgi/postdisplay.cgi?forum=Forum6&topic=000838