collisions of two objects from same list

BlitzMax Forums/BlitzMax Programming/collisions of two objects from same list

AvestheFox(Posted 2013) [#1]
I need to have two images from the same object list collide and exchange certain variables. The problem I'm having is that in the code I really don't know how to determine the two different objects when they collide since they both share the same list and also the same image handle.

How would I go about doing this?


Dabhand(Posted 2013) [#2]
Nest a For... Each loop... e.g.

For local loop:object = Eachin somelist
For local anotherLoop:object = Eachin somelist
if imagescollide(img, loopObject.x,loopObject.y,0,img,anotherLoop.x,anotherLoop.y,0)
'Do something
endif
Next
Next

Dabz

Last edited 2013


AvestheFox(Posted 2013) [#3]
I've actually tried that, but it reeeeeally slowed the program down :P

I'll see what I can do with it though

I may post the code up later today if I cant find a way around the horrible slowdown


Nest(Posted 2013) [#4]
Perhaps before doing the image colliding see if bounding boxes collide?


AvestheFox(Posted 2013) [#5]
I'm actually using a custom imagesoverlap() function for my collision check (similar to the Blitz3D function by the same name) the function returns whether the images are overlapping based on their positions and dimensions.

right now I'm trying to figure out why nesting the 'For... Each loop...' of the same object type slows the program to a nasty crawl. something's obviously wrong with my code :P


Nest(Posted 2013) [#6]
I think it might be much faster to check bounding boxes first, and if they are overlapping, then use imagesoverlap().


Cruis.In(Posted 2013) [#7]
it doesn't matter that they share the same image handle or list, because anything from anywhere can be added to the list and they are all separate and distinct. Only the particular instance of your type can see its own image. So they might use the same image variable to look alike, but they are still separate objects.

i think if you are using the code exact as above that would be the problem.

You need to refer to each image itself

either use self.image or the variablename.image

not simply image.


Ifq200(Posted 2013) [#8]
How many objects Are you cheking in that list?


Dabhand(Posted 2013) [#9]

right now I'm trying to figure out why nesting the 'For... Each loop...' of the same object type slows the program to a nasty crawl. something's obviously wrong with my code :P



I've never experience a slow down, ever, but, I do do bounding box detection first before pixel based, which I should of stated, sorry! :)


not simply image.



Well, depends on how he's implemented it doesnt it, I mean, has he made loads of handles of the image (as in loading the image in over and over), which, depending on how many images he has, that could hog a bit of memory, is he using an atlas or referencing instances of an image for each object, is he using a global handle of an image.. Without actually looking at some code, it's a bit hard to know what's what and picking out the bottle neck.

Dabz


Ifq200(Posted 2013) [#10]
I was just thinking, it could be many loops, if every instance of that type should do collision check against eachother, that would be counts * counts


Dabhand(Posted 2013) [#11]

counts * counts



Well of course, so, in essence, what he should do is pre-build the list of enemies, but use an array of objects instead (which are faster), also manipulate them in a alive/dead fashion. As it seems there seems a massive amount of optimizations needed, just a guess, but like I said before, without looking to see whats what, we can spend all night discussing the best form of action! :D

Dabz

Last edited 2013


Ifq200(Posted 2013) [#12]
I agree


AvestheFox(Posted 2013) [#13]
alright, I suppose I should be specific about what I am trying to do here.

I'm using a tile grid system to setup Wolfenstien 3D'ish maps (including the addition of textured floors and ceilings)

I'm having to setup an area system that hides and unhides the 3D wall/floor/ceiling entities to prevent rendering slow-downs

In the map editor this area system is done by using a numbered tile palette that is used to assign the floor tiles to a numbered area. I need to assign the walls to two different area numbers each, one area for each side of the wall tile (so they'd be rendered while one of those areas are active). I plan to make this system work by reading both the tiles on both sides of the wall tile and assigning the variables accordingly. And to do this, I need some invisible detectors on either side of the wall image that overlaps the floor image and reads the floor area variables and return them to the wall object.

I hope all that makes some sort of sense :P it may not be the most conventional way of going about this, but I'm just figuring all this out from scratch, so forgive me if it seems a bit amateurish.


Alberto-Diablo(Posted 2013) [#14]

For local loop:object = Eachin somelist
For local anotherLoop:object = Eachin somelist
if imagescollide(img, loopObject.x,loopObject.y,0,img,anotherLoop.x,anotherLoop.y,0)
'Do something
endif
Next
Next





If (loop = anotherLoop) That will be faced with yourself?

on business

1) Check the picture on the impact of reading.

[bbcode]
Local CollidedObjects:Object[] = CollideImage(image, x, y, frame, True, False, data)
[/bbcode]

2) If the image itself needs to collisions with other pictures that it is brought into the buffer data in write mode

[bbcode]
CollideImage(image, x, y, frame, False, True, data)
[/bbcode]

OR

If both options are needed at once, you can do this by including both modes

[bbcode]
Local CollidedObjects:Object[] = CollideImage(image, x, y, frame, True, True, data)
[/bbcode]

PS

Standard collision though accurate, but very slow. Better to Use physics engine

Last edited 2013


AvestheFox(Posted 2013) [#15]
there's functions in that code that I didnt even know about :P

I'll tinker with it and see what I can do, hopefully I can get something to work :)

thanks!


Cruis.In(Posted 2013) [#16]
collideimage adds an image to the writemask, then you can check any infinite amount of images against that particular mask for collision.


AvestheFox(Posted 2013) [#17]
alright, so I've toyed with the collideimage() function, and well, unfortunately whatever way I try to use it, it slows the program down...

the grid I'm using contains 4096 objects per layer (64 x 64 tile maps for this game) I figured I'm having problems with this due to there being way too many objects or something...

I'm really stuck, it seems :(

Last edited 2013


Jesse(Posted 2013) [#18]
look at the collideImage source. it's quite intense. And the larger the image is the slower it gets. so unless you are doing some sort of rectangle collision prior to the actual collided image it's going to absorb a lot of the frame rate to check for collision. I would avoid it if I didn't really have to. Or find an alternative. if my game had to deal with a lot of objects. I usually do multiple rectangle/oval collision per image rather than do collideImage.

Last edited 2013


AvestheFox(Posted 2013) [#19]
Alright, posting the code :P



wallTypeHorz : wall type for walls that are facing north and/or south
wallTypeVert : wall type for walls that are facing east and/or west

t.center : center image that overlaps the central wall tile (probably not neccesarry)
t.detect1 : first detector image that overlaps the first Floor tile And retreaves its area # returning it to the wall's area1 variable
t.detect2 : second detector image that overlaps the second Floor tile And retreaves its area # returning it to the wall's area2 variable
t.area1 and t.area2 : area numbers for each floor tile. t.area2 only applies to special tiles (walls)

I just cant gt this to work... :P

and yeah, I reverted it back to a more simpler code.. it was a mess when I was applying the collideimage() functions

Last edited 2013

Last edited 2013

Last edited 2013

Last edited 2013


Jesse(Posted 2013) [#20]
imagesCollide and collideImag use the same principle. they are both practically as slow.

what are you colliding and what do the images look like? and why do you need perfect pixel collision?

most games don't need it or use it. Really!


AvestheFox(Posted 2013) [#21]
well I was using an old custom collision function:



but that wasn't doing the trick, really :P

Last edited 2013