Sorted Picking

For questions about using Classic.

Post » Tue Apr 14, 2009 1:03 pm

hi,
what is the most efficient way to pick sprites in a sorted manner?

i've got another fake z-depth scenario that does not handle well with a lot of objects, probably due to bad loop management. here is the cap, in a nutshell: i want to create the illusion of skyscrapers by stacking rectangles (floors) onto each other. currently there are sprites for the bottom & a number of sprites for the floors (the bottoms are invisible). the sorting works like this:
1) pick each bottom, one after another, sorted by their y-position
2) pick all floors belonging to that bottom (by comparing a private variable)
3) pick each of these floors, one after another, sorted by their intended height (another private variable)
4) put that floor into position & send him to front
like this, it works mostly correct (few glitches): the top floors are covering the lower floors, and the closer skyscrapers cover the ones further away. but adding more skyscrapers drastically impacts the framerate (my laptop drops <60 with 100 bottoms and ~800 floors). i suspect that the three nested loops are responsible, blowing through ( bottoms * floors(all) * floors(selection)) = 640k iterations each frame.

sooo... any ideas on a more efficient approach? anything i can think of using other objects (arrays?) hits the bottleneck of picking the corresponding sprite after the sorting. any help would be welcome!

(otherwise i'd have to scale down from downtown to suburbia ;))
B
2
S
2
G
4
Posts: 171
Reputation: 1,792

Post » Tue Apr 14, 2009 1:09 pm

For each object (ordered) under System sounds like what you want.
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Tue Apr 14, 2009 1:47 pm

people looking at the cap is what i want :P
but yes, that's what i am currently using. i was just wondering wether there was a more performant way of doing it, because 3 nested loops each looking at every object are a bit slow.

i just tested to see wether picking objects by use of the ObjectPairer was faster than by comparing private variables, and it appears to be. so that's a start ...
B
2
S
2
G
4
Posts: 171
Reputation: 1,792

Post » Tue Apr 14, 2009 3:48 pm

I didn't have Construct handy earlier; so I couldn't check your current system.

I can't really see a better way to do it, but it runs well on my crappy laptop. What sort of numbers were you trying?
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Tue Apr 14, 2009 4:05 pm

i am running into problems (aka below 60fps) when there are ~60 skyscrapers with 8 floors each, like here. thanks for having a look, rich!
B
2
S
2
G
4
Posts: 171
Reputation: 1,792


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests